diff --git a/.gitignore b/.gitignore
index 5458fec72d1..ed9e4e552e6 100644
--- a/.gitignore
+++ b/.gitignore
@@ -48,7 +48,9 @@ autom4te.cache/
/vendor
/ide/
+boxfile.yml
composer.lock
php_test_results_*.txt
docker-compose.yml
build/gccarch
+tests/_cache
diff --git a/.travis.yml b/.travis.yml
index d61e6d934b5..e62a906938d 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -5,23 +5,27 @@ php:
- 'master'
- '7.3'
- '7.2'
- - '7.1'
- - '7.0'
git:
depth: 1
-branches:
- only:
- - master
- - /^(4|5)\.\d+\.(\d+|x)$/
+# TODO - Remove this when we go deploy this
+#branches:
+# only:
+# - master
+# - /^(4|5)\.\d+\.(\d+|x)$/
addons:
apt:
+ sources:
+ - mysql-5.7-trusty
packages:
- - beanstalkd
- - gdb
- - lcov
+ - beanstalkd
+ - gdb
+ - lcov
+ - mysql-server
+ - mysql-client
+ postgresql: "9.4"
matrix:
fast_finish: true
@@ -38,6 +42,7 @@ cache:
- ${HOME}/.local/opt
services:
+ - mysql
- beanstalkd
- mongodb
- redis-server
@@ -45,8 +50,9 @@ services:
env:
global:
+ - secure: "eL8spffzdRIDAjdxG+OPJPeUCdpc/jVz6PEVYcs3z4nOnjsKDURm8cmBmGeyHMxvkdHZ6g0PO/srIKAYufZkjDCeK0vl7OBv6kNlGEuO3M7SUCAVX+J2OSg+hNlK467woxsPeMB19/vkC1HmytgpdAefFGtFp4+zsMT41YVupuA="
- CC="gcc"
- - ZEPHIR_VERSION="0.10.14"
+ - ZEPHIR_VERSION="0.11.8"
- RE2C_VERSION="1.1.1"
- REPORT_EXIT_STATUS=1
- REPORT_COVERAGE=1
@@ -64,6 +70,8 @@ before_install:
- tests/_ci/setup-dbs.sh
- source tests/_ci/environment
- export $(cut -d= -f1 tests/_ci/environment)
+ - wget --no-clobber -O $HOME/bin/zephir https://github.com/phalcon/zephir/releases/download/${ZEPHIR_VERSION}/zephir.phar
+ - chmod +x $HOME/bin/zephir
install:
- tests/_ci/install-prereqs.sh
@@ -80,9 +88,10 @@ script:
- vendor/bin/phpcs
- vendor/bin/codecept build
# TODO: Add `cli' suite and refactor current cli-tests
+# - vendor/bin/codecept run -v
+ - vendor/bin/codecept run -v -n tests/cli/
- vendor/bin/codecept run -v -n tests/integration/
- vendor/bin/codecept run -v -n tests/unit/
- # TODO: Refactor legacy unit tests from the "unit-tests" directory
- phpenv config-rm xdebug.ini || true
- tests/_ci/volt-tests.sh
diff --git a/CHANGELOG-4.0.md b/CHANGELOG-4.0.md
index 70e6031b380..ea7fa7056a5 100644
--- a/CHANGELOG-4.0.md
+++ b/CHANGELOG-4.0.md
@@ -10,6 +10,7 @@
- Added ability to set a custom template for the Flash Messenger. [#13445](https://github.com/phalcon/cphalcon/issues/13445)
- Added `forUpdate` in the Sqlite dialect to override the method from the base dialect. [#13539](https://github.com/phalcon/cphalcon/issues/13539)
- Added `TYPE_ENUM` in the Mysql adapter. [#11368](https://github.com/phalcon/cphalcon/issues/11368)
+- Added more column types for the Mysql adapter. The adapter supports `TYPE_BIGINTEGER`, `TYPE_BIT`, `TYPE_BLOB`, `TYPE_BOOLEAN`, `TYPE_CHAR`, `TYPE_DATE`, `TYPE_DATETIME`, `TYPE_DECIMAL`, `TYPE_DOUBLE`, `TYPE_ENUM`, `TYPE_FLOAT`, `TYPE_INTEGER`, `TYPE_JSON`, `TYPE_JSONB`, `TYPE_LONGBLOB`, `TYPE_LONGTEXT`, `TYPE_MEDIUMBLOB`, `TYPE_MEDIUMINTEGER`, `TYPE_MEDIUMTEXT`, `TYPE_SMALLINTEGER`, `TYPE_TEXT`, `TYPE_TIME`, `TYPE_TIMESTAMP`, `TYPE_TINYBLOB`, `TYPE_TINYINTEGER`, `TYPE_TINYTEXT`, `TYPE_VARCHAR` [#13151](https://github.com/phalcon/cphalcon/issues/13151), [#12223](https://github.com/phalcon/cphalcon/issues/12223), [#524](https://github.com/phalcon/cphalcon/issues/524), [#13225](https://github.com/phalcon/cphalcon/pull/13225) [@zGaron](https://github.com/zGaron), [#12523](https://github.com/phalcon/cphalcon/pull/12523) [@Studentsov](https://github.com/Studentsov), [#12471](https://github.com/phalcon/cphalcon/pull/12471) [@ruudboon](https://github.com/ruudboon)
- Added `Phalcon\Acl\Adapter\Memory::addRole` support multiple inherited
- Added `Phalcon\Tag::renderTitle()` that renders the title enclosed in `
` tags. [#13547](https://github.com/phalcon/cphalcon/issues/13547)
- Added `hasHeader()` method to `Phalcon\Http\Response` to provide the ability to check if a header exists. [PR-12189](https://github.com/phalcon/cphalcon/pull/12189)
@@ -18,6 +19,9 @@
- Added `Phalcon\Mvc\Model\Query\BuilderInterface::offset` [#13599](https://github.com/phalcon/cphalcon/pull/13599)
- Added `Phalcon\Http\Response\Cookies::getCookies` [#13591](https://github.com/phalcon/cphalcon/pull/13591)
- Added `Phalcon\Mvc\Model::isRelationshipLoaded` to check if relationship is loaded
+- Added an easy way to work with Phalcon and run the tests locally, using [nanobox.io](https://nanobox.io) [#13578](https://github.com/phalcon/cphalcon/issues/13578)
+- Added response handler to `Phalcon\Mvc\Micro`, `Phalcon\Mvc\Micro::setResponseHandler`, to allow use of a custom response handler. [#12452](https://github.com/phalcon/cphalcon/pull/12452)
+- Added a retainer for the current token to be used during the checkings, so when `Phalcon\Security::getToken` is called the token used for checkings don't change. [#12392](https://github.com/phalcon/cphalcon/issues/12392)
## Changed
- By configuring `prefix` and `statsKey` the `Phalcon\Cache\Backend\Redis::queryKeys` no longer returns prefixed keys, now it returns original keys without prefix. [PR-13456](https://github.com/phalcon/cphalcon/pull/13456)
@@ -39,6 +43,11 @@
- Fixed `\Phalcon\Http\Response::setFileToSend` filename last much _
- Changed `Phalcon\Tag::getTitle()`. It returns only the text. It accepts `prepend`, `append` booleans to prepend or append the relevant text to the title. [#13547](https://github.com/phalcon/cphalcon/issues/13547)
- Changed `Phalcon\Di\Service` constructor to no longer takes the name of the service.
+- Changed `Phalon\Tag::textArea` to use `htmlspecialchars` to prevent XSS injection. [#12428](https://github.com/phalcon/cphalcon/issues/12428)
+- Changed `Phalon\Cache\Backend\*::get` to use only positive numbers for `lifetime`
+- Changed `Phalcon\Logger` to comply with PSR-3. The component has been rewritten to use adapters that alllow logging to different areas. The [#13438](https://github.com/phalcon/cphalcon/issues/13438)
+- Scope SQL Column Aliases (on nesting level), in `Phalcon\Mvc\Model\Query`, to prevent overwrite _root_ query's `_sqlColumnAliases` by sub-queries. [#13006](https://github.com/phalcon/cphalcon/issues/13006), [#12548](https://github.com/phalcon/cphalcon/issues/12548) and [#1731](https://github.com/phalcon/cphalcon/issues/1731)
+- CLI parameters now work like MVC parameters [#12375](https://github.com/phalcon/cphalcon/pull/12375)
## Removed
- PHP < 7.0 no longer supported
@@ -55,4 +64,13 @@
- Removed `Phalcon\Validation\MessageInterface` and `Phalcon\Mvc\Model\MessageInterface` in favor of `Phalcon\Messages\MessageInterface`
- Removed `Phalcon\Validation\Message` and `Phalcon\Mvc\Model\Message` in favor of `Phalcon\Messages\Message`
- Removed `Phalcon\Validation\Message\Group` in favor of `Phalcon\Messages\Messages`
+- Removed deprecated `Phalcon\Annotations\Adapter\Apc`
+- Removed deprecated `Phalcon\Annotations\Adapter\Xcache`
+- Removed deprecated `Phalcon\Cache\Backend\Apc`
+- Removed deprecated `Phalcon\Cache\Backend\Memcache`
+- Removed deprecated `Phalcon\Cache\Backend\Xcache`
+- Removed deprecated `Phalcon\Mvc\Model\Metadata\Apc`
+- Removed deprecated `Phalcon\Mvc\Model\Metadata\Memcache`
+- Removed deprecated `Phalcon\Mvc\Model\Metadata\Xcache`
+- Removed `Phalcon\Logger\Multiple`
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4c75b6cc3b3..a500c263f87 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,10 +7,10 @@ To see what we changed in particular framework branch refer to the relevant chan
## Index
- [**`4.0.x`**](CHANGELOG-4.0.md)
-- [**`3.4.x`**](CHANGELOG-3.4.md)
-- [**`3.3.x`**](CHANGELOG-3.3.md)
-- [**`3.2.x`**](CHANGELOG-3.2.md)
-- [**`3.1.x`**](CHANGELOG-3.1.md)
-- [**`3.0.x`**](CHANGELOG-3.0.md)
-- [**`2.0.x`**](CHANGELOG-2.0.md)
-- [**`1.x.x`**](CHANGELOG-1.x.md)
+- [**`3.4.x`**](resources/CHANGELOG-3.4.md)
+- [**`3.3.x`**](resources/CHANGELOG-3.3.md)
+- [**`3.2.x`**](resources/CHANGELOG-3.2.md)
+- [**`3.1.x`**](resources/CHANGELOG-3.1.md)
+- [**`3.0.x`**](resources/CHANGELOG-3.0.md)
+- [**`2.0.x`**](resources/CHANGELOG-2.0.md)
+- [**`1.x.x`**](resources/CHANGELOG-1.x.md)
diff --git a/codeception.yml b/codeception.yml
index 8d9c97da6d5..46cf9e64292 100644
--- a/codeception.yml
+++ b/codeception.yml
@@ -1,5 +1,4 @@
-# can be changed while bootstrapping project
-actor: Tester
+actor_suffix: Tester
paths:
# where the modules stored
@@ -23,7 +22,7 @@ settings:
coverage:
# Disable Code Coverage by default to speed up Travis tests
- enabled: false
+ enabled: false
extensions:
enabled:
diff --git a/composer.json b/composer.json
index dca976c756b..7db3b0fcc29 100644
--- a/composer.json
+++ b/composer.json
@@ -41,13 +41,12 @@
"ext-psr": "*",
"ext-xml": "*",
"codeception/codeception": "^2.4",
- "codeception/specify": "1.0.*",
- "codeception/verify": "1.0.*",
"mustache/mustache": "^2.11",
"phpunit/phpunit": "^6.4",
"predis/predis": "^1.1",
"squizlabs/php_codesniffer": "^3.2",
- "twig/twig": "~1.35"
+ "twig/twig": "~1.35",
+ "vlucas/phpdotenv": "^2.5"
},
"config": {
"optimize-autoloader": true,
@@ -59,6 +58,7 @@
"Zephir\\Optimizers\\": "optimizers/",
"Phalcon\\Test\\Unit\\": "tests/unit/",
"Phalcon\\Test\\Integration\\": "tests/integration/",
+ "Phalcon\\Test\\Fixtures\\": "tests/_data/fixtures/",
"Phalcon\\Test\\Module\\": "tests/_support/Module/",
"Phalcon\\Test\\Listener\\": "tests/_data/listener/",
"Phalcon\\Test\\Db\\": "tests/_data/db/"
diff --git a/phalcon/acl/adapter.zep b/phalcon/acl/adapter.zep
index c06e611877b..a3b22cfd304 100644
--- a/phalcon/acl/adapter.zep
+++ b/phalcon/acl/adapter.zep
@@ -49,19 +49,22 @@ abstract class Adapter implements AdapterInterface, EventsAwareInterface
/**
* Role which the list is checking if it's allowed to certain resource/access
- * @var mixed
+ *
+ * @var string
*/
protected _activeRole { get };
/**
* Resource which the list is checking if some role can access it
- * @var mixed
+ *
+ * @var string
*/
protected _activeResource { get };
/**
* Active access which the list is checking if some role can access it
- * @var mixed
+ *
+ * @var string
*/
protected _activeAccess { get };
diff --git a/phalcon/acl/adapter/memory.zep b/phalcon/acl/adapter/memory.zep
index 6d8475dc83d..a7f1d766e81 100644
--- a/phalcon/acl/adapter/memory.zep
+++ b/phalcon/acl/adapter/memory.zep
@@ -188,7 +188,7 @@ class Memory extends Adapter
* @param array|string accessInherits
* @param RoleInterface|string|array role
*/
- public function addRole(role, accessInherits = null) -> boolean
+ public function addRole(role, accessInherits = null) -> bool
{
var roleName, roleObject;
@@ -229,7 +229,7 @@ class Memory extends Adapter
* @param array|string accessInherits
* @param RoleInterface|string|array role
*/
- public function addInherit(string roleName, var roleToInherits) -> boolean
+ public function addInherit(string roleName, var roleToInherits) -> bool
{
var roleInheritName, rolesNames, roleToInherit, checkRoleToInherit,
checkRoleToInherits, usedRoleToInherits, roleToInheritList, usedRoleToInherit;
@@ -313,7 +313,7 @@ class Memory extends Adapter
/**
* Check whether role exist in the roles list
*/
- public function isRole(string roleName) -> boolean
+ public function isRole(string roleName) -> bool
{
return isset this->_rolesNames[roleName];
}
@@ -321,7 +321,7 @@ class Memory extends Adapter
/**
* Check whether resource exist in the resources list
*/
- public function isResource(string resourceName) -> boolean
+ public function isResource(string resourceName) -> bool
{
return isset this->_resourcesNames[resourceName];
}
@@ -363,7 +363,7 @@ class Memory extends Adapter
* @param Phalcon\Acl\Resource|string resourceValue
* @param array|string accessList
*/
- public function addResource(var resourceValue, var accessList) -> boolean
+ public function addResource(var resourceValue, var accessList) -> bool
{
var resourceName, resourceObject;
@@ -388,7 +388,7 @@ class Memory extends Adapter
*
* @param array|string accessList
*/
- public function addResourceAccess(string resourceName, var accessList) -> boolean
+ public function addResourceAccess(string resourceName, var accessList) -> bool
{
var accessName, accessKey, exists;
@@ -581,7 +581,7 @@ class Memory extends Adapter
* @param RoleInterface|RoleAware|string roleName
* @param ResourceInterface|ResourceAware|string resourceName
*/
- public function isAllowed(var roleName, var resourceName, string access, array parameters = null) -> boolean
+ public function isAllowed(var roleName, var resourceName, string access, array parameters = null) -> bool
{
var eventsManager, accessList, accessKey,
haveAccess = null, rolesNames,
@@ -750,7 +750,7 @@ class Memory extends Adapter
/**
* Check whether a role is allowed to access an action from a resource
*/
- protected function _isAllowed(string roleName, string resourceName, string access) -> string | boolean
+ protected function _isAllowed(string roleName, string resourceName, string access) -> string | bool
{
var accessList, accessKey,checkRoleToInherit, checkRoleToInherits, usedRoleToInherits, usedRoleToInherit;
diff --git a/phalcon/acl/adapterinterface.zep b/phalcon/acl/adapterinterface.zep
index 295314a5ba0..450d3584e48 100644
--- a/phalcon/acl/adapterinterface.zep
+++ b/phalcon/acl/adapterinterface.zep
@@ -52,22 +52,22 @@ interface AdapterInterface
/**
* Adds a role to the ACL list. Second parameter lets to inherit access data from other existing role
*/
- public function addRole(role, accessInherits = null) -> boolean;
+ public function addRole(role, accessInherits = null) -> bool;
/**
* Do a role inherit from another existing role
*/
- public function addInherit(string roleName, roleToInherit) -> boolean;
+ public function addInherit(string roleName, roleToInherit) -> bool;
/**
* Check whether role exist in the roles list
*/
- public function isRole(string roleName) -> boolean;
+ public function isRole(string roleName) -> bool;
/**
* Check whether resource exist in the resources list
*/
- public function isResource(string resourceName) -> boolean;
+ public function isResource(string resourceName) -> bool;
/**
* Adds a resource to the ACL list
@@ -75,7 +75,7 @@ interface AdapterInterface
* Access names can be a particular action, by example
* search, update, delete, etc or a list of them
*/
- public function addResource(resourceObject, accessList) -> boolean;
+ public function addResource(resourceObject, accessList) -> bool;
/**
* Adds access to resources
@@ -100,7 +100,7 @@ interface AdapterInterface
/**
* Check whether a role is allowed to access an action from a resource
*/
- public function isAllowed(roleName, resourceName, access, array parameters = null) -> boolean;
+ public function isAllowed(roleName, resourceName, string access, array parameters = null) -> bool;
/**
* Returns the role which the list is checking if it's allowed to certain resource/access
diff --git a/phalcon/annotations/adapter/apc.zep b/phalcon/annotations/adapter/apc.zep
deleted file mode 100644
index 255e0dddc58..00000000000
--- a/phalcon/annotations/adapter/apc.zep
+++ /dev/null
@@ -1,78 +0,0 @@
-
-/*
- +------------------------------------------------------------------------+
- | Phalcon Framework |
- +------------------------------------------------------------------------+
- | Copyright (c) 2011-2017 Phalcon Team (https://phalconphp.com) |
- +------------------------------------------------------------------------+
- | This source file is subject to the New BSD License that is bundled |
- | with this package in the file 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 we can send you a copy immediately. |
- +------------------------------------------------------------------------+
- | Authors: Andres Gutierrez |
- | Eduar Carvajal |
- +------------------------------------------------------------------------+
- */
-
-namespace Phalcon\Annotations\Adapter;
-
-use Phalcon\Annotations\Adapter;
-use Phalcon\Annotations\Reflection;
-
-/**
- * Phalcon\Annotations\Adapter\Apc
- *
- * Stores the parsed annotations in APC. This adapter is suitable for production
- *
- *
- * use Phalcon\Annotations\Adapter\Apc;
- *
- * $annotations = new Apc();
- *
- *
- * @see \Phalcon\Annotations\Adapter\Apcu
- * @deprecated
- */
-class Apc extends Adapter
-{
-
- protected _prefix = "";
-
- protected _ttl = 172800;
-
- /**
- * Phalcon\Annotations\Adapter\Apc constructor
- */
- public function __construct(array options = [])
- {
- var prefix, ttl;
-
- if typeof options == "array" {
- if fetch prefix, options["prefix"] {
- let this->_prefix = prefix;
- }
- if fetch ttl, options["lifetime"] {
- let this->_ttl = ttl;
- }
- }
- }
-
- /**
- * Reads parsed annotations from APC
- */
- public function read(string! key) -> | boolean
- {
- return apc_fetch(strtolower("_PHAN" . this->_prefix . key));
- }
-
- /**
- * Writes parsed annotations to APC
- */
- public function write(string! key, data)
- {
- return apc_store(strtolower("_PHAN" . this->_prefix . key), data, this->_ttl);
- }
-}
diff --git a/phalcon/annotations/adapter/apcu.zep b/phalcon/annotations/adapter/apcu.zep
index bf7cf7889e6..2e49e9f1cf5 100644
--- a/phalcon/annotations/adapter/apcu.zep
+++ b/phalcon/annotations/adapter/apcu.zep
@@ -62,7 +62,7 @@ class Apcu extends Adapter
/**
* Reads parsed annotations from APCu
*/
- public function read(string! key) -> | boolean
+ public function read(string! key) -> | bool
{
return apcu_fetch(strtolower("_PHAN" . this->_prefix . key));
}
diff --git a/phalcon/annotations/adapter/files.zep b/phalcon/annotations/adapter/files.zep
index 1419355faba..f400d7ba4fb 100644
--- a/phalcon/annotations/adapter/files.zep
+++ b/phalcon/annotations/adapter/files.zep
@@ -57,7 +57,7 @@ class Files extends Adapter
/**
* Reads parsed annotations from files
*/
- public function read(string key) -> | boolean | int
+ public function read(string key) -> | bool | int
{
var path;
diff --git a/phalcon/annotations/adapter/memory.zep b/phalcon/annotations/adapter/memory.zep
index 43b9218a4ef..57ab85dcb18 100644
--- a/phalcon/annotations/adapter/memory.zep
+++ b/phalcon/annotations/adapter/memory.zep
@@ -38,7 +38,7 @@ class Memory extends Adapter
/**
* Reads parsed annotations from memory
*/
- public function read(string! key) -> | boolean
+ public function read(string! key) -> | bool
{
var data;
diff --git a/phalcon/annotations/adapter/xcache.zep b/phalcon/annotations/adapter/xcache.zep
deleted file mode 100644
index 680cf6b4971..00000000000
--- a/phalcon/annotations/adapter/xcache.zep
+++ /dev/null
@@ -1,61 +0,0 @@
-
-/*
- +------------------------------------------------------------------------+
- | Phalcon Framework |
- +------------------------------------------------------------------------+
- | Copyright (c) 2011-2017 Phalcon Team (https://phalconphp.com) |
- +------------------------------------------------------------------------+
- | This source file is subject to the New BSD License that is bundled |
- | with this package in the file 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 we can send you a copy immediately. |
- +------------------------------------------------------------------------+
- | Authors: Andres Gutierrez |
- | Eduar Carvajal |
- | Vladimir Kolesnikov |
- +------------------------------------------------------------------------+
- */
-
-namespace Phalcon\Annotations\Adapter;
-
-use Phalcon\Annotations\Adapter;
-use Phalcon\Annotations\Reflection;
-
-/**
- * Phalcon\Annotations\Adapter\Xcache
- *
- * Stores the parsed annotations to XCache. This adapter is suitable for production
- *
- *
- * $annotations = new \Phalcon\Annotations\Adapter\Xcache();
- *
- */
-class Xcache extends Adapter
-{
- /**
- * Reads parsed annotations from XCache
- */
- public function read(string! key) -> | boolean
- {
- var serialized, data;
- let serialized = xcache_get(strtolower("_PHAN" . key));
- if typeof serialized == "string" {
- let data = unserialize(serialized);
- if typeof data == "object" {
- return data;
- }
- }
- return false;
- }
-
- /**
- * Writes parsed annotations to XCache
- */
- public function write(string! key, data)
- {
- xcache_set(strtolower("_PHAN" . key), serialize(data));
- }
-
-}
diff --git a/phalcon/annotations/annotation.zep b/phalcon/annotations/annotation.zep
index 6ad1ae924af..bd038555296 100644
--- a/phalcon/annotations/annotation.zep
+++ b/phalcon/annotations/annotation.zep
@@ -183,7 +183,7 @@ class Annotation
*
* @param int|string position
*/
- public function hasArgument(var position) -> boolean
+ public function hasArgument(var position) -> bool
{
return isset this->_arguments[position];
}
diff --git a/phalcon/annotations/collection.zep b/phalcon/annotations/collection.zep
index 54caed91500..d794676f96d 100644
--- a/phalcon/annotations/collection.zep
+++ b/phalcon/annotations/collection.zep
@@ -84,7 +84,7 @@ class Collection implements \Iterator, \Countable
/**
* Returns the current annotation in the iterator
*/
- public function current() -> | boolean
+ public function current() -> | bool
{
var annotation;
if fetch annotation, this->_annotations[this->_position] {
@@ -112,7 +112,7 @@ class Collection implements \Iterator, \Countable
/**
* Check if the current annotation in the iterator is valid
*/
- public function valid() -> boolean
+ public function valid() -> bool
{
return isset this->_annotations[this->_position];
}
@@ -166,7 +166,7 @@ class Collection implements \Iterator, \Countable
/**
* Check if an annotation exists in a collection
*/
- public function has(string name) -> boolean
+ public function has(string name) -> bool
{
var annotations, annotation;
diff --git a/phalcon/annotations/factory.zep b/phalcon/annotations/factory.zep
index 71f6c07b06b..80af116957d 100644
--- a/phalcon/annotations/factory.zep
+++ b/phalcon/annotations/factory.zep
@@ -41,7 +41,7 @@ class Factory extends BaseFactory
/**
* @param \Phalcon\Config|array config
*/
- public static function load(var config) ->
+ public static function load(var config) -> object
{
return self::loadClass("Phalcon\\Annotations\\Adapter", config);
}
diff --git a/phalcon/annotations/reflection.zep b/phalcon/annotations/reflection.zep
index a0fa3053e0c..9bc9b33dd77 100644
--- a/phalcon/annotations/reflection.zep
+++ b/phalcon/annotations/reflection.zep
@@ -63,7 +63,7 @@ class Reflection
/**
* Returns the annotations found in the class docblock
*/
- public function getClassAnnotations() -> | boolean
+ public function getClassAnnotations() -> | bool
{
var annotations, reflectionClass, collection;
@@ -83,7 +83,7 @@ class Reflection
/**
* Returns the annotations found in the methods' docblocks
*/
- public function getMethodsAnnotations() -> | boolean
+ public function getMethodsAnnotations() -> | bool
{
var annotations, reflectionMethods,
collections, methodName, reflectionMethod;
@@ -111,7 +111,7 @@ class Reflection
/**
* Returns the annotations found in the properties' docblocks
*/
- public function getPropertiesAnnotations() -> | boolean
+ public function getPropertiesAnnotations() -> | bool
{
var annotations, reflectionProperties,
collections, property, reflectionProperty;
diff --git a/phalcon/application.zep b/phalcon/application.zep
index 23c51f74f9e..b224397ab44 100644
--- a/phalcon/application.zep
+++ b/phalcon/application.zep
@@ -93,7 +93,7 @@ abstract class Application extends Injectable implements EventsAwareInterface
* );
*
*/
- public function registerModules(array modules, boolean merge = false) ->
+ public function registerModules(array modules, bool merge = false) ->
{
if merge {
let this->_modules = array_merge(this->_modules, modules);
diff --git a/phalcon/assets/collection.zep b/phalcon/assets/collection.zep
index 4d91075bf66..5a477b9cf3f 100644
--- a/phalcon/assets/collection.zep
+++ b/phalcon/assets/collection.zep
@@ -102,7 +102,7 @@ class Collection implements \Countable, \Iterator
* $collection->has($resource); // true
*
*/
- public function has( $resource) -> boolean
+ public function has( $resource) -> bool
{
var key, resources;
@@ -115,7 +115,7 @@ class Collection implements \Countable, \Iterator
/**
* Adds a CSS resource to the collection
*/
- public function addCss(string! path, var local = null, boolean filter = true, attributes = null) ->
+ public function addCss(string! path, var local = null, bool filter = true, attributes = null) ->
{
var collectionLocal, collectionAttributes;
@@ -139,7 +139,7 @@ class Collection implements \Countable, \Iterator
/**
* Adds an inline CSS to the collection
*/
- public function addInlineCss(string content, boolean filter = true, attributes = null) ->
+ public function addInlineCss(string content, bool filter = true, attributes = null) ->
{
var collectionAttributes;
@@ -158,7 +158,7 @@ class Collection implements \Countable, \Iterator
*
* @param array attributes
*/
- public function addJs(string! path, boolean local = null, boolean filter = true, attributes = null) ->
+ public function addJs(string! path, bool local = null, bool filter = true, attributes = null) ->
{
var collectionLocal, collectionAttributes;
@@ -182,7 +182,7 @@ class Collection implements \Countable, \Iterator
/**
* Adds an inline javascript to the collection
*/
- public function addInlineJs(string content, boolean filter = true, attributes = null) ->
+ public function addInlineJs(string content, bool filter = true, attributes = null) ->
{
var collectionAttributes;
@@ -240,7 +240,7 @@ class Collection implements \Countable, \Iterator
/**
* Check if the current element in the iterator is valid
*/
- public function valid() -> boolean
+ public function valid() -> bool
{
return isset this->_resources[this->_position];
}
@@ -284,7 +284,7 @@ class Collection implements \Countable, \Iterator
/**
* Sets if the collection uses local resources by default
*/
- public function setLocal(boolean! local) ->
+ public function setLocal(bool! local) ->
{
let this->_local = local;
return this;
@@ -311,7 +311,7 @@ class Collection implements \Countable, \Iterator
/**
* Sets the target local
*/
- public function setTargetLocal(boolean! targetLocal) ->
+ public function setTargetLocal(bool! targetLocal) ->
{
let this->_targetLocal = targetLocal;
return this;
@@ -320,7 +320,7 @@ class Collection implements \Countable, \Iterator
/**
* Sets if all filtered resources in the collection must be joined in a single result file
*/
- public function join(boolean join) ->
+ public function join(bool join) ->
{
let this->_join = join;
return this;
@@ -362,7 +362,7 @@ class Collection implements \Countable, \Iterator
/**
* Adds a resource or inline-code to the collection
*/
- protected final function addResource( $resource) -> boolean
+ protected final function addResource( $resource) -> bool
{
if !this->has($resource) {
if $resource instanceof $Resource {
diff --git a/phalcon/assets/inline.zep b/phalcon/assets/inline.zep
index c3a62d922da..5ba6ef37533 100644
--- a/phalcon/assets/inline.zep
+++ b/phalcon/assets/inline.zep
@@ -31,18 +31,27 @@ namespace Phalcon\Assets;
class $Inline implements ResourceInterface
{
+ /**
+ * @var string
+ */
protected _type { get };
protected _content { get };
+ /**
+ * @var bool
+ */
protected _filter { get };
+ /**
+ * @var array | null
+ */
protected _attributes { get };
/**
* Phalcon\Assets\Inline constructor
*/
- public function __construct(string type, string content, boolean filter = true, array attributes = [])
+ public function __construct(string type, string content, bool filter = true, array attributes = [])
{
let this->_type = type,
this->_content = content,
@@ -53,7 +62,7 @@ class $Inline implements ResourceInterface
/**
* Sets the inline's type
*/
- public function setType(string type) -> <$Inline>
+ public function setType(string type) ->
{
let this->_type = type;
return this;
@@ -62,7 +71,7 @@ class $Inline implements ResourceInterface
/**
* Sets if the resource must be filtered or not
*/
- public function setFilter(boolean filter) -> <$Inline>
+ public function setFilter(bool filter) ->
{
let this->_filter = filter;
return this;
@@ -71,7 +80,7 @@ class $Inline implements ResourceInterface
/**
* Sets extra HTML attributes
*/
- public function setAttributes(array attributes) -> <$Inline>
+ public function setAttributes(array attributes) ->
{
let this->_attributes = attributes;
return this;
diff --git a/phalcon/assets/inline/css.zep b/phalcon/assets/inline/css.zep
index da997a3d969..7c43dc6b07c 100644
--- a/phalcon/assets/inline/css.zep
+++ b/phalcon/assets/inline/css.zep
@@ -34,7 +34,7 @@ class Css extends InlineBase
*
* @param array attributes
*/
- public function __construct(string content, boolean filter = true, attributes = null)
+ public function __construct(string content, bool filter = true, attributes = null)
{
if attributes == null {
let attributes = ["type": "text/css"];
diff --git a/phalcon/assets/inline/js.zep b/phalcon/assets/inline/js.zep
index f6cf4fc8c07..0824e985c89 100644
--- a/phalcon/assets/inline/js.zep
+++ b/phalcon/assets/inline/js.zep
@@ -34,7 +34,7 @@ class Js extends InlineBase
*
* @param array attributes
*/
- public function __construct(string content, boolean filter = true, var attributes = null)
+ public function __construct(string content, bool filter = true, var attributes = null)
{
if attributes == null {
let attributes = ["type": "text/javascript"];
diff --git a/phalcon/assets/manager.zep b/phalcon/assets/manager.zep
index e239c6ef095..f0dc96c204e 100644
--- a/phalcon/assets/manager.zep
+++ b/phalcon/assets/manager.zep
@@ -74,7 +74,7 @@ class Manager
/**
* Sets if the HTML generated must be directly printed or returned
*/
- public function useImplicitOutput(boolean implicitOutput) ->
+ public function useImplicitOutput(bool implicitOutput) ->
{
let this->_implicitOutput = implicitOutput;
return this;
diff --git a/phalcon/assets/resource.zep b/phalcon/assets/resource.zep
index 8a17cec56ef..d6c77daa918 100644
--- a/phalcon/assets/resource.zep
+++ b/phalcon/assets/resource.zep
@@ -41,12 +41,12 @@ class $Resource implements ResourceInterface
protected _path { get };
/**
- * @var boolean
+ * @var bool
*/
protected _local { get };
/**
- * @var boolean
+ * @var bool
*/
protected _filter { get };
@@ -64,7 +64,7 @@ class $Resource implements ResourceInterface
/**
* Phalcon\Assets\Resource constructor
*/
- public function __construct(string type, string path, boolean local = true, boolean filter = true, array attributes = [])
+ public function __construct(string type, string path, bool local = true, bool filter = true, array attributes = [])
{
let this->_type = type,
this->_path = path,
@@ -76,7 +76,7 @@ class $Resource implements ResourceInterface
/**
* Sets the resource's type
*/
- public function setType(string type) -> <$Resource>
+ public function setType(string type) ->
{
let this->_type = type;
return this;
@@ -85,7 +85,7 @@ class $Resource implements ResourceInterface
/**
* Sets the resource's path
*/
- public function setPath(string path) -> <$Resource>
+ public function setPath(string path) ->
{
let this->_path = path;
return this;
@@ -94,7 +94,7 @@ class $Resource implements ResourceInterface
/**
* Sets if the resource is local or external
*/
- public function setLocal(boolean local) -> <$Resource>
+ public function setLocal(bool local) ->
{
let this->_local = local;
return this;
@@ -103,7 +103,7 @@ class $Resource implements ResourceInterface
/**
* Sets if the resource must be filtered or not
*/
- public function setFilter(boolean filter) -> <$Resource>
+ public function setFilter(bool filter) ->
{
let this->_filter = filter;
return this;
@@ -112,7 +112,7 @@ class $Resource implements ResourceInterface
/**
* Sets extra HTML attributes
*/
- public function setAttributes(array attributes) -> <$Resource>
+ public function setAttributes(array attributes) ->
{
let this->_attributes = attributes;
return this;
@@ -121,7 +121,7 @@ class $Resource implements ResourceInterface
/**
* Sets a target uri for the generated HTML
*/
- public function setTargetUri(string targetUri) -> <$Resource>
+ public function setTargetUri(string targetUri) ->
{
let this->_targetUri = targetUri;
return this;
@@ -130,7 +130,7 @@ class $Resource implements ResourceInterface
/**
* Sets the resource's source path
*/
- public function setSourcePath(string sourcePath) -> <$Resource>
+ public function setSourcePath(string sourcePath) ->
{
let this->_sourcePath = sourcePath;
return this;
@@ -139,7 +139,7 @@ class $Resource implements ResourceInterface
/**
* Sets the resource's target path
*/
- public function setTargetPath(string targetPath) -> <$Resource>
+ public function setTargetPath(string targetPath) ->
{
let this->_targetPath = targetPath;
return this;
diff --git a/phalcon/assets/resource/css.zep b/phalcon/assets/resource/css.zep
index 99a551d4a60..b6abd588b21 100644
--- a/phalcon/assets/resource/css.zep
+++ b/phalcon/assets/resource/css.zep
@@ -32,7 +32,7 @@ class Css extends ResourceBase
/**
* Phalcon\Assets\Resource\Css
*/
- public function __construct(string! path, boolean local = true, boolean filter = true, array attributes = [])
+ public function __construct(string! path, bool local = true, bool filter = true, array attributes = [])
{
parent::__construct("css", path, local, filter, attributes);
}
diff --git a/phalcon/assets/resource/js.zep b/phalcon/assets/resource/js.zep
index 476bd1a172b..c92e099f109 100644
--- a/phalcon/assets/resource/js.zep
+++ b/phalcon/assets/resource/js.zep
@@ -32,7 +32,7 @@ class Js extends ResourceBase
/**
* Phalcon\Assets\Resource\Js
*/
- public function __construct(string! path, boolean local = true, boolean filter = true, array attributes = [])
+ public function __construct(string! path, bool local = true, bool filter = true, array attributes = [])
{
parent::__construct("js", path, local, filter, attributes);
}
diff --git a/phalcon/assets/resourceinterface.zep b/phalcon/assets/resourceinterface.zep
index 8b8b3ecf5a3..34ed16798da 100644
--- a/phalcon/assets/resourceinterface.zep
+++ b/phalcon/assets/resourceinterface.zep
@@ -39,12 +39,12 @@ interface ResourceInterface
/**
* Sets if the resource must be filtered or not.
*/
- public function setFilter(boolean filter) -> ;
+ public function setFilter(bool filter) -> ;
/**
* Gets if the resource must be filtered or not.
*/
- public function getFilter() -> boolean;
+ public function getFilter() -> bool;
/**
* Sets extra HTML attributes.
diff --git a/phalcon/cache/backend.zep b/phalcon/cache/backend.zep
index 82982a1c9f3..162d5fb372c 100644
--- a/phalcon/cache/backend.zep
+++ b/phalcon/cache/backend.zep
@@ -29,12 +29,24 @@ use Phalcon\Cache\FrontendInterface;
abstract class Backend implements BackendInterface
{
- protected _frontend { get, set };
+ /**
+ * @var Phalcon\Cache\FrontendInterface
+ */
+ protected _frontend;
+ /**
+ * @var array
+ */
protected _options { get, set };
+ /**
+ * @var string
+ */
protected _prefix = "";
+ /**
+ * @var string
+ */
protected _lastKey = "" { get, set };
protected _lastLifetime = null;
@@ -61,6 +73,19 @@ abstract class Backend implements BackendInterface
this->_options = options;
}
+ /**
+ * @var Phalcon\Cache\FrontendInterface
+ */
+ public function getFrontend() ->
+ {
+ return this->_frontend;
+ }
+
+ public function setFrontend( frontend) -> void
+ {
+ let this->_frontend = frontend;
+ }
+
/**
* Starts a cache. The keyname allows to identify the created fragment
*
@@ -100,7 +125,7 @@ abstract class Backend implements BackendInterface
/**
* Stops the frontend without store any cached content
*/
- public function stop(boolean stopBuffer = true) -> void
+ public function stop(bool stopBuffer = true) -> void
{
if stopBuffer === true {
this->_frontend->stop();
@@ -111,7 +136,7 @@ abstract class Backend implements BackendInterface
/**
* Checks whether the last cache is fresh or cached
*/
- public function isFresh() -> boolean
+ public function isFresh() -> bool
{
return this->_fresh;
}
@@ -119,7 +144,7 @@ abstract class Backend implements BackendInterface
/**
* Checks whether the cache has starting buffering or not
*/
- public function isStarted() -> boolean
+ public function isStarted() -> bool
{
return this->_started;
}
diff --git a/phalcon/cache/backend/apc.zep b/phalcon/cache/backend/apc.zep
deleted file mode 100644
index ff7e5abcfe8..00000000000
--- a/phalcon/cache/backend/apc.zep
+++ /dev/null
@@ -1,296 +0,0 @@
-
-/*
- +------------------------------------------------------------------------+
- | Phalcon Framework |
- +------------------------------------------------------------------------+
- | Copyright (c) 2011-2017 Phalcon Team (https://phalconphp.com) |
- +------------------------------------------------------------------------+
- | This source file is subject to the New BSD License that is bundled |
- | with this package in the file 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 we can send you a copy immediately. |
- +------------------------------------------------------------------------+
- | Authors: Andres Gutierrez |
- | Eduar Carvajal |
- +------------------------------------------------------------------------+
- */
-
-namespace Phalcon\Cache\Backend;
-
-use Phalcon\Cache\Exception;
-use Phalcon\Cache\Backend;
-
-/**
- * Phalcon\Cache\Backend\Apc
- *
- * Allows to cache output fragments, PHP data and raw data using an APC backend
- *
- *
- * use Phalcon\Cache\Backend\Apc;
- * use Phalcon\Cache\Frontend\Data as FrontData;
- *
- * // Cache data for 2 days
- * $frontCache = new FrontData(
- * [
- * "lifetime" => 172800,
- * ]
- * );
- *
- * $cache = new Apc(
- * $frontCache,
- * [
- * "prefix" => "app-data",
- * ]
- * );
- *
- * // Cache arbitrary data
- * $cache->save("my-data", [1, 2, 3, 4, 5]);
- *
- * // Get data
- * $data = $cache->get("my-data");
- *
- *
- * @see \Phalcon\Cache\Backend\Apcu
- * @deprecated
- */
-class Apc extends Backend
-{
-
- /**
- * Returns a cached content
- */
- public function get(string keyName, int lifetime = null) -> var | null
- {
- var prefixedKey, cachedContent;
-
- let prefixedKey = "_PHCA" . this->_prefix . keyName,
- this->_lastKey = prefixedKey;
-
- let cachedContent = apc_fetch(prefixedKey);
- if cachedContent === false {
- return null;
- }
-
- return this->_frontend->afterRetrieve(cachedContent);
- }
-
- /**
- * Stores cached content into the APC backend and stops the frontend
- *
- * @param string|int keyName
- * @param string content
- * @param int lifetime
- */
- public function save(var keyName = null, var content = null, var lifetime = null, boolean stopBuffer = true) -> boolean
- {
- var lastKey, frontend, cachedContent, preparedContent, ttl, isBuffering, success;
-
- if keyName === null {
- let lastKey = this->_lastKey;
- } else {
- let lastKey = "_PHCA" . this->_prefix . keyName;
- }
-
- if !lastKey {
- throw new Exception("Cache must be started first");
- }
-
- let frontend = this->_frontend;
- if content === null {
- let cachedContent = frontend->getContent();
- } else {
- let cachedContent = content;
- }
-
- if !is_numeric(cachedContent) {
- let preparedContent = frontend->beforeStore(cachedContent);
- } else {
- let preparedContent = cachedContent;
- }
-
- /**
- * Take the lifetime from the frontend or read it from the set in start()
- */
- if lifetime === null {
- let lifetime = this->_lastLifetime;
- if lifetime === null {
- let ttl = frontend->getLifetime();
- } else {
- let ttl = lifetime,
- this->_lastKey = lastKey;
- }
- } else {
- let ttl = lifetime;
- }
-
- /**
- * Call apc_store in the PHP userland since most of the time it isn't available at compile time
- */
- let success = apc_store(lastKey, preparedContent, ttl);
-
- if !success {
- throw new Exception("Failed storing data in apc");
- }
-
- let isBuffering = frontend->isBuffering();
-
- if stopBuffer === true {
- frontend->stop();
- }
-
- if isBuffering === true {
- echo cachedContent;
- }
-
- let this->_started = false;
-
- return success;
- }
-
- /**
- * Increment of a given key, by number $value
- *
- * @param string keyName
- */
- public function increment(keyName = null, int value = 1) -> int | boolean
- {
- var prefixedKey, cachedContent, result;
-
- let prefixedKey = "_PHCA" . this->_prefix . keyName;
- let this->_lastKey = prefixedKey;
-
- if function_exists("apc_inc") {
- let result = apc_inc(prefixedKey, value);
- return result;
- } else {
- let cachedContent = apc_fetch(prefixedKey);
-
- if is_numeric(cachedContent) {
- let result = cachedContent + value;
- this->save(keyName, result);
- return result;
- }
- }
-
- return false;
- }
-
- /**
- * Decrement of a given key, by number $value
- *
- * @param string keyName
- */
- public function decrement(keyName = null, int value = 1) -> int | boolean
- {
- var lastKey, cachedContent, result;
-
- let lastKey = "_PHCA" . this->_prefix . keyName,
- this->_lastKey = lastKey;
-
- if function_exists("apc_dec") {
- return apc_dec(lastKey, value);
- } else {
- let cachedContent = apc_fetch(lastKey);
-
- if is_numeric(cachedContent) {
- let result = cachedContent - value;
- this->save(keyName, result);
- return result;
- }
- }
-
- return false;
- }
-
- /**
- * Deletes a value from the cache by its key
- */
- public function delete(string! keyName) -> boolean
- {
- return apc_delete("_PHCA" . this->_prefix . keyName);
- }
-
- /**
- * Query the existing cached keys.
- *
- *
- * $cache->save("users-ids", [1, 2, 3]);
- * $cache->save("projects-ids", [4, 5, 6]);
- *
- * var_dump($cache->queryKeys("users")); // ["users-ids"]
- *
- */
- public function queryKeys(string prefix = null) -> array
- {
- var prefixPattern, apc, keys, key;
-
- if empty prefix {
- let prefixPattern = "/^_PHCA/";
- } else {
- let prefixPattern = "/^_PHCA" . prefix . "/";
- }
-
- let keys = [],
- apc = new \APCIterator("user", prefixPattern);
-
- for key, _ in iterator(apc) {
- let keys[] = substr(key, 5);
- }
-
- return keys;
- }
-
- /**
- * Checks if cache exists and it hasn't expired
- *
- * @param string|int keyName
- * @param int lifetime
- */
- public function exists(keyName = null, lifetime = null) -> boolean
- {
- var lastKey;
-
- if keyName === null {
- let lastKey = this->_lastKey;
- } else {
- let lastKey = "_PHCA" . this->_prefix . keyName;
- }
-
- if lastKey {
- if apc_exists(lastKey) !== false {
- return true;
- }
- }
-
- return false;
- }
-
- /**
- * Immediately invalidates all existing items.
- *
- *
- * use Phalcon\Cache\Backend\Apc;
- *
- * $cache = new Apc($frontCache, ["prefix" => "app-data"]);
- *
- * $cache->save("my-data", [1, 2, 3, 4, 5]);
- *
- * // 'my-data' and all other used keys are deleted
- * $cache->flush();
- *
- */
- public function flush() -> boolean
- {
- var item, prefixPattern;
-
- let prefixPattern = "/^_PHCA" . this->_prefix . "/";
-
- for item in iterator(new \APCIterator("user", prefixPattern)) {
- apc_delete(item["key"]);
- }
-
- return true;
- }
-}
diff --git a/phalcon/cache/backend/apcu.zep b/phalcon/cache/backend/apcu.zep
index 4c2f7969c8a..c8371917fba 100644
--- a/phalcon/cache/backend/apcu.zep
+++ b/phalcon/cache/backend/apcu.zep
@@ -58,10 +58,14 @@ class Apcu extends Backend
/**
* Returns a cached content
*/
- public function get(string keyName, int lifetime = null) -> var | null
+ public function get(string keyName, var lifetime = null) -> var | null
{
var prefixedKey, cachedContent;
+ if lifetime < 1 {
+ throw new Exception("The lifetime must be at least 1 second");
+ }
+
let prefixedKey = "_PHCA" . this->_prefix . keyName,
this->_lastKey = prefixedKey;
@@ -79,9 +83,9 @@ class Apcu extends Backend
* @param string|int keyName
* @param string content
* @param int lifetime
- * @param boolean stopBuffer
+ * @param bool stopBuffer
*/
- public function save(var keyName = null, var content = null, var lifetime = null, boolean stopBuffer = true) -> boolean
+ public function save(var keyName = null, var content = null, var lifetime = null, bool stopBuffer = true) -> bool
{
var lastKey, frontend, cachedContent, preparedContent, ttl, isBuffering, success;
@@ -152,7 +156,7 @@ class Apcu extends Backend
*
* @param string keyName
*/
- public function increment(keyName = null, int value = 1) -> int | boolean
+ public function increment(keyName = null, int value = 1) -> int | bool
{
var prefixedKey;
@@ -167,7 +171,7 @@ class Apcu extends Backend
*
* @param string keyName
*/
- public function decrement(keyName = null, int value = 1) -> int | boolean
+ public function decrement(keyName = null, int value = 1) -> int | bool
{
var lastKey;
@@ -180,7 +184,7 @@ class Apcu extends Backend
/**
* Deletes a value from the cache by its key
*/
- public function delete(string! keyName) -> boolean
+ public function delete(var keyName) -> bool
{
return apcu_delete("_PHCA" . this->_prefix . keyName);
}
@@ -231,7 +235,7 @@ class Apcu extends Backend
* @param string|int keyName
* @param int lifetime
*/
- public function exists(keyName = null, lifetime = null) -> boolean
+ public function exists(var keyName = null, int lifetime = null) -> bool
{
var lastKey;
@@ -262,7 +266,7 @@ class Apcu extends Backend
* $cache->flush();
*
*/
- public function flush() -> boolean
+ public function flush() -> bool
{
var item, prefixPattern, apc = null;
diff --git a/phalcon/cache/backend/factory.zep b/phalcon/cache/backend/factory.zep
index ad1ba16d023..bbfc5d2a895 100644
--- a/phalcon/cache/backend/factory.zep
+++ b/phalcon/cache/backend/factory.zep
@@ -45,7 +45,7 @@ class Factory extends BaseFactory
/**
* @param \Phalcon\Config|array config
*/
- public static function load(var config) ->
+ public static function load(var config) -> object
{
return self::loadClass("Phalcon\\Cache\\Backend", config);
}
diff --git a/phalcon/cache/backend/file.zep b/phalcon/cache/backend/file.zep
index d0acf6a8235..b8877c97547 100644
--- a/phalcon/cache/backend/file.zep
+++ b/phalcon/cache/backend/file.zep
@@ -64,7 +64,7 @@ class File extends Backend
/**
* Default to false for backwards compatibility
*
- * @var boolean
+ * @var bool
*/
private _useSafeKey = false;
@@ -81,7 +81,7 @@ class File extends Backend
if fetch safekey, options["safekey"] {
if typeof safekey !== "boolean" {
- throw new Exception("safekey option should be a boolean.");
+ throw new Exception("safekey option should be a bool.");
}
let this->_useSafeKey = safekey;
@@ -100,9 +100,14 @@ class File extends Backend
/**
* Returns a cached content
*/
- public function get(string keyName, int lifetime = null) -> var | null
+ public function get(string keyName, var lifetime = null) -> var | null
{
- var prefixedKey, cacheDir, cacheFile, frontend, lastLifetime, ttl, cachedContent, ret, modifiedTime;
+ var prefixedKey, cacheDir, cacheFile, frontend, lastLifetime, cachedContent, ret;
+ int createdTime, ttl;
+
+ if lifetime != null && lifetime < 1 {
+ throw new Exception("The lifetime must be at least 1 second");
+ }
let prefixedKey = this->_prefix . this->getKey(keyName);
let this->_lastKey = prefixedKey;
@@ -117,33 +122,49 @@ class File extends Backend
let frontend = this->_frontend;
+ let cachedContent = json_decode(file_get_contents(cacheFile), true);
+
/**
* Take the lifetime from the frontend or read it from the set in start()
+ * if the cachedContent is not a valid json array
*/
if !lifetime {
let lastLifetime = this->_lastLifetime;
- if !lastLifetime {
- let ttl = (int) frontend->getLifeTime();
+ if this->isValidArray(cachedContent, "lifetime") {
+ let ttl = (int) cachedContent["lifetime"];
} else {
- let ttl = (int) lastLifetime;
+ let lastLifetime = this->_lastLifetime;
+ if !lastLifetime {
+ let ttl = (int) frontend->getLifeTime();
+ } else {
+ let ttl = (int) lastLifetime;
+ }
}
} else {
let ttl = (int) lifetime;
}
clearstatcache(true, cacheFile);
- let modifiedTime = (int) filemtime(cacheFile);
+ if !this->isValidArray(cachedContent, "created") {
+ let createdTime = (int) filemtime(cacheFile);
+ } else {
+ let createdTime = (int) cachedContent["created"];
+ }
/**
* Check if the file has expired
* The content is only retrieved if the content has not expired
*/
- if modifiedTime + ttl > time() {
+ if !(time() - ttl > createdTime) {
/**
* Use file-get-contents to control that the openbase_dir can't be skipped
*/
- let cachedContent = file_get_contents(cacheFile);
+ if !this->isValidArray(cachedContent, "content") {
+ let cachedContent = file_get_contents(cacheFile);
+ } else {
+ let cachedContent = cachedContent["content"];
+ }
if cachedContent === false {
throw new Exception("Cache file ". cacheFile. " could not be opened");
}
@@ -157,7 +178,15 @@ class File extends Backend
let ret = frontend->afterRetrieve(cachedContent);
return ret;
}
+ } else {
+ /**
+ * As the content is expired, deleting the cache file
+ */
+ this->delete(keyName);
+ return null;
}
+ } else {
+ return null;
}
return null;
@@ -170,9 +199,16 @@ class File extends Backend
* @param string content
* @param int lifetime
*/
- public function save(var keyName = null, var content = null, lifetime = null, boolean stopBuffer = true) -> boolean
+ public function save(var keyName = null, var content = null, var lifetime = null, bool stopBuffer = true) -> bool
{
- var lastKey, frontend, cacheDir, isBuffering, cacheFile, cachedContent, preparedContent, status;
+ var lastKey, frontend, cacheDir, isBuffering, cacheFile, cachedContent, preparedContent, status,
+ finalContent, lastLifetime;
+
+ int ttl;
+
+ if lifetime != null && lifetime < 1 {
+ throw new Exception("The lifetime must be at least 1 second");
+ }
if keyName === null {
let lastKey = this->_lastKey;
@@ -205,10 +241,27 @@ class File extends Backend
let preparedContent = cachedContent;
}
+ let preparedContent = frontend->beforeStore(cachedContent);
+ if !lifetime {
+ let lastLifetime = this->_lastLifetime;
+ if !lastLifetime {
+ let ttl = (int) frontend->getLifeTime();
+ } else {
+ let ttl = (int) lastLifetime;
+ }
+ } else {
+ let ttl = (int) lifetime;
+ }
/**
* We use file_put_contents to respect open-base-dir directive
*/
let status = file_put_contents(cacheFile, preparedContent);
+ if !is_numeric(cachedContent) {
+ let finalContent = json_encode(["created": time(), "lifetime": ttl, "content": preparedContent]);
+ } else {
+ let finalContent = json_encode(["created": time(), "lifetime": ttl, "content": cachedContent]);
+ }
+ let status = file_put_contents(cacheFile, finalContent);
if status === false {
throw new Exception("Cache file ". cacheFile . " could not be written");
@@ -234,7 +287,7 @@ class File extends Backend
*
* @param int|string keyName
*/
- public function delete(var keyName) -> boolean
+ public function delete(var keyName) -> bool
{
var cacheFile, cacheDir;
@@ -298,9 +351,11 @@ class File extends Backend
* @param string|int keyName
* @param int lifetime
*/
- public function exists(var keyName = null, int lifetime = null) -> boolean
+ public function exists(var keyName = null, int lifetime = null) -> bool
{
- var lastKey, prefix, cacheFile, ttl, modifiedTime;
+ var lastKey, prefix, cacheFile, cachedContent;
+ int ttl;
+ bool cacheFileExists;
if !keyName {
let lastKey = this->_lastKey;
@@ -313,29 +368,57 @@ class File extends Backend
let cacheFile = this->_options["cacheDir"] . lastKey;
- if file_exists(cacheFile) {
+ let cacheFileExists = file_exists(cacheFile);
+
+ if cacheFileExists {
/**
* Check if the file has expired
*/
+ let cachedContent = json_decode(file_get_contents(cacheFile), true);
if !lifetime {
- let ttl = (int) this->_frontend->getLifeTime();
+ if this->isValidArray(cachedContent, "lifetime") {
+ let ttl = (int) cachedContent["lifetime"];
+ } else {
+ let ttl = (int) this->_frontend->getLifeTime();
+ }
} else {
let ttl = (int) lifetime;
}
clearstatcache(true, cacheFile);
- let modifiedTime = (int) filemtime(cacheFile);
-
- if modifiedTime + ttl > time() {
+ if !this->isValidArray(cachedContent, "created") && filemtime(cacheFile) + ttl > time() {
return true;
+ } else {
+ if (cachedContent["created"] + ttl > time()) {
+ return true;
+ }
}
}
}
+ /**
+ * If the cache file exists and is expired, delete it
+ */
+ if cacheFileExists {
+ this->delete(keyName);
+ }
+
return false;
}
+ /**
+ * Check if given variable is array, containing the key $cacheKey
+ *
+ * @param array|null cachedContent
+ * @param string|null cacheKey
+ * @return bool
+ */
+ private function isValidArray(var cachedContent = null, var cacheKey = null)
+ {
+ return (is_array(cachedContent) && array_key_exists(cacheKey, cachedContent));
+ }
+
/**
* Increment of a given key, by number $value
*
@@ -343,8 +426,9 @@ class File extends Backend
*/
public function increment(var keyName = null, int value = 1) -> int | null
{
- var prefixedKey, cacheFile, frontend, lifetime, ttl,
- cachedContent, result, modifiedTime;
+ var prefixedKey, cacheFile, frontend,
+ cachedContent, result, lastLifetime, newValue;
+ int modifiedTime, ttl;
let prefixedKey = this->_prefix . this->getKey(keyName),
this->_lastKey = prefixedKey,
@@ -354,44 +438,73 @@ class File extends Backend
let frontend = this->_frontend;
+ /**
+ * Check if the file has expired
+ */
+ let cachedContent = json_decode(file_get_contents(cacheFile), true);
+
/**
* Take the lifetime from the frontend or read it from the set in start()
+ * if the cachedContent is not a valid array
*/
- let lifetime = this->_lastLifetime;
- if !lifetime {
- let ttl = frontend->getLifeTime();
+ if this->isValidArray(cachedContent, "lifetime") {
+ let ttl = (int) cachedContent["lifetime"];
} else {
- let ttl = lifetime;
+ let lastLifetime = this->_lastLifetime;
+ if !lastLifetime {
+ let ttl = (int) frontend->getLifeTime();
+ } else {
+ let ttl = (int) lastLifetime;
+ }
}
clearstatcache(true, cacheFile);
- let modifiedTime = (int) filemtime(cacheFile);
+
+ if !this->isValidArray(cachedContent, "created") {
+ let modifiedTime = (int) filemtime(cacheFile);
+ } else {
+ let modifiedTime = (int) cachedContent["created"];
+ }
/**
* Check if the file has expired
* The content is only retrieved if the content has not expired
*/
- if modifiedTime + ttl > time() {
+ if !(time() - ttl > modifiedTime) {
/**
* Use file-get-contents to control that the openbase_dir can't be skipped
*/
- let cachedContent = file_get_contents(cacheFile);
+ if !this->isValidArray(cachedContent, "content") {
+ let cachedContent = file_get_contents(cacheFile);
+ } else {
+ let cachedContent = cachedContent["content"];
+ }
if cachedContent === false {
throw new Exception("Cache file " . cacheFile . " could not be opened");
}
if is_numeric(cachedContent) {
+ let newValue = cachedContent + value;
+ let result = json_encode(["created": time(), "lifetime": ttl, "content": newValue]);
- let result = cachedContent + value;
if file_put_contents(cacheFile, result) === false {
throw new Exception("Cache directory could not be written");
}
- return result;
+ return newValue;
+ } else {
+ throw new Exception("The cache value is not numeric, therefore could not be incremented");
}
+ } else {
+ /**
+ * The cache file is expired, so we're removing it
+ */
+ this->delete(keyName);
+ return null;
}
+ return null;
}
return null;
@@ -404,7 +517,8 @@ class File extends Backend
*/
public function decrement(var keyName = null, int value = 1) -> int | null
{
- var prefixedKey, cacheFile, lifetime, ttl, cachedContent, result, modifiedTime;
+ var prefixedKey, cacheFile, cachedContent, result, lastLifetime, newValue;
+ int ttl, modifiedTime, lifetime;
let prefixedKey = this->_prefix . this->getKey(keyName),
this->_lastKey = prefixedKey,
@@ -412,44 +526,77 @@ class File extends Backend
if file_exists(cacheFile) {
+ /**
+ * Check if the file has expired
+ */
+ let cachedContent = json_decode(file_get_contents(cacheFile), true);
+
/**
* Take the lifetime from the frontend or read it from the set in start()
+ * if the cachedContent is not a valid array
*/
- let lifetime = this->_lastLifetime;
if !lifetime {
- let ttl = this->_frontend->getLifeTime();
+ if this->isValidArray(cachedContent, "lifetime") {
+ let ttl = (int) cachedContent["lifetime"];
+ } else {
+ let lastLifetime = this->_lastLifetime;
+ if !lastLifetime {
+ let ttl = (int) this->_frontend->getLifeTime();
+ } else {
+ let ttl = (int) lastLifetime;
+ }
+ }
+ } else {
+ let ttl = (int) lifetime;
+ }
+
+ if !this->isValidArray(cachedContent, "created") {
+ let modifiedTime = (int) filemtime(cacheFile);
+ let ttl = (int) lifetime;
} else {
- let ttl = lifetime;
+ let modifiedTime = (int) cachedContent["created"];
}
clearstatcache(true, cacheFile);
- let modifiedTime = (int) filemtime(cacheFile);
/**
* Check if the file has expired
* The content is only retrieved if the content has not expired
*/
- if modifiedTime + ttl > time() {
+ if !(time() - ttl > modifiedTime) {
/**
* Use file-get-contents to control that the openbase_dir can't be skipped
*/
- let cachedContent = file_get_contents(cacheFile);
+ if !this->isValidArray(cachedContent, "content") {
+ let cachedContent = file_get_contents(cacheFile);
+ } else {
+ let cachedContent = cachedContent["content"];
+ }
if cachedContent === false {
throw new Exception("Cache file " . cacheFile . " could not be opened");
}
if is_numeric(cachedContent) {
-
- let result = cachedContent - value;
+ let newValue = cachedContent - value;
+ let result = json_encode(["created": time(), "lifetime": ttl, "content": newValue]);
if file_put_contents(cacheFile, result) === false {
throw new Exception("Cache directory can't be written");
}
- return result;
+ return newValue;
+ } else {
+ throw new Exception("The cache value is not numeric, therefore could not decrement it");
}
+ } else {
+ /**
+ * The cache file is expired, so we're removing it
+ */
+ this->delete(keyName);
+ return null;
}
+ return null;
}
return null;
@@ -458,7 +605,7 @@ class File extends Backend
/**
* Immediately invalidates all existing items.
*/
- public function flush() -> boolean
+ public function flush() -> bool
{
var prefix, cacheDir, item, key, cacheFile;
@@ -507,3 +654,4 @@ class File extends Backend
return this;
}
}
+
diff --git a/phalcon/cache/backend/libmemcached.zep b/phalcon/cache/backend/libmemcached.zep
index f273ae4bbd2..51688a19eba 100644
--- a/phalcon/cache/backend/libmemcached.zep
+++ b/phalcon/cache/backend/libmemcached.zep
@@ -146,7 +146,7 @@ class Libmemcached extends Backend
/**
* Returns a cached content
*/
- public function get(string keyName, int lifetime = null) -> var | null
+ public function get(string keyName, var lifetime = null) -> var | null
{
var memcache, prefixedKey, cachedContent;
@@ -178,7 +178,7 @@ class Libmemcached extends Backend
* @param string content
* @param int lifetime
*/
- public function save(keyName = null, content = null, lifetime = null, boolean stopBuffer = true) -> boolean
+ public function save(keyName = null, content = null, lifetime = null, bool stopBuffer = true) -> bool
{
var lastKey, frontend, memcache, cachedContent, preparedContent, tmp, tt1, success, options,
specialKey, keys, isBuffering;
@@ -278,9 +278,9 @@ class Libmemcached extends Backend
* Deletes a value from the cache by its key
*
* @param int|string keyName
- * @return boolean
+ * @return bool
*/
- public function delete(keyName)
+ public function delete(var keyName) -> bool
{
var memcache, prefixedKey, options, keys, specialKey, ret;
@@ -367,7 +367,7 @@ class Libmemcached extends Backend
* @param string keyName
* @param int lifetime
*/
- public function exists(keyName = null, lifetime = null) -> boolean
+ public function exists(var keyName = null, int lifetime = null) -> bool
{
var lastKey, memcache, value;
@@ -398,7 +398,7 @@ class Libmemcached extends Backend
*
* @param string keyName
*/
- public function increment(keyName = null, int value = 1) -> int | boolean
+ public function increment(keyName = null, int value = 1) -> int | bool
{
var memcache, prefix, lastKey;
@@ -425,7 +425,7 @@ class Libmemcached extends Backend
*
* @param string keyName
*/
- public function decrement(keyName = null, int value = 1) -> int | boolean
+ public function decrement(keyName = null, int value = 1) -> int | bool
{
var memcache, prefix, lastKey;
@@ -467,7 +467,7 @@ class Libmemcached extends Backend
* $cache->flush();
*
*/
- public function flush() -> boolean
+ public function flush() -> bool
{
var memcache, options, keys, specialKey, key;
diff --git a/phalcon/cache/backend/memcache.zep b/phalcon/cache/backend/memcache.zep
deleted file mode 100644
index 258f41dc630..00000000000
--- a/phalcon/cache/backend/memcache.zep
+++ /dev/null
@@ -1,488 +0,0 @@
-
-/*
- +------------------------------------------------------------------------+
- | Phalcon Framework |
- +------------------------------------------------------------------------+
- | Copyright (c) 2011-2017 Phalcon Team (https://phalconphp.com) |
- +------------------------------------------------------------------------+
- | This source file is subject to the New BSD License that is bundled |
- | with this package in the file 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 we can send you a copy immediately. |
- +------------------------------------------------------------------------+
- | Authors: Andres Gutierrez |
- | Eduar Carvajal |
- +------------------------------------------------------------------------+
- */
-
-namespace Phalcon\Cache\Backend;
-
-use Phalcon\Cache\Backend;
-use Phalcon\Cache\Exception;
-use Phalcon\Cache\FrontendInterface;
-
-/**
- * Phalcon\Cache\Backend\Memcache
- *
- * Allows to cache output fragments, PHP data or raw data to a memcache backend
- *
- * This adapter uses the special memcached key "_PHCM" to store all the keys internally used by the adapter
- *
- *
- * use Phalcon\Cache\Backend\Memcache;
- * use Phalcon\Cache\Frontend\Data as FrontData;
- *
- * // Cache data for 2 days
- * $frontCache = new FrontData(
- * [
- * "lifetime" => 172800,
- * ]
- * );
- *
- * // Create the Cache setting memcached connection options
- * $cache = new Memcache(
- * $frontCache,
- * [
- * "host" => "localhost",
- * "port" => 11211,
- * "persistent" => false,
- * ]
- * );
- *
- * // Cache arbitrary data
- * $cache->save("my-data", [1, 2, 3, 4, 5]);
- *
- * // Get data
- * $data = $cache->get("my-data");
- *
- */
-class Memcache extends Backend
-{
-
- protected _memcache = null;
-
- /**
- * Phalcon\Cache\Backend\Memcache constructor
- */
- public function __construct( frontend, array options = [])
- {
- if !isset options["host"] {
- let options["host"] = "127.0.0.1";
- }
-
- if !isset options["port"] {
- let options["port"] = 11211;
- }
-
- if !isset options["persistent"] {
- let options["persistent"] = false;
- }
-
- if !isset options["statsKey"] {
- // Disable tracking of cached keys per default
- let options["statsKey"] = "";
- }
-
- parent::__construct(frontend, options);
- }
-
- /**
- * Create internal connection to memcached
- */
- public function _connect()
- {
- var options, memcache, persistent, success, host, port;
-
- let options = this->_options;
- let memcache = new \Memcache();
-
- if !fetch host, options["host"] || !fetch port, options["port"] || !fetch persistent, options["persistent"] {
- throw new Exception("Unexpected inconsistency in options");
- }
-
- if persistent {
- let success = memcache->pconnect(host, port);
- } else {
- let success = memcache->connect(host, port);
- }
-
- if !success {
- throw new Exception("Cannot connect to Memcached server");
- }
-
- let this->_memcache = memcache;
- }
-
- /**
- * Add servers to memcache pool
- */
- public function addServers(string! host, int port, boolean persistent = false) -> boolean
- {
- var memcache, success;
- /**
- * Check if a connection is created or make a new one
- */
- let memcache = this->_memcache;
- if typeof memcache != "object" {
- this->_connect();
- let memcache = this->_memcache;
- }
- let success = memcache->addServer(host, port, persistent);
- let this->_memcache = memcache;
- return success;
- }
-
- /**
- * Returns a cached content
- */
- public function get(string keyName, int lifetime = null) -> var | null
- {
- var memcache, prefixedKey, cachedContent, retrieve;
-
- let memcache = this->_memcache;
- if typeof memcache != "object" {
- this->_connect();
- let memcache = this->_memcache;
- }
-
- let prefixedKey = this->_prefix . keyName;
- let this->_lastKey = prefixedKey;
- let cachedContent = memcache->get(prefixedKey);
-
- if cachedContent === false {
- return null;
- }
-
- if is_numeric(cachedContent) {
- return cachedContent;
- }
-
- let retrieve = this->_frontend->afterRetrieve(cachedContent);
- return retrieve;
- }
-
- /**
- * Stores cached content into the file backend and stops the frontend
- *
- * @param int|string keyName
- * @param string content
- * @param int lifetime
- */
- public function save(var keyName = null, var content = null, var lifetime = null, boolean stopBuffer = true) -> boolean
- {
- var lastKey, frontend, memcache, cachedContent, preparedContent, tmp, ttl, success, options,
- specialKey, keys, isBuffering;
-
- if keyName === null {
- let lastKey = this->_lastKey;
- } else {
- let lastKey = this->_prefix . keyName,
- this->_lastKey = lastKey;
- }
-
- if !lastKey {
- throw new Exception("Cache must be started first");
- }
-
- let frontend = this->_frontend;
-
- /**
- * Check if a connection is created or make a new one
- */
- let memcache = this->_memcache;
- if typeof memcache != "object" {
- this->_connect();
- let memcache = this->_memcache;
- }
-
- if content === null {
- let cachedContent = frontend->getContent();
- } else {
- let cachedContent = content;
- }
-
- /**
- * Prepare the content in the frontend
- */
- if !is_numeric(cachedContent) {
- let preparedContent = frontend->beforeStore(cachedContent);
- } else {
- let preparedContent = cachedContent;
- }
-
- if lifetime === null {
- let tmp = this->_lastLifetime;
-
- if !tmp {
- let ttl = frontend->getLifetime();
- } else {
- let ttl = tmp;
- }
- } else {
- let ttl = lifetime;
- }
-
- /**
- * We store without flags
- */
- let success = memcache->set(lastKey, preparedContent, 0, ttl);
-
- if !success {
- throw new Exception("Failed storing data in memcached");
- }
-
- let options = this->_options;
-
- if !fetch specialKey, options["statsKey"] {
- throw new Exception("Unexpected inconsistency in options");
- }
-
- if specialKey != "" {
- /**
- * Update the stats key
- */
- let keys = memcache->get(specialKey);
- if typeof keys != "array" {
- let keys = [];
- }
-
- if !isset keys[lastKey] {
- let keys[lastKey] = ttl;
- memcache->set(specialKey, keys);
- }
- }
-
- let isBuffering = frontend->isBuffering();
-
- if stopBuffer === true {
- frontend->stop();
- }
-
- if isBuffering === true {
- echo cachedContent;
- }
-
- let this->_started = false;
-
- return success;
- }
-
- /**
- * Deletes a value from the cache by its key
- *
- * @param int|string keyName
- */
- public function delete(var keyName) -> boolean
- {
- var memcache, prefixedKey, options, keys, specialKey, ret;
-
- let memcache = this->_memcache;
- if typeof memcache != "object" {
- this->_connect();
- let memcache = this->_memcache;
- }
-
- let prefixedKey = this->_prefix . keyName;
- let options = this->_options;
-
- if !fetch specialKey, options["statsKey"] {
- throw new Exception("Unexpected inconsistency in options");
- }
-
- if specialKey != "" {
- let keys = memcache->get(specialKey);
-
- if typeof keys == "array" {
- unset keys[prefixedKey];
- memcache->set(specialKey, keys);
- }
- }
-
- /**
- * Delete the key from memcached
- */
- let ret = memcache->delete(prefixedKey);
- return ret;
- }
-
- /**
- * Query the existing cached keys.
- *
- *
- * $cache->save("users-ids", [1, 2, 3]);
- * $cache->save("projects-ids", [4, 5, 6]);
- *
- * var_dump($cache->queryKeys("users")); // ["users-ids"]
- *
- */
- public function queryKeys(string prefix = null) -> array
- {
- var memcache, options, keys, specialKey, key, idx;
-
- let memcache = this->_memcache;
-
- if typeof memcache != "object" {
- this->_connect();
- let memcache = this->_memcache;
- }
-
- let options = this->_options;
-
- if !fetch specialKey, options["statsKey"] {
- throw new Exception("Unexpected inconsistency in options");
- }
-
- if specialKey == "" {
- throw new Exception("Cached keys need to be enabled to use this function (options['statsKey'] == '_PHCM')!");
- }
-
- /**
- * Get the key from memcached
- */
- let keys = memcache->get(specialKey);
- if unlikely typeof keys != "array" {
- return [];
- }
-
- let keys = array_keys(keys);
- for idx, key in keys {
- if !empty prefix && !starts_with(key, prefix) {
- unset keys[idx];
- }
- }
-
- return keys;
- }
-
- /**
- * Checks if cache exists and it isn't expired
- *
- * @param string keyName
- * @param int lifetime
- */
- public function exists(keyName = null, lifetime = null) -> boolean
- {
- var lastKey, memcache, prefix;
-
- if !keyName {
- let lastKey = this->_lastKey;
- } else {
- let prefix = this->_prefix;
- let lastKey = prefix . keyName;
- }
-
- if lastKey {
-
- let memcache = this->_memcache;
- if typeof memcache != "object" {
- this->_connect();
- let memcache = this->_memcache;
- }
-
- if !memcache->get(lastKey) {
- return false;
- }
- return true;
- }
-
- return false;
- }
-
- /**
- * Increment of given $keyName by $value
- *
- * @param string keyName
- */
- public function increment(keyName = null, int value = 1) -> int | boolean
- {
- var memcache, prefix, lastKey;
-
- let memcache = this->_memcache;
-
- if typeof memcache != "object" {
- this->_connect();
- let memcache = this->_memcache;
- }
-
- if !keyName {
- let lastKey = this->_lastKey;
- } else {
- let prefix = this->_prefix;
- let lastKey = prefix . keyName;
- let this->_lastKey = lastKey;
- }
-
- return memcache->increment(lastKey, value);
- }
-
- /**
- * Decrement of $keyName by given $value
- *
- * @param string keyName
- */
- public function decrement(keyName = null, int value = 1) -> int | boolean
- {
- var memcache, prefix, lastKey;
-
- let memcache = this->_memcache;
-
- if typeof memcache != "object" {
- this->_connect();
- let memcache = this->_memcache;
- }
-
- if !keyName {
- let lastKey = this->_lastKey;
- } else {
- let prefix = this->_prefix;
- let lastKey = prefix . keyName;
- let this->_lastKey = lastKey;
- }
-
- return memcache->decrement(lastKey, value);
- }
-
- /**
- * Immediately invalidates all existing items.
- */
- public function flush() -> boolean
- {
- var memcache, options, keys, specialKey, key;
-
- let memcache = this->_memcache;
-
- if typeof memcache != "object" {
- this->_connect();
- let memcache = this->_memcache;
- }
-
- let options = this->_options;
-
- if !fetch specialKey, options["statsKey"] {
- throw new Exception("Unexpected inconsistency in options");
- }
-
- if specialKey == "" {
- throw new Exception("Cached keys need to be enabled to use this function (options['statsKey'] == '_PHCM')!");
- }
-
- /**
- * Get the key from memcached
- */
- let keys = memcache->get(specialKey);
- if unlikely typeof keys != "array" {
- return true;
- }
-
- for key, _ in keys {
- memcache->delete(key);
- }
-
- memcache->delete(specialKey);
-
- return true;
- }
-
-}
diff --git a/phalcon/cache/backend/memory.zep b/phalcon/cache/backend/memory.zep
index 6a5b3887401..e86a6eb3047 100644
--- a/phalcon/cache/backend/memory.zep
+++ b/phalcon/cache/backend/memory.zep
@@ -51,7 +51,7 @@ class Memory extends Backend implements \Serializable
/**
* Returns a cached content
*/
- public function get(string keyName, int lifetime = null) -> var | null
+ public function get(string keyName, var lifetime = null) -> var | null
{
var lastKey, cachedContent;
@@ -79,7 +79,7 @@ class Memory extends Backend implements \Serializable
* @param string content
* @param int lifetime
*/
- public function save(var keyName = null, var content = null, lifetime = null, boolean stopBuffer = true) -> boolean
+ public function save(var keyName = null, var content = null, lifetime = null, bool stopBuffer = true) -> bool
{
var lastKey, frontend, cachedContent, preparedContent, isBuffering;
@@ -129,7 +129,7 @@ class Memory extends Backend implements \Serializable
*
* @param string keyName
*/
- public function delete(var keyName) -> boolean
+ public function delete(var keyName) -> bool
{
var key, data;
@@ -181,7 +181,7 @@ class Memory extends Backend implements \Serializable
* @param string|int keyName
* @param int lifetime
*/
- public function exists(var keyName = null, lifetime = null) -> boolean
+ public function exists(var keyName = null, int lifetime = null) -> bool
{
var lastKey;
@@ -265,7 +265,7 @@ class Memory extends Backend implements \Serializable
/**
* Immediately invalidates all existing items.
*/
- public function flush() -> boolean
+ public function flush() -> bool
{
let this->_data = null;
return true;
diff --git a/phalcon/cache/backend/mongo.zep b/phalcon/cache/backend/mongo.zep
index 574f5dfb3a1..617d2746810 100644
--- a/phalcon/cache/backend/mongo.zep
+++ b/phalcon/cache/backend/mongo.zep
@@ -150,7 +150,7 @@ class Mongo extends Backend
/**
* Returns a cached content
*/
- public function get(string keyName, int lifetime = null) -> var | null
+ public function get(string keyName, var lifetime = null) -> var | null
{
var frontend, prefixedKey, conditions, document, cachedContent;
@@ -184,7 +184,7 @@ class Mongo extends Backend
* @param string content
* @param int lifetime
*/
- public function save(keyName = null, content = null, lifetime = null, boolean stopBuffer = true) -> boolean
+ public function save(keyName = null, content = null, lifetime = null, bool stopBuffer = true) -> bool
{
var lastkey, frontend, cachedContent, tmp, ttl,
collection, timestamp, conditions, document, preparedContent,
@@ -268,7 +268,7 @@ class Mongo extends Backend
*
* @param int|string keyName
*/
- public function delete(keyName) -> boolean
+ public function delete(var keyName) -> bool
{
this->_getCollection()->remove(["key": this->_prefix . keyName]);
@@ -320,7 +320,7 @@ class Mongo extends Backend
* @param string keyName
* @param int lifetime
*/
- public function exists(keyName = null, lifetime = null) -> boolean
+ public function exists(var keyName = null, int lifetime = null) -> bool
{
var lastKey;
@@ -424,7 +424,7 @@ class Mongo extends Backend
/**
* Immediately invalidates all existing items.
*/
- public function flush() -> boolean
+ public function flush() -> bool
{
this->_getCollection()->remove();
diff --git a/phalcon/cache/backend/redis.zep b/phalcon/cache/backend/redis.zep
index 18c702b2c26..49280d4b37c 100644
--- a/phalcon/cache/backend/redis.zep
+++ b/phalcon/cache/backend/redis.zep
@@ -168,7 +168,7 @@ class Redis extends Backend
/**
* Returns a cached content
*/
- public function get(string keyName, int lifetime = null) -> var | null
+ public function get(string keyName, var lifetime = null) -> var | null
{
var redis, frontend, cachedContent;
@@ -206,9 +206,9 @@ class Redis extends Backend
* @param int|string keyName
* @param string content
* @param int lifetime
- * @param boolean stopBuffer
+ * @param bool stopBuffer
*/
- public function save(keyName = null, content = null, lifetime = null, boolean stopBuffer = true) -> boolean
+ public function save(keyName = null, content = null, lifetime = null, bool stopBuffer = true) -> bool
{
var prefixedKey, frontend, redis, cachedContent, preparedContent,
tmp, ttl, success, isBuffering;
@@ -296,7 +296,7 @@ class Redis extends Backend
*
* @param int|string keyName
*/
- public function delete(keyName) -> boolean
+ public function delete(var keyName) -> bool
{
var redis, prefixedKey;
@@ -331,7 +331,7 @@ class Redis extends Backend
*/
public function queryKeys(string prefix = null) -> array
{
- var redis, options, keys, key, idx;
+ var redis, keys, key, idx;
let redis = this->redis;
if typeof redis != "object" {
@@ -366,7 +366,7 @@ class Redis extends Backend
* @param string keyName
* @param int lifetime
*/
- public function exists(keyName = null, lifetime = null) -> boolean
+ public function exists(var keyName = null, int lifetime = null) -> bool
{
var redis;
@@ -434,7 +434,7 @@ class Redis extends Backend
/**
* Immediately invalidates all existing items.
*/
- public function flush() -> boolean
+ public function flush() -> bool
{
var redis, keys, key, lastKey;
@@ -475,4 +475,4 @@ class Redis extends Backend
{
return this->statsKey . this->getPrefixedKey(keyName);
}
-}
\ No newline at end of file
+}
diff --git a/phalcon/cache/backend/xcache.zep b/phalcon/cache/backend/xcache.zep
deleted file mode 100644
index 138a033c961..00000000000
--- a/phalcon/cache/backend/xcache.zep
+++ /dev/null
@@ -1,382 +0,0 @@
-
-/*
- +------------------------------------------------------------------------+
- | Phalcon Framework |
- +------------------------------------------------------------------------+
- | Copyright (c) 2011-2017 Phalcon Team (https://phalconphp.com) |
- +------------------------------------------------------------------------+
- | This source file is subject to the New BSD License that is bundled |
- | with this package in the file 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 we can send you a copy immediately. |
- +------------------------------------------------------------------------+
- | Authors: Andres Gutierrez |
- | Eduar Carvajal |
- +------------------------------------------------------------------------+
- */
-
-namespace Phalcon\Cache\Backend;
-
-use Phalcon\Cache\Backend;
-use Phalcon\Cache\Exception;
-use Phalcon\Cache\FrontendInterface;
-
-/**
- * Phalcon\Cache\Backend\Xcache
- *
- * Allows to cache output fragments, PHP data and raw data using an XCache backend
- *
- *
- * use Phalcon\Cache\Backend\Xcache;
- * use Phalcon\Cache\Frontend\Data as FrontData;
- *
- * // Cache data for 2 days
- * $frontCache = new FrontData(
- * [
- * "lifetime" => 172800,
- * ]
- * );
- *
- * $cache = new Xcache(
- * $frontCache,
- * [
- * "prefix" => "app-data",
- * ]
- * );
- *
- * // Cache arbitrary data
- * $cache->save("my-data", [1, 2, 3, 4, 5]);
- *
- * // Get data
- * $data = $cache->get("my-data");
- *
- */
-class Xcache extends Backend
-{
-
- /**
- * Phalcon\Cache\Backend\Xcache constructor
- */
- public function __construct( frontend, array options = [])
- {
- if typeof options != "array" {
- let options = [];
- }
-
- if !isset options["statsKey"] {
- // Disable tracking of cached keys per default
- let options["statsKey"] = "";
- }
-
- parent::__construct(frontend, options);
- }
-
- /**
- * Returns a cached content
- */
- public function get(string keyName, int lifetime = null) -> var | null
- {
- var frontend, prefixedKey, cachedContent;
-
- let frontend = this->_frontend;
- let prefixedKey = "_PHCX" . this->_prefix . keyName;
- let this->_lastKey = prefixedKey;
- let cachedContent = xcache_get(prefixedKey);
-
- if !cachedContent {
- return null;
- }
-
- if is_numeric(cachedContent) {
- return cachedContent;
- } else {
- return frontend->afterRetrieve(cachedContent);
- }
- }
-
- /**
- * Stores cached content into the file backend and stops the frontend
- *
- * @param int|string keyName
- * @param string content
- * @param int lifetime
- */
- public function save(keyName = null, content = null, lifetime = null, boolean stopBuffer = true) -> boolean
- {
- var lastKey, frontend, cachedContent, preparedContent, tmp, tt1, success, isBuffering,
- options, keys, specialKey;
-
- if keyName === null {
- let lastKey = this->_lastKey;
- } else {
- let lastKey = "_PHCX" . this->_prefix . keyName,
- this->_lastKey = lastKey;
- }
-
- if !lastKey {
- throw new Exception("Cache must be started first");
- }
-
- let frontend = this->_frontend;
- if content === null {
- let cachedContent = frontend->getContent();
- } else {
- let cachedContent = content;
- }
-
- if !is_numeric(cachedContent) {
- let preparedContent = frontend->beforeStore(cachedContent);
- } else {
- let preparedContent = cachedContent;
- }
-
- /**
- * Take the lifetime from the frontend or read it from the set in start()
- */
- if lifetime === null {
- let tmp = this->_lastLifetime;
- if !tmp {
- let tt1 = frontend->getLifetime();
- } else {
- let tt1 = tmp;
- }
- } else {
- let tt1 = lifetime;
- }
-
- let success = xcache_set(lastKey, preparedContent, tt1);
-
- if !success {
- throw new Exception("Failed storing the data in xcache");
- }
-
- let isBuffering = frontend->isBuffering();
-
- if stopBuffer === true {
- frontend->stop();
- }
-
- if isBuffering === true {
- echo cachedContent;
- }
-
- let this->_started = false;
-
- if success {
- let options = this->_options;
-
- if !fetch specialKey, this->_options["statsKey"] {
- throw new Exception("Unexpected inconsistency in options");
- }
-
- if specialKey != "" {
- /**
- * xcache_list() is available only to the administrator (unless XCache was
- * patched). We have to update the list of the stored keys.
- */
- let keys = xcache_get(specialKey);
- if typeof keys != "array" {
- let keys = [];
- }
-
- let keys[lastKey] = tt1;
- xcache_set(specialKey, keys);
- }
- }
-
- return success;
- }
-
- /**
- * Deletes a value from the cache by its key
- *
- * @param int|string keyName
- * @return boolean
- */
- public function delete(var keyName)
- {
- var prefixedKey, specialKey, keys;
-
- let prefixedKey = "_PHCX" . this->_prefix . keyName;
-
- if !fetch specialKey, this->_options["statsKey"] {
- throw new Exception("Unexpected inconsistency in options");
- }
-
- if specialKey != "" {
- let keys = xcache_get(specialKey);
- if typeof keys != "array" {
- let keys = [];
- }
-
- unset keys[prefixedKey];
-
- xcache_set(specialKey, keys);
- }
- }
-
- /**
- * Query the existing cached keys.
- *
- *
- * $cache->save("users-ids", [1, 2, 3]);
- * $cache->save("projects-ids", [4, 5, 6]);
- *
- * var_dump($cache->queryKeys("users")); // ["users-ids"]
- *
- */
- public function queryKeys(string prefix = null) -> array
- {
- var options, prefixed, specialKey, keys, retval, key, realKey;
-
- if !prefix {
- let prefixed = "_PHCX";
- } else {
- let prefixed = "_PHCX" . prefix;
- }
-
- let options = this->_options;
-
- if !fetch specialKey, this->_options["statsKey"] {
- throw new Exception("Unexpected inconsistency in options");
- }
-
- if specialKey == "" {
- throw new Exception("Cached keys need to be enabled to use this function (options['statsKey'] == '_PHCX')!");
- }
-
- /**
- * Get the key from XCache (we cannot use xcache_list() as it is available only to
- * the administrator)
- */
- let keys = xcache_get(specialKey);
- if typeof keys != "array" {
- return [];
- }
-
- let retval = [];
-
- for key, _ in keys {
- if starts_with(key, prefixed) {
- let realKey = substr(key, 5);
- let retval[] = realKey;
- }
- }
-
- return retval;
- }
-
- /**
- * Checks if cache exists and it isn't expired
- *
- * @param string keyName
- * @param int lifetime
- */
- public function exists(var keyName = null, lifetime = null) -> boolean
- {
- var lastKey;
-
- if !keyName {
- let lastKey = this->_lastKey;
- } else {
- let lastKey = "_PHCX" . this->_prefix . keyName;
- }
-
- if lastKey {
- return xcache_isset(lastKey);
- }
- return false;
- }
-
- /**
- * Atomic increment of a given key, by number $value
- *
- * @param string keyName
- */
- public function increment(var keyName, int value = 1) -> int
- {
- var lastKey, newVal, origVal;
-
- if !keyName {
- let lastKey = this->_lastKey;
- } else {
- let lastKey = "_PHCX" . this->_prefix . keyName;
- }
-
- if !lastKey {
- throw new Exception("Cache must be started first");
- }
-
- if function_exists("xcache_inc") {
- let newVal = xcache_inc(lastKey, value);
- } else {
- let origVal = xcache_get(lastKey);
- let newVal = origVal - value;
- xcache_set(lastKey, newVal);
- }
-
- return newVal;
- }
-
- /**
- * Atomic decrement of a given key, by number $value
- *
- * @param string keyName
- */
- public function decrement(keyName, int value = 1) -> int
- {
- var lastKey, newVal, origVal, success;
-
- if !keyName {
- let lastKey = this->_lastKey;
- } else {
- let lastKey = "_PHCX" . this->_prefix . keyName;
- }
-
- if !lastKey {
- throw new Exception("Cache must be started first");
- }
-
- if function_exists("xcache_dec") {
- let newVal = xcache_dec(lastKey, value);
- } else {
- let origVal = xcache_get(lastKey);
- let newVal = origVal - value;
- let success = xcache_set(lastKey, newVal);
- }
-
- return newVal;
- }
-
- /**
- * Immediately invalidates all existing items.
- */
- public function flush() -> boolean
- {
- var options, specialKey, keys, key;
-
- let options = this->_options;
-
- if !fetch specialKey, this->_options["statsKey"] {
- throw new Exception("Unexpected inconsistency in options");
- }
-
- if specialKey == "" {
- throw new Exception("Cached keys need to be enabled to use this function (options['statsKey'] == '_PHCM')!");
- }
-
- let keys = xcache_get(specialKey);
-
- if typeof keys == "array" {
- for key, _ in keys {
- unset keys[key];
- xcache_unset(key);
- }
- xcache_set(specialKey, keys);
- }
-
- return true;
- }
-}
diff --git a/phalcon/cache/backendinterface.zep b/phalcon/cache/backendinterface.zep
index b5a9de5ed77..51b7c400a57 100644
--- a/phalcon/cache/backendinterface.zep
+++ b/phalcon/cache/backendinterface.zep
@@ -38,7 +38,7 @@ interface BackendInterface
/**
* Stops the frontend without store any cached content
*/
- public function stop(boolean stopBuffer = true);
+ public function stop(bool stopBuffer = true);
/**
* Returns front-end instance adapter related to the back-end
@@ -53,12 +53,12 @@ interface BackendInterface
/**
* Checks whether the last cache is fresh or cached
*/
- public function isFresh() -> boolean;
+ public function isFresh() -> bool;
/**
* Checks whether the cache has starting buffering or not
*/
- public function isStarted() -> boolean;
+ public function isStarted() -> bool;
/**
* Sets the last key used in the cache
@@ -73,7 +73,7 @@ interface BackendInterface
/**
* Returns a cached content
*/
- public function get(string keyName, int lifetime = null) -> var | null;
+ public function get(string keyName, var lifetime = null) -> var | null;
/**
* Stores cached content into the file backend and stops the frontend
@@ -81,16 +81,16 @@ interface BackendInterface
* @param int|string keyName
* @param string content
* @param int lifetime
- * @return boolean true on success/false otherwise
+ * @return bool true on success/false otherwise
*/
- public function save(keyName = null, content = null, lifetime = null, boolean stopBuffer = true) -> boolean;
+ public function save(keyName = null, content = null, lifetime = null, bool stopBuffer = true) -> bool;
/**
* Deletes a value from the cache by its key
*
* @param int|string keyName
*/
- public function delete(keyName) -> boolean;
+ public function delete(keyName) -> bool;
/**
* Query the existing cached keys
@@ -103,5 +103,5 @@ interface BackendInterface
* @param string keyName
* @param int lifetime
*/
- public function exists(keyName = null, int lifetime = null) -> boolean;
+ public function exists(var keyName = null, int lifetime = null) -> bool;
}
diff --git a/phalcon/cache/frontend/base64.zep b/phalcon/cache/frontend/base64.zep
index 29e5fc2c1fe..e951d01875c 100644
--- a/phalcon/cache/frontend/base64.zep
+++ b/phalcon/cache/frontend/base64.zep
@@ -97,7 +97,7 @@ class Base64 implements FrontendInterface
/**
* Check whether if frontend is buffering output
*/
- public function isBuffering() -> boolean
+ public function isBuffering() -> bool
{
return false;
}
diff --git a/phalcon/cache/frontend/data.zep b/phalcon/cache/frontend/data.zep
index 8f2facf5525..53a338ab37c 100644
--- a/phalcon/cache/frontend/data.zep
+++ b/phalcon/cache/frontend/data.zep
@@ -102,7 +102,7 @@ class Data implements FrontendInterface
/**
* Check whether if frontend is buffering output
*/
- public function isBuffering() -> boolean
+ public function isBuffering() -> bool
{
return false;
}
diff --git a/phalcon/cache/frontend/factory.zep b/phalcon/cache/frontend/factory.zep
index 86dbe0dfc6c..6d33109202c 100644
--- a/phalcon/cache/frontend/factory.zep
+++ b/phalcon/cache/frontend/factory.zep
@@ -42,7 +42,7 @@ class Factory extends BaseFactory
/**
* @param \Phalcon\Config|array config
*/
- public static function load(var config) ->
+ public static function load(var config) -> object
{
return self::loadClass("Phalcon\\Cache\\Frontend", config);
}
diff --git a/phalcon/cache/frontend/igbinary.zep b/phalcon/cache/frontend/igbinary.zep
index 8baaf267a48..5c4bdcf66d3 100644
--- a/phalcon/cache/frontend/igbinary.zep
+++ b/phalcon/cache/frontend/igbinary.zep
@@ -99,7 +99,7 @@ class Igbinary extends Data implements FrontendInterface
/**
* Check whether if frontend is buffering output
*/
- public function isBuffering() -> boolean
+ public function isBuffering() -> bool
{
return false;
}
diff --git a/phalcon/cache/frontend/json.zep b/phalcon/cache/frontend/json.zep
index 145370390cd..f074a215f17 100644
--- a/phalcon/cache/frontend/json.zep
+++ b/phalcon/cache/frontend/json.zep
@@ -89,7 +89,7 @@ class Json implements FrontendInterface
/**
* Check whether if frontend is buffering output
*/
- public function isBuffering() -> boolean
+ public function isBuffering() -> bool
{
return false;
}
diff --git a/phalcon/cache/frontend/msgpack.zep b/phalcon/cache/frontend/msgpack.zep
index 167d0a4c893..88146604188 100644
--- a/phalcon/cache/frontend/msgpack.zep
+++ b/phalcon/cache/frontend/msgpack.zep
@@ -110,7 +110,7 @@ class Msgpack extends Data implements FrontendInterface
/**
* Check whether if frontend is buffering output
*/
- public function isBuffering() -> boolean
+ public function isBuffering() -> bool
{
return false;
}
diff --git a/phalcon/cache/frontend/none.zep b/phalcon/cache/frontend/none.zep
index afe63eebad8..c851acd68f4 100644
--- a/phalcon/cache/frontend/none.zep
+++ b/phalcon/cache/frontend/none.zep
@@ -79,7 +79,7 @@ class None implements FrontendInterface
/**
* Check whether if frontend is buffering output, always false
*/
- public function isBuffering() -> boolean
+ public function isBuffering() -> bool
{
return false;
}
diff --git a/phalcon/cache/frontend/output.zep b/phalcon/cache/frontend/output.zep
index 2fe57f44127..453d41902d7 100644
--- a/phalcon/cache/frontend/output.zep
+++ b/phalcon/cache/frontend/output.zep
@@ -106,7 +106,7 @@ class Output implements FrontendInterface
/**
* Check whether if frontend is buffering output
*/
- public function isBuffering() -> boolean
+ public function isBuffering() -> bool
{
return this->_buffering;
}
diff --git a/phalcon/cache/frontendinterface.zep b/phalcon/cache/frontendinterface.zep
index 8a484f1e4a2..e7c8414ca5a 100644
--- a/phalcon/cache/frontendinterface.zep
+++ b/phalcon/cache/frontendinterface.zep
@@ -35,7 +35,7 @@ interface FrontendInterface
/**
* Check whether if frontend is buffering output
*/
- public function isBuffering() -> boolean;
+ public function isBuffering() -> bool;
/**
* Starts the frontend
diff --git a/phalcon/cache/multiple.zep b/phalcon/cache/multiple.zep
index 4567db18c49..c5f8218f31a 100644
--- a/phalcon/cache/multiple.zep
+++ b/phalcon/cache/multiple.zep
@@ -154,7 +154,7 @@ class Multiple
* @param string keyName
* @param string content
* @param int lifetime
- * @param boolean stopBuffer
+ * @param bool stopBuffer
*/
public function save(var keyName = null, content = null, lifetime = null, stopBuffer = null) -> void
{
@@ -170,7 +170,7 @@ class Multiple
*
* @param string|int keyName
*/
- public function delete(var keyName) -> boolean
+ public function delete(var keyName) -> bool
{
var backend;
@@ -187,7 +187,7 @@ class Multiple
* @param string|int keyName
* @param int lifetime
*/
- public function exists(var keyName = null, lifetime = null) -> boolean
+ public function exists(var keyName = null, lifetime = null) -> bool
{
var backend;
@@ -203,7 +203,7 @@ class Multiple
/**
* Flush all backend(s)
*/
- public function flush() -> boolean
+ public function flush() -> bool
{
var backend;
diff --git a/phalcon/cli/console.zep b/phalcon/cli/console.zep
index b3d9b736591..56385a80372 100644
--- a/phalcon/cli/console.zep
+++ b/phalcon/cli/console.zep
@@ -146,7 +146,7 @@ class Console extends BaseApplication
/**
* Set an specific argument
*/
- public function setArgument(array! arguments = null, boolean! str = true, boolean! shift = true) ->
+ public function setArgument(array! arguments = null, bool! str = true, bool! shift = true) ->
{
var arg, pos, args, opts, handleArgs;
diff --git a/phalcon/cli/dispatcher.zep b/phalcon/cli/dispatcher.zep
index e56f3ab3fde..ff88848a6b7 100644
--- a/phalcon/cli/dispatcher.zep
+++ b/phalcon/cli/dispatcher.zep
@@ -195,7 +195,7 @@ class Dispatcher extends CliDispatcher implements DispatcherInterface
/**
* Check if an option exists
*/
- public function hasOption(var option) -> boolean
+ public function hasOption(var option) -> bool
{
return isset this->_options[option];
}
@@ -204,11 +204,14 @@ class Dispatcher extends CliDispatcher implements DispatcherInterface
* Calls the action method.
*/
public function callActionMethod(handler, string actionMethod, array! params = []) -> var
- {
- var options;
+ {
+ var params;
- let options = this->_options;
-
- return call_user_func_array([handler, actionMethod], [params, options]);
+ // This is to make sure that the paramters are zero-indexed and
+ // their order isn't overriden by any options when we merge the array.
+ let params = array_values(params);
+ let params = array_merge(params, this->_options);
+
+ return call_user_func_array([handler, actionMethod], params);
}
}
diff --git a/phalcon/cli/router.zep b/phalcon/cli/router.zep
index 01cb0034753..217cfe9c585 100644
--- a/phalcon/cli/router.zep
+++ b/phalcon/cli/router.zep
@@ -78,7 +78,7 @@ class Router implements \Phalcon\Di\InjectionAwareInterface
/**
* Phalcon\Cli\Router constructor
*/
- public function __construct(boolean defaultRoutes = true)
+ public function __construct(bool defaultRoutes = true)
{
var routes;
@@ -448,7 +448,7 @@ class Router implements \Phalcon\Di\InjectionAwareInterface
/**
* Checks if the router matches any of the defined routes
*/
- public function wasMatched() -> boolean
+ public function wasMatched() -> bool
{
return this->_wasMatched;
}
@@ -466,7 +466,7 @@ class Router implements \Phalcon\Di\InjectionAwareInterface
*
* @param int id
*/
- public function getRouteById(var id) -> | boolean
+ public function getRouteById(var id) -> | bool
{
var route;
@@ -481,7 +481,7 @@ class Router implements \Phalcon\Di\InjectionAwareInterface
/**
* Returns a route object by its name
*/
- public function getRouteByName(string! name) -> | boolean
+ public function getRouteByName(string! name) -> | bool
{
var route;
diff --git a/phalcon/cli/router/route.zep b/phalcon/cli/router/route.zep
index 560875a42f9..05e0657fbdb 100644
--- a/phalcon/cli/router/route.zep
+++ b/phalcon/cli/router/route.zep
@@ -152,13 +152,13 @@ class Route
/**
* Extracts parameters from a string
*
- * @return array|boolean
+ * @return array|bool
*/
public function extractNamedParams(string! pattern)
{
char ch;
var tmp, matches;
- boolean notValid;
+ bool notValid;
int cursor, cursorVar, marker, bracketCount = 0, parenthesesCount = 0, foundPattern = 0;
int intermediate = 0, numberMatches = 0;
string route, item, variable, regexp;
diff --git a/phalcon/cli/routerinterface.zep b/phalcon/cli/routerinterface.zep
index a905e93f924..74b01e38d08 100644
--- a/phalcon/cli/routerinterface.zep
+++ b/phalcon/cli/routerinterface.zep
@@ -94,7 +94,7 @@ interface RouterInterface
/**
* Check if the router matches any of the defined routes
*/
- public function wasMatched() -> boolean;
+ public function wasMatched() -> bool;
/**
* Return all the routes defined in the router
diff --git a/phalcon/config.zep b/phalcon/config.zep
index 664cb326245..6b374d610a1 100644
--- a/phalcon/config.zep
+++ b/phalcon/config.zep
@@ -75,7 +75,7 @@ class Config implements \ArrayAccess, \Countable
* );
*
*/
- public function offsetExists(var index) -> boolean
+ public function offsetExists(var index) -> bool
{
let index = strval(index);
@@ -153,7 +153,7 @@ class Config implements \ArrayAccess, \Countable
* );
*
*/
- public function offsetGet(var index) -> string
+ public function offsetGet(var index) -> var
{
let index = strval(index);
@@ -169,7 +169,7 @@ class Config implements \ArrayAccess, \Countable
* ];
*
*/
- public function offsetSet(var index, var value)
+ public function offsetSet(var index, var value) -> void
{
let index = strval(index);
@@ -187,7 +187,7 @@ class Config implements \ArrayAccess, \Countable
* unset($config["database"]);
*
*/
- public function offsetUnset(var index)
+ public function offsetUnset(var index) -> void
{
let index = strval(index);
diff --git a/phalcon/config/factory.zep b/phalcon/config/factory.zep
index d7abc1e0812..ca783942304 100644
--- a/phalcon/config/factory.zep
+++ b/phalcon/config/factory.zep
@@ -42,7 +42,7 @@ class Factory extends BaseFactory
/**
* @param \Phalcon\Config|array config
*/
- public static function load(var config) ->
+ public static function load(var config) -> object
{
return self::loadClass("Phalcon\\Config\\Adapter", config);
}
diff --git a/phalcon/crypt.zep b/phalcon/crypt.zep
index 8472208d16e..b7b0feff0e6 100644
--- a/phalcon/crypt.zep
+++ b/phalcon/crypt.zep
@@ -93,7 +93,7 @@ class Crypt implements CryptInterface
/**
* Phalcon\Crypt constructor.
*/
- public function __construct(string! cipher = "aes-256-cfb", boolean useSigning = false)
+ public function __construct(string! cipher = "aes-256-cfb", bool useSigning = false)
{
this->initializeAvailableCiphers();
@@ -119,7 +119,7 @@ class Crypt implements CryptInterface
* The `aes-256-ctr' is arguably the best choice for cipher
* algorithm for current openssl library version.
*/
- public function setCipher(string! cipher) ->
+ public function setCipher(string! cipher) ->
{
this->assertCipherIsAvailable(cipher);
@@ -153,7 +153,7 @@ class Crypt implements CryptInterface
*
* @see \Phalcon\Security\Random
*/
- public function setKey(string! key) ->
+ public function setKey(string! key) ->
{
let this->_key = key;
return this;
@@ -172,7 +172,7 @@ class Crypt implements CryptInterface
*
* @throws \Phalcon\Crypt\Exception
*/
- public function setHashAlgo(string! hashAlgo) ->
+ public function setHashAlgo(string! hashAlgo) ->
{
this->assertHashAlgorithmAvailable(hashAlgo);
@@ -194,7 +194,7 @@ class Crypt implements CryptInterface
*
* NOTE: This feature will be enabled by default in Phalcon 4.0.0
*/
- public function useSigning(boolean useSigning) ->
+ public function useSigning(bool useSigning) ->
{
let this->useSigning = useSigning;
@@ -497,7 +497,7 @@ class Crypt implements CryptInterface
/**
* Encrypts a text returning the result as a base64 string.
*/
- public function encryptBase64(string! text, key = null, boolean! safe = false) -> string
+ public function encryptBase64(string! text, key = null, bool! safe = false) -> string
{
if safe == true {
return rtrim(strtr(base64_encode(this->encrypt(text, key)), "+/", "-_"), "=");
@@ -510,7 +510,7 @@ class Crypt implements CryptInterface
*
* @throws \Phalcon\Crypt\Mismatch
*/
- public function decryptBase64(string! text, key = null, boolean! safe = false) -> string
+ public function decryptBase64(string! text, key = null, bool! safe = false) -> string
{
if safe == true {
return this->decrypt(base64_decode(strtr(text, "-_", "+/") . substr("===", (strlen(text) + 3) % 4)), key);
diff --git a/phalcon/cryptinterface.zep b/phalcon/cryptinterface.zep
index a9c7bc4662f..fad88343dff 100644
--- a/phalcon/cryptinterface.zep
+++ b/phalcon/cryptinterface.zep
@@ -50,7 +50,7 @@ interface CryptInterface
/**
* Encrypts a text
*/
- public function encrypt(string! text, key = null) -> string;
+ public function encrypt(string! text, string! key = null) -> string;
/**
* Decrypts a text
diff --git a/phalcon/db/adapter.zep b/phalcon/db/adapter.zep
index 40624566b72..a67e9f8c28d 100644
--- a/phalcon/db/adapter.zep
+++ b/phalcon/db/adapter.zep
@@ -46,6 +46,8 @@ abstract class Adapter implements AdapterInterface, EventsAwareInterface
/**
* Name of the dialect used
+ *
+ * @var string
*/
protected _dialectType { get };
@@ -89,6 +91,8 @@ abstract class Adapter implements AdapterInterface, EventsAwareInterface
/**
* Type of database system the adapter is used for
+ *
+ * @var string
*/
protected _type { get };
@@ -127,7 +131,7 @@ abstract class Adapter implements AdapterInterface, EventsAwareInterface
/**
* Adds a column to a table
*/
- public function addColumn(string! tableName, string! schemaName, column) -> boolean
+ public function addColumn(string! tableName, string! schemaName, column) -> bool
{
return this->{"execute"}(this->_dialect->addColumn(tableName, schemaName, column));
}
@@ -135,7 +139,7 @@ abstract class Adapter implements AdapterInterface, EventsAwareInterface
/**
* Adds a foreign key to a table
*/
- public function addForeignKey(string! tableName, string! schemaName, reference) -> boolean
+ public function addForeignKey(string! tableName, string! schemaName, reference) -> bool
{
return this->{"execute"}(this->_dialect->addForeignKey(tableName, schemaName, reference));
}
@@ -143,7 +147,7 @@ abstract class Adapter implements AdapterInterface, EventsAwareInterface
/**
* Adds an index to a table
*/
- public function addIndex(string! tableName, string! schemaName, index) -> boolean
+ public function addIndex(string! tableName, string! schemaName, index) -> bool
{
return this->{"execute"}(this->_dialect->addIndex(tableName, schemaName, index));
}
@@ -151,7 +155,7 @@ abstract class Adapter implements AdapterInterface, EventsAwareInterface
/**
* Adds a primary key to a table
*/
- public function addPrimaryKey(string! tableName, string! schemaName, index) -> boolean
+ public function addPrimaryKey(string! tableName, string! schemaName, index) -> bool
{
return this->{"execute"}(this->_dialect->addPrimaryKey(tableName, schemaName, index));
}
@@ -159,7 +163,7 @@ abstract class Adapter implements AdapterInterface, EventsAwareInterface
/**
* Creates a new savepoint
*/
- public function createSavepoint(string! name) -> boolean
+ public function createSavepoint(string! name) -> bool
{
var dialect;
@@ -175,7 +179,7 @@ abstract class Adapter implements AdapterInterface, EventsAwareInterface
/**
* Creates a table
*/
- public function createTable(string! tableName, string! schemaName, array! definition) -> boolean
+ public function createTable(string! tableName, string! schemaName, array! definition) -> bool
{
var columns;
@@ -193,7 +197,7 @@ abstract class Adapter implements AdapterInterface, EventsAwareInterface
/**
* Creates a view
*/
- public function createView(string! viewName, array! definition, var schemaName = null) -> boolean
+ public function createView(string! viewName, array! definition, string schemaName = null) -> bool
{
if !isset definition["sql"] {
throw new Exception("The table must contain at least one column");
@@ -220,7 +224,7 @@ abstract class Adapter implements AdapterInterface, EventsAwareInterface
* @param array placeholders
* @param array dataTypes
*/
- public function delete(string table, var whereCondition = null, var placeholders = null, var dataTypes = null) -> boolean
+ public function delete(string table, var whereCondition = null, var placeholders = null, var dataTypes = null) -> bool
{
var sql, escapedTable;
@@ -249,7 +253,7 @@ abstract class Adapter implements AdapterInterface, EventsAwareInterface
*
* @param string schema
*/
- public function describeIndexes(string! table, schema = null) ->
+ public function describeIndexes(string! table, string schema = null) ->
{
var indexes, index, keyName, indexObjects, name, indexColumns, columns;
@@ -288,7 +292,7 @@ abstract class Adapter implements AdapterInterface, EventsAwareInterface
* );
*
*/
- public function describeReferences(string! table, string! schema = null) ->
+ public function describeReferences(string! table, string! schema = null) ->
{
var references, reference,
arrayReference, constraintName, referenceObjects, name,
@@ -338,7 +342,7 @@ abstract class Adapter implements AdapterInterface, EventsAwareInterface
/**
* Drops a column from a table
*/
- public function dropColumn(string! tableName, string! schemaName, string columnName) -> boolean
+ public function dropColumn(string! tableName, string! schemaName, string columnName) -> bool
{
return this->{"execute"}(this->_dialect->dropColumn(tableName, schemaName, columnName));
}
@@ -346,7 +350,7 @@ abstract class Adapter implements AdapterInterface, EventsAwareInterface
/**
* Drops a foreign key from a table
*/
- public function dropForeignKey(string! tableName, string! schemaName, string! referenceName) -> boolean
+ public function dropForeignKey(string! tableName, string! schemaName, string! referenceName) -> bool
{
return this->{"execute"}(this->_dialect->dropForeignKey(tableName, schemaName, referenceName));
}
@@ -354,7 +358,7 @@ abstract class Adapter implements AdapterInterface, EventsAwareInterface
/**
* Drop an index from a table
*/
- public function dropIndex(string! tableName, string! schemaName, indexName) -> boolean
+ public function dropIndex(string! tableName, string! schemaName, indexName) -> bool
{
return this->{"execute"}(this->_dialect->dropIndex(tableName, schemaName, indexName));
}
@@ -362,7 +366,7 @@ abstract class Adapter implements AdapterInterface, EventsAwareInterface
/**
* Drops a table's primary key
*/
- public function dropPrimaryKey(string! tableName, string! schemaName) -> boolean
+ public function dropPrimaryKey(string! tableName, string! schemaName) -> bool
{
return this->{"execute"}(this->_dialect->dropPrimaryKey(tableName, schemaName));
}
@@ -370,7 +374,7 @@ abstract class Adapter implements AdapterInterface, EventsAwareInterface
/**
* Drops a table from a schema/database
*/
- public function dropTable(string! tableName, string! schemaName = null, boolean ifExists = true) -> boolean
+ public function dropTable(string! tableName, string! schemaName = null, bool ifExists = true) -> bool
{
return this->{"execute"}(this->_dialect->dropTable(tableName, schemaName, ifExists));
}
@@ -378,7 +382,7 @@ abstract class Adapter implements AdapterInterface, EventsAwareInterface
/**
* Drops a view
*/
- public function dropView(string! viewName, string! schemaName = null, boolean ifExists = true) -> boolean
+ public function dropView(string! viewName, string! schemaName = null, bool ifExists = true) -> bool
{
return this->{"execute"}(this->_dialect->dropView(viewName, schemaName, ifExists));
}
@@ -474,7 +478,7 @@ abstract class Adapter implements AdapterInterface, EventsAwareInterface
*
* @param int|string column
*/
- public function fetchColumn(string sqlQuery, array placeholders = [], var column = 0) -> string | boolean
+ public function fetchColumn(string sqlQuery, array placeholders = [], var column = 0) -> string | bool
{
var row, columnValue;
@@ -670,7 +674,7 @@ abstract class Adapter implements AdapterInterface, EventsAwareInterface
* @param array fields
* @param array dataTypes
*/
- public function insert(string table, array! values, var fields = null, var dataTypes = null) -> boolean
+ public function insert(string table, array! values, var fields = null, var dataTypes = null) -> bool
{
var placeholders, insertValues, bindDataTypes, bindType,
position, value, escapedTable, joinedValues, escapedFields,
@@ -761,7 +765,7 @@ abstract class Adapter implements AdapterInterface, EventsAwareInterface
* @param array data
* @param array dataTypes
*/
- public function insertAsDict(string table, data, var dataTypes = null) -> boolean
+ public function insertAsDict(string table, data, var dataTypes = null) -> bool
{
var values = [], fields = [];
var field, value;
@@ -781,7 +785,7 @@ abstract class Adapter implements AdapterInterface, EventsAwareInterface
/**
* Returns if nested transactions should use savepoints
*/
- public function isNestedTransactionsWithSavepoints() -> boolean
+ public function isNestedTransactionsWithSavepoints() -> bool
{
return this->_transactionsWithSavepoints;
}
@@ -841,7 +845,7 @@ abstract class Adapter implements AdapterInterface, EventsAwareInterface
/**
* Modifies a table column based on a definition
*/
- public function modifyColumn(string! tableName, string! schemaName, column, currentColumn = null) -> boolean
+ public function modifyColumn(string! tableName, string! schemaName, column, currentColumn = null) -> bool
{
return this->{"execute"}(this->_dialect->modifyColumn(tableName, schemaName, column, currentColumn));
}
@@ -849,7 +853,7 @@ abstract class Adapter implements AdapterInterface, EventsAwareInterface
/**
* Releases given savepoint
*/
- public function releaseSavepoint(string! name) -> boolean
+ public function releaseSavepoint(string! name) -> bool
{
var dialect;
@@ -869,7 +873,7 @@ abstract class Adapter implements AdapterInterface, EventsAwareInterface
/**
* Rollbacks given savepoint
*/
- public function rollbackSavepoint(string! name) -> boolean
+ public function rollbackSavepoint(string! name) -> bool
{
var dialect;
@@ -901,7 +905,7 @@ abstract class Adapter implements AdapterInterface, EventsAwareInterface
/**
* Set if nested transactions should use savepoints
*/
- public function setNestedTransactionsWithSavepoints(boolean nestedTransactionsWithSavepoints) ->
+ public function setNestedTransactionsWithSavepoints(bool nestedTransactionsWithSavepoints) ->
{
if this->_transactionLevel > 0 {
@@ -927,7 +931,7 @@ abstract class Adapter implements AdapterInterface, EventsAwareInterface
/**
* Check whether the database system requires a sequence to produce auto-numeric values
*/
- public function supportSequences() -> boolean
+ public function supportSequences() -> bool
{
return false;
}
@@ -941,7 +945,7 @@ abstract class Adapter implements AdapterInterface, EventsAwareInterface
* );
*
*/
- public function tableExists(string! tableName, string! schemaName = null) -> boolean
+ public function tableExists(string! tableName, string! schemaName = null) -> bool
{
return this->fetchOne(this->_dialect->tableExists(tableName, schemaName), Db::FETCH_NUM)[0] > 0;
}
@@ -1005,7 +1009,7 @@ abstract class Adapter implements AdapterInterface, EventsAwareInterface
* @param string|array whereCondition
* @param array dataTypes
*/
- public function update(string table, var fields, var values, var whereCondition = null, var dataTypes = null) -> boolean
+ public function update(string table, var fields, var values, var whereCondition = null, var dataTypes = null) -> bool
{
var placeholders, updateValues, position, value,
field, bindDataTypes, escapedField, bindType, escapedTable,
@@ -1127,7 +1131,7 @@ abstract class Adapter implements AdapterInterface, EventsAwareInterface
* @param string whereCondition
* @param array dataTypes
*/
- public function updateAsDict(string table, var data, var whereCondition = null, var dataTypes = null) -> boolean
+ public function updateAsDict(string table, var data, var whereCondition = null, var dataTypes = null) -> bool
{
var values = [], fields = [];
var field, value;
@@ -1147,7 +1151,7 @@ abstract class Adapter implements AdapterInterface, EventsAwareInterface
/**
* Check whether the database system requires an explicit value for identity columns
*/
- public function useExplicitIdValue() -> boolean
+ public function useExplicitIdValue() -> bool
{
return false;
}
@@ -1161,7 +1165,7 @@ abstract class Adapter implements AdapterInterface, EventsAwareInterface
* );
*
*/
- public function viewExists(string! viewName, string! schemaName = null) -> boolean
+ public function viewExists(string! viewName, string! schemaName = null) -> bool
{
return this->fetchOne(this->_dialect->viewExists(viewName, schemaName), Db::FETCH_NUM)[0] > 0;
}
diff --git a/phalcon/db/adapter/pdo.zep b/phalcon/db/adapter/pdo.zep
index 3bfda363358..0c320e42d0b 100644
--- a/phalcon/db/adapter/pdo.zep
+++ b/phalcon/db/adapter/pdo.zep
@@ -80,7 +80,7 @@ abstract class Pdo extends Adapter
/**
* Starts a transaction in the connection
*/
- public function begin(boolean nesting = true) -> boolean
+ public function begin(bool nesting = true) -> bool
{
var pdo, transactionLevel, eventsManager, savepointName;
@@ -138,7 +138,7 @@ abstract class Pdo extends Adapter
/**
* Commits the active transaction in the connection
*/
- public function commit(boolean nesting = true) -> boolean
+ public function commit(bool nesting = true) -> bool
{
var pdo, transactionLevel, eventsManager, savepointName;
@@ -211,7 +211,7 @@ abstract class Pdo extends Adapter
* Closes the active connection returning success. Phalcon automatically closes and destroys
* active connections when the request ends
*/
- public function close() -> boolean
+ public function close() -> bool
{
var pdo;
let pdo = this->_pdo;
@@ -244,7 +244,7 @@ abstract class Pdo extends Adapter
* $connection->connect();
*
*/
- public function connect(array descriptor = null) -> boolean
+ public function connect(array descriptor = null) -> bool
{
var username, password, dsnParts, dsnAttributes,
persistent, options, key, value;
@@ -409,7 +409,7 @@ abstract class Pdo extends Adapter
* );
*
*/
- public function execute(string! sqlStatement, var bindParams = null, var bindTypes = null) -> boolean
+ public function execute(string! sqlStatement, var bindParams = null, var bindTypes = null) -> bool
{
var eventsManager, affectedRows, pdo, newStatement, statement;
@@ -496,10 +496,11 @@ abstract class Pdo extends Adapter
if typeof dataTypes == "array" && fetch type, dataTypes[wildcard] {
/**
- * The bind type is double so we try to get the double value
+ * The bind type needs to be string because the precision
+ * is lost if it is casted as a double
*/
if type == Column::BIND_PARAM_DECIMAL {
- let castValue = doubleval(value),
+ let castValue = (string) value,
type = Column::BIND_SKIP;
} else {
if globals_get("db.force_casting") {
@@ -519,7 +520,7 @@ abstract class Pdo extends Adapter
break;
case Column::BIND_PARAM_BOOL:
- let castValue = (boolean) value;
+ let castValue = (bool) value;
break;
default:
@@ -605,7 +606,7 @@ abstract class Pdo extends Adapter
* );
*
*/
- public function isUnderTransaction() -> boolean
+ public function isUnderTransaction() -> bool
{
var pdo;
let pdo = this->_pdo;
@@ -638,7 +639,7 @@ abstract class Pdo extends Adapter
*
* @param string sequenceName
*/
- public function lastInsertId(sequenceName = null) -> int | boolean
+ public function lastInsertId(sequenceName = null) -> int | bool
{
var pdo;
let pdo = this->_pdo;
@@ -692,7 +693,7 @@ abstract class Pdo extends Adapter
* );
*
*/
- public function query(string! sqlStatement, var bindParams = null, var bindTypes = null) -> | boolean
+ public function query(string! sqlStatement, var bindParams = null, var bindTypes = null) -> | bool
{
var eventsManager, pdo, statement, params, types;
@@ -742,7 +743,7 @@ abstract class Pdo extends Adapter
/**
* Rollbacks the active transaction in the connection
*/
- public function rollback(boolean nesting = true) -> boolean
+ public function rollback(bool nesting = true) -> bool
{
var pdo, transactionLevel, eventsManager, savepointName;
diff --git a/phalcon/db/adapter/pdo/factory.zep b/phalcon/db/adapter/pdo/factory.zep
index 52cd17eeedb..e43e83617cf 100644
--- a/phalcon/db/adapter/pdo/factory.zep
+++ b/phalcon/db/adapter/pdo/factory.zep
@@ -35,7 +35,7 @@ class Factory extends BaseFactory
/**
* @param \Phalcon\Config|array config
*/
- public static function load(var config) ->
+ public static function load(var config) -> object
{
return self::loadClass("Phalcon\\Db\\Adapter\\Pdo", config);
}
diff --git a/phalcon/db/adapter/pdo/mysql.zep b/phalcon/db/adapter/pdo/mysql.zep
index 545a2bf2ef1..5f42201e064 100644
--- a/phalcon/db/adapter/pdo/mysql.zep
+++ b/phalcon/db/adapter/pdo/mysql.zep
@@ -13,6 +13,7 @@ namespace Phalcon\Db\Adapter\Pdo;
use Phalcon\Db;
use Phalcon\Db\Adapter\Pdo as PdoAdapter;
use Phalcon\Db\Column;
+use Phalcon\Db\ColumnInterface;
use Phalcon\Db\Exception;
use Phalcon\Db\Index;
use Phalcon\Db\IndexInterface;
@@ -48,7 +49,7 @@ class Mysql extends PdoAdapter
/**
* Adds a foreign key to a table
*/
- public function addForeignKey(string! tableName, string! schemaName, reference) -> boolean
+ public function addForeignKey(string! tableName, string! schemaName, reference) -> bool
{
var foreignKeyCheck;
@@ -69,7 +70,7 @@ class Mysql extends PdoAdapter
* );
*
*/
- public function describeColumns(string table, string schema = null) ->
+ public function describeColumns(string table, string schema = null) ->
{
var columns, columnType, field, definition,
oldColumn, sizePattern, matches, matchOne, matchTwo, columnName;
@@ -97,107 +98,233 @@ class Mysql extends PdoAdapter
*/
let columnType = field[1];
- if memstr(columnType, "enum") {
+ /**
+ * The order of these IF statements matters. Since we are using memstr
+ * to figure out whether a particular string exists in the columnType
+ * we will end up with false positives if the order changes.
+ *
+ * For instance if we have a `varchar` column and we check for `char`
+ * first, then that will match. Therefore we have firs the IF
+ * statements that are "unique" and further down the ones that can
+ * appear a substrings of the columnType above them.
+ */
+
+ switch true {
/**
- * Enum are treated as char
+ * BOOL
*/
- let definition["type"] = Column::TYPE_CHAR;
- } elseif memstr(columnType, "bigint") {
+ case memstr(columnType, "tinyint(1)"):
+ /**
+ * tinyint(1) is boolean
+ */
+ let definition["type"] = Column::TYPE_BOOLEAN,
+ definition["isNumeric"] = true,
+ definition["bindType"] = Column::BIND_PARAM_BOOL;
+ break;
+
/**
- * Smallint/Bigint/Integers/Int are int
+ * BIGINT
*/
- let definition["type"] = Column::TYPE_BIGINTEGER,
- definition["isNumeric"] = true,
- definition["bindType"] = Column::BIND_PARAM_INT;
- } elseif memstr(columnType, "int") {
+ case memstr(columnType, "bigint"):
+ let definition["type"] = Column::TYPE_BIGINTEGER,
+ definition["isNumeric"] = true,
+ definition["bindType"] = Column::BIND_PARAM_INT;
+ break;
+
/**
- * Smallint/Bigint/Integers/Int are int
+ * MEDIUMINT
*/
- let definition["type"] = Column::TYPE_INTEGER,
- definition["isNumeric"] = true,
- definition["bindType"] = Column::BIND_PARAM_INT;
- } elseif memstr(columnType, "varchar") {
+ case memstr(columnType, "mediumint"):
+ let definition["type"] = Column::TYPE_MEDIUMINTEGER,
+ definition["isNumeric"] = true,
+ definition["bindType"] = Column::BIND_PARAM_INT;
+ break;
+
/**
- * Varchar are varchars
+ * SMALLINT
*/
- let definition["type"] = Column::TYPE_VARCHAR;
- } elseif memstr(columnType, "datetime") {
+ case memstr(columnType, "smallint"):
+ let definition["type"] = Column::TYPE_SMALLINTEGER,
+ definition["isNumeric"] = true,
+ definition["bindType"] = Column::BIND_PARAM_INT;
+ break;
+
/**
- * Special type for datetime
+ * TINYINT
*/
- let definition["type"] = Column::TYPE_DATETIME;
- } elseif memstr(columnType, "char") {
+ case memstr(columnType, "tinyint"):
+ /**
+ * Smallint/Bigint/Integers/Int are int
+ */
+ let definition["type"] = Column::TYPE_TINYINTEGER,
+ definition["isNumeric"] = true,
+ definition["bindType"] = Column::BIND_PARAM_INT;
+ break;
+
/**
- * Chars are chars
+ * INT
*/
- let definition["type"] = Column::TYPE_CHAR;
- } elseif memstr(columnType, "date") {
+ case memstr(columnType, "int"):
+ let definition["type"] = Column::TYPE_INTEGER,
+ definition["isNumeric"] = true,
+ definition["bindType"] = Column::BIND_PARAM_INT;
+
+ break;
+
/**
- * Date are dates
+ * BIT
*/
- let definition["type"] = Column::TYPE_DATE;
- } elseif memstr(columnType, "timestamp") {
+ case memstr(columnType, "bit"):
+ let definition["type"] = Column::TYPE_BIT,
+ definition["bindType"] = Column::BIND_PARAM_INT;
+ break;
+
/**
- * Timestamp are dates
+ * ENUM
*/
- let definition["type"] = Column::TYPE_TIMESTAMP;
- } elseif memstr(columnType, "text") {
+ case memstr(columnType, "enum"):
+ let definition["type"] = Column::TYPE_ENUM;
+ break;
+
+
/**
- * Text are varchars
+ * DATE
*/
- let definition["type"] = Column::TYPE_TEXT;
- } elseif memstr(columnType, "decimal") {
+ case memstr(columnType, "datetime"):
+ let definition["type"] = Column::TYPE_DATETIME;
+ break;
+
+ /**
+ * DATETIME
+ */
+ case memstr(columnType, "date"):
+ let definition["type"] = Column::TYPE_DATE;
+ break;
+
/**
- * Decimals are floats
+ * DECIMAL - This will need to be a string so as not to lose
+ * the decimals
*/
- let definition["type"] = Column::TYPE_DECIMAL,
- definition["isNumeric"] = true,
- definition["bindType"] = Column::BIND_PARAM_DECIMAL;
- } elseif memstr(columnType, "double") {
+ case memstr(columnType, "decimal"):
+ let definition["type"] = Column::TYPE_DECIMAL,
+ definition["isNumeric"] = true;
+ break;
+
/**
- * Doubles
+ * DOUBLE
*/
- let definition["type"] = Column::TYPE_DOUBLE,
- definition["isNumeric"] = true,
- definition["bindType"] = Column::BIND_PARAM_DECIMAL;
- } elseif memstr(columnType, "float") {
+ case memstr(columnType, "double"):
+ let definition["type"] = Column::TYPE_DOUBLE,
+ definition["isNumeric"] = true,
+ definition["bindType"] = Column::BIND_PARAM_DECIMAL;
+ break;
+
/**
- * Float/Smallfloats/Decimals are float
+ * FLOAT
*/
- let definition["type"] = Column::TYPE_FLOAT,
- definition["isNumeric"] = true,
- definition["bindType"] = Column::BIND_PARAM_DECIMAL;
- } elseif memstr(columnType, "bit") {
+ case memstr(columnType, "float"):
+ let definition["type"] = Column::TYPE_FLOAT,
+ definition["isNumeric"] = true,
+ definition["bindType"] = Column::BIND_PARAM_DECIMAL;
+ break;
+
/**
- * Boolean
+ * MEDIUMBLOB
*/
- let definition["type"] = Column::TYPE_BOOLEAN,
- definition["bindType"] = Column::BIND_PARAM_BOOL;
- } elseif memstr(columnType, "tinyblob") {
+ case memstr(columnType, "mediumblob"):
+ let definition["type"] = Column::TYPE_MEDIUMBLOB;
+ break;
+
/**
- * Tinyblob
+ * LONGBLOB
*/
- let definition["type"] = Column::TYPE_TINYBLOB;
- } elseif memstr(columnType, "mediumblob") {
+ case memstr(columnType, "longblob"):
+ let definition["type"] = Column::TYPE_LONGBLOB;
+ break;
+
/**
- * Mediumblob
+ * TINYBLOB
*/
- let definition["type"] = Column::TYPE_MEDIUMBLOB;
- } elseif memstr(columnType, "longblob") {
+ case memstr(columnType, "tinyblob"):
+ let definition["type"] = Column::TYPE_TINYBLOB;
+ break;
+
/**
- * Longblob
+ * BLOB
*/
- let definition["type"] = Column::TYPE_LONGBLOB;
- } elseif memstr(columnType, "blob") {
+ case memstr(columnType, "blob"):
+ let definition["type"] = Column::TYPE_BLOB;
+ break;
+
/**
- * Blob
+ * TIMESTAMP
*/
- let definition["type"] = Column::TYPE_BLOB;
- } else {
+ case memstr(columnType, "timestamp"):
+ let definition["type"] = Column::TYPE_TIMESTAMP;
+ break;
+
+ /**
+ * TIME
+ */
+ case memstr(columnType, "time"):
+ let definition["type"] = Column::TYPE_TIME;
+ break;
+
+ /**
+ * JSON
+ */
+ case memstr(columnType, "json"):
+ let definition["type"] = Column::TYPE_JSON;
+ break;
+
+ /**
+ * LONGTEXT
+ */
+ case memstr(columnType, "longtext"):
+ let definition["type"] = Column::TYPE_LONGTEXT;
+ break;
+
+ /**
+ * MEDIUMTEXT
+ */
+ case memstr(columnType, "mediumtext"):
+ let definition["type"] = Column::TYPE_MEDIUMTEXT;
+ break;
+
+ /**
+ * TINYTEXT
+ */
+ case memstr(columnType, "tinytext"):
+ let definition["type"] = Column::TYPE_TINYTEXT;
+ break;
+
+ /**
+ * TEXT
+ */
+ case memstr(columnType, "text"):
+ let definition["type"] = Column::TYPE_TEXT;
+ break;
+
+ /**
+ * VARCHAR
+ */
+ case memstr(columnType, "varchar"):
+ let definition["type"] = Column::TYPE_VARCHAR;
+ break;
+
+ /**
+ * CHAR
+ */
+ case memstr(columnType, "char"):
+ let definition["type"] = Column::TYPE_CHAR;
+ break;
+
/**
- * By default is string
+ * Default
*/
- let definition["type"] = Column::TYPE_VARCHAR;
+ default:
+ let definition["type"] = Column::TYPE_VARCHAR;
+ break;
}
/**
@@ -205,7 +332,9 @@ class Mysql extends PdoAdapter
*/
if memstr(columnType, "(") {
let matches = null;
- if preg_match(sizePattern, columnType, matches) {
+ if definition["type"] == Column::TYPE_ENUM {
+ let definition["size"] = substr(columnType, 5, -1);
+ } elseif preg_match(sizePattern, columnType, matches) {
if fetch matchOne, matches[1] {
let definition["size"] = (int) matchOne;
}
@@ -329,7 +458,7 @@ class Mysql extends PdoAdapter
* );
*
*/
- public function describeReferences(string! table, string! schema = null) ->
+ public function describeReferences(string! table, string! schema = null) ->
{
var references, reference,
arrayReference, constraintName, referenceObjects, name,
diff --git a/phalcon/db/adapter/pdo/postgresql.zep b/phalcon/db/adapter/pdo/postgresql.zep
index af9e808de66..bacbb5396aa 100644
--- a/phalcon/db/adapter/pdo/postgresql.zep
+++ b/phalcon/db/adapter/pdo/postgresql.zep
@@ -14,6 +14,7 @@ namespace Phalcon\Db\Adapter\Pdo;
use Phalcon\Db;
use Phalcon\Db\Adapter\Pdo as PdoAdapter;
use Phalcon\Db\Column;
+use Phalcon\Db\ColumnInterface;
use Phalcon\Db\Exception;
use Phalcon\Db\RawValue;
use Phalcon\Db\Reference;
@@ -49,7 +50,7 @@ class Postgresql extends PdoAdapter
* This method is automatically called in Phalcon\Db\Adapter\Pdo constructor.
* Call it when you need to restore a database connection.
*/
- public function connect(array descriptor = null) -> boolean
+ public function connect(array descriptor = null) -> bool
{
var schema, sql, status;
@@ -82,7 +83,7 @@ class Postgresql extends PdoAdapter
/**
* Creates a table
*/
- public function createTable(string! tableName, string! schemaName, array! definition) -> boolean
+ public function createTable(string! tableName, string! schemaName, array! definition) -> bool
{
var sql,queries,query,exception,columns;
@@ -128,7 +129,7 @@ class Postgresql extends PdoAdapter
* );
*
*/
- public function describeColumns(string table, string schema = null) ->
+ public function describeColumns(string table, string schema = null) ->
{
var columns, columnType, field, definition,
oldColumn, columnName, charSize, numericSize, numericScale;
@@ -154,117 +155,259 @@ class Postgresql extends PdoAdapter
numericSize = field[3],
numericScale = field[4];
- if memstr(columnType, "smallint(1)") {
+ /**
+ * The order of these IF statements matters. Since we are using memstr
+ * to figure out whether a particular string exists in the columnType
+ * we will end up with false positives if the order changes.
+ *
+ * For instance if we have a `varchar` column and we check for `char`
+ * first, then that will match. Therefore we have firs the IF
+ * statements that are "unique" and further down the ones that can
+ * appear a substrings of the columnType above them.
+ */
+
+ switch true {
+ /**
+ * BOOL
+ */
+ case memstr(columnType, "boolean"):
+ /**
+ * tinyint(1) is boolean
+ */
+ let definition["type"] = Column::TYPE_BOOLEAN,
+ definition["isNumeric"] = true,
+ definition["bindType"] = Column::BIND_PARAM_BOOL;
+ break;
+
+ /**
+ * BIGINT
+ */
+ case memstr(columnType, "bigint"):
+ let definition["type"] = Column::TYPE_BIGINTEGER,
+ definition["isNumeric"] = true,
+ definition["bindType"] = Column::BIND_PARAM_INT;
+ break;
+
+ /**
+ * MEDIUMINT
+ */
+ case memstr(columnType, "mediumint"):
+ let definition["type"] = Column::TYPE_MEDIUMINTEGER,
+ definition["isNumeric"] = true,
+ definition["bindType"] = Column::BIND_PARAM_INT;
+ break;
+
+ /**
+ * SMALLINT
+ */
+ case memstr(columnType, "smallint"):
+ let definition["type"] = Column::TYPE_SMALLINTEGER,
+ definition["isNumeric"] = true,
+ definition["bindType"] = Column::BIND_PARAM_INT;
+ break;
+
+ /**
+ * TINYINT
+ */
+ case memstr(columnType, "tinyint"):
+ /**
+ * Smallint/Bigint/Integers/Int are int
+ */
+ let definition["type"] = Column::TYPE_TINYINTEGER,
+ definition["isNumeric"] = true,
+ definition["bindType"] = Column::BIND_PARAM_INT;
+ break;
+
+ /**
+ * INT
+ */
+ case memstr(columnType, "int"):
+ let definition["type"] = Column::TYPE_INTEGER,
+ definition["isNumeric"] = true,
+ definition["bindType"] = Column::BIND_PARAM_INT;
+
+ break;
+
+ /**
+ * BIT
+ */
+ case memstr(columnType, "bit"):
+ let definition["type"] = Column::TYPE_BIT,
+ definition["size"] = numericSize;
+ break;
+
+ /**
+ * ENUM
+ */
+ case memstr(columnType, "enum"):
+ let definition["type"] = Column::TYPE_ENUM;
+ break;
+
+
/**
- * Smallint(1) is boolean
+ * DATE
*/
- let definition["type"] = Column::TYPE_BOOLEAN,
- definition["bindType"] = Column::BIND_PARAM_BOOL;
- } elseif memstr(columnType, "bigint") {
+ case memstr(columnType, "datetime"):
+ let definition["type"] = Column::TYPE_DATETIME,
+ definition["size"] = 0;
+ break;
+
/**
- * Bigint
+ * DATETIME
*/
- let definition["type"] = Column::TYPE_BIGINTEGER,
- definition["isNumeric"] = true,
- definition["bindType"] = Column::BIND_PARAM_INT;
- } elseif memstr(columnType, "int") {
+ case memstr(columnType, "date"):
+ let definition["type"] = Column::TYPE_DATE,
+ definition["size"] = 0;
+ break;
+
/**
- * Int
+ * NUMERIC -> DECIMAL - This will need to be a string so as not
+ * to lose the decimals
*/
- let definition["type"] = Column::TYPE_INTEGER,
- definition["isNumeric"] = true,
- definition["size"] = numericSize,
- definition["bindType"] = Column::BIND_PARAM_INT;
- } elseif memstr(columnType, "double precision") {
+ case memstr(columnType, "decimal"):
+ case memstr(columnType, "numeric"):
+ let definition["type"] = Column::TYPE_DECIMAL,
+ definition["size"] = numericSize,
+ definition["isNumeric"] = true,
+ definition["bindType"] = Column::BIND_PARAM_DECIMAL;
+ break;
+
/**
- * Double Precision
+ * DOUBLE
*/
- let definition["type"] = Column::TYPE_DOUBLE,
- definition["isNumeric"] = true,
- definition["size"] = numericSize,
- definition["bindType"] = Column::BIND_PARAM_DECIMAL;
- } elseif memstr(columnType, "real") {
+ case memstr(columnType, "double precision"):
+ let definition["type"] = Column::TYPE_DOUBLE,
+ definition["isNumeric"] = true,
+ definition["size"] = numericSize,
+ definition["bindType"] = Column::BIND_PARAM_DECIMAL;
+ break;
+
/**
- * Real
+ * FLOAT
*/
- let definition["type"] = Column::TYPE_FLOAT,
- definition["isNumeric"] = true,
- definition["size"] = numericSize,
- definition["bindType"] = Column::BIND_PARAM_DECIMAL;
- } elseif memstr(columnType, "varying") {
+ case memstr(columnType, "float"):
+ case memstr(columnType, "real"):
+ let definition["type"] = Column::TYPE_FLOAT,
+ definition["isNumeric"] = true,
+ definition["size"] = numericSize,
+ definition["bindType"] = Column::BIND_PARAM_DECIMAL;
+ break;
+
/**
- * Varchar
+ * MEDIUMBLOB
*/
- let definition["type"] = Column::TYPE_VARCHAR,
- definition["size"] = charSize;
- } elseif memstr(columnType, "date") {
+ case memstr(columnType, "mediumblob"):
+ let definition["type"] = Column::TYPE_TEXT;
+ break;
+
/**
- * Special type for datetime
+ * LONGBLOB
*/
- let definition["type"] = Column::TYPE_DATE,
- definition["size"] = 0;
- } elseif memstr(columnType, "timestamp") {
+ case memstr(columnType, "longblob"):
+ let definition["type"] = Column::TYPE_LONGBLOB;
+ break;
+
/**
- * Timestamp
+ * TINYBLOB
*/
- let definition["type"] = Column::TYPE_TIMESTAMP;
- } elseif memstr(columnType, "numeric") {
+ case memstr(columnType, "tinyblob"):
+ let definition["type"] = Column::TYPE_TINYBLOB;
+ break;
+
/**
- * Numeric
+ * BLOB
*/
- let definition["type"] = Column::TYPE_DECIMAL,
- definition["isNumeric"] = true,
- definition["size"] = numericSize,
- definition["scale"] = numericScale,
- definition["bindType"] = Column::BIND_PARAM_DECIMAL;
- } elseif memstr(columnType, "char") {
+ case memstr(columnType, "blob"):
+ let definition["type"] = Column::TYPE_BLOB;
+ break;
+
/**
- * Chars are chars
+ * TIMESTAMP
*/
- let definition["type"] = Column::TYPE_CHAR,
- definition["size"] = charSize;
- } elseif memstr(columnType, "text") {
+ case memstr(columnType, "timestamp"):
+ let definition["type"] = Column::TYPE_TIMESTAMP;
+ break;
+
/**
- * Text are varchars
+ * TIME
*/
- let definition["type"] = Column::TYPE_TEXT,
- definition["size"] = charSize;
- } elseif memstr(columnType, "float") {
+ case memstr(columnType, "time"):
+ let definition["type"] = Column::TYPE_TIME;
+ break;
+
/**
- * Float/Smallfloats/Decimals are float
+ * JSONB
*/
- let definition["type"] = Column::TYPE_FLOAT,
- definition["isNumeric"] = true,
- definition["size"] = numericSize,
- definition["bindType"] = Column::BIND_PARAM_DECIMAL;
- } elseif memstr(columnType, "bool") {
+ case memstr(columnType, "jsonb"):
+ let definition["type"] = Column::TYPE_JSONB;
+ break;
+
/**
- * Boolean
+ * JSON
*/
- let definition["type"] = Column::TYPE_BOOLEAN,
- definition["size"] = 0,
- definition["bindType"] = Column::BIND_PARAM_BOOL;
- } elseif memstr(columnType, "jsonb") {
+ case memstr(columnType, "json"):
+ let definition["type"] = Column::TYPE_JSON;
+ break;
+
/**
- * Jsonb
+ * LONGTEXT
*/
- let definition["type"] = Column::TYPE_JSONB;
- } elseif memstr(columnType, "json") {
+ case memstr(columnType, "longtext"):
+ let definition["type"] = Column::TYPE_LONGTEXT;
+ break;
+
/**
- * Json
+ * MEDIUMTEXT
*/
- let definition["type"] = Column::TYPE_JSON;
- } elseif memstr(columnType, "uuid") {
+ case memstr(columnType, "mediumtext"):
+ let definition["type"] = Column::TYPE_MEDIUMTEXT;
+ break;
+
+ /**
+ * TINYTEXT
+ */
+ case memstr(columnType, "tinytext"):
+ let definition["type"] = Column::TYPE_TINYTEXT;
+ break;
+
+ /**
+ * TEXT
+ */
+ case memstr(columnType, "text"):
+ let definition["type"] = Column::TYPE_TEXT;
+ break;
+
+ /**
+ * VARCHAR
+ */
+ case memstr(columnType, "varying"):
+ case memstr(columnType, "varchar"):
+ let definition["type"] = Column::TYPE_VARCHAR,
+ definition["size"] = charSize;
+ break;
+
+ /**
+ * CHAR
+ */
+ case memstr(columnType, "char"):
+ let definition["type"] = Column::TYPE_CHAR,
+ definition["size"] = charSize;
+ break;
+
/**
* UUID
*/
- let definition["type"] = Column::TYPE_CHAR,
- definition["size"] = 36;
- } else {
+ case memstr(columnType, "uuid"):
+ let definition["type"] = Column::TYPE_CHAR,
+ definition["size"] = 36;
+ break;
+
/**
- * By default is string
+ * Default
*/
- let definition["type"] = Column::TYPE_VARCHAR;
+ default:
+ let definition["type"] = Column::TYPE_VARCHAR;
+ break;
}
/**
@@ -412,7 +555,7 @@ class Postgresql extends PdoAdapter
/**
* Modifies a table column based on a definition
*/
- public function modifyColumn(string! tableName, string! schemaName, <\Phalcon\Db\ColumnInterface> column, <\Phalcon\Db\ColumnInterface> currentColumn = null) -> boolean
+ public function modifyColumn(string! tableName, string! schemaName, column, currentColumn = null) -> bool
{
var sql,queries,query,exception;
@@ -446,7 +589,7 @@ class Postgresql extends PdoAdapter
/**
* Check whether the database system requires a sequence to produce auto-numeric values
*/
- public function supportSequences() -> boolean
+ public function supportSequences() -> bool
{
return true;
}
@@ -454,7 +597,7 @@ class Postgresql extends PdoAdapter
/**
* Check whether the database system requires an explicit value for identity columns
*/
- public function useExplicitIdValue() -> boolean
+ public function useExplicitIdValue() -> bool
{
return true;
}
diff --git a/phalcon/db/adapter/pdo/sqlite.zep b/phalcon/db/adapter/pdo/sqlite.zep
index aa5f2c97303..50607c46530 100644
--- a/phalcon/db/adapter/pdo/sqlite.zep
+++ b/phalcon/db/adapter/pdo/sqlite.zep
@@ -13,6 +13,7 @@ namespace Phalcon\Db\Adapter\Pdo;
use Phalcon\Db;
use Phalcon\Db\Adapter\Pdo as PdoAdapter;
use Phalcon\Db\Column;
+use Phalcon\Db\ColumnInterface;
use Phalcon\Db\Exception;
use Phalcon\Db\Index;
use Phalcon\Db\IndexInterface;
@@ -46,7 +47,7 @@ class Sqlite extends PdoAdapter
* This method is automatically called in Phalcon\Db\Adapter\Pdo constructor.
* Call it when you need to restore a database connection.
*/
- public function connect(array descriptor = null) -> boolean
+ public function connect(array descriptor = null) -> bool
{
var dbname;
@@ -72,7 +73,7 @@ class Sqlite extends PdoAdapter
* );
*
*/
- public function describeColumns(string! table, string! schema = null) ->
+ public function describeColumns(string! table, string! schema = null) ->
{
var columns, columnType, field, definition,
oldColumn, sizePattern, matches, matchOne, matchTwo, columnName;
@@ -97,14 +98,19 @@ class Sqlite extends PdoAdapter
*/
let columnType = field[2];
- if memstr(columnType, "tinyint(1)") {
- /**
- * Tinyint(1) is boolean
- */
- let definition["type"] = Column::TYPE_BOOLEAN,
- definition["bindType"] = Column::BIND_PARAM_BOOL,
- columnType = "boolean"; // Change column type to skip size check
- } elseif memstr(columnType, "bigint") {
+ /**
+ * The order of these IF statements matters. Since we are using memstr
+ * to figure out whether a particular string exists in the columnType
+ * we will end up with false positives if the order changes.
+ *
+ * For instance if we have a `varchar` column and we check for `char`
+ * first, then that will match. Therefore we have firs the IF
+ * statements that are "unique" and further down the ones that can
+ * appear a substrings of the columnType above them.
+ *
+ * BIGINT/INT
+ */
+ if memstr(columnType, "bigint") {
/**
* Bigint are int
*/
@@ -122,21 +128,40 @@ class Sqlite extends PdoAdapter
if field[5] {
let definition["autoIncrement"] = true;
}
- } elseif memstr(columnType, "varchar") {
+ } elseif memstr(columnType, "tinyint(1)") {
/**
- * Varchar are varchars
+ * Tinyint(1) is boolean
*/
- let definition["type"] = Column::TYPE_VARCHAR;
+ let definition["type"] = Column::TYPE_BOOLEAN,
+ definition["bindType"] = Column::BIND_PARAM_BOOL,
+ columnType = "boolean"; // Change column type to skip size check
+
+ /**
+ * ENUM
+ */
+ } elseif memstr(columnType, "enum") {
+ /**
+ * Enum are treated as char
+ */
+ let definition["type"] = Column::TYPE_CHAR;
+
+ /**
+ * DATE/DATETIME
+ */
+ } elseif memstr(columnType, "datetime") {
+ /**
+ * Special type for datetime
+ */
+ let definition["type"] = Column::TYPE_DATETIME;
} elseif memstr(columnType, "date") {
/**
* Date/Datetime are varchars
*/
let definition["type"] = Column::TYPE_DATE;
- } elseif memstr(columnType, "timestamp") {
- /**
- * Timestamp as date
- */
- let definition["type"] = Column::TYPE_TIMESTAMP;
+
+ /**
+ * FLOAT/DECIMAL/DOUBLE
+ */
} elseif memstr(columnType, "decimal") {
/**
* Decimals are floats
@@ -144,21 +169,6 @@ class Sqlite extends PdoAdapter
let definition["type"] = Column::TYPE_DECIMAL,
definition["isNumeric"] = true,
definition["bindType"] = Column::BIND_PARAM_DECIMAL;
- } elseif memstr(columnType, "char") {
- /**
- * Chars are chars
- */
- let definition["type"] = Column::TYPE_CHAR;
- } elseif memstr(columnType, "datetime") {
- /**
- * Special type for datetime
- */
- let definition["type"] = Column::TYPE_DATETIME;
- } elseif memstr(columnType, "text") {
- /**
- * Text are varchars
- */
- let definition["type"] = Column::TYPE_TEXT;
} elseif memstr(columnType, "float") {
/**
* Float/Smallfloats/Decimals are float
@@ -166,11 +176,35 @@ class Sqlite extends PdoAdapter
let definition["type"] = Column::TYPE_FLOAT,
definition["isNumeric"] = true,
definition["bindType"] = Column::TYPE_DECIMAL;
- } elseif memstr(columnType, "enum") {
+
+ /**
+ * TIMESTAMP
+ */
+ } elseif memstr(columnType, "timestamp") {
/**
- * Enum are treated as char
+ * Timestamp as date
+ */
+ let definition["type"] = Column::TYPE_TIMESTAMP;
+
+ /**
+ * TEXT/VARCHAR/CHAR
+ */
+ } elseif memstr(columnType, "varchar") {
+ /**
+ * Varchar are varchars
+ */
+ let definition["type"] = Column::TYPE_VARCHAR;
+ } elseif memstr(columnType, "char") {
+ /**
+ * Chars are chars
*/
let definition["type"] = Column::TYPE_CHAR;
+ } elseif memstr(columnType, "text") {
+ /**
+ * Text are varchars
+ */
+ let definition["type"] = Column::TYPE_TEXT;
+
} else {
/**
* By default is string
@@ -372,7 +406,7 @@ class Sqlite extends PdoAdapter
/**
* Check whether the database system requires an explicit value for identity columns
*/
- public function useExplicitIdValue() -> boolean
+ public function useExplicitIdValue() -> bool
{
return true;
}
diff --git a/phalcon/db/adapterinterface.zep b/phalcon/db/adapterinterface.zep
index 9e3827c4215..dd500eddbe1 100644
--- a/phalcon/db/adapterinterface.zep
+++ b/phalcon/db/adapterinterface.zep
@@ -20,22 +20,22 @@ interface AdapterInterface
/**
* Adds a column to a table
*/
- public function addColumn(string! tableName, string! schemaName, column) -> boolean;
+ public function addColumn(string! tableName, string! schemaName, column) -> bool;
/**
* Adds an index to a table
*/
- public function addIndex(string! tableName, string! schemaName, index) -> boolean;
+ public function addIndex(string! tableName, string! schemaName, index) -> bool;
/**
* Adds a foreign key to a table
*/
- public function addForeignKey(string! tableName, string! schemaName, reference) -> boolean;
+ public function addForeignKey(string! tableName, string! schemaName, reference) -> bool;
/**
* Adds a primary key to a table
*/
- public function addPrimaryKey(string! tableName, string! schemaName, index) -> boolean;
+ public function addPrimaryKey(string! tableName, string! schemaName, index) -> bool;
/**
* Returns the number of affected rows by the last INSERT/UPDATE/DELETE reported by the database system
@@ -45,39 +45,39 @@ interface AdapterInterface
/**
* Starts a transaction in the connection
*/
- public function begin(boolean nesting = true) -> boolean;
+ public function begin(bool nesting = true) -> bool;
/**
* Closes active connection returning success. Phalcon automatically closes
* and destroys active connections within Phalcon\Db\Pool
*/
- public function close() -> boolean;
+ public function close() -> bool;
/**
* Commits the active transaction in the connection
*/
- public function commit(boolean nesting = true) -> boolean;
+ public function commit(bool nesting = true) -> bool;
/**
* This method is automatically called in \Phalcon\Db\Adapter\Pdo constructor.
* Call it when you need to restore a database connection
*/
- public function connect(array descriptor = null) -> boolean;
+ public function connect(array descriptor = null) -> bool;
/**
* Creates a new savepoint
*/
- public function createSavepoint(string! name) -> boolean;
+ public function createSavepoint(string! name) -> bool;
/**
* Creates a table
*/
- public function createTable(string! tableName, string! schemaName, array! definition) -> boolean;
+ public function createTable(string! tableName, string! schemaName, array! definition) -> bool;
/**
* Creates a view
*/
- public function createView(string! viewName, array! definition, string schemaName = null) -> boolean;
+ public function createView(string! viewName, array! definition, string schemaName = null) -> bool;
/**
* Deletes data from a table using custom RDBMS SQL syntax
@@ -86,7 +86,7 @@ interface AdapterInterface
* @param array placeholders
* @param array dataTypes
*/
- public function delete(string table, whereCondition = null, placeholders = null, dataTypes = null) -> boolean;
+ public function delete(string table, whereCondition = null, placeholders = null, dataTypes = null) -> bool;
/**
* Returns an array of Phalcon\Db\Column objects describing a table
@@ -106,32 +106,32 @@ interface AdapterInterface
/**
* Drops a column from a table
*/
- public function dropColumn(string! tableName, string! schemaName, string columnName) -> boolean;
+ public function dropColumn(string! tableName, string! schemaName, string columnName) -> bool;
/**
* Drops a foreign key from a table
*/
- public function dropForeignKey(string! tableName, string! schemaName, string referenceName) -> boolean;
+ public function dropForeignKey(string! tableName, string! schemaName, string referenceName) -> bool;
/**
* Drop an index from a table
*/
- public function dropIndex(string! tableName, string! schemaName, string indexName) -> boolean;
+ public function dropIndex(string! tableName, string! schemaName, string indexName) -> bool;
/**
* Drops primary key from a table
*/
- public function dropPrimaryKey(string! tableName, string! schemaName) -> boolean;
+ public function dropPrimaryKey(string! tableName, string! schemaName) -> bool;
/**
* Drops a table from a schema/database
*/
- public function dropTable(string! tableName, string! schemaName = null, boolean ifExists = true) -> boolean;
+ public function dropTable(string! tableName, string! schemaName = null, bool ifExists = true) -> bool;
/**
* Drops a view
*/
- public function dropView(string! viewName, string! schemaName = null, boolean ifExists = true) -> boolean;
+ public function dropView(string! viewName, string! schemaName = null, bool ifExists = true) -> bool;
/**
* Escapes a column/table/schema name
@@ -149,7 +149,7 @@ interface AdapterInterface
* Sends SQL statements to the database server returning the success state.
* Use this method only when the SQL statement sent to the server doesn't return any rows
*/
- public function execute(string! sqlStatement, var placeholders = null, var dataTypes = null) -> boolean;
+ public function execute(string! sqlStatement, var placeholders = null, var dataTypes = null) -> bool;
/**
* Dumps the complete result of a query into an array
@@ -248,17 +248,17 @@ interface AdapterInterface
* @param array fields
* @param array dataTypes
*/
- public function insert(string table, array! values, fields = null, dataTypes = null) -> boolean;
+ public function insert(string table, array! values, fields = null, dataTypes = null) -> bool;
/**
* Returns if nested transactions should use savepoints
*/
- public function isNestedTransactionsWithSavepoints() -> boolean;
+ public function isNestedTransactionsWithSavepoints() -> bool;
/**
* Checks whether connection is under database transaction
*/
- public function isUnderTransaction() -> boolean;
+ public function isUnderTransaction() -> bool;
/**
* Returns insert id for the auto_increment column inserted in the last SQL statement
@@ -286,28 +286,28 @@ interface AdapterInterface
/**
* Modifies a table column based on a definition
*/
- public function modifyColumn(string! tableName, string! schemaName, column, currentColumn = null) -> boolean;
+ public function modifyColumn(string! tableName, string! schemaName, column, currentColumn = null) -> bool;
/**
* Sends SQL statements to the database server returning the success state.
* Use this method only when the SQL statement sent to the server return rows
*/
- public function query(string! sqlStatement, var placeholders = null, var dataTypes = null) -> | boolean;
+ public function query(string! sqlStatement, var placeholders = null, var dataTypes = null) -> | bool;
/**
* Releases given savepoint
*/
- public function releaseSavepoint(string! name) -> boolean;
+ public function releaseSavepoint(string! name) -> bool;
/**
* Rollbacks the active transaction in the connection
*/
- public function rollback(boolean nesting = true) -> boolean;
+ public function rollback(bool nesting = true) -> bool;
/**
* Rollbacks given savepoint
*/
- public function rollbackSavepoint(string! name) -> boolean;
+ public function rollbackSavepoint(string! name) -> bool;
/**
* Returns a SQL modified with a LOCK IN SHARE MODE clause
@@ -317,17 +317,17 @@ interface AdapterInterface
/**
* Set if nested transactions should use savepoints
*/
- public function setNestedTransactionsWithSavepoints(boolean nestedTransactionsWithSavepoints) -> ;
+ public function setNestedTransactionsWithSavepoints(bool nestedTransactionsWithSavepoints) -> ;
/**
* Check whether the database system requires a sequence to produce auto-numeric values
*/
- public function supportSequences() -> boolean;
+ public function supportSequences() -> bool;
/**
* Generates SQL checking for the existence of a schema.table
*/
- public function tableExists(string! tableName, string! schemaName = null) -> boolean;
+ public function tableExists(string! tableName, string! schemaName = null) -> bool;
/**
* Gets creation options from a table
@@ -342,16 +342,16 @@ interface AdapterInterface
* @param string whereCondition
* @param array dataTypes
*/
- public function update(string table, fields, values, whereCondition = null, dataTypes = null) -> boolean;
+ public function update(string table, fields, values, whereCondition = null, dataTypes = null) -> bool;
/**
* Check whether the database system requires an explicit value for identity columns
*/
- public function useExplicitIdValue() -> boolean;
+ public function useExplicitIdValue() -> bool;
/**
* Generates SQL checking for the existence of a schema.view
*/
- public function viewExists(string! viewName, string! schemaName = null) -> boolean;
+ public function viewExists(string! viewName, string! schemaName = null) -> bool;
}
diff --git a/phalcon/db/column.zep b/phalcon/db/column.zep
index 6acdcca5566..3753b846a37 100644
--- a/phalcon/db/column.zep
+++ b/phalcon/db/column.zep
@@ -81,33 +81,38 @@ class Column implements ColumnInterface
*/
const TYPE_BIGINTEGER = 14;
+ /**
+ * Bit abstract data type
+ */
+ const TYPE_BIT = 19;
+
/**
* Blob abstract data type
*/
const TYPE_BLOB = 11;
/**
- * Boolean abstract data type
+ * Bool abstract data type
*/
const TYPE_BOOLEAN = 8;
/**
- * Char abstract type
+ * Char abstract data type
*/
const TYPE_CHAR = 5;
/**
- * Date abstract type
+ * Date abstract data type
*/
const TYPE_DATE = 1;
/**
- * Datetime abstract type
+ * Datetime abstract data type
*/
const TYPE_DATETIME = 4;
/**
- * Decimal abstract type
+ * Decimal abstract data type
*/
const TYPE_DECIMAL = 3;
@@ -116,23 +121,28 @@ class Column implements ColumnInterface
*/
const TYPE_DOUBLE = 9;
+ /**
+ * Enum abstract data type
+ */
+ const TYPE_ENUM = 18;
+
/**
* Float abstract data type
*/
const TYPE_FLOAT = 7;
/**
- * Integer abstract type
+ * Int abstract data type
*/
const TYPE_INTEGER = 0;
/**
- * Json abstract type
+ * Json abstract data type
*/
const TYPE_JSON = 15;
/**
- * Jsonb abstract type
+ * Jsonb abstract data type
*/
const TYPE_JSONB = 16;
@@ -141,18 +151,43 @@ class Column implements ColumnInterface
*/
const TYPE_LONGBLOB = 13;
+ /**
+ * Longtext abstract data type
+ */
+ const TYPE_LONGTEXT = 24;
+
/**
* Mediumblob abstract data type
*/
const TYPE_MEDIUMBLOB = 12;
+ /**
+ * Mediumintegerr abstract data type
+ */
+ const TYPE_MEDIUMINTEGER = 21;
+
+ /**
+ * Mediumtext abstract data type
+ */
+ const TYPE_MEDIUMTEXT = 23;
+
+ /**
+ * Smallint abstract data type
+ */
+ const TYPE_SMALLINTEGER = 22;
+
/**
* Text abstract data type
*/
const TYPE_TEXT = 6;
/**
- * Datetime abstract type
+ * Time abstract data type
+ */
+ const TYPE_TIME = 20;
+
+ /**
+ * Timestamp abstract data type
*/
const TYPE_TIMESTAMP = 17;
@@ -162,7 +197,17 @@ class Column implements ColumnInterface
const TYPE_TINYBLOB = 10;
/**
- * Varchar abstract type
+ * Tinyint abstract data type
+ */
+ const TYPE_TINYINTEGER = 26;
+
+ /**
+ * Tinytext abstract data type
+ */
+ const TYPE_TINYTEXT = 25;
+
+ /**
+ * Varchar abstract data type
*/
const TYPE_VARCHAR = 2;
@@ -176,7 +221,7 @@ class Column implements ColumnInterface
/**
* Column is autoIncrement?
*
- * @var boolean
+ * @var bool
*/
protected _autoIncrement = false;
@@ -193,7 +238,7 @@ class Column implements ColumnInterface
/**
* Position is first
*
- * @var boolean
+ * @var bool
*/
protected _first = false;
@@ -212,7 +257,7 @@ class Column implements ColumnInterface
/**
* Column not nullable?
*
- * @var boolean
+ * @var bool
*/
protected _notNull = false;
@@ -245,7 +290,7 @@ class Column implements ColumnInterface
/**
* Column data type
*
- * @var int|string
+ * @var int
*/
protected _type { get };
@@ -266,7 +311,7 @@ class Column implements ColumnInterface
/**
* Integer column unsigned?
*
- * @var boolean
+ * @var bool
*/
protected _unsigned = false;
@@ -402,7 +447,7 @@ class Column implements ColumnInterface
/**
* Restores the internal state of a Phalcon\Db\Column object
*/
- public static function __set_state(array! data) ->
+ public static function __set_state(array! data) ->
{
var definition, columnType, notNull, size, dunsigned, after,
isNumeric, first, bindType, primary, columnName, scale,
@@ -509,7 +554,7 @@ class Column implements ColumnInterface
/**
* Check whether column has default value
*/
- public function hasDefault() -> boolean
+ public function hasDefault() -> bool
{
if this->isAutoIncrement() {
return false;
@@ -521,7 +566,7 @@ class Column implements ColumnInterface
/**
* Auto-Increment
*/
- public function isAutoIncrement() -> boolean
+ public function isAutoIncrement() -> bool
{
return this->_autoIncrement;
}
@@ -529,7 +574,7 @@ class Column implements ColumnInterface
/**
* Check whether column have first position in table
*/
- public function isFirst() -> boolean
+ public function isFirst() -> bool
{
return this->_first;
}
@@ -537,7 +582,7 @@ class Column implements ColumnInterface
/**
* Not null
*/
- public function isNotNull() -> boolean
+ public function isNotNull() -> bool
{
return this->_notNull;
}
@@ -545,7 +590,7 @@ class Column implements ColumnInterface
/**
* Check whether column have an numeric type
*/
- public function isNumeric() -> boolean
+ public function isNumeric() -> bool
{
return this->_isNumeric;
}
@@ -553,7 +598,7 @@ class Column implements ColumnInterface
/**
* Column is part of the primary key?
*/
- public function isPrimary() -> boolean
+ public function isPrimary() -> bool
{
return this->_primary;
}
@@ -561,7 +606,7 @@ class Column implements ColumnInterface
/**
* Returns true if number column is unsigned
*/
- public function isUnsigned() -> boolean
+ public function isUnsigned() -> bool
{
return this->_unsigned;
}
diff --git a/phalcon/db/columninterface.zep b/phalcon/db/columninterface.zep
index dea00eadac3..692443f23d5 100644
--- a/phalcon/db/columninterface.zep
+++ b/phalcon/db/columninterface.zep
@@ -17,7 +17,6 @@ namespace Phalcon\Db;
*/
interface ColumnInterface
{
-
/**
* Restores the internal state of a Phalcon\Db\Column object
*/
@@ -73,7 +72,7 @@ interface ColumnInterface
/**
* Returns column type
*
- * @return int
+ * @return int|string
*/
public function getType() -> int;
@@ -87,44 +86,42 @@ interface ColumnInterface
/**
* Returns column type values
*
- * @return int
+ * @return array|string
*/
- public function getTypeValues() -> int;
+ public function getTypeValues() -> array | string;
/**
* Check whether column has default value
*/
- public function hasDefault() -> boolean;
+ public function hasDefault() -> bool;
/**
* Auto-Increment
*/
- public function isAutoIncrement() -> boolean;
+ public function isAutoIncrement() -> bool;
/**
* Check whether column have first position in table
*/
- public function isFirst() -> boolean;
+ public function isFirst() -> bool;
/**
* Not null
*/
- public function isNotNull() -> boolean;
+ public function isNotNull() -> bool;
/**
* Check whether column have an numeric type
*/
- public function isNumeric() -> boolean;
+ public function isNumeric() -> bool;
/**
* Column is part of the primary key?
*/
- public function isPrimary() -> boolean;
+ public function isPrimary() -> bool;
/**
* Returns true if number column is unsigned
*/
- public function isUnsigned() -> boolean;
-
-
+ public function isUnsigned() -> bool;
}
diff --git a/phalcon/db/dialect.zep b/phalcon/db/dialect.zep
index a664d9278e3..e4ecb405a94 100644
--- a/phalcon/db/dialect.zep
+++ b/phalcon/db/dialect.zep
@@ -485,7 +485,7 @@ abstract class Dialect implements DialectInterface
/**
* Checks whether the platform supports savepoints
*/
- public function supportsSavepoints() -> boolean
+ public function supportsSavepoints() -> bool
{
return true;
}
@@ -493,7 +493,7 @@ abstract class Dialect implements DialectInterface
/**
* Checks whether the platform supports releasing savepoints.
*/
- public function supportsReleaseSavepoints() -> boolean
+ public function supportsReleaseSavepoints() -> bool
{
return this->supportsSavePoints();
}
@@ -522,6 +522,46 @@ abstract class Dialect implements DialectInterface
return "ROLLBACK TO SAVEPOINT " . name;
}
+ /**
+ * Checks the column type and if not string it returns the type reference
+ */
+ protected function checkColumnType( column) -> string
+ {
+ if typeof column->getType() == "string" {
+ return column->getTypeReference();
+ }
+
+ return column->getType();
+ }
+
+ /**
+ * Checks the column type and returns the updated SQL statement
+ */
+ protected function checkColumnTypeSql( column) -> string
+ {
+ if typeof column->getType() == "string" {
+ return column->getType();
+ }
+
+ return "";
+ }
+
+ /**
+ * Returns the size of the column enclosed in parentheses
+ */
+ protected function getColumnSize( column) -> string
+ {
+ return "(" . column->getSize() . ")";
+ }
+
+ /**
+ * Returns the column size and scale enclosed in parentheses
+ */
+ protected function getColumnSizeAndScale( column) -> string
+ {
+ return "(" . column->getSize() . "," . column->getScale() . ")";
+ }
+
/**
* Resolve Column expressions
*/
diff --git a/phalcon/db/dialect/mysql.zep b/phalcon/db/dialect/mysql.zep
index 182eea767bf..9d76dc237fe 100644
--- a/phalcon/db/dialect/mysql.zep
+++ b/phalcon/db/dialect/mysql.zep
@@ -42,26 +42,44 @@ class Mysql extends Dialect
*/
public function getColumnDefinition( column) -> string
{
- var columnSql, size, scale, type, typeValues;
+ var columnType, columnSql, typeValues;
- let columnSql = "";
+ let columnSql = this->checkColumnTypeSql(column);
+ let columnType = this->checkColumnType(column);
- let type = column->getType();
- if typeof type == "string" {
- let columnSql .= type;
- let type = column->getTypeReference();
- }
+ switch columnType {
- switch type {
+ case Column::TYPE_BIGINTEGER:
+ if empty columnSql {
+ let columnSql .= "BIGINT";
+ }
+ let columnSql .= this->getColumnSize(column) . this->checkColumnUnsigned(column);
+ break;
- case Column::TYPE_INTEGER:
+ case Column::TYPE_BIT:
if empty columnSql {
- let columnSql .= "INT";
+ let columnSql .= "BIT";
+ }
+ let columnSql .= this->getColumnSize(column);
+ break;
+
+ case Column::TYPE_BLOB:
+ if empty columnSql {
+ let columnSql .= "BLOB";
}
- let columnSql .= "(" . column->getSize() . ")";
- if column->isUnsigned() {
- let columnSql .= " UNSIGNED";
+ break;
+
+ case Column::TYPE_BOOLEAN:
+ if empty columnSql {
+ let columnSql .= "TINYINT(1)";
+ }
+ break;
+
+ case Column::TYPE_CHAR:
+ if empty columnSql {
+ let columnSql .= "CHAR";
}
+ let columnSql .= this->getColumnSize(column);
break;
case Column::TYPE_DATE:
@@ -70,101 +88,106 @@ class Mysql extends Dialect
}
break;
- case Column::TYPE_VARCHAR:
+ case Column::TYPE_DATETIME:
if empty columnSql {
- let columnSql .= "VARCHAR";
+ let columnSql .= "DATETIME";
}
- let columnSql .= "(" . column->getSize() . ")";
break;
case Column::TYPE_DECIMAL:
if empty columnSql {
let columnSql .= "DECIMAL";
}
- let columnSql .= "(" . column->getSize() . "," . column->getScale() . ")";
- if column->isUnsigned() {
- let columnSql .= " UNSIGNED";
- }
+ let columnSql .= this->getColumnSizeAndScale(column) . this->checkColumnUnsigned(column);
break;
- case Column::TYPE_DATETIME:
+ case Column::TYPE_DOUBLE:
if empty columnSql {
- let columnSql .= "DATETIME";
+ let columnSql .= "DOUBLE";
}
+ let columnSql .= this->checkColumnSizeAndScale(column) . this->checkColumnUnsigned(column);
break;
- case Column::TYPE_TIMESTAMP:
+ case Column::TYPE_ENUM:
if empty columnSql {
- let columnSql .= "TIMESTAMP";
+ let columnSql .= "ENUM";
}
+ let columnSql .= this->getColumnSize(column);
break;
- case Column::TYPE_CHAR:
+ case Column::TYPE_FLOAT:
if empty columnSql {
- let columnSql .= "CHAR";
+ let columnSql .= "FLOAT";
}
- let columnSql .= "(" . column->getSize() . ")";
+ let columnSql .= this->checkColumnSizeAndScale(column) . this->checkColumnUnsigned(column);
break;
- case Column::TYPE_TEXT:
+ case Column::TYPE_INTEGER:
if empty columnSql {
- let columnSql .= "TEXT";
+ let columnSql .= "INT";
}
+ let columnSql .= this->getColumnSize(column) . this->checkColumnUnsigned(column);
break;
- case Column::TYPE_BOOLEAN:
+ case Column::TYPE_JSON:
if empty columnSql {
- let columnSql .= "TINYINT(1)";
+ let columnSql .= "JSON";
}
break;
- case Column::TYPE_FLOAT:
+ case Column::TYPE_LONGBLOB:
if empty columnSql {
- let columnSql .= "FLOAT";
+ let columnSql .= "LONGBLOB";
}
- let size = column->getSize();
- if size {
- let scale = column->getScale();
- if scale {
- let columnSql .= "(" . size . "," . scale . ")";
- } else {
- let columnSql .= "(" . size . ")";
- }
+ break;
+
+ case Column::TYPE_LONGTEXT:
+ if empty columnSql {
+ let columnSql .= "LONGTEXT";
}
- if column->isUnsigned() {
- let columnSql .= " UNSIGNED";
+ break;
+
+ case Column::TYPE_MEDIUMBLOB:
+ if empty columnSql {
+ let columnSql .= "MEDIUMBLOB";
}
break;
- case Column::TYPE_DOUBLE:
+ case Column::TYPE_MEDIUMINTEGER:
if empty columnSql {
- let columnSql .= "DOUBLE";
+ let columnSql .= "MEDIUMINT";
}
- let size = column->getSize();
- if size {
- let scale = column->getScale(),
- columnSql .= "(" . size;
- if scale {
- let columnSql .= "," . scale . ")";
- } else {
- let columnSql .= ")";
- }
+ let columnSql .= this->getColumnSize(column) . this->checkColumnUnsigned(column);
+ break;
+
+ case Column::TYPE_MEDIUMTEXT:
+ if empty columnSql {
+ let columnSql .= "MEDIUMTEXT";
}
- if column->isUnsigned() {
- let columnSql .= " UNSIGNED";
+ break;
+
+ case Column::TYPE_SMALLINTEGER:
+ if empty columnSql {
+ let columnSql .= "SMALLINT";
}
+ let columnSql .= this->getColumnSize(column) . this->checkColumnUnsigned(column);
break;
- case Column::TYPE_BIGINTEGER:
+ case Column::TYPE_TEXT:
if empty columnSql {
- let columnSql .= "BIGINT";
+ let columnSql .= "TEXT";
}
- let scale = column->getSize();
- if scale {
- let columnSql .= "(" . column->getSize() . ")";
+ break;
+
+ case Column::TYPE_TIME:
+ if empty columnSql {
+ let columnSql .= "TIME";
}
- if column->isUnsigned() {
- let columnSql .= " UNSIGNED";
+ break;
+
+ case Column::TYPE_TIMESTAMP:
+ if empty columnSql {
+ let columnSql .= "TIMESTAMP";
}
break;
@@ -174,22 +197,24 @@ class Mysql extends Dialect
}
break;
- case Column::TYPE_BLOB:
+ case Column::TYPE_TINYINTEGER:
if empty columnSql {
- let columnSql .= "BLOB";
+ let columnSql .= "TINYINT";
}
+ let columnSql .= this->getColumnSize(column) . this->checkColumnUnsigned(column);
break;
- case Column::TYPE_MEDIUMBLOB:
+ case Column::TYPE_TINYTEXT:
if empty columnSql {
- let columnSql .= "MEDIUMBLOB";
+ let columnSql .= "TINYTEXT";
}
break;
- case Column::TYPE_LONGBLOB:
+ case Column::TYPE_VARCHAR:
if empty columnSql {
- let columnSql .= "LONGBLOB";
+ let columnSql .= "VARCHAR";
}
+ let columnSql .= this->getColumnSize(column);
break;
default:
@@ -535,7 +560,7 @@ class Mysql extends Dialect
/**
* Generates SQL to drop a table
*/
- public function dropTable(string! tableName, string schemaName = null, boolean! ifExists = true) -> string
+ public function dropTable(string! tableName, string schemaName = null, bool! ifExists = true) -> string
{
var sql, table;
@@ -567,7 +592,7 @@ class Mysql extends Dialect
/**
* Generates SQL to drop a view
*/
- public function dropView(string! viewName, string schemaName = null, boolean! ifExists = true) -> string
+ public function dropView(string! viewName, string schemaName = null, bool! ifExists = true) -> string
{
var sql, view;
@@ -759,4 +784,38 @@ class Mysql extends Dialect
{
return sqlQuery . " LOCK IN SHARE MODE";
}
+
+ /**
+ * Checks if the size and/or scale are present and encloses those values
+ * in parentheses if need be
+ */
+ private function checkColumnSizeAndScale( column) -> string
+ {
+ var columnSql;
+
+ if column->getSize() {
+ let columnSql .= "(" . column->getSize();
+ if column->getScale() {
+ let columnSql .= "," . column->getScale() . ")";
+ } else {
+ let columnSql .= ")";
+ }
+ } else {
+ let columnSql .= ")";
+ }
+
+ return columnSql;
+ }
+
+ /**
+ * Checks if a column is unsigned or not and returns the relevant SQL syntax
+ */
+ private function checkColumnUnsigned( column) -> string
+ {
+ if column->isUnsigned() {
+ return " UNSIGNED";
+ }
+
+ return "";
+ }
}
diff --git a/phalcon/db/dialect/postgresql.zep b/phalcon/db/dialect/postgresql.zep
index e8c3de4cc26..103e6ba86fb 100644
--- a/phalcon/db/dialect/postgresql.zep
+++ b/phalcon/db/dialect/postgresql.zep
@@ -43,47 +43,40 @@ class Postgresql extends Dialect
*/
public function getColumnDefinition( column) -> string
{
- var size, columnType, columnSql, typeValues;
+ var columnType, columnSql, typeValues;
- let size = column->getSize();
- let columnType = column->getType();
- let columnSql = "";
-
- if typeof columnType == "string" {
- let columnSql .= columnType;
- let columnType = column->getTypeReference();
- }
+ let columnSql = this->checkColumnTypeSql(column);
+ let columnType = this->checkColumnType(column);
switch columnType {
- case Column::TYPE_INTEGER:
+ case Column::TYPE_BIGINTEGER:
if empty columnSql {
if column->isAutoIncrement() {
- let columnSql .= "SERIAL";
+ let columnSql .= "BIGSERIAL";
} else {
- let columnSql .= "INT";
+ let columnSql .= "BIGINT";
}
}
break;
- case Column::TYPE_DATE:
+ case Column::TYPE_BOOLEAN:
if empty columnSql {
- let columnSql .= "DATE";
+ let columnSql .= "BOOLEAN";
}
break;
- case Column::TYPE_VARCHAR:
+ case Column::TYPE_CHAR:
if empty columnSql {
- let columnSql .= "CHARACTER VARYING";
+ let columnSql .= "CHARACTER";
}
- let columnSql .= "(" . size . ")";
+ let columnSql .= this->getColumnSize(column);
break;
- case Column::TYPE_DECIMAL:
+ case Column::TYPE_DATE:
if empty columnSql {
- let columnSql .= "NUMERIC";
+ let columnSql .= "DATE";
}
- let columnSql .= "(" . size . "," . column->getScale() . ")";
break;
case Column::TYPE_DATETIME:
@@ -92,23 +85,11 @@ class Postgresql extends Dialect
}
break;
- case Column::TYPE_TIMESTAMP:
- if empty columnSql {
- let columnSql .= "TIMESTAMP";
- }
- break;
-
- case Column::TYPE_CHAR:
- if empty columnSql {
- let columnSql .= "CHARACTER";
- }
- let columnSql .= "(" . size . ")";
- break;
-
- case Column::TYPE_TEXT:
+ case Column::TYPE_DECIMAL:
if empty columnSql {
- let columnSql .= "TEXT";
+ let columnSql .= "NUMERIC";
}
+ let columnSql .= this->getColumnSizeAndScale(column);
break;
case Column::TYPE_FLOAT:
@@ -117,12 +98,12 @@ class Postgresql extends Dialect
}
break;
- case Column::TYPE_BIGINTEGER:
+ case Column::TYPE_INTEGER:
if empty columnSql {
if column->isAutoIncrement() {
- let columnSql .= "BIGSERIAL";
+ let columnSql .= "SERIAL";
} else {
- let columnSql .= "BIGINT";
+ let columnSql .= "INT";
}
}
break;
@@ -139,12 +120,26 @@ class Postgresql extends Dialect
}
break;
- case Column::TYPE_BOOLEAN:
+ case Column::TYPE_TIMESTAMP:
if empty columnSql {
- let columnSql .= "BOOLEAN";
+ let columnSql .= "TIMESTAMP";
+ }
+ break;
+
+ case Column::TYPE_TEXT:
+ if empty columnSql {
+ let columnSql .= "TEXT";
}
break;
+ case Column::TYPE_VARCHAR:
+ if empty columnSql {
+ let columnSql .= "CHARACTER VARYING";
+ }
+ let columnSql .= this->getColumnSize(column);
+ break;
+
+
default:
if empty columnSql {
throw new Exception("Unrecognized PostgreSQL data type at column " . column->getName());
@@ -336,7 +331,7 @@ class Postgresql extends Dialect
/**
* Generates SQL to create a table
*/
- public function createTable(string! tableName, string! schemaName, array! definition) -> string | array
+ public function createTable(string! tableName, string! schemaName, array! definition) -> string
{
var temporary, options, table, createLines, columns,
column, indexes, index, reference, references, indexName,
@@ -486,7 +481,7 @@ class Postgresql extends Dialect
/**
* Generates SQL to drop a table
*/
- public function dropTable(string! tableName, string schemaName = null, boolean! ifExists = true) -> string
+ public function dropTable(string! tableName, string schemaName = null, bool! ifExists = true) -> string
{
var table, sql;
@@ -518,7 +513,7 @@ class Postgresql extends Dialect
/**
* Generates SQL to drop a view
*/
- public function dropView(string! viewName, string schemaName = null, boolean! ifExists = true) -> string
+ public function dropView(string! viewName, string schemaName = null, bool! ifExists = true) -> string
{
var view, sql;
diff --git a/phalcon/db/dialect/sqlite.zep b/phalcon/db/dialect/sqlite.zep
index 3763a79b82a..8ddca226121 100644
--- a/phalcon/db/dialect/sqlite.zep
+++ b/phalcon/db/dialect/sqlite.zep
@@ -44,75 +44,69 @@ class Sqlite extends Dialect
*/
public function getColumnDefinition( column) -> string
{
- var columnSql, type, typeValues;
+ var columnType, columnSql, typeValues;
- let columnSql = "";
-
- let type = column->getType();
- if typeof type == "string" {
- let columnSql .= type;
- let type = column->getTypeReference();
- }
+ let columnSql = this->checkColumnTypeSql(column);
+ let columnType = this->checkColumnType(column);
// SQLite has dynamic column typing. The conversion below maximizes
// compatibility with other DBMS's while following the type affinity
// rules: http://www.sqlite.org/datatype3.html.
- switch type {
+ switch columnType {
- case Column::TYPE_INTEGER:
+ case Column::TYPE_BIGINTEGER:
if empty columnSql {
- let columnSql .= "INTEGER";
+ let columnSql .= "BIGINT";
}
- break;
-
- case Column::TYPE_DATE:
- if empty columnSql {
- let columnSql .= "DATE";
+ if column->isUnsigned() {
+ let columnSql .= " UNSIGNED";
}
break;
- case Column::TYPE_VARCHAR:
+ case Column::TYPE_BLOB:
if empty columnSql {
- let columnSql .= "VARCHAR";
+ let columnSql .= "BLOB";
}
- let columnSql .= "(" . column->getSize() . ")";
break;
- case Column::TYPE_DECIMAL:
+ case Column::TYPE_BOOLEAN:
if empty columnSql {
- let columnSql .= "NUMERIC";
+ let columnSql .= "TINYINT";
}
- let columnSql .= "(" . column->getSize() . "," . column->getScale() . ")";
break;
- case Column::TYPE_DATETIME:
+ case Column::TYPE_CHAR:
if empty columnSql {
- let columnSql .= "DATETIME";
+ let columnSql .= "CHARACTER";
}
+ let columnSql .= this->getColumnSize(column);
break;
- case Column::TYPE_TIMESTAMP:
+ case Column::TYPE_DATE:
if empty columnSql {
- let columnSql .= "TIMESTAMP";
+ let columnSql .= "DATE";
}
break;
- case Column::TYPE_CHAR:
+ case Column::TYPE_DATETIME:
if empty columnSql {
- let columnSql .= "CHARACTER";
+ let columnSql .= "DATETIME";
}
- let columnSql .= "(" . column->getSize() . ")";
break;
- case Column::TYPE_TEXT:
+ case Column::TYPE_DECIMAL:
if empty columnSql {
- let columnSql .= "TEXT";
+ let columnSql .= "NUMERIC";
}
+ let columnSql .= this->getColumnSizeAndScale(column);
break;
- case Column::TYPE_BOOLEAN:
+ case Column::TYPE_DOUBLE:
if empty columnSql {
- let columnSql .= "TINYINT";
+ let columnSql .= "DOUBLE";
+ }
+ if column->isUnsigned() {
+ let columnSql .= " UNSIGNED";
}
break;
@@ -122,46 +116,47 @@ class Sqlite extends Dialect
}
break;
- case Column::TYPE_DOUBLE:
+ case Column::TYPE_INTEGER:
if empty columnSql {
- let columnSql .= "DOUBLE";
- }
- if column->isUnsigned() {
- let columnSql .= " UNSIGNED";
+ let columnSql .= "INTEGER";
}
break;
- case Column::TYPE_BIGINTEGER:
+ case Column::TYPE_LONGBLOB:
if empty columnSql {
- let columnSql .= "BIGINT";
+ let columnSql .= "LONGBLOB";
}
- if column->isUnsigned() {
- let columnSql .= " UNSIGNED";
+ break;
+
+ case Column::TYPE_MEDIUMBLOB:
+ if empty columnSql {
+ let columnSql .= "MEDIUMBLOB";
}
break;
- case Column::TYPE_TINYBLOB:
+ case Column::TYPE_TEXT:
if empty columnSql {
- let columnSql .= "TINYBLOB";
+ let columnSql .= "TEXT";
}
break;
- case Column::TYPE_BLOB:
+ case Column::TYPE_TIMESTAMP:
if empty columnSql {
- let columnSql .= "BLOB";
+ let columnSql .= "TIMESTAMP";
}
break;
- case Column::TYPE_MEDIUMBLOB:
+ case Column::TYPE_TINYBLOB:
if empty columnSql {
- let columnSql .= "MEDIUMBLOB";
+ let columnSql .= "TINYBLOB";
}
break;
- case Column::TYPE_LONGBLOB:
+ case Column::TYPE_VARCHAR:
if empty columnSql {
- let columnSql .= "LONGBLOB";
+ let columnSql .= "VARCHAR";
}
+ let columnSql .= this->getColumnSize(column);
break;
default:
@@ -443,7 +438,7 @@ class Sqlite extends Dialect
/**
* Generates SQL to drop a table
*/
- public function dropTable(string! tableName, string schemaName = null, boolean! ifExists = true) -> string
+ public function dropTable(string! tableName, string schemaName = null, bool! ifExists = true) -> string
{
var sql, table;
@@ -475,7 +470,7 @@ class Sqlite extends Dialect
/**
* Generates SQL to drop a view
*/
- public function dropView(string! viewName, string schemaName = null, boolean! ifExists = true) -> string
+ public function dropView(string! viewName, string schemaName = null, bool! ifExists = true) -> string
{
var view;
diff --git a/phalcon/db/dialectinterface.zep b/phalcon/db/dialectinterface.zep
index 84ed7174f52..ea2748213b5 100644
--- a/phalcon/db/dialectinterface.zep
+++ b/phalcon/db/dialectinterface.zep
@@ -126,7 +126,7 @@ interface DialectInterface
/**
* Generates SQL to drop a view
*/
- public function dropView(string! viewName, string schemaName = null, boolean! ifExists = true) -> string;
+ public function dropView(string! viewName, string schemaName = null, bool! ifExists = true) -> string;
/**
* Generates SQL checking for the existence of a schema.table
@@ -166,12 +166,12 @@ interface DialectInterface
/**
* Checks whether the platform supports savepoints
*/
- public function supportsSavepoints() -> boolean;
+ public function supportsSavepoints() -> bool;
/**
* Checks whether the platform supports releasing savepoints.
*/
- public function supportsReleaseSavepoints() -> boolean;
+ public function supportsReleaseSavepoints() -> bool;
/**
* Generate SQL to create a new savepoint
diff --git a/phalcon/db/index.zep b/phalcon/db/index.zep
index 54c8ed5dda0..0a64baa1589 100644
--- a/phalcon/db/index.zep
+++ b/phalcon/db/index.zep
@@ -87,7 +87,7 @@ class Index implements IndexInterface
/**
* Restore a Phalcon\Db\Index object from export
*/
- public static function __set_state(array! data) ->
+ public static function __set_state(array! data) ->
{
var indexName, columns, type;
diff --git a/phalcon/db/reference.zep b/phalcon/db/reference.zep
index 9e60bb5ced5..bfd2c551954 100644
--- a/phalcon/db/reference.zep
+++ b/phalcon/db/reference.zep
@@ -44,7 +44,6 @@ namespace Phalcon\Db;
*/
class Reference implements ReferenceInterface
{
-
/**
* Constraint name
*
@@ -52,8 +51,18 @@ class Reference implements ReferenceInterface
*/
protected _name { get };
+ /**
+ * Schema name
+ *
+ * @var string
+ */
protected _schemaName { get };
+ /**
+ * Referenced Schema
+ *
+ * @var string
+ */
protected _referencedSchema { get };
/**
@@ -80,14 +89,14 @@ class Reference implements ReferenceInterface
/**
* ON DELETE
*
- * @var array
+ * @var string
*/
protected _onDelete { get };
/**
* ON UPDATE
*
- * @var array
+ * @var string
*/
protected _onUpdate { get };
@@ -144,7 +153,7 @@ class Reference implements ReferenceInterface
/**
* Restore a Phalcon\Db\Reference object from export
*/
- public static function __set_state(array! data) ->
+ public static function __set_state(array! data) ->
{
var referencedSchema, referencedTable, columns,
referencedColumns, constraintName,
diff --git a/phalcon/db/result/pdo.zep b/phalcon/db/result/pdo.zep
index 282f64e27fd..2ff4f30d64e 100644
--- a/phalcon/db/result/pdo.zep
+++ b/phalcon/db/result/pdo.zep
@@ -101,7 +101,7 @@ class Pdo implements ResultInterface
* Allows to execute the statement again. Some database systems don't support scrollable cursors,
* So, as cursors are forward only, we need to execute the cursor again to fetch rows from the begining
*/
- public function execute() -> boolean
+ public function execute() -> bool
{
return this->_pdoStatement->execute();
}
@@ -328,7 +328,7 @@ class Pdo implements ResultInterface
* );
*
*/
- public function setFetchMode(int fetchMode, var colNoOrClassNameOrObject = null, var ctorargs = null) -> boolean
+ public function setFetchMode(int fetchMode, var colNoOrClassNameOrObject = null, var ctorargs = null) -> bool
{
var pdoStatement;
diff --git a/phalcon/db/resultinterface.zep b/phalcon/db/resultinterface.zep
index ccb0644c901..4665ad22199 100644
--- a/phalcon/db/resultinterface.zep
+++ b/phalcon/db/resultinterface.zep
@@ -30,7 +30,7 @@ interface ResultInterface
* Allows to executes the statement again. Some database systems don't support scrollable cursors,
* So, as cursors are forward only, we need to execute the cursor again to fetch rows from the begining
*/
- public function execute() -> boolean;
+ public function execute() -> bool;
/**
* Fetches an array/object of strings that corresponds to the fetched row, or FALSE if there are no more rows.
@@ -62,14 +62,14 @@ interface ResultInterface
/**
* Moves internal resultset cursor to another position letting us to fetch a certain row
*
- * @param int number
+ * @param long number
*/
- public function dataSeek(number);
+ public function dataSeek(long number);
/**
* Changes the fetching mode affecting Phalcon\Db\Result\Pdo::fetch()
*/
- public function setFetchMode(int fetchMode) -> boolean;
+ public function setFetchMode(int fetchMode) -> bool;
/**
* Gets the internal PDO result object
diff --git a/phalcon/debug.zep b/phalcon/debug.zep
index ae8d9fe0e8a..aad635ff570 100644
--- a/phalcon/debug.zep
+++ b/phalcon/debug.zep
@@ -54,7 +54,7 @@ class Debug
/**
* Sets if files the exception's backtrace must be showed
*/
- public function setShowBackTrace(boolean showBackTrace) ->
+ public function setShowBackTrace(bool showBackTrace) ->
{
let this->_showBackTrace = showBackTrace;
return this;
@@ -63,7 +63,7 @@ class Debug
/**
* Set if files part of the backtrace must be shown in the output
*/
- public function setShowFiles(boolean showFiles) ->
+ public function setShowFiles(bool showFiles) ->
{
let this->_showFiles = showFiles;
return this;
@@ -73,7 +73,7 @@ class Debug
* Sets if files must be completely opened and showed in the output
* or just the fragment related to the exception
*/
- public function setShowFileFragment(boolean showFileFragment) ->
+ public function setShowFileFragment(bool showFileFragment) ->
{
let this->_showFileFragment = showFileFragment;
return this;
@@ -82,7 +82,7 @@ class Debug
/**
* Listen for uncaught exceptions and unsilent notices or warnings
*/
- public function listen(boolean exceptions = true, boolean lowSeverity = false) ->
+ public function listen(bool exceptions = true, bool lowSeverity = false) ->
{
if exceptions {
this->listenExceptions();
@@ -556,7 +556,7 @@ class Debug
/**
* Handles uncaught exceptions
*/
- public function onUncaughtException(<\Exception> exception) -> boolean
+ public function onUncaughtException(<\Exception> exception) -> bool
{
var obLevel, className, escapedMessage, html, showBackTrace,
dataVars, n, traceItem, keyRequest, value, keyServer, keyFile, keyVar, dataVar;
diff --git a/phalcon/debug/dump.zep b/phalcon/debug/dump.zep
index 25611f9d779..6920523d4bd 100644
--- a/phalcon/debug/dump.zep
+++ b/phalcon/debug/dump.zep
@@ -52,9 +52,9 @@ class Dump
/**
* Phalcon\Debug\Dump constructor
*
- * @param boolean detailed debug object's private and protected properties
+ * @param bool detailed debug object's private and protected properties
*/
- public function __construct(array styles = [], boolean detailed = false)
+ public function __construct(array styles = [], bool detailed = false)
{
this->setStyles(styles);
diff --git a/phalcon/di.zep b/phalcon/di.zep
index 1ba72916018..41ab0fcdd74 100644
--- a/phalcon/di.zep
+++ b/phalcon/di.zep
@@ -125,7 +125,7 @@ class Di implements DiInterface
/**
* Registers a service in the services container
*/
- public function set(string! name, var definition, boolean shared = false) ->
+ public function set(string! name, var definition, bool shared = false) ->
{
var service;
let service = new Service(definition, shared),
@@ -156,7 +156,7 @@ class Di implements DiInterface
* Only is successful if a service hasn't been registered previously
* with the same name
*/
- public function attempt(string! name, definition, boolean shared = false) -> | boolean
+ public function attempt(string! name, definition, bool shared = false) -> | bool
{
var service;
@@ -309,7 +309,7 @@ class Di implements DiInterface
/**
* Check whether the DI contains a service by a name
*/
- public function has(string! name) -> boolean
+ public function has(string! name) -> bool
{
return isset this->_services[name];
}
@@ -317,7 +317,7 @@ class Di implements DiInterface
/**
* Check whether the last service obtained via getShared produced a fresh instance or an existing one
*/
- public function wasFreshInstance() -> boolean
+ public function wasFreshInstance() -> bool
{
return this->_freshInstance;
}
@@ -325,7 +325,7 @@ class Di implements DiInterface
/**
* Return the services registered in the DI
*/
- public function getServices() ->
+ public function getServices() ->
{
return this->_services;
}
@@ -333,7 +333,7 @@ class Di implements DiInterface
/**
* Check if a service is registered using the array syntax
*/
- public function offsetExists(string! name) -> boolean
+ public function offsetExists(var name) -> bool
{
return this->has(name);
}
@@ -345,10 +345,9 @@ class Di implements DiInterface
* $di["request"] = new \Phalcon\Http\Request();
*
*/
- public function offsetSet(string! name, var definition) -> boolean
+ public function offsetSet(var name, var definition) -> void
{
this->setShared(name, definition);
- return true;
}
/**
@@ -358,7 +357,7 @@ class Di implements DiInterface
* var_dump($di["request"]);
*
*/
- public function offsetGet(string! name) -> var
+ public function offsetGet(var name) -> var
{
return this->getShared(name);
}
@@ -366,9 +365,9 @@ class Di implements DiInterface
/**
* Removes a service from the services container using the array syntax
*/
- public function offsetUnset(string! name) -> boolean
+ public function offsetUnset(var name) -> void
{
- return false;
+ this->remove(name);
}
/**
@@ -434,7 +433,7 @@ class Di implements DiInterface
/**
* Set a default dependency injection container to be obtained into static methods
*/
- public static function setDefault( dependencyInjector)
+ public static function setDefault( dependencyInjector) -> void
{
let self::_default = dependencyInjector;
}
@@ -442,7 +441,7 @@ class Di implements DiInterface
/**
* Return the latest DI created
*/
- public static function getDefault() ->
+ public static function getDefault() -> | null
{
return self::_default;
}
diff --git a/phalcon/di/exception/serviceresolutionexception.zep b/phalcon/di/exception/serviceresolutionexception.zep
index a325331a9ab..903a46225fe 100644
--- a/phalcon/di/exception/serviceresolutionexception.zep
+++ b/phalcon/di/exception/serviceresolutionexception.zep
@@ -13,14 +13,14 @@
+------------------------------------------------------------------------+
*/
-namespace Phalcon\Di\Exception;
+ namespace Phalcon\Di\Exception;
-use Phalcon\Di\Exception\ServiceResolutionException;
-
-/**
- * Phalcon\Di\Exception\ServiceResolutionException
- *
- */
-class ServiceResolutionException extends \Phalcon\Di\Exception
-{
-}
\ No newline at end of file
+ use Phalcon\Di\Exception\ServiceResolutionException;
+
+ /**
+ * Phalcon\Di\Exception\ServiceResolutionException
+ *
+ */
+ class ServiceResolutionException extends \Phalcon\Di\Exception
+ {
+ }
\ No newline at end of file
diff --git a/phalcon/di/service.zep b/phalcon/di/service.zep
index 66e3fecc2b8..ff0e1d6ac7d 100644
--- a/phalcon/di/service.zep
+++ b/phalcon/di/service.zep
@@ -55,7 +55,7 @@ class Service implements ServiceInterface
*
* @param mixed definition
*/
- public final function __construct(definition, boolean shared = false)
+ public final function __construct(definition, bool shared = false)
{
let this->_definition = definition,
this->_shared = shared;
@@ -64,7 +64,7 @@ class Service implements ServiceInterface
/**
* Sets if the service is shared or not
*/
- public function setShared(boolean shared) -> void
+ public function setShared(bool shared) -> void
{
let this->_shared = shared;
}
@@ -72,7 +72,7 @@ class Service implements ServiceInterface
/**
* Check whether the service is shared or not
*/
- public function isShared() -> boolean
+ public function isShared() -> bool
{
return this->_shared;
}
@@ -115,7 +115,7 @@ class Service implements ServiceInterface
*/
public function resolve(parameters = null, dependencyInjector = null)
{
- boolean found;
+ bool found;
var shared, definition, sharedInstance, instance, builder;
let shared = this->_shared;
@@ -210,7 +210,7 @@ class Service implements ServiceInterface
/**
* Changes a parameter in the definition without resolve the service
*/
- public function setParameter(int position, array! parameter) ->
+ public function setParameter(int position, array! parameter) ->
{
var definition, arguments;
@@ -270,7 +270,7 @@ class Service implements ServiceInterface
/**
* Returns true if the service was resolved
*/
- public function isResolved() -> boolean
+ public function isResolved() -> bool
{
return this->_resolved;
}
@@ -278,9 +278,9 @@ class Service implements ServiceInterface
/**
* Restore the internal state of a service
*/
- public static function __set_state(array! attributes) ->
+ public static function __set_state(array! attributes) ->
{
- var name, definition, shared;
+ var definition, shared;
if !fetch definition, attributes["_definition"] {
throw new Exception("The attribute '_definition' is required");
diff --git a/phalcon/di/serviceinterface.zep b/phalcon/di/serviceinterface.zep
index 74083be2ef6..605037d29e1 100644
--- a/phalcon/di/serviceinterface.zep
+++ b/phalcon/di/serviceinterface.zep
@@ -31,12 +31,12 @@ interface ServiceInterface
/**
* Sets if the service is shared or not
*/
- public function setShared(boolean shared);
+ public function setShared(bool shared);
/**
* Check whether the service is shared or not
*/
- public function isShared() -> boolean;
+ public function isShared() -> bool;
/**
* Set the service definition
diff --git a/phalcon/diinterface.zep b/phalcon/diinterface.zep
index 7723b62de6a..37320c16ac6 100644
--- a/phalcon/diinterface.zep
+++ b/phalcon/diinterface.zep
@@ -35,7 +35,7 @@ interface DiInterface extends \ArrayAccess
*
* @param mixed definition
*/
- public function set(string! name, definition, boolean shared = false) -> ;
+ public function set(string! name, definition, bool shared = false) -> ;
/**
* Registers an "always shared" service in the services container
@@ -56,7 +56,7 @@ interface DiInterface extends \ArrayAccess
*
* @param mixed definition
*/
- public function attempt(string! name, definition, boolean shared = false) -> ;
+ public function attempt(string! name, definition, bool shared = false) -> | bool;
/**
* Resolves the service based on its configuration
@@ -90,12 +90,12 @@ interface DiInterface extends \ArrayAccess
/**
* Check whether the DI contains a service by a name
*/
- public function has(string! name) -> boolean;
+ public function has(string! name) -> bool;
/**
* Check whether the last service obtained via getShared produced a fresh instance or an existing one
*/
- public function wasFreshInstance() -> boolean;
+ public function wasFreshInstance() -> bool;
/**
* Return the services registered in the DI
diff --git a/phalcon/dispatcher.zep b/phalcon/dispatcher.zep
index fab276d5328..708a7038be8 100644
--- a/phalcon/dispatcher.zep
+++ b/phalcon/dispatcher.zep
@@ -283,7 +283,7 @@ abstract class Dispatcher implements DispatcherInterface, InjectionAwareInterfac
/**
* Check if a param exists
*/
- public function hasParam(var param) -> boolean
+ public function hasParam(var param) -> bool
{
return isset this->_params[param];
}
@@ -299,7 +299,7 @@ abstract class Dispatcher implements DispatcherInterface, InjectionAwareInterfac
/**
* Checks if the dispatch loop is finished or has more pendent controllers/tasks to dispatch
*/
- public function isFinished() -> boolean
+ public function isFinished() -> bool
{
return this->_finished;
}
@@ -387,7 +387,7 @@ abstract class Dispatcher implements DispatcherInterface, InjectionAwareInterfac
*/
public function dispatch()
{
- boolean hasService, hasEventsManager;
+ bool hasService, hasEventsManager;
int numberDispatches;
var value, handler, dependencyInjector, namespaceName, handlerName,
actionName, params, eventsManager,
@@ -815,7 +815,7 @@ abstract class Dispatcher implements DispatcherInterface, InjectionAwareInterfac
/**
* Check if the current executed action was forwarded by another one
*/
- public function wasForwarded() -> boolean
+ public function wasForwarded() -> bool
{
return this->_forwarded;
}
diff --git a/phalcon/dispatcherinterface.zep b/phalcon/dispatcherinterface.zep
index 67ab599caf6..7fa946cc7e8 100644
--- a/phalcon/dispatcherinterface.zep
+++ b/phalcon/dispatcherinterface.zep
@@ -107,12 +107,12 @@ interface DispatcherInterface
/**
* Check if a param exists
*/
- public function hasParam(var param) -> boolean;
+ public function hasParam(var param) -> bool;
/**
* Checks if the dispatch loop is finished or has more pendent controllers/tasks to dispatch
*/
- public function isFinished() -> boolean;
+ public function isFinished() -> bool;
/**
* Returns value returned by the latest dispatched action
diff --git a/phalcon/escaper.zep b/phalcon/escaper.zep
index 6a6b1388d68..40423c768f9 100644
--- a/phalcon/escaper.zep
+++ b/phalcon/escaper.zep
@@ -88,7 +88,7 @@ class Escaper implements EscaperInterface
* $escaper->setDoubleEncode(false);
*
*/
- public function setDoubleEncode(boolean doubleEncode) -> void
+ public function setDoubleEncode(bool doubleEncode) -> void
{
let this->_doubleEncode = doubleEncode;
}
diff --git a/phalcon/events/event.zep b/phalcon/events/event.zep
index 9ec4cc194cb..62501e0ec0d 100644
--- a/phalcon/events/event.zep
+++ b/phalcon/events/event.zep
@@ -50,14 +50,14 @@ class Event implements EventInterface
/**
* Is event propagation stopped?
*
- * @var boolean
+ * @var bool
*/
protected _stopped = false;
/**
* Is event cancelable?
*
- * @var boolean
+ * @var bool
*/
protected _cancelable = true;
@@ -66,7 +66,7 @@ class Event implements EventInterface
*
* @param object source
*/
- public function __construct(string! type, source, var data = null, boolean cancelable = true)
+ public function __construct(string! type, source, var data = null, bool cancelable = true)
{
let this->_type = type,
this->_source = source;
@@ -123,7 +123,7 @@ class Event implements EventInterface
/**
* Check whether the event is currently stopped.
*/
- public function isStopped() -> boolean
+ public function isStopped() -> bool
{
return this->_stopped;
}
@@ -137,7 +137,7 @@ class Event implements EventInterface
* }
*
*/
- public function isCancelable() -> boolean
+ public function isCancelable() -> bool
{
return this->_cancelable;
}
diff --git a/phalcon/events/eventinterface.zep b/phalcon/events/eventinterface.zep
index f6daca28933..31aba52afd4 100644
--- a/phalcon/events/eventinterface.zep
+++ b/phalcon/events/eventinterface.zep
@@ -54,10 +54,10 @@ interface EventInterface
/**
* Check whether the event is currently stopped
*/
- public function isStopped() -> boolean;
+ public function isStopped() -> bool;
/**
* Check whether the event is cancelable
*/
- public function isCancelable() -> boolean;
+ public function isCancelable() -> bool;
}
diff --git a/phalcon/events/manager.zep b/phalcon/events/manager.zep
index baaeec44711..197eacc4e17 100644
--- a/phalcon/events/manager.zep
+++ b/phalcon/events/manager.zep
@@ -129,7 +129,7 @@ class Manager implements ManagerInterface
/**
* Set if priorities are enabled in the EventsManager
*/
- public function enablePriorities(boolean enablePriorities)
+ public function enablePriorities(bool enablePriorities)
{
let this->_enablePriorities = enablePriorities;
}
@@ -137,7 +137,7 @@ class Manager implements ManagerInterface
/**
* Returns if priorities are enabled
*/
- public function arePrioritiesEnabled() -> boolean
+ public function arePrioritiesEnabled() -> bool
{
return this->_enablePriorities;
}
@@ -146,7 +146,7 @@ class Manager implements ManagerInterface
* Tells the event manager if it needs to collect all the responses returned by every
* registered listener in a single fire
*/
- public function collectResponses(boolean collect)
+ public function collectResponses(bool collect)
{
let this->_collect = collect;
}
@@ -155,7 +155,7 @@ class Manager implements ManagerInterface
* Check if the events manager is collecting all all the responses returned by every
* registered listener in a single fire
*/
- public function isCollecting() -> boolean
+ public function isCollecting() -> bool
{
return this->_collect;
}
@@ -191,7 +191,7 @@ class Manager implements ManagerInterface
public final function fireQueue(var queue, event)
{
var status, arguments, eventName, data, iterator, source, handler;
- boolean collect, cancelable;
+ bool collect, cancelable;
if typeof queue != "array" {
if typeof queue == "object" {
@@ -223,10 +223,10 @@ class Manager implements ManagerInterface
let data = event->getData();
// Tell if the event is cancelable
- let cancelable = (boolean) event->isCancelable();
+ let cancelable = (bool) event->isCancelable();
// Responses need to be traced?
- let collect = (boolean) this->_collect;
+ let collect = (bool) this->_collect;
if typeof queue == "object" {
@@ -365,7 +365,7 @@ class Manager implements ManagerInterface
* @param mixed data
* @return mixed
*/
- public function fire(string! eventType, source, data = null, boolean cancelable = true)
+ public function fire(string! eventType, source, data = null, bool cancelable = true)
{
var events, eventParts, type, eventName, event, status, fireEvents;
@@ -426,7 +426,7 @@ class Manager implements ManagerInterface
/**
* Check whether certain type of event has listeners
*/
- public function hasListeners(string! type) -> boolean
+ public function hasListeners(string! type) -> bool
{
return isset this->_events[type];
}
diff --git a/phalcon/filter.zep b/phalcon/filter.zep
index e36530a7141..f5731b2a15c 100644
--- a/phalcon/filter.zep
+++ b/phalcon/filter.zep
@@ -73,7 +73,7 @@ class Filter implements FilterInterface
/**
* Adds a user-defined filter
*/
- public function add(string! name, handler) ->
+ public function add(string! name, handler) ->
{
if typeof handler != "object" && !is_callable(handler) {
throw new Exception("Filter must be an object or callable");
@@ -86,7 +86,7 @@ class Filter implements FilterInterface
/**
* Sanitizes a value with a specified single or set of filters
*/
- public function sanitize(var value, var filters, boolean noRecursive = false) -> var
+ public function sanitize(var value, var filters, bool noRecursive = false) -> var
{
var filter, arrayValue, itemKey, itemValue, sanitizedValue;
diff --git a/phalcon/flash.zep b/phalcon/flash.zep
index 08281dc04c3..3048476ac0d 100644
--- a/phalcon/flash.zep
+++ b/phalcon/flash.zep
@@ -82,7 +82,7 @@ abstract class Flash implements FlashInterface, InjectionAwareInterface
* $flash->error("This is an error");
*
*/
- public function error(var message) -> string
+ public function error(string message) -> string
{
return this->{"message"}("error", message);
}
@@ -142,7 +142,7 @@ abstract class Flash implements FlashInterface, InjectionAwareInterface
* $flash->notice("This is an information");
*
*/
- public function notice(var message) -> string
+ public function notice(string message) -> string
{
return this->{"message"}("notice", message);
}
@@ -150,7 +150,7 @@ abstract class Flash implements FlashInterface, InjectionAwareInterface
/**
* Set the autoescape mode in generated html
*/
- public function setAutoescape(boolean autoescape) ->
+ public function setAutoescape(bool autoescape) ->
{
let this->_autoescape = autoescape;
return this;
@@ -159,7 +159,7 @@ abstract class Flash implements FlashInterface, InjectionAwareInterface
/**
* Set if the output must be implicitly formatted with HTML
*/
- public function setAutomaticHtml(boolean automaticHtml) ->
+ public function setAutomaticHtml(bool automaticHtml) ->
{
let this->_automaticHtml = automaticHtml;
return this;
@@ -204,7 +204,7 @@ abstract class Flash implements FlashInterface, InjectionAwareInterface
/**
* Set whether the output must be implicitly flushed to the output or returned as string
*/
- public function setImplicitFlush(boolean implicitFlush) ->
+ public function setImplicitFlush(bool implicitFlush) ->
{
let this->_implicitFlush = implicitFlush;
return this;
@@ -217,7 +217,7 @@ abstract class Flash implements FlashInterface, InjectionAwareInterface
* $flash->success("The process was finished successfully");
*
*/
- public function success(var message) -> string
+ public function success(string message) -> string
{
return this->{"message"}("success", message);
}
@@ -234,7 +234,7 @@ abstract class Flash implements FlashInterface, InjectionAwareInterface
*/
public function outputMessage(string type, var message)
{
- boolean implicitFlush;
+ bool implicitFlush;
var content, msg,
htmlMessage, preparedMsg;
@@ -307,7 +307,7 @@ abstract class Flash implements FlashInterface, InjectionAwareInterface
* $flash->warning("Hey, this is important");
*
*/
- public function warning(var message) -> string
+ public function warning(string message) -> string
{
return this->{"message"}("warning", message);
}
diff --git a/phalcon/flash/direct.zep b/phalcon/flash/direct.zep
index d4302f6ae62..db46de4edec 100644
--- a/phalcon/flash/direct.zep
+++ b/phalcon/flash/direct.zep
@@ -40,7 +40,7 @@ class Direct extends FlashBase
/**
* Prints the messages accumulated in the flasher
*/
- public function output(boolean remove = true) -> void
+ public function output(bool remove = true) -> void
{
var message, messages;
diff --git a/phalcon/flash/session.zep b/phalcon/flash/session.zep
index 667e5b73390..67a739dfe2c 100644
--- a/phalcon/flash/session.zep
+++ b/phalcon/flash/session.zep
@@ -34,7 +34,7 @@ class Session extends FlashBase
/**
* Returns the messages stored in session
*/
- protected function _getSessionMessages(boolean remove, type = null) -> array
+ protected function _getSessionMessages(bool remove, type = null) -> array
{
var dependencyInjector, session, messages, returnMessages;
@@ -99,7 +99,7 @@ class Session extends FlashBase
/**
* Checks whether there are messages
*/
- public function has(type = null) -> boolean
+ public function has(type = null) -> bool
{
var messages;
@@ -116,7 +116,7 @@ class Session extends FlashBase
/**
* Returns the messages in the session flasher
*/
- public function getMessages(type = null, boolean remove = true) -> array
+ public function getMessages(type = null, bool remove = true) -> array
{
return this->_getSessionMessages(remove, type);
}
@@ -124,7 +124,7 @@ class Session extends FlashBase
/**
* Prints the messages in the session flasher
*/
- public function output(boolean remove = true) -> void
+ public function output(bool remove = true) -> void
{
var type, message, messages;
diff --git a/phalcon/flashinterface.zep b/phalcon/flashinterface.zep
index 20ce5b474c8..e9903583587 100644
--- a/phalcon/flashinterface.zep
+++ b/phalcon/flashinterface.zep
@@ -30,25 +30,25 @@ interface FlashInterface
/**
* Shows a HTML error message
*/
- public function error(message);
+ public function error(string message);
/**
* Outputs a message
*/
- public function message(string type, var message);
+ public function message(string type, string message);
/**
* Shows a HTML notice/information message
*/
- public function notice(message);
+ public function notice(string message);
/**
* Shows a HTML success message
*/
- public function success(message);
+ public function success(string message);
/**
* Shows a HTML warning message
*/
- public function warning(message);
+ public function warning(string message);
}
diff --git a/phalcon/forms/element.zep b/phalcon/forms/element.zep
index f639ad362fc..a40e503ca42 100644
--- a/phalcon/forms/element.zep
+++ b/phalcon/forms/element.zep
@@ -149,7 +149,7 @@ abstract class Element implements ElementInterface
*
* @param \Phalcon\Validation\ValidatorInterface[] validators
*/
- public function addValidators(array! validators, boolean merge = true) ->
+ public function addValidators(array! validators, bool merge = true) ->
{
var currentValidators, mergedValidators;
if merge {
@@ -186,7 +186,7 @@ abstract class Element implements ElementInterface
* Returns an array of prepared attributes for Phalcon\Tag helpers
* according to the element parameters
*/
- public function prepareAttributes(array attributes = null, boolean useChecked = false) -> array
+ public function prepareAttributes(array attributes = null, bool useChecked = false) -> array
{
var value, name, widgetAttributes, mergedAttributes,
defaultAttributes, currentValue;
@@ -451,7 +451,7 @@ abstract class Element implements ElementInterface
/**
* Checks whether there are messages attached to the element
*/
- public function hasMessages() -> boolean
+ public function hasMessages() -> bool
{
return count(this->_messages) > 0;
}
@@ -477,7 +477,7 @@ abstract class Element implements ElementInterface
/**
* Clears element to its default value
*/
- public function clear() ->
+ public function clear() ->
{
var form = this->_form,
name = this->_name,
diff --git a/phalcon/forms/elementinterface.zep b/phalcon/forms/elementinterface.zep
index 79331b21fea..519ecaf2a3f 100644
--- a/phalcon/forms/elementinterface.zep
+++ b/phalcon/forms/elementinterface.zep
@@ -76,7 +76,7 @@ interface ElementInterface
*
* @param \Phalcon\Validation\ValidatorInterface[]
*/
- public function addValidators(array! validators, boolean merge = true) -> ;
+ public function addValidators(array! validators, bool merge = true) -> ;
/**
* Adds a validator to the element
@@ -92,7 +92,7 @@ interface ElementInterface
* Returns an array of prepared attributes for Phalcon\Tag helpers
* according to the element's parameters
*/
- public function prepareAttributes(array attributes = null, boolean useChecked = false) -> array;
+ public function prepareAttributes(array attributes = null, bool useChecked = false) -> array;
/**
* Sets a default attribute for the element
@@ -174,7 +174,7 @@ interface ElementInterface
/**
* Checks whether there are messages attached to the element
*/
- public function hasMessages() -> boolean;
+ public function hasMessages() -> bool;
/**
* Sets the validation messages related to the element
diff --git a/phalcon/forms/form.zep b/phalcon/forms/form.zep
index 76f51fdd533..b8a5f61614a 100644
--- a/phalcon/forms/form.zep
+++ b/phalcon/forms/form.zep
@@ -245,7 +245,7 @@ class Form extends Injectable implements \Countable, \Iterator
* @param array data
* @param object entity
*/
- public function isValid(var data = null, var entity = null) -> boolean
+ public function isValid(var data = null, var entity = null) -> bool
{
var validationStatus, messages, element,
validators, name, filters,
@@ -379,7 +379,7 @@ class Form extends Injectable implements \Countable, \Iterator
* }
*
*/
- public function getMessages(boolean byItemName = false) -> | array
+ public function getMessages(bool byItemName = false) -> | array
{
var messages, messagesByItem, elementMessage, fieldName;
@@ -426,7 +426,7 @@ class Form extends Injectable implements \Countable, \Iterator
/**
* Check if messages were generated for a specific element
*/
- public function hasMessagesFor(string! name) -> boolean
+ public function hasMessagesFor(string! name) -> bool
{
return this->getMessagesFor(name)->count() > 0;
}
@@ -434,7 +434,7 @@ class Form extends Injectable implements \Countable, \Iterator
/**
* Adds an element to the form
*/
- public function add( element, string position = null, boolean type = null) ->