diff --git a/.travis.yml b/.travis.yml index abb824697..7116ace32 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,8 +5,9 @@ php: - 5.5 - 5.6 -sudo: - false +sudo: required +dist: precise +group: edge services: - memcached @@ -15,8 +16,20 @@ services: env: global: - - TEST_BT_HOST=127.0.0.1 TEST_BT_PORT=11300 TEST_MC_HOST=127.0.0.1 TEST_MC_PORT=11211 + - TEST_BT_HOST="127.0.0.1" + - TEST_BT_PORT="11300" + - TEST_MC_HOST="127.0.0.1" + - TEST_MC_PORT="11211" + - TEST_AS_HOST="127.0.0.1" + - TEST_AS_PORT="3000" + - TEST_DB_HOST="127.0.0.1" + - TEST_DB_PORT="3306" + - TEST_DB_USER="root" + - TEST_DB_PASSWD="" + - TEST_DB_NAME="incubator_tests" + - TEST_DB_CHARSET="utf8" matrix: + - PHALCON_VERSION="2.0.10" - PHALCON_VERSION="2.0.9" - PHALCON_VERSION="2.0.8" - PHALCON_VERSION="2.0.7" @@ -25,37 +38,57 @@ env: - PHALCON_VERSION="2.0.4" before_install: + - phpenv config-rm xdebug.ini - bash tests/_ci/setup_beanstalkd.sh - beanstalkd -v - beanstalkd -l ${TEST_BT_HOST} -p ${TEST_BT_PORT} & # start queue listener - - sleep 5 # give server some time to boot + - sleep 5 - cd $TRAVIS_BUILD_DIR - pecl channel-update pecl.php.net - (CFLAGS="-O1 -g3 -fno-strict-aliasing"; pecl install yaml < /dev/null &) + - phpenv config-add tests/_ci/yaml.ini - pecl install mongo < /dev/null & + - phpenv config-add tests/_ci/mongo.ini - phpenv config-add tests/_ci/memcached.ini - - php -m + - wget -O aerospike.tgz 'http://aerospike.com/download/server/latest/artifact/ubuntu12' + - tar -xvf aerospike.tgz + - cd aerospike-server-community-*-ubuntu12* + - sudo ./asinstall + - sudo service aerospike start + - sudo service aerospike status + - sleep 5 + - cd $TRAVIS_BUILD_DIR install: - composer self-update - git clone -q --depth=1 https://github.com/phalcon/cphalcon.git -b phalcon-v${PHALCON_VERSION} - - (cd cphalcon/ext; export CFLAGS="-g3 -O1 -fno-delete-null-pointer-checks -Wall"; phpize &> /dev/null && ./configure --silent --enable-phalcon &> /dev/null && make --silent -j4 > /dev/null && make --silent install && phpenv config-add ../unit-tests/ci/phalcon.ini &> /dev/null) - - php -r 'echo \Phalcon\Version::get()."\n";' + - (cd cphalcon/ext; export CFLAGS="-g0 -O0 -std=gnu90"; phpize &> /dev/null && ./configure --silent --enable-phalcon &> /dev/null && make --silent -j2 &> /dev/null && make --silent install && phpenv config-add ../unit-tests/ci/phalcon.ini &> /dev/null) + - php --ri phalcon + - travis_retry composer require aerospike/aerospike-client-php "*" + - find vendor/aerospike/aerospike-client-php/ -name "*.sh" -exec chmod +x {} \; + - cd vendor/aerospike/aerospike-client-php + - sudo $(which composer) run-script -q post-install-cmd + - cd $TRAVIS_BUILD_DIR + - echo "extension=${TRAVIS_BUILD_DIR}/vendor/aerospike/aerospike-client-php/src/aerospike/modules/aerospike.so" | tee -a tests/_ci/aerospike.ini + - phpenv config-add tests/_ci/aerospike.ini + - php -m - travis_retry composer install --prefer-source --no-interaction - - travis_retry composer require "duncan3dc/fork-helper":"*" before_script: + - stty cols 160 - mysql -e 'create database incubator_tests charset=utf8mb4 collate=utf8mb4_unicode_ci;' script: - vendor/bin/phpcs --standard=PSR2 --colors --extensions=php --encoding=utf-8 Library/ - vendor/bin/codecept build - - vendor/bin/codecept run --coverage-text + - vendor/bin/codecept run addons: apt: packages: - libyaml-dev + - libssl-dev + - autoconf notifications: email: diff --git a/Library/Phalcon/Acl/Adapter/Database.php b/Library/Phalcon/Acl/Adapter/Database.php index fe532f488..51a896202 100644 --- a/Library/Phalcon/Acl/Adapter/Database.php +++ b/Library/Phalcon/Acl/Adapter/Database.php @@ -3,7 +3,7 @@ +------------------------------------------------------------------------+ | Phalcon Framework | +------------------------------------------------------------------------+ - | Copyright (c) 2011-2015 Phalcon Team (http://www.phalconphp.com) | + | Copyright (c) 2011-2016 Phalcon Team (http://www.phalconphp.com) | +------------------------------------------------------------------------+ | This source file is subject to the New BSD License that is bundled | | with this package in the file docs/LICENSE.txt. | @@ -22,17 +22,17 @@ use Phalcon\Db; use Phalcon\Db\AdapterInterface as DbAdapter; use Phalcon\Acl\Adapter; -use Phalcon\Acl\AdapterInterface; use Phalcon\Acl\Exception; use Phalcon\Acl\Resource; use Phalcon\Acl; use Phalcon\Acl\Role; +use Phalcon\Acl\RoleInterface; /** * Phalcon\Acl\Adapter\Database - * Manages ACL lists in memory + * Manages ACL lists in database tables */ -class Database extends Adapter implements AdapterInterface +class Database extends Adapter { /** * @var DbAdapter @@ -96,6 +96,7 @@ public function __construct(array $options) /** * {@inheritdoc} + * * Example: * $acl->addRole(new Phalcon\Acl\Role('administrator'), 'consultor'); * $acl->addRole('administrator', 'consultor'); @@ -103,11 +104,16 @@ public function __construct(array $options) * @param \Phalcon\Acl\Role|string $role * @param string $accessInherits * @return boolean + * @throws \Phalcon\Acl\Exception */ public function addRole($role, $accessInherits = null) { - if (!is_object($role)) { - $role = new Role($role); + if (is_string($role)) { + $role = new Role($role, ucwords($role) . ' Role'); + } + + if (!$role instanceof RoleInterface) { + throw new Exception('Role must be either an string or implement RoleInterface'); } $exists = $this->connection->fetchOne( @@ -138,8 +144,8 @@ public function addRole($role, $accessInherits = null) /** * {@inheritdoc} * - * @param string $roleName - * @param string $roleToInherit + * @param string $roleName + * @param string $roleToInherit * @throws \Phalcon\Acl\Exception */ public function addInherit($roleName, $roleToInherit) @@ -243,8 +249,8 @@ public function addResource($resource, $accessList = null) /** * {@inheritdoc} * - * @param string $resourceName - * @param array|string $accessList + * @param string $resourceName + * @param array|string $accessList * @return boolean * @throws \Phalcon\Acl\Exception */ @@ -293,7 +299,7 @@ public function getResources() /** * {@inheritdoc} * - * @return \Phalcon\Acl\Role[] + * @return RoleInterface[] */ public function getRoles() { @@ -315,6 +321,7 @@ public function getRoles() */ public function dropResourceAccess($resourceName, $accessList) { + throw new \BadMethodCallException('Not implemented yet.'); } /** @@ -385,7 +392,7 @@ public function deny($roleName, $resourceName, $access) public function isAllowed($role, $resource, $access) { $sql = implode(' ', [ - "SELECT 'allowed' FROM {$this->accessList} AS a", + "SELECT " . $this->connection->escapeIdentifier('allowed') . " FROM {$this->accessList} AS a", // role_name in: 'WHERE roles_name IN (', // given 'role'-parameter @@ -421,10 +428,10 @@ public function isAllowed($role, $resource, $access) /** * Inserts/Updates a permission in the access list * - * @param string $roleName - * @param string $resourceName - * @param string $accessName - * @param integer $action + * @param string $roleName + * @param string $resourceName + * @param string $accessName + * @param integer $action * @return boolean * @throws \Phalcon\Acl\Exception */ @@ -475,10 +482,10 @@ protected function insertOrUpdateAccess($roleName, $resourceName, $accessName, $ /** * Inserts/Updates a permission in the access list * - * @param string $roleName - * @param string $resourceName - * @param array|string $access - * @param integer $action + * @param string $roleName + * @param string $resourceName + * @param array|string $access + * @param integer $action * @throws \Phalcon\Acl\Exception */ protected function allowOrDeny($roleName, $resourceName, $access, $action) diff --git a/Library/Phalcon/Acl/Adapter/Mongo.php b/Library/Phalcon/Acl/Adapter/Mongo.php index 0847463fd..d95785b28 100644 --- a/Library/Phalcon/Acl/Adapter/Mongo.php +++ b/Library/Phalcon/Acl/Adapter/Mongo.php @@ -3,7 +3,7 @@ +------------------------------------------------------------------------+ | Phalcon Framework | +------------------------------------------------------------------------+ - | Copyright (c) 2011-2015 Phalcon Team (http://www.phalconphp.com) | + | Copyright (c) 2011-2016 Phalcon Team (http://www.phalconphp.com) | +------------------------------------------------------------------------+ | This source file is subject to the New BSD License that is bundled | | with this package in the file docs/LICENSE.txt. | @@ -20,17 +20,17 @@ namespace Phalcon\Acl\Adapter; use Phalcon\Acl\Adapter; -use Phalcon\Acl\AdapterInterface; use Phalcon\Acl\Exception; use Phalcon\Acl\Resource; use Phalcon\Acl; use Phalcon\Acl\Role; +use Phalcon\Acl\RoleInterface; /** * Phalcon\Acl\Adapter\Mongo * Manages ACL lists using Mongo Collections */ -class Mongo extends Adapter implements AdapterInterface +class Mongo extends Adapter { /** * @var array @@ -40,7 +40,7 @@ class Mongo extends Adapter implements AdapterInterface /** * Class constructor. * - * @param array $options + * @param array $options * @throws \Phalcon\Acl\Exception */ public function __construct($options) @@ -74,6 +74,7 @@ public function __construct($options) /** * {@inheritdoc} + * * Example: * $acl->addRole(new Phalcon\Acl\Role('administrator'), 'consultor'); * $acl->addRole('administrator', 'consultor'); @@ -81,28 +82,33 @@ public function __construct($options) * @param string $role * @param array $accessInherits * @return boolean + * @throws \Phalcon\Acl\Exception */ public function addRole($role, $accessInherits = null) { - if (!is_object($role)) { - $role = new Role($role); + if (is_string($role)) { + $role = new Role($role, ucwords($role) . ' Role'); + } + + if (!$role instanceof RoleInterface) { + throw new Exception('Role must be either an string or implement RoleInterface'); } $roles = $this->getCollection('roles'); - $exists = $roles->count(array('name' => $role->getName())); + $exists = $roles->count(['name' => $role->getName()]); if (!$exists) { - $roles->insert(array( + $roles->insert([ 'name' => $role->getName(), 'description' => $role->getDescription() - )); + ]); - $this->getCollection('accessList')->insert(array( + $this->getCollection('accessList')->insert([ 'roles_name' => $role->getName(), 'resources_name' => '*', 'access_name' => '*', 'allowed' => $this->_defaultAccess - )); + ]); } if ($accessInherits) { @@ -115,13 +121,13 @@ public function addRole($role, $accessInherits = null) /** * {@inheritdoc} * - * @param string $roleName - * @param string $roleToInherit - * @throws \Phalcon\Acl\Exception + * @param string $roleName + * @param string $roleToInherit + * @throws \BadMethodCallException */ public function addInherit($roleName, $roleToInherit) { - // TODO: implement later + throw new \BadMethodCallException('Not implemented yet.'); } /** @@ -132,7 +138,7 @@ public function addInherit($roleName, $roleToInherit) */ public function isRole($roleName) { - return $this->getCollection('roles')->count(array('name' => $roleName)) > 0; + return $this->getCollection('roles')->count(['name' => $roleName]) > 0; } /** @@ -143,11 +149,12 @@ public function isRole($roleName) */ public function isResource($resourceName) { - return $this->getCollection('resources')->count(array('name' => $resourceName)) > 0; + return $this->getCollection('resources')->count(['name' => $resourceName]) > 0; } /** * {@inheritdoc} + * * Example: * * //Add a resource to the the list allowing access to an action @@ -170,12 +177,12 @@ public function addResource($resource, $accessList = null) $resources = $this->getCollection('resources'); - $exists = $resources->count(array('name' => $resource->getName())); + $exists = $resources->count(['name' => $resource->getName()]); if (!$exists) { - $resources->insert(array( + $resources->insert([ 'name' => $resource->getName(), 'description' => $resource->getDescription() - )); + ]); } if ($accessList) { @@ -188,8 +195,8 @@ public function addResource($resource, $accessList = null) /** * {@inheritdoc} * - * @param string $resourceName - * @param array|string $accessList + * @param string $resourceName + * @param array|string $accessList * @return boolean * @throws \Phalcon\Acl\Exception */ @@ -202,19 +209,19 @@ public function addResourceAccess($resourceName, $accessList) $resourcesAccesses = $this->getCollection('resourcesAccesses'); if (!is_array($accessList)) { - $accessList = array($accessList); + $accessList = [$accessList]; } foreach ($accessList as $accessName) { - $exists = $resourcesAccesses->count(array( + $exists = $resourcesAccesses->count([ 'resources_name' => $resourceName, 'access_name' => $accessName - )); + ]); if (!$exists) { - $resourcesAccesses->insert(array( + $resourcesAccesses->insert([ 'resources_name' => $resourceName, 'access_name' => $accessName - )); + ]); } } @@ -228,7 +235,7 @@ public function addResourceAccess($resourceName, $accessList) */ public function getResources() { - $resources = array(); + $resources = []; foreach ($this->getCollection('resources')->find() as $row) { $resources[] = new Resource($row['name'], $row['description']); @@ -240,11 +247,11 @@ public function getResources() /** * {@inheritdoc} * - * @return \Phalcon\Acl\Role[] + * @return RoleInterface[] */ public function getRoles() { - $roles = array(); + $roles = []; foreach ($this->getCollection('roles')->find() as $row) { $roles[] = new Role($row['name'], $row['description']); @@ -261,10 +268,12 @@ public function getRoles() */ public function dropResourceAccess($resourceName, $accessList) { + throw new \BadMethodCallException('Not implemented yet.'); } /** * {@inheritdoc} + * * You can use '*' as wildcard * Example: * @@ -289,6 +298,7 @@ public function allow($roleName, $resourceName, $access) /** * {@inheritdoc} + * * You can use '*' as wildcard * Example: * @@ -314,6 +324,7 @@ public function deny($roleName, $resourceName, $access) /** * {@inheritdoc} + * * Example: * * //Does Andres have access to the customers resource to create? @@ -330,11 +341,11 @@ public function deny($roleName, $resourceName, $access) public function isAllowed($role, $resource, $access) { $accessList = $this->getCollection('accessList'); - $access = $accessList->findOne(array( + $access = $accessList->findOne([ 'roles_name' => $role, 'resources_name' => $resource, 'access_name' => $access - )); + ]); if (is_array($access)) { return (bool) $access['allowed']; @@ -343,11 +354,12 @@ public function isAllowed($role, $resource, $access) /** * Check if there is an common rule for that resource */ - $access = $accessList->findOne(array( + $access = $accessList->findOne([ 'roles_name' => $role, 'resources_name' => $resource, 'access_name' => '*' - )); + ]); + if (is_array($access)) { return (bool) $access['allowed']; } @@ -369,10 +381,10 @@ protected function getCollection($name) /** * Inserts/Updates a permission in the access list * - * @param string $roleName - * @param string $resourceName - * @param string $accessName - * @param integer $action + * @param string $roleName + * @param string $resourceName + * @param string $accessName + * @param integer $action * @return boolean * @throws \Phalcon\Acl\Exception */ @@ -381,10 +393,11 @@ protected function insertOrUpdateAccess($roleName, $resourceName, $accessName, $ /** * Check if the access is valid in the resource */ - $exists = $this->getCollection('resourcesAccesses')->count(array( + $exists = $this->getCollection('resourcesAccesses')->count([ 'resources_name' => $resourceName, 'access_name' => $accessName - )); + ]); + if (!$exists) { throw new Exception( "Access '" . $accessName . "' does not exist in resource '" . $resourceName . "' in ACL" @@ -393,18 +406,19 @@ protected function insertOrUpdateAccess($roleName, $resourceName, $accessName, $ $accessList = $this->getCollection('accessList'); - $access = $accessList->findOne(array( + $access = $accessList->findOne([ 'roles_name' => $roleName, 'resources_name' => $resourceName, 'access_name' => $accessName - )); + ]); + if (!$access) { - $accessList->insert(array( + $accessList->insert([ 'roles_name' => $roleName, 'resources_name' => $resourceName, 'access_name' => $accessName, 'allowed' => $action - )); + ]); } else { $access['allowed'] = $action; $accessList->save($access); @@ -413,18 +427,19 @@ protected function insertOrUpdateAccess($roleName, $resourceName, $accessName, $ /** * Update the access '*' in access_list */ - $exists = $accessList->count(array( + $exists = $accessList->count([ 'roles_name' => $roleName, 'resources_name' => $resourceName, 'access_name' => '*' - )); + ]); + if (!$exists) { - $accessList->insert(array( + $accessList->insert([ 'roles_name' => $roleName, 'resources_name' => $resourceName, 'access_name' => '*', 'allowed' => $this->_defaultAccess - )); + ]); } return true; @@ -433,10 +448,10 @@ protected function insertOrUpdateAccess($roleName, $resourceName, $accessName, $ /** * Inserts/Updates a permission in the access list * - * @param string $roleName - * @param string $resourceName - * @param string $access - * @param integer $action + * @param string $roleName + * @param string $resourceName + * @param string $access + * @param integer $action * @throws \Phalcon\Acl\Exception */ protected function allowOrDeny($roleName, $resourceName, $access, $action) @@ -446,7 +461,7 @@ protected function allowOrDeny($roleName, $resourceName, $access, $action) } if (!is_array($access)) { - $access = array($access); + $access = [$access]; } foreach ($access as $accessName) { diff --git a/Library/Phalcon/Acl/Adapter/Redis.php b/Library/Phalcon/Acl/Adapter/Redis.php index 24f4a0fba..e528df1e3 100644 --- a/Library/Phalcon/Acl/Adapter/Redis.php +++ b/Library/Phalcon/Acl/Adapter/Redis.php @@ -3,7 +3,7 @@ +------------------------------------------------------------------------+ | Phalcon Framework | +------------------------------------------------------------------------+ - | Copyright (c) 2011-2015 Phalcon Team (http://www.phalconphp.com) | + | Copyright (c) 2011-2016 Phalcon Team (http://www.phalconphp.com) | +------------------------------------------------------------------------+ | This source file is subject to the New BSD License that is bundled | | with this package in the file docs/LICENSE.txt. | @@ -21,17 +21,17 @@ use Phalcon\Db; use Phalcon\Acl\Adapter; -use Phalcon\Acl\AdapterInterface; use Phalcon\Acl\Exception; use Phalcon\Acl\Resource; use Phalcon\Acl; use Phalcon\Acl\Role; +use Phalcon\Acl\RoleInterface; /** * Phalcon\Acl\Adapter\Database * Manages ACL lists in memory */ -class Redis extends Adapter implements AdapterInterface +class Redis extends Adapter { /** @var bool */ protected $setNXAccess = true; @@ -57,6 +57,7 @@ public function getRedis() /** * {@inheritdoc} + * * Example: * $acl->addRole(new Phalcon\Acl\Role('administrator'), 'consultor'); * $acl->addRole('administrator', 'consultor'); @@ -64,14 +65,19 @@ public function getRedis() * @param \Phalcon\Acl\Role|string $role * @param string $accessInherits * @return boolean + * @throws \Phalcon\Acl\Exception */ public function addRole($role, $accessInherits = null) { - if (!is_object($role)) { - $role = new Role($role, ucwords($role) . " Role"); + if (is_string($role)) { + $role = new Role($role, ucwords($role) . ' Role'); } - $this->redis->hMset("roles", array($role->getName() => $role->getDescription())); + if (!$role instanceof RoleInterface) { + throw new Exception('Role must be either an string or implement RoleInterface'); + } + + $this->redis->hMset('roles', [$role->getName() => $role->getDescription()]); $this->redis->sAdd("accessList:$role:*:{$this->getDefaultAction()}}", "*"); if ($accessInherits) { @@ -90,9 +96,12 @@ public function addRole($role, $accessInherits = null) */ public function addInherit($roleName, $roleToInherit) { - $exists = $this->redis->hGet("roles", $roleName); + $exists = $this->redis->hGet('roles', $roleName); + if (!$exists) { - throw new Exception("Role '" . $roleName . "' does not exist in the role list"); + throw new Exception( + sprintf("Role '%s' does not exist in the role list", $roleName) + ); } $this->redis->sAdd("rolesInherits:$roleName", $roleToInherit); @@ -196,7 +205,7 @@ public function getResources() /** * {@inheritdoc} * - * @return \Phalcon\Acl\Role[] + * @return RoleInterface[] */ public function getRoles() { diff --git a/Library/Phalcon/Acl/Factory/Memory.php b/Library/Phalcon/Acl/Factory/Memory.php index cd56e32e4..3c0cf4d63 100644 --- a/Library/Phalcon/Acl/Factory/Memory.php +++ b/Library/Phalcon/Acl/Factory/Memory.php @@ -3,7 +3,7 @@ +------------------------------------------------------------------------+ | Phalcon Framework | +------------------------------------------------------------------------+ - | Copyright (c) 2011-2015 Phalcon Team (http://www.phalconphp.com) | + | Copyright (c) 2011-2016 Phalcon Team (http://www.phalconphp.com) | +------------------------------------------------------------------------+ | This source file is subject to the New BSD License that is bundled | | with this package in the file docs/LICENSE.txt. | diff --git a/Library/Phalcon/Annotations/Adapter/Base.php b/Library/Phalcon/Annotations/Adapter/Base.php index dc8ec3bcf..394ffb28f 100644 --- a/Library/Phalcon/Annotations/Adapter/Base.php +++ b/Library/Phalcon/Annotations/Adapter/Base.php @@ -3,7 +3,7 @@ +------------------------------------------------------------------------+ | Phalcon Framework | +------------------------------------------------------------------------+ - | Copyright (c) 2011-2015 Phalcon Team (http://www.phalconphp.com) | + | Copyright (c) 2011-2016 Phalcon Team (http://www.phalconphp.com) | +------------------------------------------------------------------------+ | This source file is subject to the New BSD License that is bundled | | with this package in the file docs/LICENSE.txt. | diff --git a/Library/Phalcon/Annotations/Adapter/Memcached.php b/Library/Phalcon/Annotations/Adapter/Memcached.php index 5255704bc..cb2adef60 100644 --- a/Library/Phalcon/Annotations/Adapter/Memcached.php +++ b/Library/Phalcon/Annotations/Adapter/Memcached.php @@ -3,7 +3,7 @@ +------------------------------------------------------------------------+ | Phalcon Framework | +------------------------------------------------------------------------+ - | Copyright (c) 2011-2015 Phalcon Team (http://www.phalconphp.com) | + | Copyright (c) 2011-2016 Phalcon Team (http://www.phalconphp.com) | +------------------------------------------------------------------------+ | This source file is subject to the New BSD License that is bundled | | with this package in the file docs/LICENSE.txt. | diff --git a/Library/Phalcon/Avatar/Avatarable.php b/Library/Phalcon/Avatar/Avatarable.php index 987e9780c..6f99f0350 100644 --- a/Library/Phalcon/Avatar/Avatarable.php +++ b/Library/Phalcon/Avatar/Avatarable.php @@ -4,7 +4,7 @@ +------------------------------------------------------------------------+ | Phalcon Framework | +------------------------------------------------------------------------+ - | Copyright (c) 2011-2015 Phalcon Team (http://www.phalconphp.com) | + | Copyright (c) 2011-2016 Phalcon Team (http://www.phalconphp.com) | +------------------------------------------------------------------------+ | This source file is subject to the New BSD License that is bundled | | with this package in the file docs/LICENSE.txt. | diff --git a/Library/Phalcon/Avatar/Gravatar.php b/Library/Phalcon/Avatar/Gravatar.php index 243373225..325fecc24 100644 --- a/Library/Phalcon/Avatar/Gravatar.php +++ b/Library/Phalcon/Avatar/Gravatar.php @@ -4,7 +4,7 @@ +------------------------------------------------------------------------+ | Phalcon Framework | +------------------------------------------------------------------------+ - | Copyright (c) 2011-2015 Phalcon Team (http://www.phalconphp.com) | + | Copyright (c) 2011-2016 Phalcon Team (http://www.phalconphp.com) | +------------------------------------------------------------------------+ | This source file is subject to the New BSD License that is bundled | | with this package in the file docs/LICENSE.txt. | diff --git a/Library/Phalcon/Avatar/README.md b/Library/Phalcon/Avatar/README.md index 510450eef..46713b305 100644 --- a/Library/Phalcon/Avatar/README.md +++ b/Library/Phalcon/Avatar/README.md @@ -16,7 +16,7 @@ use Phalcon\Avatar\Gravatar; $di->setShared('gravatar', function () { // Get Gravatar instance - $gravatar = new Gravatar; + $gravatar = new Gravatar([]); // Setting default image, maximum size and maximum allowed Gravatar rating $gravatar->setDefaultImage('retro') diff --git a/Library/Phalcon/Cache/Backend/Aerospike.php b/Library/Phalcon/Cache/Backend/Aerospike.php new file mode 100644 index 000000000..d0a92c494 --- /dev/null +++ b/Library/Phalcon/Cache/Backend/Aerospike.php @@ -0,0 +1,374 @@ + | + +------------------------------------------------------------------------+ + */ + +namespace Phalcon\Cache\Backend; + +use Aerospike as AerospikeDb; +use Phalcon\Cache\FrontendInterface; +use Phalcon\Cache\Exception; +use Phalcon\Cache\Backend; +use Phalcon\Cache\BackendInterface; + +/** + * Phalcon\Cache\Backend\Aerospike + * + * Allows to cache output fragments, PHP data or raw data to a Aerospike backend. + * + * + * use Phalcon\Cache\Frontend\Data; + * use Phalcon\Cache\Backend\Aerospike as CacheBackend; + * + * // Cache data for 2 days + * $frontCache = new Data(['lifetime' => 172800]); + * + * // Create the Cache setting redis connection options + * $cache = new CacheBackend($frontCache, [ + * 'hosts' => [ + * ['addr' => '127.0.0.1', 'port' => 3000] + * ], + * 'persistent' => true, + * 'namespace' => 'test', + * 'prefix' => 'cache_', + * 'options' => [ + * \Aerospike::OPT_CONNECT_TIMEOUT => 1250, + * \Aerospike::OPT_WRITE_TIMEOUT => 1500 + * ] + * ]); + * + * // Cache arbitrary data + * $cache->save('my-data', [1, 2, 3, 4, 5]); + * + * // Get data + * $data = $cache->get('my-data'); + * + * + * @package Phalcon\Cache\Backend + * @property \Phalcon\Cache\FrontendInterface _frontend + */ +class Aerospike extends Backend implements BackendInterface +{ + use Prefixable; + + /** + * The Aerospike DB + * @var AerospikeDb + */ + protected $db; + + /** + * Default Aerospike namespace + * @var string + */ + protected $namespace = 'test'; + + /** + * The Aerospike Set for store sessions + * @var string + */ + protected $set = 'cache'; + + /** + * Phalcon\Cache\Backend\Aerospike constructor + * + * @param FrontendInterface $frontend Frontend Interface + * @param array $options Constructor options + * @throws Exception + */ + public function __construct(FrontendInterface $frontend, array $options) + { + if (!isset($options['hosts']) || !is_array($options['hosts'])) { + throw new Exception('No hosts given in options'); + } + + if (isset($options['namespace'])) { + $this->namespace = $options['namespace']; + } + + if (isset($options['prefix'])) { + $this->_prefix = $options['prefix']; + } + + $persistent = false; + if (isset($options['persistent'])) { + $persistent = (bool) $options['persistent']; + } + + $opts = []; + if (isset($options['options']) && is_array($options['options'])) { + $opts = $options['options']; + } + + $this->db = new AerospikeDb(['hosts' => $options['hosts']], $persistent, $opts); + + if (!$this->db->isConnected()) { + throw new Exception( + sprintf("Aerospike failed to connect [%s]: %s", $this->db->errorno(), $this->db->error()) + ); + } + + parent::__construct($frontend, $options); + } + + /** + * Gets the Aerospike instance. + * + * @return AerospikeDb + */ + public function getDb() + { + return $this->db; + } + + /** + * {@inheritdoc} + * + * @param int|string $keyName + * @param string $content + * @param int $lifetime + * @param bool $stopBuffer + * + * @throws Exception + */ + public function save($keyName = null, $content = null, $lifetime = null, $stopBuffer = true) + { + if ($keyName === null) { + $prefixedKey = $this->_lastKey; + } else { + $prefixedKey = $this->getPrefixedIdentifier($keyName); + } + + if (!$prefixedKey) { + throw new Exception('The cache must be started first'); + } + + if (null === $content) { + $cachedContent = $this->_frontend->getContent(); + } else { + $cachedContent = $content; + } + + if (null === $lifetime) { + $lifetime = $this->_lastLifetime; + + if (null === $lifetime) { + $lifetime = $this->_frontend->getLifetime(); + } + } + + $aKey = $this->buildKey($prefixedKey); + + if (is_numeric($cachedContent)) { + $bins = ['value' => $cachedContent]; + } else { + $bins = ['value' => $this->_frontend->beforeStore($cachedContent)]; + } + + $status = $this->db->put( + $aKey, + $bins, + $lifetime, + [AerospikeDb::OPT_POLICY_KEY => AerospikeDb::POLICY_KEY_SEND] + ); + + if (AerospikeDb::OK != $status) { + throw new Exception( + sprintf('Failed storing data in Aerospike: %s', $this->db->error()), + $this->db->errorno() + ); + } + + if (true === $stopBuffer) { + $this->_frontend->stop(); + } + + if (true === $this->_frontend->isBuffering()) { + echo $cachedContent; + } + + $this->_started = false; + } + + /** + * {@inheritdoc} + * + * @param string $prefix + * @return array + */ + public function queryKeys($prefix = null) + { + if (!$prefix) { + $prefix = $this->_prefix; + } else { + $prefix = $this->getPrefixedIdentifier($prefix); + } + + $keys = []; + $globalPrefix = $this->_prefix; + + $this->db->scan($this->namespace, $this->set, function ($record) use (&$keys, $prefix, $globalPrefix) { + $key = $record['key']['key']; + + if (empty($prefix) || 0 === strpos($key, $prefix)) { + $keys[] = preg_replace(sprintf('#^%s(.+)#u', preg_quote($globalPrefix)), '$1', $key); + } + }); + + return $keys; + } + + /** + * {@inheritdoc} + * + * @param int|string $keyName + * @param int $lifetime + * @return mixed + */ + public function get($keyName, $lifetime = null) + { + $prefixedKey = $this->getPrefixedIdentifier($keyName); + $aKey = $this->buildKey($prefixedKey); + $this->_lastKey = $prefixedKey; + + $status = $this->db->get($aKey, $cache); + + if ($status != AerospikeDb::OK) { + return null; + } + + $cachedContent = $cache['bins']['value']; + + if (is_numeric($cachedContent)) { + return $cachedContent; + } + + return $this->_frontend->afterRetrieve($cachedContent); + } + + /** + * {@inheritdoc} + * + * @param int|string $keyName + * @return boolean + */ + public function delete($keyName) + { + $prefixedKey = $this->getPrefixedIdentifier($keyName); + $aKey = $this->buildKey($prefixedKey); + $this->_lastKey = $prefixedKey; + + $status = $this->db->remove($aKey); + + return $status == AerospikeDb::OK; + } + + /** + * {@inheritdoc} + * + * @param string $keyName + * @param int $lifetime + * @return boolean + */ + public function exists($keyName = null, $lifetime = null) + { + if ($keyName === null) { + $prefixedKey = $this->_lastKey; + } else { + $prefixedKey = $this->getPrefixedIdentifier($keyName); + } + + if (!$prefixedKey) { + return false; + } + + $aKey = $this->buildKey($prefixedKey); + $status = $this->db->get($aKey, $cache); + + return $status == AerospikeDb::OK; + } + + /** + * Increment of given $keyName by $value + * + * @param string $keyName + * @param int $value + * @return int|false + */ + public function increment($keyName = null, $value = null) + { + if ($keyName === null) { + $prefixedKey = $this->_lastKey; + } else { + $prefixedKey = $this->getPrefixedIdentifier($keyName); + } + + if (!$prefixedKey) { + return false; + } + + $this->_lastKey = $prefixedKey; + + if (!$value) { + $value = 1; + } + + $aKey = $this->buildKey($prefixedKey); + $this->db->increment($aKey, 'value', $value); + + $status = $this->db->get($aKey, $cache); + + if ($status != AerospikeDb::OK) { + return false; + } + + return $cache['bins']['value']; + } + + /** + * Decrement of $keyName by given $value + * + * @param string $keyName + * @param int $value + * @return int|false + */ + public function decrement($keyName = null, $value = null) + { + if (!$value) { + $value = -1; + } elseif ($value > 0) { + $value = -1 * abs($value); + } + + return $this->increment($keyName, $value); + } + + /** + * Generates a unique key used for storing cache data in Aerospike DB. + * + * @param string $key Cache key + * @return array + */ + protected function buildKey($key) + { + return $this->db->initKey( + $this->namespace, + $this->set, + $key + ); + } +} diff --git a/Library/Phalcon/Cache/Backend/Database.php b/Library/Phalcon/Cache/Backend/Database.php index 364ee7859..bf4b77d34 100644 --- a/Library/Phalcon/Cache/Backend/Database.php +++ b/Library/Phalcon/Cache/Backend/Database.php @@ -3,7 +3,7 @@ +------------------------------------------------------------------------+ | Phalcon Framework | +------------------------------------------------------------------------+ - | Copyright (c) 2011-2015 Phalcon Team (http://www.phalconphp.com) | + | Copyright (c) 2011-2016 Phalcon Team (http://www.phalconphp.com) | +------------------------------------------------------------------------+ | This source file is subject to the New BSD License that is bundled | | with this package in the file docs/LICENSE.txt. | @@ -24,15 +24,23 @@ use Phalcon\Cache\FrontendInterface; use Phalcon\Db; use Phalcon\Db\AdapterInterface as DbAdapterInterface; +use Phalcon\Cache\Backend; +use Phalcon\Cache\BackendInterface; /** * Phalcon\Cache\Backend\Database + * * This backend uses a database as cache backend + * + * @package Phalcon\Cache\Backend + * @property \Phalcon\Cache\FrontendInterface _frontend */ -class Database extends Prefixable +class Database extends Backend implements BackendInterface { + use Prefixable; + /** - * @var \Phalcon\Db\AdapterInterface + * @var DbAdapterInterface */ protected $db = null; @@ -42,28 +50,28 @@ class Database extends Prefixable protected $table = null; /** - * Class constructor. + * {@inheritdoc} * - * @param \Phalcon\Cache\FrontendInterface $frontend - * @param array $options - * @throws \Phalcon\Cache\Exception + * @param FrontendInterface $frontend + * @param array $options + * @throws Exception */ - public function __construct(FrontendInterface $frontend, $options = array()) + public function __construct(FrontendInterface $frontend, array $options) { - if (!isset($options['db'])) { - throw new Exception("Parameter 'db' is required"); - } - - if (!($options['db'] instanceof DbAdapterInterface)) { - throw new Exception("Parameter 'db' must implement Phalcon\\Db\\AdapterInterface"); + if (!isset($options['db']) || !$options['db'] instanceof DbAdapterInterface) { + throw new Exception( + 'Parameter "db" is required and it must be an instance of Phalcon\Acl\AdapterInterface' + ); } - if (!isset($options['table'])) { - throw new Exception("Parameter 'table' is required"); + if (!isset($options['table']) || empty($options['table']) || !is_string($options['table'])) { + throw new Exception("Parameter 'table' is required and it must be a non empty string"); } $this->db = $options['db']; - $this->table = $options['table']; + $this->table = $this->db->escapeIdentifier($options['table']); + + unset($options['db'], $options['table']); parent::__construct($frontend, $options); } @@ -78,8 +86,8 @@ public function __construct(FrontendInterface $frontend, $options = array()) public function get($keyName, $lifetime = null) { $prefixedKey = $this->getPrefixedIdentifier($keyName); - $sql = "SELECT data, lifetime FROM " . $this->table . " WHERE key_name = ?"; - $cache = $this->db->fetchOne($sql, Db::FETCH_ASSOC, array($prefixedKey)); + $sql = "SELECT data, lifetime FROM {$this->table} WHERE key_name = ?"; + $cache = $this->db->fetchOne($sql, Db::FETCH_ASSOC, [$prefixedKey]); $this->_lastKey = $prefixedKey; if (!$cache) { @@ -91,7 +99,7 @@ public function get($keyName, $lifetime = null) // Remove the cache if expired if ($cache['lifetime'] < time()) { - $this->db->execute("DELETE FROM " . $this->table . " WHERE key_name = ?", array($prefixedKey)); + $this->db->execute("DELETE FROM {$this->table} WHERE key_name = ?", [$prefixedKey]); return null; } @@ -102,10 +110,10 @@ public function get($keyName, $lifetime = null) /** * {@inheritdoc} * - * @param string $keyName - * @param string $content - * @param integer $lifetime - * @param boolean $stopBuffer + * @param string $keyName + * @param string $content + * @param int $lifetime + * @param bool $stopBuffer * @throws \Phalcon\Cache\Exception */ public function save($keyName = null, $content = null, $lifetime = null, $stopBuffer = true) @@ -136,23 +144,23 @@ public function save($keyName = null, $content = null, $lifetime = null, $stopBu $lifetime = time() + $lifetime; // Check if the cache already exist - $sql = "SELECT data, lifetime FROM " . $this->table . " WHERE key_name = ?"; + $sql = "SELECT data, lifetime FROM {$this->table} WHERE key_name = ?"; $cache = $this->db->fetchOne($sql, Db::FETCH_ASSOC, array($prefixedKey)); if (!$cache) { - $this->db->execute("INSERT INTO " . $this->table . " VALUES (?, ?, ?)", array( + $this->db->execute("INSERT INTO {$this->table} VALUES (?, ?, ?)", [ $prefixedKey, $frontend->beforeStore($cachedContent), $lifetime - )); + ]); } else { $this->db->execute( - "UPDATE " . $this->table . " SET data = ?, lifetime = ? WHERE key_name = ?", - array( + "UPDATE {$this->table} SET data = ?, lifetime = ? WHERE key_name = ?", + [ $frontend->beforeStore($cachedContent), $lifetime, $prefixedKey - ) + ] ); } @@ -171,19 +179,19 @@ public function save($keyName = null, $content = null, $lifetime = null, $stopBu * {@inheritdoc} * * @param string $keyName - * @return boolean + * @return bool */ public function delete($keyName) { $prefixedKey = $this->getPrefixedIdentifier($keyName); - $sql = "SELECT COUNT(*) AS rowcount FROM " . $this->table . " WHERE key_name = ?"; - $row = $this->db->fetchOne($sql, Db::FETCH_ASSOC, array($prefixedKey)); + $sql = "SELECT COUNT(*) AS rowcount FROM {$this->table} WHERE key_name = ?"; + $row = $this->db->fetchOne($sql, Db::FETCH_ASSOC, [$prefixedKey]); if (!$row['rowcount']) { return false; } - return $this->db->execute("DELETE FROM " . $this->table . " WHERE key_name = ?", array($prefixedKey)); + return $this->db->execute("DELETE FROM {$this->table} WHERE key_name = ?", [$prefixedKey]); } /** @@ -201,16 +209,16 @@ public function queryKeys($prefix = null) } if (!empty($prefix)) { - $sql = "SELECT key_name FROM " . $this->table . " WHERE key_name LIKE ? ORDER BY lifetime"; - $rs = $this->db->query($sql, array($prefix . '%')); + $sql = "SELECT key_name FROM {$this->table} WHERE key_name LIKE ? ORDER BY lifetime"; + $rs = $this->db->query($sql, [$prefix . '%']); } else { - $sql = "SELECT key_name FROM " . $this->table . " ORDER BY lifetime"; + $sql = "SELECT key_name FROM {$this->table} ORDER BY lifetime"; $rs = $this->db->query($sql); } $rs->setFetchMode(Db::FETCH_ASSOC); - $keys = array(); + $keys = []; while ($row = $rs->fetch()) { $keys[] = !empty($prefix) ? str_replace($prefix, '', $row['key_name']) : $row['key_name']; @@ -224,13 +232,13 @@ public function queryKeys($prefix = null) * * @param string $keyName * @param string $lifetime - * @return boolean + * @return bool */ public function exists($keyName = null, $lifetime = null) { $prefixedKey = $this->getPrefixedIdentifier($keyName); - $sql = "SELECT lifetime FROM " . $this->table . " WHERE key_name = ?"; - $cache = $this->db->fetchOne($sql, Db::FETCH_ASSOC, array($prefixedKey)); + $sql = "SELECT lifetime FROM {$this->table} WHERE key_name = ?"; + $cache = $this->db->fetchOne($sql, Db::FETCH_ASSOC, [$prefixedKey]); if (!$cache) { return false; @@ -238,7 +246,7 @@ public function exists($keyName = null, $lifetime = null) // Remove the cache if expired if ($cache['lifetime'] < time()) { - $this->db->execute("DELETE FROM " . $this->table . " WHERE key_name = ?", array($prefixedKey)); + $this->db->execute("DELETE FROM {$this->table} WHERE key_name = ?", [$prefixedKey]); return false; } @@ -249,11 +257,11 @@ public function exists($keyName = null, $lifetime = null) /** * {@inheritdoc} * - * @return boolean + * @return bool */ public function flush() { - $this->db->execute('DELETE FROM ' . $this->table); + $this->db->execute("DELETE FROM {$this->table}"); return true; } diff --git a/Library/Phalcon/Cache/Backend/Prefixable.php b/Library/Phalcon/Cache/Backend/Prefixable.php index d89386d26..a1ad985c3 100644 --- a/Library/Phalcon/Cache/Backend/Prefixable.php +++ b/Library/Phalcon/Cache/Backend/Prefixable.php @@ -3,7 +3,7 @@ +------------------------------------------------------------------------+ | Phalcon Framework | +------------------------------------------------------------------------+ - | Copyright (c) 2011-2015 Phalcon Team (http://www.phalconphp.com) | + | Copyright (c) 2011-2016 Phalcon Team (http://www.phalconphp.com) | +------------------------------------------------------------------------+ | This source file is subject to the New BSD License that is bundled | | with this package in the file docs/LICENSE.txt. | @@ -18,14 +18,14 @@ namespace Phalcon\Cache\Backend; -use Phalcon\Cache\Backend; -use Phalcon\Cache\BackendInterface; - /** * Phalcon\Cache\Backend\Prefixable - * Abstract class for backend with support of «prefix» option. + * + * Trait for backend cache adapters with support of "prefix" option. + * + * @package Phalcon\Cache\Backend */ -abstract class Prefixable extends Backend implements BackendInterface +trait Prefixable { /** * Returns prefixed identifier. diff --git a/Library/Phalcon/Cache/Backend/README.md b/Library/Phalcon/Cache/Backend/README.md index c19d9aa8c..61df27fa9 100644 --- a/Library/Phalcon/Cache/Backend/README.md +++ b/Library/Phalcon/Cache/Backend/README.md @@ -1,10 +1,42 @@ -Phalcon\Cache\Backend -===================== +# Phalcon\Cache\Backend Usage examples of the adapters available here: -Database --------- +## Aerospike + +This adapter uses an Aerospike Database to store the cached content. + +To use this adapter on your machine, you need at least: + +- [Aerospike Server][1] >= 3.5.3 +- [Aerospike PHP Extension][2] + +Usage: + +```php +use Phalcon\Cache\Backend\Aerospike as BackendCache; +use Phalcon\Cache\Frontend\Data; + +$di->set('cache', function () { + $cache = new BackendCache(new Data(['lifetime' => 3600]), [ + 'hosts' => [ + ['addr' => '127.0.0.1', 'port' => 3000] + ], + 'persistent' => true, + 'namespace' => 'test', + 'prefix' => 'cache_', + 'options' => [ + \Aerospike::OPT_CONNECT_TIMEOUT => 1250, + \Aerospike::OPT_WRITE_TIMEOUT => 1500 + ] + ]); + + return $cache; +}); +``` + +## Database + This adapter uses a database backend to store the cached content: ```php @@ -61,6 +93,9 @@ echo $time; ``` -Wincache --------- +## Wincache + This adapter uses [windows cache extension](http://pecl.php.net/package/wincache) for PHP + +[1]: http://www.aerospike.com/ +[2]: http://www.aerospike.com/docs/client/php/install/ diff --git a/Library/Phalcon/Cache/Backend/Wincache.php b/Library/Phalcon/Cache/Backend/Wincache.php index dbacf488b..a78c327b2 100644 --- a/Library/Phalcon/Cache/Backend/Wincache.php +++ b/Library/Phalcon/Cache/Backend/Wincache.php @@ -3,7 +3,7 @@ +------------------------------------------------------------------------+ | Phalcon Framework | +------------------------------------------------------------------------+ - | Copyright (c) 2011-2015 Phalcon Team (http://www.phalconphp.com) | + | Copyright (c) 2011-2016 Phalcon Team (http://www.phalconphp.com) | +------------------------------------------------------------------------+ | This source file is subject to the New BSD License that is bundled | | with this package in the file docs/LICENSE.txt. | @@ -20,14 +20,21 @@ namespace Phalcon\Cache\Backend; use Phalcon\Cache\Exception; +use Phalcon\Cache\Backend; +use Phalcon\Cache\BackendInterface; /** * Phalcon\Cache\Backend\Wincache * * This backend uses wincache as cache backend + * + * @package Phalcon\Cache\Backend + * @property \Phalcon\Cache\FrontendInterface _frontend */ -class Wincache extends Prefixable +class Wincache extends Backend implements BackendInterface { + use Prefixable; + /** * {@inheritdoc} * diff --git a/Library/Phalcon/Cli/Console/Extended.php b/Library/Phalcon/Cli/Console/Extended.php index 28518f263..0e69845ee 100644 --- a/Library/Phalcon/Cli/Console/Extended.php +++ b/Library/Phalcon/Cli/Console/Extended.php @@ -4,7 +4,7 @@ +------------------------------------------------------------------------+ | Phalcon Framework | +------------------------------------------------------------------------+ - | Copyright (c) 2011-2015 Phalcon Team (http://www.phalconphp.com) | + | Copyright (c) 2011-2016 Phalcon Team (http://www.phalconphp.com) | +------------------------------------------------------------------------+ | This source file is subject to the New BSD License that is bundled | | with this package in the file docs/LICENSE.txt. | diff --git a/Library/Phalcon/Cli/Console/README.md b/Library/Phalcon/Cli/Console/README.md index 814b2f498..ccb42213b 100644 --- a/Library/Phalcon/Cli/Console/README.md +++ b/Library/Phalcon/Cli/Console/README.md @@ -130,7 +130,7 @@ Also is available instruction for hiding action from help. Just use `@DoNotCover Assume that we have developed a task, to list a directory's content. So the file of the task must be located within the tasks folder. **For instance: /path/to/your/project/tasks/LsTask.php** -Pay attention to the file name. This must be named as **Task.php** +Pay attention to the file name. This must be named as **\Task.php** ```php use Phalcon\Cli\Task; diff --git a/Library/Phalcon/Cli/Environment/Environment.php b/Library/Phalcon/Cli/Environment/Environment.php index 64add0083..ef5663909 100644 --- a/Library/Phalcon/Cli/Environment/Environment.php +++ b/Library/Phalcon/Cli/Environment/Environment.php @@ -4,7 +4,7 @@ +------------------------------------------------------------------------+ | Phalcon Framework | +------------------------------------------------------------------------+ - | Copyright (c) 2011-2015 Phalcon Team (http://www.phalconphp.com) | + | Copyright (c) 2011-2016 Phalcon Team (http://www.phalconphp.com) | +------------------------------------------------------------------------+ | This source file is subject to the New BSD License that is bundled | | with this package in the file docs/LICENSE.txt. | diff --git a/Library/Phalcon/Cli/Environment/EnvironmentAwareInterface.php b/Library/Phalcon/Cli/Environment/EnvironmentAwareInterface.php index c0bd442cc..d6989fb0a 100644 --- a/Library/Phalcon/Cli/Environment/EnvironmentAwareInterface.php +++ b/Library/Phalcon/Cli/Environment/EnvironmentAwareInterface.php @@ -4,7 +4,7 @@ +------------------------------------------------------------------------+ | Phalcon Framework | +------------------------------------------------------------------------+ - | Copyright (c) 2011-2015 Phalcon Team (http://www.phalconphp.com) | + | Copyright (c) 2011-2016 Phalcon Team (http://www.phalconphp.com) | +------------------------------------------------------------------------+ | This source file is subject to the New BSD License that is bundled | | with this package in the file docs/LICENSE.txt. | diff --git a/Library/Phalcon/Cli/Environment/EnvironmentInterface.php b/Library/Phalcon/Cli/Environment/EnvironmentInterface.php index 8a08e2dbd..ffc275135 100644 --- a/Library/Phalcon/Cli/Environment/EnvironmentInterface.php +++ b/Library/Phalcon/Cli/Environment/EnvironmentInterface.php @@ -4,7 +4,7 @@ +------------------------------------------------------------------------+ | Phalcon Framework | +------------------------------------------------------------------------+ - | Copyright (c) 2011-2015 Phalcon Team (http://www.phalconphp.com) | + | Copyright (c) 2011-2016 Phalcon Team (http://www.phalconphp.com) | +------------------------------------------------------------------------+ | This source file is subject to the New BSD License that is bundled | | with this package in the file docs/LICENSE.txt. | diff --git a/Library/Phalcon/Cli/Input/ArgumentInterface.php b/Library/Phalcon/Cli/Input/ArgumentInterface.php index ec59491cb..17503ce12 100644 --- a/Library/Phalcon/Cli/Input/ArgumentInterface.php +++ b/Library/Phalcon/Cli/Input/ArgumentInterface.php @@ -4,7 +4,7 @@ +------------------------------------------------------------------------+ | Phalcon Framework | +------------------------------------------------------------------------+ - | Copyright (c) 2011-2015 Phalcon Team (http://www.phalconphp.com) | + | Copyright (c) 2011-2016 Phalcon Team (http://www.phalconphp.com) | +------------------------------------------------------------------------+ | This source file is subject to the New BSD License that is bundled | | with this package in the file docs/LICENSE.txt. | diff --git a/Library/Phalcon/Cli/Input/OptionInterface.php b/Library/Phalcon/Cli/Input/OptionInterface.php index 881a17552..fcb29fab0 100644 --- a/Library/Phalcon/Cli/Input/OptionInterface.php +++ b/Library/Phalcon/Cli/Input/OptionInterface.php @@ -4,7 +4,7 @@ +------------------------------------------------------------------------+ | Phalcon Framework | +------------------------------------------------------------------------+ - | Copyright (c) 2011-2015 Phalcon Team (http://www.phalconphp.com) | + | Copyright (c) 2011-2016 Phalcon Team (http://www.phalconphp.com) | +------------------------------------------------------------------------+ | This source file is subject to the New BSD License that is bundled | | with this package in the file docs/LICENSE.txt. | diff --git a/Library/Phalcon/Cli/Input/ParameterInterface.php b/Library/Phalcon/Cli/Input/ParameterInterface.php index 05494a529..5fd9297ca 100644 --- a/Library/Phalcon/Cli/Input/ParameterInterface.php +++ b/Library/Phalcon/Cli/Input/ParameterInterface.php @@ -4,7 +4,7 @@ +------------------------------------------------------------------------+ | Phalcon Framework | +------------------------------------------------------------------------+ - | Copyright (c) 2011-2015 Phalcon Team (http://www.phalconphp.com) | + | Copyright (c) 2011-2016 Phalcon Team (http://www.phalconphp.com) | +------------------------------------------------------------------------+ | This source file is subject to the New BSD License that is bundled | | with this package in the file docs/LICENSE.txt. | diff --git a/Library/Phalcon/Config/Loader.php b/Library/Phalcon/Config/Loader.php index 6d0f6106a..f795d670a 100644 --- a/Library/Phalcon/Config/Loader.php +++ b/Library/Phalcon/Config/Loader.php @@ -3,7 +3,7 @@ +------------------------------------------------------------------------+ | Phalcon Framework | +------------------------------------------------------------------------+ - | Copyright (c) 2011-2015 Phalcon Team (http://www.phalconphp.com) | + | Copyright (c) 2011-2016 Phalcon Team (http://www.phalconphp.com) | +------------------------------------------------------------------------+ | This source file is subject to the New BSD License that is bundled | | with this package in the file docs/LICENSE.txt. | diff --git a/Library/Phalcon/Db/Adapter/Cacheable/Mysql.php b/Library/Phalcon/Db/Adapter/Cacheable/Mysql.php index 8210d635b..add16f821 100644 --- a/Library/Phalcon/Db/Adapter/Cacheable/Mysql.php +++ b/Library/Phalcon/Db/Adapter/Cacheable/Mysql.php @@ -3,7 +3,7 @@ +------------------------------------------------------------------------+ | Phalcon Framework | +------------------------------------------------------------------------+ - | Copyright (c) 2011-2012 Phalcon Team (http://www.phalconphp.com) | + | Copyright (c) 2011-2016 Phalcon Team (http://www.phalconphp.com) | +------------------------------------------------------------------------+ | This source file is subject to the New BSD License that is bundled | | with this package in the file docs/LICENSE.txt. | diff --git a/Library/Phalcon/Db/Adapter/Factory.php b/Library/Phalcon/Db/Adapter/Factory.php index a17c74dd9..f3e6c9900 100644 --- a/Library/Phalcon/Db/Adapter/Factory.php +++ b/Library/Phalcon/Db/Adapter/Factory.php @@ -3,7 +3,7 @@ +------------------------------------------------------------------------+ | Phalcon Framework | +------------------------------------------------------------------------+ - | Copyright (c) 2011-2015 Phalcon Team (http://www.phalconphp.com) | + | Copyright (c) 2011-2016 Phalcon Team (http://www.phalconphp.com) | +------------------------------------------------------------------------+ | This source file is subject to the New BSD License that is bundled | | with this package in the file docs/LICENSE.txt. | diff --git a/Library/Phalcon/Db/Adapter/Mongo/Client.php b/Library/Phalcon/Db/Adapter/Mongo/Client.php index 7603ba7a1..3fc648069 100644 --- a/Library/Phalcon/Db/Adapter/Mongo/Client.php +++ b/Library/Phalcon/Db/Adapter/Mongo/Client.php @@ -3,7 +3,7 @@ +------------------------------------------------------------------------+ | Phalcon Framework | +------------------------------------------------------------------------+ - | Copyright (c) 2011-2014 Phalcon Team (http://www.phalconphp.com) | + | Copyright (c) 2011-2016 Phalcon Team (http://www.phalconphp.com) | +------------------------------------------------------------------------+ | This source file is subject to the New BSD License that is bundled | | with this package in the file docs/LICENSE.txt. | diff --git a/Library/Phalcon/Db/Adapter/Mongo/Collection.php b/Library/Phalcon/Db/Adapter/Mongo/Collection.php index d53badbe9..6ac1ce4e0 100644 --- a/Library/Phalcon/Db/Adapter/Mongo/Collection.php +++ b/Library/Phalcon/Db/Adapter/Mongo/Collection.php @@ -3,7 +3,7 @@ +------------------------------------------------------------------------+ | Phalcon Framework | +------------------------------------------------------------------------+ - | Copyright (c) 2011-2014 Phalcon Team (http://www.phalconphp.com) | + | Copyright (c) 2011-2016 Phalcon Team (http://www.phalconphp.com) | +------------------------------------------------------------------------+ | This source file is subject to the New BSD License that is bundled | | with this package in the file docs/LICENSE.txt. | diff --git a/Library/Phalcon/Db/Adapter/Mongo/Cursor.php b/Library/Phalcon/Db/Adapter/Mongo/Cursor.php index 56cf08895..a6eb25d13 100644 --- a/Library/Phalcon/Db/Adapter/Mongo/Cursor.php +++ b/Library/Phalcon/Db/Adapter/Mongo/Cursor.php @@ -3,7 +3,7 @@ +------------------------------------------------------------------------+ | Phalcon Framework | +------------------------------------------------------------------------+ - | Copyright (c) 2011-2014 Phalcon Team (http://www.phalconphp.com) | + | Copyright (c) 2011-2016 Phalcon Team (http://www.phalconphp.com) | +------------------------------------------------------------------------+ | This source file is subject to the New BSD License that is bundled | | with this package in the file docs/LICENSE.txt. | diff --git a/Library/Phalcon/Db/Adapter/Mongo/Db.php b/Library/Phalcon/Db/Adapter/Mongo/Db.php index f76bd5c71..92463e228 100644 --- a/Library/Phalcon/Db/Adapter/Mongo/Db.php +++ b/Library/Phalcon/Db/Adapter/Mongo/Db.php @@ -3,7 +3,7 @@ +------------------------------------------------------------------------+ | Phalcon Framework | +------------------------------------------------------------------------+ - | Copyright (c) 2011-2014 Phalcon Team (http://www.phalconphp.com) | + | Copyright (c) 2011-2016 Phalcon Team (http://www.phalconphp.com) | +------------------------------------------------------------------------+ | This source file is subject to the New BSD License that is bundled | | with this package in the file docs/LICENSE.txt. | diff --git a/Library/Phalcon/Db/Adapter/Mongo/DbRef.php b/Library/Phalcon/Db/Adapter/Mongo/DbRef.php index c17e72cb3..3b7a19b49 100644 --- a/Library/Phalcon/Db/Adapter/Mongo/DbRef.php +++ b/Library/Phalcon/Db/Adapter/Mongo/DbRef.php @@ -3,7 +3,7 @@ +------------------------------------------------------------------------+ | Phalcon Framework | +------------------------------------------------------------------------+ - | Copyright (c) 2011-2014 Phalcon Team (http://www.phalconphp.com) | + | Copyright (c) 2011-2016 Phalcon Team (http://www.phalconphp.com) | +------------------------------------------------------------------------+ | This source file is subject to the New BSD License that is bundled | | with this package in the file docs/LICENSE.txt. | diff --git a/Library/Phalcon/Db/Adapter/Mongo/Document.php b/Library/Phalcon/Db/Adapter/Mongo/Document.php index f311d1eb8..e9eed238e 100644 --- a/Library/Phalcon/Db/Adapter/Mongo/Document.php +++ b/Library/Phalcon/Db/Adapter/Mongo/Document.php @@ -3,7 +3,7 @@ +------------------------------------------------------------------------+ | Phalcon Framework | +------------------------------------------------------------------------+ - | Copyright (c) 2011-2014 Phalcon Team (http://www.phalconphp.com) | + | Copyright (c) 2011-2016 Phalcon Team (http://www.phalconphp.com) | +------------------------------------------------------------------------+ | This source file is subject to the New BSD License that is bundled | | with this package in the file docs/LICENSE.txt. | diff --git a/Library/Phalcon/Db/Dialect/MysqlExtended.php b/Library/Phalcon/Db/Dialect/MysqlExtended.php index 9ea00a853..2e75a638f 100644 --- a/Library/Phalcon/Db/Dialect/MysqlExtended.php +++ b/Library/Phalcon/Db/Dialect/MysqlExtended.php @@ -4,7 +4,7 @@ +------------------------------------------------------------------------+ | Phalcon Framework | +------------------------------------------------------------------------+ - | Copyright (c) 2011-2015 Phalcon Team (http://www.phalconphp.com) | + | Copyright (c) 2011-2016 Phalcon Team (http://www.phalconphp.com) | +------------------------------------------------------------------------+ | This source file is subject to the New BSD License that is bundled | | with this package in the file docs/LICENSE.txt. | diff --git a/Library/Phalcon/Db/Result/Serializable.php b/Library/Phalcon/Db/Result/Serializable.php index 94f024b0c..c9747c342 100644 --- a/Library/Phalcon/Db/Result/Serializable.php +++ b/Library/Phalcon/Db/Result/Serializable.php @@ -3,7 +3,7 @@ +------------------------------------------------------------------------+ | Phalcon Framework | +------------------------------------------------------------------------+ - | Copyright (c) 2011-2015 Phalcon Team (http://www.phalconphp.com) | + | Copyright (c) 2011-2016 Phalcon Team (http://www.phalconphp.com) | +------------------------------------------------------------------------+ | This source file is subject to the New BSD License that is bundled | | with this package in the file docs/LICENSE.txt. | diff --git a/Library/Phalcon/Error/Application.php b/Library/Phalcon/Error/Application.php index 17d69cf63..f85e4421a 100644 --- a/Library/Phalcon/Error/Application.php +++ b/Library/Phalcon/Error/Application.php @@ -3,7 +3,7 @@ +------------------------------------------------------------------------+ | Phalcon Framework | +------------------------------------------------------------------------+ - | Copyright (c) 2011-2015 Phalcon Team (http://www.phalconphp.com) | + | Copyright (c) 2011-2016 Phalcon Team (http://www.phalconphp.com) | +------------------------------------------------------------------------+ | This source file is subject to the New BSD License that is bundled | | with this package in the file docs/LICENSE.txt. | diff --git a/Library/Phalcon/Error/Error.php b/Library/Phalcon/Error/Error.php index 762697d3e..ae8685ab9 100644 --- a/Library/Phalcon/Error/Error.php +++ b/Library/Phalcon/Error/Error.php @@ -3,7 +3,7 @@ +------------------------------------------------------------------------+ | Phalcon Framework | +------------------------------------------------------------------------+ - | Copyright (c) 2011-2015 Phalcon Team (http://www.phalconphp.com) | + | Copyright (c) 2011-2016 Phalcon Team (http://www.phalconphp.com) | +------------------------------------------------------------------------+ | This source file is subject to the New BSD License that is bundled | | with this package in the file docs/LICENSE.txt. | diff --git a/Library/Phalcon/Error/Handler.php b/Library/Phalcon/Error/Handler.php index e2586bcca..129b3a9fd 100644 --- a/Library/Phalcon/Error/Handler.php +++ b/Library/Phalcon/Error/Handler.php @@ -3,7 +3,7 @@ +------------------------------------------------------------------------+ | Phalcon Framework | +------------------------------------------------------------------------+ - | Copyright (c) 2011-2015 Phalcon Team (http://www.phalconphp.com) | + | Copyright (c) 2011-2016 Phalcon Team (http://www.phalconphp.com) | +------------------------------------------------------------------------+ | This source file is subject to the New BSD License that is bundled | | with this package in the file docs/LICENSE.txt. | diff --git a/Library/Phalcon/Http/Client/Exception.php b/Library/Phalcon/Http/Client/Exception.php index ea882e3f3..8f96cc7b5 100755 --- a/Library/Phalcon/Http/Client/Exception.php +++ b/Library/Phalcon/Http/Client/Exception.php @@ -3,7 +3,7 @@ +------------------------------------------------------------------------+ | Phalcon Framework | +------------------------------------------------------------------------+ - | Copyright (c) 2011-2015 Phalcon Team (http://www.phalconphp.com) | + | Copyright (c) 2011-2016 Phalcon Team (http://www.phalconphp.com) | +------------------------------------------------------------------------+ | This source file is subject to the New BSD License that is bundled | | with this package in the file docs/LICENSE.txt. | diff --git a/Library/Phalcon/Http/Client/Header.php b/Library/Phalcon/Http/Client/Header.php index 9d8c31173..3fc8ba185 100755 --- a/Library/Phalcon/Http/Client/Header.php +++ b/Library/Phalcon/Http/Client/Header.php @@ -3,7 +3,7 @@ +------------------------------------------------------------------------+ | Phalcon Framework | +------------------------------------------------------------------------+ - | Copyright (c) 2011-2015 Phalcon Team (http://www.phalconphp.com) | + | Copyright (c) 2011-2016 Phalcon Team (http://www.phalconphp.com) | +------------------------------------------------------------------------+ | This source file is subject to the New BSD License that is bundled | | with this package in the file docs/LICENSE.txt. | diff --git a/Library/Phalcon/Http/Client/Provider/Curl.php b/Library/Phalcon/Http/Client/Provider/Curl.php index 17694ccf6..70dae91de 100755 --- a/Library/Phalcon/Http/Client/Provider/Curl.php +++ b/Library/Phalcon/Http/Client/Provider/Curl.php @@ -3,7 +3,7 @@ +------------------------------------------------------------------------+ | Phalcon Framework | +------------------------------------------------------------------------+ - | Copyright (c) 2011-2012 Phalcon Team (http://www.phalconphp.com) | + | Copyright (c) 2011-2016 Phalcon Team (http://www.phalconphp.com) | +------------------------------------------------------------------------+ | This source file is subject to the New BSD License that is bundled | | with this package in the file docs/LICENSE.txt. | @@ -103,7 +103,7 @@ private function send($customHeader = array(), $fullResponse = false) } $header[] = 'Expect:'; } - + $this->setOption(CURLOPT_HTTPHEADER, $header); $content = curl_exec($this->handle); @@ -116,7 +116,7 @@ private function send($customHeader = array(), $fullResponse = false) $response = new Response(); $response->header->parse(substr($content, 0, $headerSize)); - + if ($fullResponse) { $response->body = $content; } else { diff --git a/Library/Phalcon/Http/Client/Provider/Exception.php b/Library/Phalcon/Http/Client/Provider/Exception.php index dd1f9940b..ebeb710cc 100755 --- a/Library/Phalcon/Http/Client/Provider/Exception.php +++ b/Library/Phalcon/Http/Client/Provider/Exception.php @@ -3,7 +3,7 @@ +------------------------------------------------------------------------+ | Phalcon Framework | +------------------------------------------------------------------------+ - | Copyright (c) 2011-2012 Phalcon Team (http://www.phalconphp.com) | + | Copyright (c) 2011-2016 Phalcon Team (http://www.phalconphp.com) | +------------------------------------------------------------------------+ | This source file is subject to the New BSD License that is bundled | | with this package in the file docs/LICENSE.txt. | diff --git a/Library/Phalcon/Http/Client/Provider/Stream.php b/Library/Phalcon/Http/Client/Provider/Stream.php index c572e1729..6fd11d20a 100755 --- a/Library/Phalcon/Http/Client/Provider/Stream.php +++ b/Library/Phalcon/Http/Client/Provider/Stream.php @@ -3,7 +3,7 @@ +------------------------------------------------------------------------+ | Phalcon Framework | +------------------------------------------------------------------------+ - | Copyright (c) 2011-2012 Phalcon Team (http://www.phalconphp.com) | + | Copyright (c) 2011-2016 Phalcon Team (http://www.phalconphp.com) | +------------------------------------------------------------------------+ | This source file is subject to the New BSD License that is bundled | | with this package in the file docs/LICENSE.txt. | diff --git a/Library/Phalcon/Http/Client/Response.php b/Library/Phalcon/Http/Client/Response.php index f2fd8af71..b13173919 100755 --- a/Library/Phalcon/Http/Client/Response.php +++ b/Library/Phalcon/Http/Client/Response.php @@ -3,7 +3,7 @@ +------------------------------------------------------------------------+ | Phalcon Framework | +------------------------------------------------------------------------+ - | Copyright (c) 2011-2015 Phalcon Team (http://www.phalconphp.com) | + | Copyright (c) 2011-2016 Phalcon Team (http://www.phalconphp.com) | +------------------------------------------------------------------------+ | This source file is subject to the New BSD License that is bundled | | with this package in the file docs/LICENSE.txt. | diff --git a/Library/Phalcon/Http/Request/Method.php b/Library/Phalcon/Http/Request/Method.php index ff08e7875..81f7fce70 100644 --- a/Library/Phalcon/Http/Request/Method.php +++ b/Library/Phalcon/Http/Request/Method.php @@ -3,7 +3,7 @@ +------------------------------------------------------------------------+ | Phalcon Framework | +------------------------------------------------------------------------+ - | Copyright (c) 2011-2015 Phalcon Team (http://www.phalconphp.com) | + | Copyright (c) 2011-2016 Phalcon Team (http://www.phalconphp.com) | +------------------------------------------------------------------------+ | This source file is subject to the New BSD License that is bundled | | with this package in the file docs/LICENSE.txt. | diff --git a/Library/Phalcon/Http/Response/StatusCode.php b/Library/Phalcon/Http/Response/StatusCode.php index 3c89e17b5..01812b820 100644 --- a/Library/Phalcon/Http/Response/StatusCode.php +++ b/Library/Phalcon/Http/Response/StatusCode.php @@ -3,7 +3,7 @@ +------------------------------------------------------------------------+ | Phalcon Framework | +------------------------------------------------------------------------+ - | Copyright (c) 2011-2015 Phalcon Team (http://www.phalconphp.com) | + | Copyright (c) 2011-2016 Phalcon Team (http://www.phalconphp.com) | +------------------------------------------------------------------------+ | This source file is subject to the New BSD License that is bundled | | with this package in the file docs/LICENSE.txt. | diff --git a/Library/Phalcon/Http/Uri.php b/Library/Phalcon/Http/Uri.php index 7d399d002..5193b4cfb 100755 --- a/Library/Phalcon/Http/Uri.php +++ b/Library/Phalcon/Http/Uri.php @@ -3,7 +3,7 @@ +------------------------------------------------------------------------+ | Phalcon Framework | +------------------------------------------------------------------------+ - | Copyright (c) 2011-2015 Phalcon Team (http://www.phalconphp.com) | + | Copyright (c) 2011-2016 Phalcon Team (http://www.phalconphp.com) | +------------------------------------------------------------------------+ | This source file is subject to the New BSD License that is bundled | | with this package in the file docs/LICENSE.txt. | diff --git a/Library/Phalcon/Loader/Extended.php b/Library/Phalcon/Loader/Extended.php index 66d736cde..44a3f4127 100644 --- a/Library/Phalcon/Loader/Extended.php +++ b/Library/Phalcon/Loader/Extended.php @@ -3,7 +3,7 @@ +------------------------------------------------------------------------+ | Phalcon Framework | +------------------------------------------------------------------------+ - | Copyright (c) 2011-2015 Phalcon Team (http://www.phalconphp.com) | + | Copyright (c) 2011-2016 Phalcon Team (http://www.phalconphp.com) | +------------------------------------------------------------------------+ | This source file is subject to the New BSD License that is bundled | | with this package in the file docs/LICENSE.txt. | diff --git a/Library/Phalcon/Loader/PSR.php b/Library/Phalcon/Loader/PSR.php index e08b5c2c6..aebe5f239 100644 --- a/Library/Phalcon/Loader/PSR.php +++ b/Library/Phalcon/Loader/PSR.php @@ -3,7 +3,7 @@ +------------------------------------------------------------------------+ | Phalcon Framework | +------------------------------------------------------------------------+ - | Copyright (c) 2011-2015 Phalcon Team (http://www.phalconphp.com) | + | Copyright (c) 2011-2016 Phalcon Team (http://www.phalconphp.com) | +------------------------------------------------------------------------+ | This source file is subject to the New BSD License that is bundled | | with this package in the file docs/LICENSE.txt. | diff --git a/Library/Phalcon/Logger/Adapter/Database.php b/Library/Phalcon/Logger/Adapter/Database.php index db62d4e7a..3d306eda8 100644 --- a/Library/Phalcon/Logger/Adapter/Database.php +++ b/Library/Phalcon/Logger/Adapter/Database.php @@ -3,7 +3,7 @@ +------------------------------------------------------------------------+ | Phalcon Framework | +------------------------------------------------------------------------+ - | Copyright (c) 2011-2015 Phalcon Team (http://www.phalconphp.com) | + | Copyright (c) 2011-2016 Phalcon Team (http://www.phalconphp.com) | +------------------------------------------------------------------------+ | This source file is subject to the New BSD License that is bundled | | with this package in the file docs/LICENSE.txt. | diff --git a/Library/Phalcon/Mailer/Manager.php b/Library/Phalcon/Mailer/Manager.php index 6f97165db..3ae0dca78 100644 --- a/Library/Phalcon/Mailer/Manager.php +++ b/Library/Phalcon/Mailer/Manager.php @@ -3,7 +3,7 @@ +------------------------------------------------------------------------+ | Phalcon Framework | +------------------------------------------------------------------------+ - | Copyright (c) 2011-2012 Phalcon Team (http://www.phalconphp.com) | + | Copyright (c) 2011-2016 Phalcon Team (http://www.phalconphp.com) | +------------------------------------------------------------------------+ | This source file is subject to the New BSD License that is bundled | | with this package in the file docs/LICENSE.txt. | diff --git a/Library/Phalcon/Mailer/Message.php b/Library/Phalcon/Mailer/Message.php index 1b85dc8b8..f671bbe35 100644 --- a/Library/Phalcon/Mailer/Message.php +++ b/Library/Phalcon/Mailer/Message.php @@ -3,7 +3,7 @@ +------------------------------------------------------------------------+ | Phalcon Framework | +------------------------------------------------------------------------+ - | Copyright (c) 2011-2012 Phalcon Team (http://www.phalconphp.com) | + | Copyright (c) 2011-2016 Phalcon Team (http://www.phalconphp.com) | +------------------------------------------------------------------------+ | This source file is subject to the New BSD License that is bundled | | with this package in the file docs/LICENSE.txt. | @@ -532,7 +532,7 @@ public function getFormat() * @see Phalcon\Mailer\Message::createAttachmentViaPath() * @see Phalcon\Mailer\Message::prepareAttachment() */ - public function attachment($file, Array $options = []) + public function attachment($file, array $options = []) { $attachment = $this->createAttachmentViaPath($file); return $this->prepareAttachment($attachment, $options); @@ -550,7 +550,7 @@ public function attachment($file, Array $options = []) * @see Phalcon\Mailer\Message::createAttachmentViaData() * @see Phalcon\Mailer\Message::prepareAttachment() */ - public function attachmentData($data, $name, Array $options = []) + public function attachmentData($data, $name, array $options = []) { $attachment = $this->createAttachmentViaData($data, $name); return $this->prepareAttachment($attachment, $options); @@ -662,7 +662,7 @@ public function send() * * @see \Swift_Message::attach() */ - protected function prepareAttachment(\Swift_Attachment $attachment, Array $options = []) + protected function prepareAttachment(\Swift_Attachment $attachment, array $options = []) { if (isset($options['mime'])) { $attachment->setContentType($options['mime']); diff --git a/Library/Phalcon/Queue/Beanstalk/Extended.php b/Library/Phalcon/Queue/Beanstalk/Extended.php index 80cd271c2..21117cef1 100644 --- a/Library/Phalcon/Queue/Beanstalk/Extended.php +++ b/Library/Phalcon/Queue/Beanstalk/Extended.php @@ -4,7 +4,7 @@ +------------------------------------------------------------------------+ | Phalcon Framework | +------------------------------------------------------------------------+ - | Copyright (c) 2011-2015 Phalcon Team (http://www.phalconphp.com) | + | Copyright (c) 2011-2016 Phalcon Team (http://www.phalconphp.com) | +------------------------------------------------------------------------+ | This source file is subject to the New BSD License that is bundled | | with this package in the file docs/LICENSE.txt. | @@ -141,19 +141,15 @@ public function doWork($ignoreErrors = false) $that = clone $this; // Run the worker in separate process. - $fork->call(function () use ($tube, $worker, $that, $fork, $ignoreErrors) { + $fork->call(function () use ($tube, $worker, $that, $ignoreErrors) { $that->connect(); do { $job = $that->reserveFromTube($tube); if ($job && ($job instanceof Job)) { - $fork->call(function () use ($worker, $job) { - call_user_func($worker, $job); - }); - try { - $fork->wait(); + call_user_func($worker, $job); try { $job->delete(); diff --git a/Library/Phalcon/Session/Adapter/Aerospike.php b/Library/Phalcon/Session/Adapter/Aerospike.php new file mode 100644 index 000000000..acb4c56f9 --- /dev/null +++ b/Library/Phalcon/Session/Adapter/Aerospike.php @@ -0,0 +1,245 @@ + | + +------------------------------------------------------------------------+ + */ + +namespace Phalcon\Session\Adapter; + +use Aerospike as AerospikeDb; +use Phalcon\Session\Adapter; +use Phalcon\Session\AdapterInterface; +use Phalcon\Session\Exception; + +/** + * Phalcon\Session\Adapter\Aerospike + * + * This adapter store sessions in Aerospike + * + * + * use Phalcon\Session\Adapter\Aerospike as AerospikeSession; + * + * $session = new AerospikeSession([ + * 'hosts' => [ + * ['addr' => '127.0.0.1', 'port' => 3000] + * ], + * 'persistent' => true, + * 'namespace' => 'test', + * 'prefix' => 'session_', + * 'lifetime' => 8600, + * 'uniqueId' => '3Hf90KdjQ18', + * 'options' => [ + * \Aerospike::OPT_CONNECT_TIMEOUT => 1250, + * \Aerospike::OPT_WRITE_TIMEOUT => 1500 + * ] + * ]); + * + * $session->start(); + * + * $session->set('var', 'some-value'); + * + * echo $session->get('var'); + * + */ +class Aerospike extends Adapter implements AdapterInterface +{ + /** + * The Aerospike DB + * @var AerospikeDb + */ + protected $db; + + /** + * Default Aerospike namespace + * @var string + */ + protected $namespace = 'test'; + + /** + * The Aerospike Set for store sessions + * @var string + */ + protected $set = 'session'; + + /** + * Key prefix + * @var string + */ + protected $prefix = ''; + + /** + * Session lifetime + * @var int + */ + protected $lifetime = 8600; + + /** + * Phalcon\Session\Adapter\Aerospike constructor + * + * @param array $options Constructor options + * @throws Exception + */ + public function __construct(array $options) + { + if (!isset($options['hosts']) || !is_array($options['hosts'])) { + throw new Exception('No hosts given in options'); + } + + if (isset($options['namespace'])) { + $this->namespace = $options['namespace']; + } + + if (isset($options['prefix'])) { + $this->prefix = $options['prefix']; + } + + if (isset($options['lifetime'])) { + $this->lifetime = $options['lifetime']; + } + + $persistent = false; + if (isset($options['persistent'])) { + $persistent = (bool) $options['persistent']; + } + + $opts = []; + if (isset($options['options']) && is_array($options['options'])) { + $opts = $options['options']; + } + + $this->db = new AerospikeDb(['hosts' => $options['hosts']], $persistent, $opts); + + if (!$this->db->isConnected()) { + throw new Exception( + sprintf("Aerospike failed to connect [%s]: %s", $this->db->errorno(), $this->db->error()) + ); + } + + parent::__construct($options); + + session_set_save_handler( + [$this, 'open'], + [$this, 'close'], + [$this, 'read'], + [$this, 'write'], + [$this, 'destroy'], + [$this, 'gc'] + ); + } + + /** + * Gets the Aerospike instance. + * + * @return AerospikeDb + */ + public function getDb() + { + return $this->db; + } + + /** + * {@inheritdoc} + * + * @return bool + */ + public function open() + { + return true; + } + + /** + * {@inheritdoc} + * + * @return bool + */ + public function close() + { + return true; + } + + /** + * {@inheritdoc} + * + * @param string $sessionId Session variable name + * @return string + */ + public function read($sessionId) + { + $key = $this->buildKey($sessionId); + $status = $this->db->get($key, $record); + + if ($status != AerospikeDb::OK) { + return false; + } + + return base64_decode($record['bins']['value']); + } + + /** + * {@inheritdoc} + * + * @param string $sessionId Session variable name + * @param string $data Session data + */ + public function write($sessionId, $data) + { + $key = $this->buildKey($sessionId); + $bins = ['value' => base64_encode($data)]; + + $this->db->put($key, $bins, $this->lifetime); + } + + /** + * {@inheritdoc} + * + * @param string $sessionId Session variable name [Optional] + * @return bool + */ + public function destroy($sessionId = null) + { + $sessionId = $sessionId ?: $this->getId(); + $key = $this->buildKey($sessionId); + + $status = $this->db->remove($key); + + return $status == AerospikeDb::OK; + } + + /** + * {@inheritdoc} + * + * @return bool + */ + public function gc() + { + return true; + } + + /** + * Generates a unique key used for storing session data in Aerospike DB. + * + * @param string $sessionId Session variable name + * @return array + */ + protected function buildKey($sessionId) + { + return $this->db->initKey( + $this->namespace, + $this->set, + $this->prefix . $sessionId + ); + } +} diff --git a/Library/Phalcon/Session/Adapter/Database.php b/Library/Phalcon/Session/Adapter/Database.php index 43d8fa74e..907027666 100644 --- a/Library/Phalcon/Session/Adapter/Database.php +++ b/Library/Phalcon/Session/Adapter/Database.php @@ -3,7 +3,7 @@ +------------------------------------------------------------------------+ | Phalcon Framework | +------------------------------------------------------------------------+ - | Copyright (c) 2011-2012 Phalcon Team (http://www.phalconphp.com) | + | Copyright (c) 2011-2016 Phalcon Team (http://www.phalconphp.com) | +------------------------------------------------------------------------+ | This source file is subject to the New BSD License that is bundled | | with this package in the file docs/LICENSE.txt. | @@ -23,6 +23,7 @@ use Phalcon\Session\Adapter; use Phalcon\Session\AdapterInterface; use Phalcon\Session\Exception; +use Phalcon\Db\AdapterInterface as DbAdapter; /** * Phalcon\Session\Adapter\Database @@ -31,59 +32,54 @@ class Database extends Adapter implements AdapterInterface { /** - * Flag to check if session is destroyed. - * - * @var boolean + * @var DbAdapter */ - protected $isDestroyed = false; + protected $connection; /** * {@inheritdoc} * * @param array $options - * - * @throws \Phalcon\Session\Exception + * @throws Exception */ public function __construct($options = null) { - if (!isset($options['db'])) { - throw new Exception("The parameter 'db' is required"); - } - - if (!isset($options['table'])) { - throw new Exception("The parameter 'table' is required"); - } - - if (!isset($options['column_session_id'])) { - $options['column_session_id'] = 'session_id'; + if (!isset($options['db']) || !$options['db'] instanceof DbAdapter) { + throw new Exception( + 'Parameter "db" is required and it must be an instance of Phalcon\Acl\AdapterInterface' + ); } - if (!isset($options['column_data'])) { - $options['column_data'] = 'data'; - } + $this->connection = $options['db']; + unset($options['db']); - if (!isset($options['column_created_at'])) { - $options['column_created_at'] = 'created_at'; + if (!isset($options['table']) || empty($options['table']) || !is_string($options['table'])) { + throw new Exception("Parameter 'table' is required and it must be a non empty string"); } - if (!isset($options['column_modified_at'])) { - $options['column_modified_at'] = 'modified_at'; + $columns = ['session_id', 'data', 'created_at', 'modified_at']; + foreach ($columns as $column) { + $oColumn = "column_$column"; + if (!isset($options[$oColumn]) || !is_string($options[$oColumn]) || empty($options[$oColumn])) { + $options[$oColumn] = $column; + } } parent::__construct($options); session_set_save_handler( - array($this, 'open'), - array($this, 'close'), - array($this, 'read'), - array($this, 'write'), - array($this, 'destroy'), - array($this, 'gc') + [$this, 'open'], + [$this, 'close'], + [$this, 'read'], + [$this, 'write'], + [$this, 'destroy'], + [$this, 'gc'] ); } /** * {@inheritdoc} + * * @return boolean */ public function open() @@ -93,6 +89,7 @@ public function open() /** * {@inheritdoc} + * * @return boolean */ public function close() @@ -102,26 +99,27 @@ public function close() /** * {@inheritdoc} - * @param string $sessionId * + * @param string $sessionId * @return string */ public function read($sessionId) { - $maxlifetime = (int) ini_get('session.gc_maxlifetime'); + $maxLifetime = (int) ini_get('session.gc_maxlifetime'); + $options = $this->getOptions(); $row = $options['db']->fetchOne( sprintf( 'SELECT %s FROM %s WHERE %s = ? AND COALESCE(%s, %s) + %d >= ?', - $options['db']->escapeIdentifier($options['column_data']), - $options['db']->escapeIdentifier($options['table']), - $options['db']->escapeIdentifier($options['column_session_id']), - $options['db']->escapeIdentifier($options['column_modified_at']), - $options['db']->escapeIdentifier($options['column_created_at']), - $maxlifetime + $this->connection->escapeIdentifier($options['column_data']), + $this->connection->escapeIdentifier($options['table']), + $this->connection->escapeIdentifier($options['column_session_id']), + $this->connection->escapeIdentifier($options['column_modified_at']), + $this->connection->escapeIdentifier($options['column_created_at']), + $maxLifetime ), Db::FETCH_NUM, - array($sessionId, time()) + [$sessionId, time()] ); if (empty($row)) { @@ -133,61 +131,58 @@ public function read($sessionId) /** * {@inheritdoc} + * * @param string $sessionId * @param string $data - * * @return boolean */ public function write($sessionId, $data) { - if ($this->isDestroyed || empty($data)) { - return false; - } - $options = $this->getOptions(); - $row = $options['db']->fetchOne( + $row = $this->connection->fetchOne( sprintf( 'SELECT COUNT(*) FROM %s WHERE %s = ?', - $options['db']->escapeIdentifier($options['table']), - $options['db']->escapeIdentifier($options['column_session_id']) + $this->connection->escapeIdentifier($options['table']), + $this->connection->escapeIdentifier($options['column_session_id']) ), Db::FETCH_NUM, - array($sessionId) + [$sessionId] ); if (!empty($row) && intval($row[0]) > 0) { - return $options['db']->execute( + return $this->connection->execute( sprintf( 'UPDATE %s SET %s = ?, %s = ? WHERE %s = ?', - $options['db']->escapeIdentifier($options['table']), - $options['db']->escapeIdentifier($options['column_data']), - $options['db']->escapeIdentifier($options['column_modified_at']), - $options['db']->escapeIdentifier($options['column_session_id']) + $this->connection->escapeIdentifier($options['table']), + $this->connection->escapeIdentifier($options['column_data']), + $this->connection->escapeIdentifier($options['column_modified_at']), + $this->connection->escapeIdentifier($options['column_session_id']) ), - array($data, time(), $sessionId) + [$data, time(), $sessionId] ); } else { - return $options['db']->execute( + return $this->connection->execute( sprintf( 'INSERT INTO %s (%s, %s, %s, %s) VALUES (?, ?, ?, NULL)', - $options['db']->escapeIdentifier($options['table']), - $options['db']->escapeIdentifier($options['column_session_id']), - $options['db']->escapeIdentifier($options['column_data']), - $options['db']->escapeIdentifier($options['column_created_at']), - $options['db']->escapeIdentifier($options['column_modified_at']) + $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']) ), - array($sessionId, $data, time()) + [$sessionId, $data, time()] ); } } /** * {@inheritdoc} + * * @return boolean */ public function destroy($session_id = null) { - if (!$this->isStarted() || $this->isDestroyed) { + if (!$this->isStarted()) { return true; } @@ -195,20 +190,18 @@ public function destroy($session_id = null) $session_id = $this->getId(); } - $this->isDestroyed = true; + $this->_started = false; $options = $this->getOptions(); - $result = $options['db']->execute( + $result = $this->connection->execute( sprintf( 'DELETE FROM %s WHERE %s = ?', - $options['db']->escapeIdentifier($options['table']), - $options['db']->escapeIdentifier($options['column_session_id']) + $this->connection->escapeIdentifier($options['table']), + $this->connection->escapeIdentifier($options['column_session_id']) ), - array($session_id) + [$session_id] ); - session_regenerate_id(); - - return $result; + return $result && session_destroy(); } /** @@ -224,12 +217,12 @@ public function gc($maxlifetime) return $options['db']->execute( sprintf( 'DELETE FROM %s WHERE COALESCE(%s, %s) + %d < ?', - $options['db']->escapeIdentifier($options['table']), - $options['db']->escapeIdentifier($options['column_modified_at']), - $options['db']->escapeIdentifier($options['column_created_at']), + $this->connection->escapeIdentifier($options['table']), + $this->connection->escapeIdentifier($options['column_modified_at']), + $this->connection->escapeIdentifier($options['column_created_at']), $maxlifetime ), - array(time()) + [time()] ); } } diff --git a/Library/Phalcon/Session/Adapter/Mongo.php b/Library/Phalcon/Session/Adapter/Mongo.php index 91d4129d6..07b00aaee 100644 --- a/Library/Phalcon/Session/Adapter/Mongo.php +++ b/Library/Phalcon/Session/Adapter/Mongo.php @@ -3,7 +3,7 @@ +------------------------------------------------------------------------+ | Phalcon Framework | +------------------------------------------------------------------------+ - | Copyright (c) 2011-2012 Phalcon Team (http://www.phalconphp.com) | + | Copyright (c) 2011-2016 Phalcon Team (http://www.phalconphp.com) | +------------------------------------------------------------------------+ | This source file is subject to the New BSD License that is bundled | | with this package in the file docs/LICENSE.txt. | @@ -48,12 +48,12 @@ public function __construct($options = null) } session_set_save_handler( - array($this, 'open'), - array($this, 'close'), - array($this, 'read'), - array($this, 'write'), - array($this, 'destroy'), - array($this, 'gc') + [$this, 'open'], + [$this, 'close'], + [$this, 'read'], + [$this, 'write'], + [$this, 'destroy'], + [$this, 'gc'] ); parent::__construct($options); @@ -62,11 +62,9 @@ public function __construct($options = null) /** * {@inheritdoc} * - * @param string $savePath - * @param string $name * @return boolean */ - public function open($savePath, $name) + public function open() { return true; } @@ -86,9 +84,10 @@ public function close() */ public function read($sessionId) { - $sessionData = $this->getCollection()->findOne(array('_id' => $sessionId)); + $sessionData = $this->getCollection()->findOne(['_id' => $sessionId]); + if (!isset($sessionData['data'])) { - return null; + return ''; } $this->data = $sessionData['data']; @@ -108,11 +107,11 @@ public function write($sessionId, $sessionData) return true; } - $sessionData = array( - '_id' => $sessionId, + $sessionData = [ + '_id' => $sessionId, 'modified' => new \MongoDate(), - 'data' => $sessionData - ); + 'data' => $sessionData + ]; $this->getCollection()->save($sessionData); @@ -125,30 +124,30 @@ public function write($sessionId, $sessionData) public function destroy($sessionId = null) { if (is_null($sessionId)) { - $sessionId = session_id(); + $sessionId =$this->getId(); } $this->data = null; - $remove = $this->getCollection()->remove(array('_id' => $sessionId)); + $remove = $this->getCollection()->remove(['_id' => $sessionId]); - return (bool)$remove['ok']; + return (bool) $remove['ok']; } /** * {@inheritdoc} - * @param string $maxlifetime + * @param string $maxLifetime */ - public function gc($maxlifetime) + public function gc($maxLifetime) { $minAge = new \DateTime(); - $minAge->sub(new \DateInterval('PT' . $maxlifetime . 'S')); + $minAge->sub(new \DateInterval('PT' . $maxLifetime . 'S')); $minAgeMongo = new \MongoDate($minAge->getTimestamp()); - $query = array('modified' => array('$lte' => $minAgeMongo)); + $query = ['modified' => ['$lte' => $minAgeMongo]]; $remove = $this->getCollection()->remove($query); - return (bool)$remove['ok']; + return (bool) $remove['ok']; } /** @@ -157,6 +156,7 @@ public function gc($maxlifetime) protected function getCollection() { $options = $this->getOptions(); + return $options['collection']; } } diff --git a/Library/Phalcon/Session/Adapter/README.md b/Library/Phalcon/Session/Adapter/README.md index fdf6e2fd5..5c83d5d6e 100644 --- a/Library/Phalcon/Session/Adapter/README.md +++ b/Library/Phalcon/Session/Adapter/README.md @@ -1,32 +1,69 @@ -Phalcon\Session\Adapter -======================= +# Phalcon\Session\Adapter Usage examples of the adapters available here: -Database --------- -This adapter uses a database backend to store session data: +## Aerospike + +This adapter uses an Aerospike Database to store session data. + +To use this adapter on your machine, you need at least: + +- [Aerospike Server][1] >= 3.5.3 +- [Aerospike PHP Extension][2] + +Usage: ```php +use Phalcon\Session\Adapter\Aerospike as SessionHandler; + +$di->set('session', function () { + $session = new SessionHandler([ + 'hosts' => [ + ['addr' => '127.0.0.1', 'port' => 3000] + ], + 'persistent' => true, + 'namespace' => 'test', + 'prefix' => 'session_', + 'lifetime' => 8600, + 'uniqueId' => '3Hf90KdjQ18', + 'options' => [ + \Aerospike::OPT_CONNECT_TIMEOUT => 1250, + \Aerospike::OPT_WRITE_TIMEOUT => 1500 + ] + ]); + + $session->start(); + + return $session; +}); +``` -$di->set('session', function() { - // Create a connection - $connection = new \Phalcon\Db\Adapter\Pdo\Mysql(array( - "host" => "localhost", - "username" => "root", - "password" => "secret", - "dbname" => "test" - )); +## Database - $session = new Phalcon\Session\Adapter\Database(array( - 'db' => $connection, - 'table' => 'session_data' - )); +This adapter uses a database backend to store session data: - $session->start(); +```php +use Phalcon\Db\Adapter\Pdo\Mysql; +use Phalcon\Session\Adapter\Database; - return $session; +$di->set('session', function() { + // Create a connection + $connection = new Mysql([ + 'host' => 'localhost', + 'username' => 'root', + 'password' => 'secret', + 'dbname' => 'test' + ]); + + $session = new Database([ + 'db' => $connection, + 'table' => 'session_data' + ]); + + $session->start(); + + return $session; }); ``` @@ -35,60 +72,58 @@ This adapter uses the following table to store the data: ```sql CREATE TABLE `session_data` ( - `session_id` varchar(35) NOT NULL, + `session_id` VARCHAR(35) NOT NULL, `data` text NOT NULL, - `created_at` int(15) unsigned NOT NULL, - `modified_at` int(15) unsigned DEFAULT NULL, + `created_at` INT unsigned NOT NULL, + `modified_at` INT unsigned DEFAULT NULL, PRIMARY KEY (`session_id`) -) +); ``` -Mongo ------ +## Mongo + This adapter uses a Mongo database backend to store session data: ```php +use Phalcon\Session\Adapter\Mongo as MongoSession; $di->set('session', function() { + // Create a connection to mongo + $mongo = new \Mongo(); - //Create a connection to mongo - $mongo = new Mongo(); + // Passing a collection to the adapter + $session = new MongoSession([ + 'collection' => $mongo->test->session_data + ]); - //Passing a collection to the adapter - $session = new Phalcon\Session\Adapter\Mongo(array( - 'collection' => $mongo->test->session_data - )); + $session->start(); - $session->start(); - - return $session; + return $session; }); ``` -Redis ------ +## Redis -This adapter uses a [Redis](http://redis.io) backend to store session data. -You would need a [phpredis](https://github.com/nicolasff/phpredis) extension installed to use it: +This adapter uses a [Redis][2] backend to store session data. +You would need a [phpredis][4] extension installed to use it: ```php +use Phalcon\Session\Adapter\Redis; $di->set('session', function() { + $session = new Redis([ + 'path' => 'tcp://127.0.0.1:6379?weight=1' + ]); - $session = new Phalcon\Session\Adapter\Redis(array( - 'path' => "tcp://127.0.0.1:6379?weight=1" - )); - - $session->start(); + $session->start(); - return $session; + return $session; }); ``` -HandlerSocket -------------- +## HandlerSocket This adapter uses the MySQL's plugin HandlerSocket. HandlerSocket is a NoSQL plugin for MySQL. It works as a daemon inside the mysqld process, accept tcp connections, and execute requests from clients. HandlerSocket does not support SQL queries. @@ -96,35 +131,41 @@ Instead, it supports simple CRUD operations on tables. ```sql CREATE TABLE `php_session` ( - `id` varchar(32) NOT NULL DEFAULT '', - `modified` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', - `data` text, - PRIMARY KEY (`id`), - KEY `modified` (`modified`) - ) ENGINE=InnoDB DEFAULT CHARACTER SET utf8; - ``` + `id` VARCHAR(32) NOT NULL DEFAULT '', + `modified` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00', + `data` TEXT, + PRIMARY KEY (`id`), + KEY `modified` (`modified`) +) ENGINE=InnoDB DEFAULT CHARACTER SET utf8; +``` - ```php +```php +use Phalcon\Session\Adapter\HandlerSocket; $di->set('session', function() { - - $session = new Phalcon\Session\Adapter\HandlerSocket(array( - 'cookie_path' => '/', - 'cookie_domain' => '', - 'lifetime' => 3600, - 'server' => array( - 'host' => 'localhost', - 'port' => 9999, - 'dbname' => 'session', - 'dbtable' => 'php_session' - ) - )); - - $session->start(); - - return $session; + $session = new HandlerSocket([ + 'cookie_path' => '/', + 'cookie_domain' => '', + 'lifetime' => 3600, + 'server' => [ + 'host' => 'localhost', + 'port' => 9999, + 'dbname' => 'session', + 'dbtable' => 'php_session' + ] + ]); + + $session->start(); + + return $session; }); ``` -The extension handlersocket (https://github.com/kjdev/php-ext-handlersocketi/) is required to use this adapter. +The extension [`handlersocket`][5] is required to use this adapter. + +[1]: http://www.aerospike.com/ +[2]: http://www.aerospike.com/docs/client/php/install/ +[3]: http://redis.io +[4]: https://github.com/nicolasff/phpredis +[5]: https://github.com/kjdev/php-ext-handlersocketi diff --git a/Library/Phalcon/Test/FunctionalTestCase.php b/Library/Phalcon/Test/FunctionalTestCase.php index af304142e..3b3149086 100755 --- a/Library/Phalcon/Test/FunctionalTestCase.php +++ b/Library/Phalcon/Test/FunctionalTestCase.php @@ -3,7 +3,7 @@ +------------------------------------------------------------------------+ | Phalcon Framework | +------------------------------------------------------------------------+ - | Copyright (c) 2011-2015 Phalcon Team (http://www.phalconphp.com) | + | Copyright (c) 2011-2016 Phalcon Team (http://www.phalconphp.com) | +------------------------------------------------------------------------+ | This source file is subject to the New BSD License that is bundled | | with this package in the file docs/LICENSE.txt. | diff --git a/Library/Phalcon/Test/ModelTestCase.php b/Library/Phalcon/Test/ModelTestCase.php index 853ac1791..2e3319584 100755 --- a/Library/Phalcon/Test/ModelTestCase.php +++ b/Library/Phalcon/Test/ModelTestCase.php @@ -3,7 +3,7 @@ +------------------------------------------------------------------------+ | Phalcon Framework | +------------------------------------------------------------------------+ - | Copyright (c) 2011-2015 Phalcon Team (http://www.phalconphp.com) | + | Copyright (c) 2011-2016 Phalcon Team (http://www.phalconphp.com) | +------------------------------------------------------------------------+ | This source file is subject to the New BSD License that is bundled | | with this package in the file docs/LICENSE.txt. | diff --git a/Library/Phalcon/Test/UnitTestCase.php b/Library/Phalcon/Test/UnitTestCase.php index fa5656b3b..708517664 100755 --- a/Library/Phalcon/Test/UnitTestCase.php +++ b/Library/Phalcon/Test/UnitTestCase.php @@ -3,7 +3,7 @@ +------------------------------------------------------------------------+ | Phalcon Framework | +------------------------------------------------------------------------+ - | Copyright (c) 2011-2015 Phalcon Team (http://www.phalconphp.com) | + | Copyright (c) 2011-2016 Phalcon Team (http://www.phalconphp.com) | +------------------------------------------------------------------------+ | This source file is subject to the New BSD License that is bundled | | with this package in the file docs/LICENSE.txt. | diff --git a/Library/Phalcon/Translate/Adapter/Database.php b/Library/Phalcon/Translate/Adapter/Database.php index 4f0982c57..18907d2fc 100644 --- a/Library/Phalcon/Translate/Adapter/Database.php +++ b/Library/Phalcon/Translate/Adapter/Database.php @@ -3,7 +3,7 @@ +------------------------------------------------------------------------+ | Phalcon Framework | +------------------------------------------------------------------------+ - | Copyright (c) 2011-2015 Phalcon Team (http://www.phalconphp.com) | + | Copyright (c) 2011-2016 Phalcon Team (http://www.phalconphp.com) | +------------------------------------------------------------------------+ | This source file is subject to the New BSD License that is bundled | | with this package in the file docs/LICENSE.txt. | diff --git a/Library/Phalcon/Utils/Slug.php b/Library/Phalcon/Utils/Slug.php index 30631b2a8..3c03e00cb 100644 --- a/Library/Phalcon/Utils/Slug.php +++ b/Library/Phalcon/Utils/Slug.php @@ -3,7 +3,7 @@ +------------------------------------------------------------------------+ | Phalcon Framework | +------------------------------------------------------------------------+ - | Copyright (c) 2011-2012 Phalcon Team (http://www.phalconphp.com) | + | Copyright (c) 2011-2016 Phalcon Team (http://www.phalconphp.com) | +------------------------------------------------------------------------+ | This source file is subject to the New BSD License that is bundled | | with this package in the file docs/LICENSE.txt. | @@ -34,8 +34,6 @@ class Slug /** * Creates a slug to be used for pretty URLs. * - * @link http://cubiq.org/the-perfect-php-clean-url-generator - * * @param string $string * @param array $replace * @param string $delimiter @@ -45,8 +43,8 @@ class Slug */ public static function generate($string, $replace = [], $delimiter = '-') { - if (!extension_loaded('iconv')) { - throw new Exception('iconv module not loaded'); + if (!extension_loaded('intl')) { + throw new Exception('intl module not loaded'); } // Save the old locale and set the new locale to UTF-8 @@ -59,15 +57,18 @@ public static function generate($string, $replace = [], $delimiter = '-') $string = str_replace(array_keys($replace), array_values($replace), $string); } + $transliterator = \Transliterator::create('Any-Latin; Latin-ASCII'); + $string = $transliterator->transliterate( + mb_convert_encoding(htmlspecialchars_decode($string), 'UTF-8', 'auto') + ); + // replace non letter or non digits by - $string = preg_replace('#[^\pL\d]+#u', '-', $string); // Trim trailing - $string = trim($string, '-'); - $clean = iconv('UTF-8', 'ASCII//TRANSLIT', $string); - - $clean = preg_replace('#[^a-zA-Z0-9\/_|+ -]#', '', $clean); + $clean = preg_replace('~[^-\w]+~', '', $string); $clean = strtolower($clean); $clean = preg_replace('#[\/_|+ -]+#', $delimiter, $clean); $clean = trim($clean, $delimiter); diff --git a/Library/Phalcon/Validation/Validator/Db/Uniqueness.php b/Library/Phalcon/Validation/Validator/Db/Uniqueness.php index 032d46016..397da2f52 100644 --- a/Library/Phalcon/Validation/Validator/Db/Uniqueness.php +++ b/Library/Phalcon/Validation/Validator/Db/Uniqueness.php @@ -3,7 +3,7 @@ +------------------------------------------------------------------------+ | Phalcon Framework | +------------------------------------------------------------------------+ - | Copyright (c) 2011-2015 Phalcon Team (http://www.phalconphp.com) | + | Copyright (c) 2011-2016 Phalcon Team (http://www.phalconphp.com) | +------------------------------------------------------------------------+ | This source file is subject to the New BSD License that is bundled | | with this package in the file docs/LICENSE.txt. | diff --git a/Library/Phalcon/Validation/Validator/MongoId.php b/Library/Phalcon/Validation/Validator/MongoId.php index 48188080f..736078b1b 100644 --- a/Library/Phalcon/Validation/Validator/MongoId.php +++ b/Library/Phalcon/Validation/Validator/MongoId.php @@ -3,7 +3,7 @@ +------------------------------------------------------------------------+ | Phalcon Framework | +------------------------------------------------------------------------+ - | Copyright (c) 2011-2015 Phalcon Team (http://www.phalconphp.com) | + | Copyright (c) 2011-2016 Phalcon Team (http://www.phalconphp.com) | +------------------------------------------------------------------------+ | This source file is subject to the New BSD License that is bundled | | with this package in the file docs/LICENSE.txt. | diff --git a/README.md b/README.md index ad9384362..f5abc6e2c 100644 --- a/README.md +++ b/README.md @@ -18,28 +18,28 @@ The code in this repository is written in PHP. ### Installing via Composer -Install composer in a common location or in your project: +Install Composer in a common location or in your project: ```bash curl -s http://getcomposer.org/installer | php ``` -Create the composer.json file as follows: +If you are still using Phalcon 2.0.x, create the `composer.json` file as follows: ```json { "require": { - "phalcon/incubator": "dev-master" + "phalcon/incubator": "^2.0" } } ``` -If you are still using Phalcon 1.3.x, create a composer.json with the following instead: +If you are still using Phalcon 1.3.x, create a `composer.json` with the following instead: ```json { "require": { - "phalcon/incubator": "v1.3.5" + "phalcon/incubator": "^1.3" } } ``` @@ -48,7 +48,7 @@ If you are still using Phalcon 1.3.x, create a composer.json with the following Run the composer installer: ```bash -php composer.phar install +$ php composer.phar install ``` ### Installing via GitHub @@ -81,89 +81,13 @@ $loader->registerNamespaces([ $loader->register(); ``` -## Tests +## Testing -Incubator uses [Codeception](http://codeception.com/) unit tests. - -First you need to re-generate base classes for all suites: - -```sh -$ vendor/bin/codecept build -``` - -You can execute all test with `run` command: - -```sh -$ vendor/bin/codecept run -# OR -$ vendor/bin/codecept run --debug # Detailed output -``` - -Execute test groups with `run -g ` command. - -Available groups: -* `Acl` -* `Annotation` -* `Avatar` -* `Beanstalk` -* `Cache` -* `Config` -* `DbValidation` -* `EagerLoading` -* `Http` -* `Loader` -* `MetaData` -* `Paginator` -* `Utils` -* `Validation` - -Read more about the installation and configuration of Codeception: -* [Codeception Introduction](http://codeception.com/docs/01-Introduction) -* [Codeception Console Commands](http://codeception.com/docs/reference/Commands) - -Some tests require a connection to the database. For those you need to create a test database using MySQL: -```sh -$ echo 'create database incubator_tests charset=utf8mb4 collate=utf8mb4_unicode_ci;' | mysql -u root -``` - -For these tests we use the user `root` without a password. You may need to change this in `codeception.yml` file. - -Obviously, Beanstalk-tests use Beanstalk and Memcached-tests use Memcached. - -We use the following settings of these services: - -**Beanstalk** -+ Host: `127.0.0.1` -+ Port: `11300` - -**Memcached** -+ Host: `127.0.0.1` -+ Port: `11211` - -You can change the connection settings of these services **before** running tests -by using [environment variables](https://wiki.archlinux.org/index.php/Environment_variables): -```sh -# Beanstalk -export TEST_BT_HOST="127.0.0.1" -export TEST_BT_PORT="11300" - -# Memcached -export TEST_MC_HOST="127.0.0.1" -export TEST_MC_PORT="11211" -``` - -If you cannot run the tests, please refer to the `.travis.yml` file for more instructions how we test Incubator. -For detailed information on our testing environment setting refer to `tests/_bootstrap.php` file. - -## The testing process - -Incubator is built under [Travis CI](https://travis-ci.org/) service. -Every commit pushed to this repository will queue a build into the continuous integration service and will run all tests -to ensure that everything is going well and the project is stable. +See [TESTING.md](docs/TESTING.md) # Contributing -See [CONTRIBUTING.md](CONTRIBUTING.md) +See [CONTRIBUTING.md](docs/CONTRIBUTING.md) ## Contributions Index @@ -177,10 +101,11 @@ See [CONTRIBUTING.md](CONTRIBUTING.md) * [Phalcon\Annotations\Adapter\Memcached](Library/Phalcon/Annotations/Adapter) - Memcached adapter for storing annotations (@igusev) ### Behaviors -* [Phalcon\Mvc\Model\Behavior\Blameable](Library/Phalcon/Mvc/Model/Behavior) - logs with every created or updated row in your database who created and who updated it (@phalcon) +* [Phalcon\Mvc\Model\Behavior\Blameable](Library/Phalcon/Mvc/Model/Behavior) - logs with every created or updated row in your database who created and who updated it (@phalcon) * [Phalcon\Mvc\Model\Behavior\NestedSet](Library/Phalcon/Mvc/Model/Behavior) - Nested Set behavior for models (@braska) ### Cache +* [Phalcon\Cache\Backend\Aerospike](Library/Phalcon/Cache/Backend) - Aerospike backend for caching data (@sergeyklay) * [Phalcon\Cache\Backend\Database](Library/Phalcon/Cache/Backend) - Database backend for caching data (@phalcon) * [Phalcon\Cache\Backend\Wincache](Library/Phalcon/Cache/Backend) - Wincache backend for caching data (@nazwa) @@ -195,9 +120,13 @@ See [CONTRIBUTING.md](CONTRIBUTING.md) * [Phalcon\Db\Adapter\Cacheable\Mysql](Library/Phalcon/Db) - MySQL adapter that aggressively caches all the queries executed (@phalcon) * [Phalcon\Db\Adapter\Factory](Library/Phalcon/Db/Adapter/Factory.php) - Phalcon DB adapters Factory (@Kachit) +### Http +* [Phalcon\Http](Library/Phalcon/Http) - Uri utility (@tugrul) +* [Phalcon\Http\Client](Library/Phalcon/Http\Client) - Http Request and Response (@tugrul) + ### Loader * [Phalcon\Loader\Extended](Library/Phalcon/Loader/Extended.php) - This component extends `Phalcon\Loader` and added ability to set multiple directories per namespace (@sergeyklay) -* [Phalcon\Loader\PSR](Library/Phalcon/Loader/PSR.php) - Implements PSR-0 autoloader for your apps (!Piyush) +* [Phalcon\Loader\PSR](Library/Phalcon/Loader/PSR.php) - Implements PSR-0 autoloader for your apps (@Piyush) ### Logger * [Phalcon\Logger\Adapter\Database](Library/Phalcon/Logger) - Adapter to store logs in a database table (!phalcon) @@ -215,7 +144,7 @@ See [CONTRIBUTING.md](CONTRIBUTING.md) ### ORM Validators * [Phalcon\Mvc\Model\Validator\ConfirmationOf](Library/Phalcon/Mvc/Model/Validator) - Allows to validate if a field has a confirmation field with the same value (@suxxes) * [Phalcon\Mvc\Model\Validator\CardNumber](Library/Phalcon/Mvc/Model/Validator) - Allows to validate credit card number using Luhn algorithm (@parshikov) -* [Phalcon\Mvc\Model\Validator\Decimal](Library/Phalcon/Mvc/Model/Validator) - Allows to validate if a field has a valid number in proper decimal format (negative and decimal numbers allowed) (@sergeyklay) +* [Phalcon\Mvc\Model\Validator\Decimal](Library/Phalcon/Mvc/Model/Validator) - Allows to validate if a field has a valid number in proper decimal format (negative and decimal numbers allowed) (@sergeyklay) * [Phalcon\Mvc\Model\Validator\Between](Library/Phalcon/Mvc/Model/Validator) - Validates that a value is between a range of two values (@sergeyklay) ### Error Handling @@ -235,6 +164,7 @@ See [CONTRIBUTING.md](CONTRIBUTING.md) * [Phalcon\Translate\Adapter\ResourceBundle](Library/Phalcon/Translate/Adapter) - Translation adapter using ResourceBundle (@phalcon) ### Session +* [Phalcon\Session\Adapter\Aerospike](Library/Phalcon/Session/Adapter) - Aerospike adapter for storing sessions (@sergeyklay) * [Phalcon\Session\Adapter\Database](Library/Phalcon/Session/Adapter) - Database adapter for storing sessions (@phalcon) * [Phalcon\Session\Adapter\Mongo](Library/Phalcon/Session/Adapter) - MongoDb adapter for storing sessions (@phalcon) * [Phalcon\Session\Adapter\HandlerSocket](Library/Phalcon/Session/Adapter) - HandlerSocket adapter for storing sessions (@Xrymz) diff --git a/codeception.yml b/codeception.yml index f1c84493b..b5aaae614 100644 --- a/codeception.yml +++ b/codeception.yml @@ -1,5 +1,6 @@ # can be changed while bootstrapping project actor: Tester + paths: # where the modules stored tests: tests @@ -9,6 +10,7 @@ paths: # directory for custom modules (helpers) support: tests/_support envs: tests/_envs + settings: # name of bootstrap that will be used # each bootstrap file should be @@ -18,6 +20,7 @@ settings: # Tests (especially functional) can take a lot of memory # We set a high limit for them by default. memory_limit: 1024M + coverage: enabled: true whitelist: @@ -27,16 +30,3 @@ coverage: extensions: enabled: - Codeception\Extension\RunFailed - -# Global modules configuration. -modules: - config: - Db: - dsn: 'mysql:host=localhost;dbname=incubator_tests' - user: 'root' - password: '' - dump: tests/_data/dump.sql - populate: true - cleanup: false - -error_level: "E_ALL | E_STRICT" diff --git a/composer.json b/composer.json index ca90c36f1..1e16ed3ac 100644 --- a/composer.json +++ b/composer.json @@ -11,26 +11,32 @@ "email": "team@phalconphp.com" } ], + "support": { + "issues": "https://github.com/phalcon/incubator/issues", + "source": "https://github.com/phalcon/incubator", + "forum": "https://forum.phalconphp.com/" + }, "require": { "php": ">=5.4", "ext-phalcon": ">=2.0.4", - "swiftmailer/swiftmailer": "~5.2", - "duncan3dc/fork-helper": "*" + "swiftmailer/swiftmailer": "~5.2" }, "require-dev": { - "phpunit/phpunit": "4.*", - "squizlabs/php_codesniffer": "2.*", - "codeception/codeception": "2.*", - "mockery/mockery": "*", - "php-mock/php-mock": "*" + "squizlabs/php_codesniffer": "^2.5", + "codeception/codeception": "^2.1", + "codeception/mockery-module": "^0.2", + "codeception/aerospike-module": "^0.1" }, "suggest": { - "duncan3dc/fork-helper": "Allows using Phalcon\\Queue\\Beanstalk\\Extended" + "ext-aerospike": "*", + "duncan3dc/fork-helper": "To use extended class to access the beanstalk queue service" }, "autoload": { "psr-4": { "Phalcon\\": "Library/Phalcon/" } }, "autoload-dev": { - "psr-4": { "Phalcon\\Test\\": "tests/unit/" } + "psr-4": { + "Phalcon\\Test\\": "tests/unit/" + } } } diff --git a/CONTRIBUTING.md b/docs/CONTRIBUTING.md similarity index 100% rename from CONTRIBUTING.md rename to docs/CONTRIBUTING.md diff --git a/docs/LICENSE.md b/docs/LICENSE.md index c0ea4062c..61e91a18d 100644 --- a/docs/LICENSE.md +++ b/docs/LICENSE.md @@ -2,7 +2,7 @@ New BSD License =============== -Copyright (c) 2011-2015, Phalcon Framework Team +Copyright (c) 2011-2016, Phalcon Framework Team All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: diff --git a/docs/LICENSE.txt b/docs/LICENSE.txt index e410b384b..25d9aec89 100644 --- a/docs/LICENSE.txt +++ b/docs/LICENSE.txt @@ -1,6 +1,6 @@ New BSD License -Copyright (c) 2011-2015, Phalcon Framework Team +Copyright (c) 2011-2016, Phalcon Framework Team All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/docs/TESTING.md b/docs/TESTING.md new file mode 100644 index 000000000..8b131915f --- /dev/null +++ b/docs/TESTING.md @@ -0,0 +1,123 @@ +# Phalcon Incubator Testing + +Thanks for reading this page, [test](tests) folder includes all the unit tests +we used to be sure that Phalcon Incubator will run properly and have a stable state. + +The main dependency is [Codeception][1] which can be installed using Composer: + +```sh +# run this command from project root +$ composer install --dev --prefer-source +``` + +A MySQL database is also required for several tests. Follow these instructions to create the database: + +```sh +$ echo 'create database incubator_tests charset=utf8mb4 collate=utf8mb4_unicode_ci;' | mysql -u root +cat tests/_data/dump.sql | mysql incubator_tests -u root +``` + +Then you need to re-generate base classes for all suites: + +```sh +$ vendor/bin/codecept build +``` + +You can execute all test with `run` command: + +```sh +$ vendor/bin/codecept run +# OR +$ vendor/bin/codecept run --debug # Detailed output +``` + +For these tests we use the user `root` without a password. You may need to change this in `codeception.yml` file. + +Obviously, Beanstalk-tests use Beanstalk, Memcached-tests use Memcached, Aerospike-tests use Aerospike, etc. + +We use the following settings of these services: + +**Beanstalk** ++ Host: `127.0.0.1` ++ Port: `11300` + +**Memcached** ++ Host: `127.0.0.1` ++ Port: `11211` + +**Aerospike** ++ Host: `127.0.0.1` ++ Port: `3000` + +**Database** (MySQL) ++ Host: `127.0.0.1` ++ Port: `3306` ++ Username: `root` ++ Password: `''` _(empty string)_ ++ DB Name: `incubator_tests` ++ Charset: `urf8` + +You can change the connection settings of these services **before** running tests +by using [environment variables][4]: +```sh +# Beanstalk +export TEST_BT_HOST="127.0.0.1" +export TEST_BT_PORT="11300" + +# Memcached +export TEST_MC_HOST="127.0.0.1" +export TEST_MC_PORT="11211" + +# Aerospike +export TEST_AS_HOST="127.0.0.1" +export TEST_AS_PORT="3000" + +# Database +export TEST_DB_HOST="127.0.0.1" +export TEST_DB_PORT="3306" +export TEST_DB_USER="root" +export TEST_DB_PASSWD="" +export TEST_DB_NAME="incubator_tests" +export TEST_DB_CHARSET="urf8" +``` + +Execute test groups with `run -g ` command. + +Available groups: +* `Acl` +* `aerospike` +* `Annotation` +* `Avatar` +* `db` +* `Beanstalk` +* `Cache` +* `Config` +* `DbValidation` +* `EagerLoading` +* `Http` +* `Loader` +* `MetaData` +* `Paginator` +* `Session` +* `utils` +* `Validation` + +Read more about the installation and configuration of Codeception: +* [Codeception Introduction][2] +* [Codeception Console Commands][3] + +Additionally, the file `.travis.yml` contains full instructions to test Phalcon Incubator on Ubuntu 12+ +If you cannot run the tests, please refer to the `.travis.yml` file for more instructions how we test Incubator. +For detailed information on our testing environment setting refer to `tests/_bootstrap.php` file. + +## The testing process + +Incubator is built under [Travis CI][5] service. +Every commit pushed to this repository will queue a build into the continuous integration service and will run all tests +to ensure that everything is going well and the project is stable. + +[1]: http://codeception.com/ +[2]: http://codeception.com/docs/01-Introduction +[3]: http://codeception.com/docs/reference/Commands +[4]: https://wiki.archlinux.org/index.php/Environment_variables +[5]: https://travis-ci.org/ diff --git a/tests/_bootstrap.php b/tests/_bootstrap.php index 05080d152..d0d93bde5 100644 --- a/tests/_bootstrap.php +++ b/tests/_bootstrap.php @@ -1,7 +1,6 @@ * @package Phalcon\Test\Acl\Adapter diff --git a/tests/unit/Acl/Factory/MemoryTest.php b/tests/unit/Acl/Factory/MemoryTest.php index eb55b77c4..50b98fdc4 100644 --- a/tests/unit/Acl/Factory/MemoryTest.php +++ b/tests/unit/Acl/Factory/MemoryTest.php @@ -14,7 +14,7 @@ * \Phalcon\Test\Acl\Factory\MemoryTest * Tests for Phalcon\Acl\Factory\Memory component * - * @copyright (c) 2011-2015 Phalcon Team + * @copyright (c) 2011-2016 Phalcon Team * @link http://www.phalconphp.com * @author Nemanja Ognjanovic * @package Phalcon\Test\Acl\Factory diff --git a/tests/unit/Annotations/Adapter/BaseTest.php b/tests/unit/Annotations/Adapter/BaseTest.php index b715b7a5a..302ef5c50 100644 --- a/tests/unit/Annotations/Adapter/BaseTest.php +++ b/tests/unit/Annotations/Adapter/BaseTest.php @@ -12,7 +12,7 @@ * \Phalcon\Test\Annotations\Adapter\BaseTest * Tests for Phalcon\Annotations\Adapter\Base component * - * @copyright (c) 2011-2015 Phalcon Team + * @copyright (c) 2011-2016 Phalcon Team * @author Ilya Gusev * @link http://phalconphp.com/ * @package Phalcon\Test\Annotations\Adapter diff --git a/tests/unit/Annotations/Adapter/MemcachedTest.php b/tests/unit/Annotations/Adapter/MemcachedTest.php index 9b0570951..94a9f8849 100644 --- a/tests/unit/Annotations/Adapter/MemcachedTest.php +++ b/tests/unit/Annotations/Adapter/MemcachedTest.php @@ -13,7 +13,7 @@ * \Phalcon\Test\Annotations\Adapter\MemcachedTest * Tests for Phalcon\Annotations\Adapter\Memcached component * - * @copyright (c) 2011-2015 Phalcon Team + * @copyright (c) 2011-2016 Phalcon Team * @author Ilya Gusev * @link http://phalconphp.com/ * @package Phalcon\Test\Annotations\Adapter diff --git a/tests/unit/Avatar/GravatarTest.php b/tests/unit/Avatar/GravatarTest.php index dd5558789..d3165925b 100644 --- a/tests/unit/Avatar/GravatarTest.php +++ b/tests/unit/Avatar/GravatarTest.php @@ -11,7 +11,7 @@ * \Phalcon\Test\Avatar\GravatarTest * Tests for Phalcon\Avatar\Gravatar component * - * @copyright (c) 2011-2015 Phalcon Team + * @copyright (c) 2011-2016 Phalcon Team * @author Serghei Iakovlev * @link http://phalconphp.com/ * @package Phalcon\Test\Avatar diff --git a/tests/unit/Cache/Backend/AerospikeTest.php b/tests/unit/Cache/Backend/AerospikeTest.php new file mode 100644 index 000000000..03e3bd102 --- /dev/null +++ b/tests/unit/Cache/Backend/AerospikeTest.php @@ -0,0 +1,216 @@ + + * @package Phalcon\Test\Cache\Backend + * @group aerospike + * + * The contents of this file are subject to the New BSD License that is + * bundled with this package in the file docs/LICENSE.txt + * + * If you did not receive a copy of the license and are unable to obtain it + * through the world-wide-web, please send an email to license@phalconphp.com + * so that we can send you a copy immediately. + */ +class AerospikeTest extends Test +{ + /** + * UnitTester Object + * @var UnitTester + */ + protected $tester; + + protected $keys = []; + + /** + * executed before each test + */ + protected function _before() + { + if (!extension_loaded('aerospike')) { + $this->markTestSkipped( + 'The aerospike module is not available.' + ); + } else { + $this->getModule('Aerospike')->_reconfigure(['set' => 'cache']); + } + } + + /** + * executed after each test + */ + protected function _after() + { + $this->cleanup(); + } + + public function testShouldGetAerospikeInstance() + { + $this->assertInstanceOf('\Aerospike', $this->getAdapter()->getDb()); + } + + /** + * @expectedException \Phalcon\Cache\Exception + * @expectedExceptionMessage The cache must be started first + */ + public function testShouldThrowExceptionIfCacheIsNotStarted() + { + $this->getAdapter()->save(); + } + + public function testShouldIncrementValue() + { + $cache = $this->getAdapter(); + $this->tester->haveInAerospike('increment', 1); + + $this->assertEquals(2, $cache->increment('increment')); + $this->assertEquals(4, $cache->increment('increment', 2)); + $this->assertEquals(14, $cache->increment('increment', 10)); + } + + public function testShouldDecrementValue() + { + $cache = $this->getAdapter(); + $this->tester->haveInAerospike('decrement', 100); + + $this->assertEquals(99, $cache->decrement('decrement')); + $this->assertEquals(97, $cache->decrement('decrement', 2)); + $this->assertEquals(87, $cache->decrement('decrement', 10)); + } + + public function testShouldGetKeys() + { + $cache = $this->getAdapter(null); + $this->assertEquals(0, count($cache->queryKeys())); + + $cache->save('a', 1, 10); + $cache->save('long-key', 'long-val', 10); + $cache->save('bcd', 3, 10); + + $this->keys[] = 'a'; + $this->keys[] = 'long-key'; + $this->keys[] = 'bcd'; + + $keys = $cache->queryKeys(); + sort($keys); + + $this->assertEquals(['a', 'bcd', 'long-key'], $keys); + $this->assertEquals(['long-key'], $cache->queryKeys('long')); + } + + public function testShouldSaveData() + { + $cache = $this->getAdapter(); + $this->keys[] = 'test-data'; + + $data = [1, 2, 3, 4, 5]; + $cache->save('test-data', $data); + $this->tester->seeInAerospike('test-data', serialize($data)); + + $data = "sure, nothing interesting"; + $cache->save('test-data', $data); + $this->tester->seeInAerospike('test-data', serialize($data)); + } + + public function testShouldDeleteData() + { + $cache = $this->getAdapter(); + $this->keys[] = 'test-data'; + + $data = rand(0, 99); + $this->tester->haveInAerospike('test-data', $data); + + $this->assertTrue($cache->delete('test-data')); + $this->tester->dontSeeInAerospike('test-data'); + } + + public function testShouldUseOutputFrontend() + { + $time = date('H:i:s'); + + $frontCache = new CacheOutput(['lifetime' => 10]); + $cache = new CacheAerospike($frontCache, $this->getConfig()); + + ob_start(); + + $content = $cache->start('test-output'); + $this->keys[] = 'test-output'; + $this->assertNull($content); + + echo $time; + + $obContent = ob_get_contents(); + $cache->save(null, null, null, true); + + ob_end_clean(); + + $this->assertEquals($time, $obContent); + $this->assertEquals($time, $cache->get('test-output')); + + $content = $cache->start('test-output'); + + $this->assertEquals($content, $obContent); + $this->assertEquals($content, $cache->get('test-output')); + + $keys = $cache->queryKeys(); + $this->assertEquals([0 => 'test-output'], $keys); + } + + private function getAdapter($lifetime = 20) + { + if ($lifetime) { + $frontCache = new CacheData(['lifetime' => $lifetime]); + } else { + $frontCache = new CacheData; + } + + $cache = new CacheAerospike($frontCache, $this->getConfig()); + + return $cache; + } + + private function getConfig() + { + return [ + 'hosts' => [ + ['addr' => TEST_AS_HOST, 'port' => TEST_AS_PORT] + ], + 'persistent' => false, // important + 'namespace' => 'test', + 'prefix' => '' + ]; + } + + private function cleanup() + { + $aerospike = new Aerospike(['hosts' => [['addr' => TEST_AS_HOST, 'port' => TEST_AS_PORT]]], false); + + foreach ($this->keys as $i => $key) { + $aerospike->remove($this->buildKey($aerospike, $key)); + unset($this->keys[$i]); + } + } + + private function buildKey(Aerospike $aerospike, $key) + { + return $aerospike->initKey( + 'test', + 'cache', + $key + ); + } +} diff --git a/tests/unit/Cache/Backend/DatabaseTest.php b/tests/unit/Cache/Backend/DatabaseTest.php index d7cbadc5a..9d827294d 100644 --- a/tests/unit/Cache/Backend/DatabaseTest.php +++ b/tests/unit/Cache/Backend/DatabaseTest.php @@ -4,7 +4,7 @@ use Phalcon\Cache\Backend\Database as CacheBackend; use Phalcon\Cache\Frontend\Data as CacheFrontend; -use Phalcon\Db\Adapter\Pdo\Sqlite as DbAdapter; +use Phalcon\Db\Adapter\Pdo\Mysql as DbAdapter; use Codeception\TestCase\Test; use UnitTester; @@ -12,11 +12,11 @@ * \Phalcon\Test\Cache\Backend\DatabaseTest * Tests for Phalcon\Cache\Backend\Database component * - * @copyright (c) 2011-2015 Phalcon Team + * @copyright (c) 2011-2016 Phalcon Team * @link http://www.phalconphp.com * @author Nikita Vershinin * @package Phalcon\Test\Cache\Backend - * @group Cache + * @group db * * The contents of this file are subject to the New BSD License that is * bundled with this package in the file docs/LICENSE.txt @@ -50,6 +50,31 @@ protected function _after() { } + /** + * @dataProvider incorrectDbProvider + * @expectedException \Phalcon\Cache\Exception + * @expectedExceptionMessage Parameter "db" is required and it must be an instance of Phalcon\Acl\AdapterInterface + * @param array $options + */ + public function testShouldThrowExceptionIfDbIsMissingOrInvalid($options) + { + new CacheBackend(new CacheFrontend, $options); + } + + public function incorrectDbProvider() + { + return [ + [['abc' => '']], + [['db' => null]], + [['db' => true]], + [['db' => __CLASS__]], + [['db' => new \stdClass()]], + [['db' => []]], + [['db' => microtime(true)]], + [['db' => PHP_INT_MAX]], + ]; + } + public function testPrefixed() { $backend = $this->getBackend('pre_'); @@ -69,11 +94,15 @@ public function testNotPrefixed() protected function getBackend($prefix = '') { $frontend = new CacheFrontend(['lifetime' => 10]); - $connection = new DbAdapter(['dbname' => ':memory:']); - - // Make table structure - $connection->getInternalHandler()->exec( - 'CREATE TABLE "cache_data" ("key_name" TEXT PRIMARY KEY, "data" TEXT, "lifetime" INTEGER)' + $connection = new DbAdapter( + [ + 'host' => TEST_DB_HOST, + 'username' => TEST_DB_USER, + 'password' => TEST_DB_PASSWD, + 'dbname' => TEST_DB_NAME, + 'charset' => TEST_DB_CHARSET, + 'port' => TEST_DB_PORT, + ] ); return new CacheBackend($frontend, [ diff --git a/tests/unit/Config/LoaderTest.php b/tests/unit/Config/LoaderTest.php index 0c0c4d432..3cb5b7b04 100644 --- a/tests/unit/Config/LoaderTest.php +++ b/tests/unit/Config/LoaderTest.php @@ -10,7 +10,7 @@ * \Phalcon\Test\Config\LoaderTest * Tests for Phalcon\Config\Loader component * - * @copyright (c) 2011-2015 Phalcon Team + * @copyright (c) 2011-2016 Phalcon Team * @link http://www.phalconphp.com * @author Anton Kornilov * @package Phalcon\Test\Config diff --git a/tests/unit/Db/Adapter/FactoryTest.php b/tests/unit/Db/Adapter/FactoryTest.php index 449325c67..61c536198 100644 --- a/tests/unit/Db/Adapter/FactoryTest.php +++ b/tests/unit/Db/Adapter/FactoryTest.php @@ -10,11 +10,11 @@ * \Phalcon\Test\Db\Adapter\Factory * Tests for Phalcon\Db\Adapter\Factory component * - * @copyright (c) 2011-2015 Phalcon Team + * @copyright (c) 2011-2016 Phalcon Team * @link http://www.phalconphp.com * @author Anton Kornilov * @package Phalcon\Test\Db\Adapter - * @group Db + * @group db * * The contents of this file are subject to the New BSD License that is * bundled with this package in the file docs/LICENSE.txt @@ -43,11 +43,11 @@ protected function _before() { $this->testable = [ 'adapter' => null, - 'host' => 'localhost', - 'username' => 'root', - 'password' => '', - 'dbname' => 'incubator_tests', - 'charset' => 'utf8', + 'host' => TEST_DB_HOST, + 'username' => TEST_DB_USER, + 'password' => TEST_DB_PASSWD, + 'dbname' => TEST_DB_NAME, + 'charset' => TEST_DB_CHARSET, ]; } diff --git a/tests/unit/Http/Client/HeaderTest.php b/tests/unit/Http/Client/HeaderTest.php index bb53213d9..a08f6fd24 100644 --- a/tests/unit/Http/Client/HeaderTest.php +++ b/tests/unit/Http/Client/HeaderTest.php @@ -10,7 +10,7 @@ * \Phalcon\Tests\Http\Client\HeaderTest * Tests for Phalcon\Http\Client\Header * - * @copyright (c) 2011-2015 Phalcon Team + * @copyright (c) 2011-2016 Phalcon Team * @link http://www.phalconphp.com * @author Ruslan Khaibullin * @package Phalcon\Http\Client\Header diff --git a/tests/unit/Loader/ExtendedTest.php b/tests/unit/Loader/ExtendedTest.php index 3f287c84a..7dc520f41 100644 --- a/tests/unit/Loader/ExtendedTest.php +++ b/tests/unit/Loader/ExtendedTest.php @@ -10,7 +10,7 @@ * \Phalcon\Test\Loader\ExtendedTest * Tests the Phalcon\Loader\Extended component * - * @copyright (c) 2011-2015 Phalcon Team + * @copyright (c) 2011-2016 Phalcon Team * @link http://www.phalconphp.com * @author Serghei Iakovlev * @package Phalcon\Loader diff --git a/tests/unit/Loader/PSRTest.php b/tests/unit/Loader/PSRTest.php index 6ec115ce2..0cb1e5e67 100644 --- a/tests/unit/Loader/PSRTest.php +++ b/tests/unit/Loader/PSRTest.php @@ -12,7 +12,7 @@ * \Phalcon\Test\Loader\PSRTest * Tests the Phalcon\Loader\PSR component * - * @copyright (c) 2011-2015 Phalcon Team + * @copyright (c) 2011-2016 Phalcon Team * @link http://www.phalconphp.com * @author Serghei Iakovlev * @package Phalcon\Loader diff --git a/tests/unit/Mvc/Model/EagerLoading/EagerLoadingTest.php b/tests/unit/Mvc/Model/EagerLoading/EagerLoadingTest.php index 103c46f31..2cc7b32a7 100644 --- a/tests/unit/Mvc/Model/EagerLoading/EagerLoadingTest.php +++ b/tests/unit/Mvc/Model/EagerLoading/EagerLoadingTest.php @@ -21,7 +21,7 @@ * \Phalcon\Test\Mvc\Model\EagerLoading\EagerLoadingTest * Tests for Phalcon\Mvc\Model\EagerLoading\Loader component * - * @copyright (c) 2011-2015 Phalcon Team + * @copyright (c) 2011-2016 Phalcon Team * @link http://www.phalconphp.com * @author Óscar Enríquez * @package Phalcon\Test\Mvc\Model\EagerLoading diff --git a/tests/unit/Mvc/Model/MetaData/BaseTest.php b/tests/unit/Mvc/Model/MetaData/BaseTest.php index d66e6c09f..ba92ca9d0 100644 --- a/tests/unit/Mvc/Model/MetaData/BaseTest.php +++ b/tests/unit/Mvc/Model/MetaData/BaseTest.php @@ -10,7 +10,7 @@ * \Phalcon\Test\Mvc\Model\MetaData\BaseTest * Tests for Phalcon\Mvc\Model\MetaData\Base component * - * @copyright (c) 2011-2015 Phalcon Team + * @copyright (c) 2011-2016 Phalcon Team * @link http://www.phalconphp.com * @author Nemanja Ognjanovic * @package Phalcon\Test\Mvc\Model\MetaData @@ -43,7 +43,6 @@ protected function _before() */ protected function _after() { - Mockery::close(); } public function testBaseMetaDataAdapterImplementsMetaDataInterface() diff --git a/tests/unit/Mvc/Model/Validator/BetweenTest.php b/tests/unit/Mvc/Model/Validator/BetweenTest.php index fd5aed81b..b8757abe8 100644 --- a/tests/unit/Mvc/Model/Validator/BetweenTest.php +++ b/tests/unit/Mvc/Model/Validator/BetweenTest.php @@ -14,7 +14,7 @@ * \Phalcon\Test\Mvc\Model\Validator\BetweenTest * Tests for Phalcon\Mvc\Model\Validator\Between component * - * @copyright (c) 2011-2015 Phalcon Team + * @copyright (c) 2011-2016 Phalcon Team * @link http://www.phalconphp.com * @author Ilya Gusev * @package Phalcon\Test\Mvc\Model\Validator diff --git a/tests/unit/Mvc/Model/Validator/CardNumberTest.php b/tests/unit/Mvc/Model/Validator/CardNumberTest.php index f91d674c1..5b6e2891f 100644 --- a/tests/unit/Mvc/Model/Validator/CardNumberTest.php +++ b/tests/unit/Mvc/Model/Validator/CardNumberTest.php @@ -16,7 +16,7 @@ * \Phalcon\Test\Mvc\Model\Validator\CardNumberTest * Tests for Phalcon\Mvc\Model\Validator\CardNumber component * - * @copyright (c) 2011-2015 Phalcon Team + * @copyright (c) 2011-2016 Phalcon Team * @link http://www.phalconphp.com * @author Ilya Gusev * @package Phalcon\Test\Mvc\Model\Validator diff --git a/tests/unit/Mvc/Model/Validator/DecimalTest.php b/tests/unit/Mvc/Model/Validator/DecimalTest.php index 1d2f5163f..4c2192aff 100644 --- a/tests/unit/Mvc/Model/Validator/DecimalTest.php +++ b/tests/unit/Mvc/Model/Validator/DecimalTest.php @@ -13,7 +13,7 @@ * \Phalcon\Test\Mvc\Model\Validator\CardNumberTest * Tests for Phalcon\Mvc\Model\Validator\CardNumber component * - * @copyright (c) 2011-2015 Phalcon Team + * @copyright (c) 2011-2016 Phalcon Team * @link http://www.phalconphp.com * @author Nikita Vershinin * @package Phalcon\Test\Mvc\Model\Validator diff --git a/tests/unit/Paginator/PagerTest.php b/tests/unit/Paginator/PagerTest.php index 9348eeb08..3bb1edf05 100644 --- a/tests/unit/Paginator/PagerTest.php +++ b/tests/unit/Paginator/PagerTest.php @@ -12,7 +12,7 @@ * \Phalcon\Tests\Paginator\PagerTest * Tests the Phalcon\Paginator\Pager component * - * @copyright (c) 2011-2015 Phalcon Team + * @copyright (c) 2011-2016 Phalcon Team * @link http://www.phalconphp.com * @author Nikita Vershinin * @package Phalcon\Tests\Paginator @@ -47,7 +47,6 @@ protected function _before() */ protected function _after() { - Mockery::close(); } public function testCreatingPagerObjectWithoutOptionsShouldConstructObject() diff --git a/tests/unit/Queue/Beanstalk/ExtendedTest.php b/tests/unit/Queue/Beanstalk/ExtendedTest.php index 206712ffd..295475dd5 100644 --- a/tests/unit/Queue/Beanstalk/ExtendedTest.php +++ b/tests/unit/Queue/Beanstalk/ExtendedTest.php @@ -1,17 +1,16 @@ * @package Phalcon\Tests\Queue\Beanstalk @@ -79,11 +78,15 @@ protected function _after() public function testShouldPutAndReserve() { - $this->client->putInTube(self::TUBE_NAME, 'testPutInTube'); + $jobId = $this->client->putInTube(self::TUBE_NAME, 'testPutInTube'); + + $this->assertNotEquals(false, $jobId); + $job = $this->client->reserveFromTube(self::TUBE_NAME); $this->assertNotEmpty($job); $this->assertInstanceOf(self::JOB_CLASS, $job); + $this->assertEquals($jobId, $job->getId()); $this->assertTrue($job->delete()); } @@ -96,6 +99,23 @@ public function testShouldGetTubes() $this->assertNotEmpty($tubes); $this->assertContains(self::TUBE_NAME, $tubes); + + // Cleanup tubes + foreach ($tubes as $tube) { + $isRunning = true; + + $this->client->watch($tube); + + do { + $job = $this->client->reserve(0.1); + + if ($job) { + $this->assertTrue($job->delete()); + } else { + $isRunning = false; + } + } while ($isRunning); + } } /** @@ -111,28 +131,50 @@ public function testShouldDoWork() )); } + $memory = shmop_open($this->shmKey, 'c', 0644, $this->shmLimit); + + if (false === $memory) { + $this->markTestSkipped('Cannot create shared memory block'); + } else { + shmop_close($memory); + } + $expected = [ 'test-tube-1' => '1', 'test-tube-2' => '2', ]; - foreach ($expected as $tube => $value) { - $this->client->addWorker($tube, function (Job $job) { - // Store string "test-tube-%JOB_BODY%" in shared memory - $memory = shmop_open($this->shmKey, 'c', 0644, $this->shmLimit); - $output = trim(shmop_read($memory, 0, $this->shmLimit)); - $output .= sprintf("\ntest-tube-%s", $job->getBody()); + $fork = new \duncan3dc\Helpers\Fork(); + $fork->call(function () use ($expected) { + foreach ($expected as $tube => $value) { + $this->client->addWorker($tube, function (Job $job) { + // Store string "test-tube-%JOB_BODY%" in a shared memory + $memory = shmop_open($this->shmKey, 'c', 0644, $this->shmLimit); + $output = trim(shmop_read($memory, 0, $this->shmLimit)); + $output .= sprintf("\ntest-tube-%s", $job->getBody()); - shmop_write($memory, $output, 0); - shmop_close($memory); + shmop_write($memory, $output, 0); + shmop_close($memory); - exit(1); - }); + throw new \RuntimeException('Forced exception to stop worker'); + }); - $this->client->putInTube($tube, $value); - } + $this->assertNotEquals(false, $this->client->putInTube($tube, $value)); + } + + $this->client->doWork(); + + exit(0); + }); - $this->client->doWork(); + $reflectionFork = new \ReflectionClass($fork); + $reflectionThreads = $reflectionFork->getProperty('threads'); + $reflectionThreads->setAccessible(true); + + sleep(2); + + $reflectionThreads->setValue($fork, []); + unset($fork); $memory = shmop_open($this->shmKey, 'a', 0, 0); $output = shmop_read($memory, 0, $this->shmLimit); @@ -142,10 +184,13 @@ public function testShouldDoWork() $this->assertNotEmpty($output); + $actual = explode("\n", trim($output)); + // Compare number of items in expected list with lines in shared memory - $this->assertEquals( - count($expected), - count(array_unique(explode("\n", trim($output)))) - ); + $this->assertEquals(count($expected), count($actual)); + + foreach ($actual as $value) { + $this->assertArrayHasKey($value, $expected); + } } } diff --git a/tests/unit/Session/Adapter/AerospikeTest.php b/tests/unit/Session/Adapter/AerospikeTest.php new file mode 100644 index 000000000..9a60f86d1 --- /dev/null +++ b/tests/unit/Session/Adapter/AerospikeTest.php @@ -0,0 +1,150 @@ + + * @package Phalcon\Test\Session\Adapter + * @group aerospike + * + * The contents of this file are subject to the New BSD License that is + * bundled with this package in the file docs/LICENSE.txt + * + * If you did not receive a copy of the license and are unable to obtain it + * through the world-wide-web, please send an email to license@phalconphp.com + * so that we can send you a copy immediately. + */ +class AerospikeTest extends Test +{ + /** + * UnitTester Object + * @var UnitTester + */ + protected $tester; + + protected $keys = []; + + /** + * executed before each test + */ + protected function _before() + { + if (!extension_loaded('aerospike')) { + $this->markTestSkipped( + 'The aerospike module is not available.' + ); + } else { + $this->getModule('Aerospike')->_reconfigure(['set' => 'session']); + } + } + + /** + * executed after each test + */ + protected function _after() + { + $this->cleanup(); + } + + private function getConfig() + { + return [ + 'hosts' => [ + ['addr' => TEST_AS_HOST, 'port' => TEST_AS_PORT] + ], + 'persistent' => false, + 'namespace' => 'test', + 'prefix' => '', + 'lifetime' => 10, + 'uniqueId' => 'some-unique-id', + 'options' => [ + \Aerospike::OPT_CONNECT_TIMEOUT => 1250, + \Aerospike::OPT_WRITE_TIMEOUT => 1500 + ] + ]; + } + + public function testShouldWriteSession() + { + $sessionId = 'abcdef123458'; + $session = new SessionHandler($this->getConfig()); + + $data = serialize( + [ + 321 => microtime(true), + 'def' => '678', + 'xyz' => 'zyx' + ] + ); + + $session->write($sessionId, $data); + $this->tester->seeInAerospike($sessionId, base64_encode($data)); + } + + public function testShouldReadSession() + { + $sessionId = 'abcdef123458'; + $session = new SessionHandler($this->getConfig()); + + $data = serialize( + [ + 321 => microtime(true), + 'def' => '678', + 'xyz' => 'zyx' + ] + ); + + $this->tester->haveInAerospike($sessionId, base64_encode($data)); + $this->keys[] = $sessionId; + + $expected = $session->read($sessionId); + $this->assertEquals($data, $expected); + } + + public function testShouldDestroySession() + { + $sessionId = 'abcdef123457'; + $session = new SessionHandler($this->getConfig()); + + $data = serialize( + [ + 'abc' => 345, + 'def' => ['foo' => 'bar'], + 'zyx' => 'xyz' + ] + ); + + $this->tester->haveInAerospike($sessionId, base64_encode($data)); + $session->destroy($sessionId); + $this->tester->dontSeeInAerospike($sessionId); + } + + private function cleanup() + { + $aerospike = new Aerospike(['hosts' => [['addr' => TEST_AS_HOST, 'port' => TEST_AS_PORT]]], false); + + foreach ($this->keys as $i => $key) { + $aerospike->remove($this->buildKey($aerospike, $key)); + unset($this->keys[$i]); + } + } + + private function buildKey(Aerospike $aerospike, $key) + { + return $aerospike->initKey( + 'test', + 'cache', + $key + ); + } +} diff --git a/tests/unit/Utils/SlugTest.php b/tests/unit/Utils/SlugTest.php index e22a9d4ee..f3cf4d9fd 100644 --- a/tests/unit/Utils/SlugTest.php +++ b/tests/unit/Utils/SlugTest.php @@ -10,11 +10,11 @@ * \Phalcon\Test\Utils\SlugTest * Tests for Phalcon\Utils\Slug component * - * @copyright (c) 2011-2015 Phalcon Team + * @copyright (c) 2011-2016 Phalcon Team * @link http://www.phalconphp.com * @author Ilya Gusev * @package Phalcon\Test\Utils - * @group Utils + * @group utils * * The contents of this file are subject to the New BSD License that is * bundled with this package in the file docs/LICENSE.txt @@ -36,9 +36,9 @@ class SlugTest extends Test */ protected function _before() { - if (!extension_loaded('iconv')) { + if (!extension_loaded('intl')) { $this->markTestSkipped( - 'The iconv module is not available.' + 'The intl module is not available.' ); } } @@ -55,11 +55,19 @@ protected function _after() * @param string $string * @param mixed $replace * @param string $delimiter - * @param string $willReturn + * @param string $expected */ - public function testGenerateSlug($string, $replace, $delimiter, $willReturn) + public function testGenerateSlug($string, $replace, $delimiter, $expected) { - $this->assertEquals(Slug::generate($string, $replace, $delimiter), strtolower($willReturn)); + $this->assertEquals( + $expected, + Slug::generate($string, $replace, $delimiter), + 'Two strings are equals', + 0.0, + 10, + false, + true + ); } public function providerStrings() @@ -112,7 +120,25 @@ public function providerStrings() ['ı' => 'i'], "-", "what-does-it-mean-yapilir-in-turkish" - ] // Turkish + ], // Turkish + [ + 'Àà Ââ Ææ Ää Çç Éé Èè Êê Ëë Îî Ïï Ôô Œœ Öö Ùù Ûû Üü Ÿÿ', + [], + '-', + 'aa-aa-aeae-aa-cc-ee-ee-ee-ee-ii-ii-oo-oeoe-oo-uu-uu-uu-yy' + ], + [ + 'а б в г д е ё ж з и й к л м н о п р с т у ф х ц ч ш щ ъ ы ь э ю я', + [], + '-', + 'a-b-v-g-d-e-e-z-z-i-j-k-l-m-n-o-p-r-s-t-u-f-h-c-c-s-s-y-e-u-a' + ], // Russian + [ + 'Keramik og stentøj Populære kategorier', + [], + '-', + 'keramik-og-stentoj-populaere-kategorier' + ], // Danish ]; } } diff --git a/tests/unit/Validation/Validator/Db/UniquenessTest.php b/tests/unit/Validation/Validator/Db/UniquenessTest.php index a63fd5c0f..47b56f37d 100644 --- a/tests/unit/Validation/Validator/Db/UniquenessTest.php +++ b/tests/unit/Validation/Validator/Db/UniquenessTest.php @@ -13,7 +13,7 @@ * \Phalcon\Test\Validation\Validator\Db\UniquenessTest * Tests for Phalcon\Validation\Validator\Db\Uniqueness component * - * @copyright (c) 2011-2015 Phalcon Team + * @copyright (c) 2011-2016 Phalcon Team * @link http://www.phalconphp.com * @author Tomasz Ślązok * @package Phalcon\Test\Validation\Validator\Db diff --git a/tests/unit/Validation/Validator/MongoIdTest.php b/tests/unit/Validation/Validator/MongoIdTest.php index d258ee862..61ca119ad 100644 --- a/tests/unit/Validation/Validator/MongoIdTest.php +++ b/tests/unit/Validation/Validator/MongoIdTest.php @@ -12,7 +12,7 @@ * \Phalcon\Test\Validation\Validator\MongoIdTest * Tests for Phalcon\Validation\Validator\MongoId component * - * @copyright (c) 2011-2015 Phalcon Team + * @copyright (c) 2011-2016 Phalcon Team * @link http://www.phalconphp.com * @author Anton Kornilov * @package Phalcon\Test\Validation\Validator