Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3.4.2 #876

Merged
merged 7 commits into from
Nov 16, 2018
Merged

3.4.2 #876

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions Library/Phalcon/Cache/Backend/NullCache.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php

namespace Phalcon\Cache\Backend;

use Phalcon\Cache\BackendInterface;
use Phalcon\Cache\Frontend\None as NoneFrontend;

/**
* A cache adapter that does nothing.
*/
final class NullCache implements BackendInterface
{
public function start($keyName, $lifetime = null)
{
return true;
}

public function stop($stopBuffer = true)
{
}

public function getFrontend()
{
return new NoneFrontend();
}

public function getOptions()
{
return [];
}

public function isFresh()
{
return true;
}

public function isStarted()
{
return true;
}

public function setLastKey($lastKey)
{
}

public function getLastKey()
{
return '';
}

public function get($keyName, $lifetime = null)
{
return null;
}

public function save($keyName = null, $content = null, $lifetime = null, $stopBuffer = true)
{
return true;
}

public function delete($keyName)
{
return true;
}

public function queryKeys($prefix = null)
{
return [];
}

public function exists($keyName = null, $lifetime = null)
{
return false;
}
}
5 changes: 5 additions & 0 deletions Library/Phalcon/Cache/Backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,10 @@ echo $time;

This adapter uses [windows cache extension](http://pecl.php.net/package/wincache) for PHP


## NullCache

NullCache adapter can be useful when you have dependency injection and wants to provider an Adapter that does nothing.

[1]: http://www.aerospike.com/
[2]: http://www.aerospike.com/docs/client/php/install/
76 changes: 46 additions & 30 deletions Library/Phalcon/Db/Adapter/MongoDB/Operation/Update.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
*/
class Update implements Executable
{
private static $wireVersionForDocumentLevelValidation=4;
private static $wireVersionForDocumentLevelValidation = 4;

private $databaseName;
private $collectionName;
Expand All @@ -61,63 +61,71 @@ class Update implements Executable
*
* * writeConcern (MongoDB\Driver\WriteConcern): Write concern.
*
* @param string $databaseName Database name
* @param string $collectionName Collection name
* @param string $databaseName Database name
* @param string $collectionName Collection name
* @param array|object $filter Query by which to delete documents
* @param array|object $update Update to apply to the matched
* document(s) or a replacement document
* @param array $options Command options
* @param array $options Command options
*
* @throws InvalidArgumentException
*/
public function __construct($databaseName, $collectionName, $filter, $update, array $options = [])
{
if (!is_array($filter)&&!is_object($filter)) {
if (! is_array($filter) && ! is_object($filter)) {
throw InvalidArgumentException::invalidType('$filter', $filter, 'array or object');
}

if (!is_array($update)&&!is_object($update)) {
if (! is_array($update) && ! is_object($update)) {
throw InvalidArgumentException::invalidType('$update', $filter, 'array or object');
}

$options+=[
'multi' =>false,
'upsert'=>false,
$options += [
'multi' => false,
'upsert' => false,
];

if (isset($options['bypassDocumentValidation'])&&!is_bool($options['bypassDocumentValidation'])) {
if (isset($options['bypassDocumentValidation']) && ! is_bool($options['bypassDocumentValidation'])) {
throw InvalidArgumentException::invalidType(
'"bypassDocumentValidation" option',
$options['bypassDocumentValidation'],
'boolean'
);
}

if (!is_bool($options['multi'])) {
throw InvalidArgumentException::invalidType('"multi" option', $options['multi'], 'boolean');
if (! is_bool($options['multi'])) {
throw InvalidArgumentException::invalidType(
'"multi" option',
$options['multi'],
'boolean'
);
}

if ($options['multi']&&!Functions::isFirstKeyOperator($update)) {
if ($options['multi'] && ! Functions::isFirstKeyOperator($update)) {
throw new InvalidArgumentException('"multi" option cannot be true if $update is a replacement document');
}

if (!is_bool($options['upsert'])) {
throw InvalidArgumentException::invalidType('"upsert" option', $options['upsert'], 'boolean');
if (! is_bool($options['upsert'])) {
throw InvalidArgumentException::invalidType(
'"upsert" option',
$options['upsert'],
'boolean'
);
}

if (isset($options['writeConcern'])&&!$options['writeConcern'] instanceof WriteConcern) {
if (isset($options['writeConcern']) && ! $options['writeConcern'] instanceof WriteConcern) {
throw InvalidArgumentException::invalidType(
'"writeConcern" option',
$options['writeConcern'],
'MongoDB\Driver\WriteConcern'
);
}

$this->databaseName =(string)$databaseName;
$this->collectionName=(string)$collectionName;
$this->filter =$filter;
$this->update =$update;
$this->options =$options;
$this->databaseName = (string)$databaseName;
$this->collectionName = (string)$collectionName;
$this->filter = $filter;
$this->update = $update;
$this->options = $options;
}

/**
Expand All @@ -131,26 +139,34 @@ public function __construct($databaseName, $collectionName, $filter, $update, ar
*/
public function execute(Server $server)
{
$updateOptions=[
'multi' =>$this->options['multi'],
'upsert'=>$this->options['upsert'],
$updateOptions = [
'multi' => $this->options['multi'],
'upsert' => $this->options['upsert']
];

$bulkOptions=[];
if (isset($this->options['arrayFilters'])) {
$updateOptions['arrayFilters'] = $this->options['arrayFilters'];
}

$bulkOptions = [];

if (isset($this->options['bypassDocumentValidation'])&&Functions::serverSupportsFeature(
if (isset($this->options['bypassDocumentValidation']) && Functions::serverSupportsFeature(
$server,
self::$wireVersionForDocumentLevelValidation
)
) {
$bulkOptions['bypassDocumentValidation']=$this->options['bypassDocumentValidation'];
$bulkOptions['bypassDocumentValidation'] = $this->options['bypassDocumentValidation'];
}

$bulk=new Bulk($bulkOptions);
$bulk = new Bulk($bulkOptions);
$bulk->update($this->filter, $this->update, $updateOptions);

$writeConcern=isset($this->options['writeConcern'])?$this->options['writeConcern']:null;
$writeResult =$server->executeBulkWrite($this->databaseName.'.'.$this->collectionName, $bulk, $writeConcern);
$writeConcern = isset($this->options['writeConcern']) ? $this->options['writeConcern'] : null;
$writeResult = $server->executeBulkWrite(
$this->databaseName . '.' . $this->collectionName,
$bulk,
$writeConcern
);

return new UpdateResult($writeResult);
}
Expand Down
16 changes: 16 additions & 0 deletions Library/Phalcon/Db/Dialect/MysqlExtended.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,22 @@ public function getSqlExpression(array $expression, $escapeChar = null, $bindCou
return $this->getSqlExpression($expression['arguments'][0]) .
' REGEXP (' . $this->getSqlExpression($expression['arguments'][1]) . ')';
break;

case 'JSON_EXTRACT':
if (count($expression["arguments"]) < 2) {
throw new Exception('JSON_EXTRACT requires 2 parameters');
}

$arguments = [];
$length = count($expression["arguments"]);
for ($i = 0; $i < $length; $i++) {
$arguments[] = $i === 0 ?
$this->getSqlExpression($expression["arguments"][$i]) :
$expression["arguments"][$i]['value'];
}

return 'JSON_EXTRACT(' . join(', ', $arguments) . ')';
break;
}
}

Expand Down
42 changes: 26 additions & 16 deletions Library/Phalcon/Session/Adapter/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ public function __construct($options = null)
*/
public function open()
{
return true;
$this->_started = true;
return $this->isStarted();
}

/**
Expand All @@ -97,7 +98,8 @@ public function open()
*/
public function close()
{
return false;
$this->_started = false;
return $this->isStarted();
}

/**
Expand All @@ -109,7 +111,11 @@ public function close()
public function read($sessionId)
{
$maxLifetime = (int) ini_get('session.gc_maxlifetime');


if (!$this->isStarted()) {
return false;
}

$options = $this->getOptions();
$row = $this->connection->fetchOne(
sprintf(
Expand Down Expand Up @@ -152,7 +158,7 @@ public function write($sessionId, $data)
Db::FETCH_NUM,
[$sessionId]
);

if ($row[0] > 0) {
return $this->connection->execute(
sprintf(
Expand All @@ -164,19 +170,23 @@ public function write($sessionId, $data)
),
[$data, time(), $sessionId]
);
} else {
return $this->connection->execute(
sprintf(
'INSERT INTO %s (%s, %s, %s, %s) VALUES (?, ?, ?, NULL)',
$this->connection->escapeIdentifier($options['table']),
$this->connection->escapeIdentifier($options['column_session_id']),
$this->connection->escapeIdentifier($options['column_data']),
$this->connection->escapeIdentifier($options['column_created_at']),
$this->connection->escapeIdentifier($options['column_modified_at'])
),
[$sessionId, $data, time()]
);
}

if (!$this->isStarted()) {
return false;
}

return $this->connection->execute(
sprintf(
'INSERT INTO %s (%s, %s, %s, %s) VALUES (?, ?, ?, NULL)',
$this->connection->escapeIdentifier($options['table']),
$this->connection->escapeIdentifier($options['column_session_id']),
$this->connection->escapeIdentifier($options['column_data']),
$this->connection->escapeIdentifier($options['column_created_at']),
$this->connection->escapeIdentifier($options['column_modified_at'])
),
[$sessionId, $data, time()]
);
}

/**
Expand Down
Loading