From 9868e945f06e916af203942fb8d0017fbbc5fa64 Mon Sep 17 00:00:00 2001 From: Serghei Iakovlev Date: Sat, 12 Sep 2015 00:35:20 +0300 Subject: [PATCH 01/50] Fixed misspelling in doc --- phalcon/db/dialect/mysql.zep | 2 +- phalcon/db/dialect/postgresql.zep | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/phalcon/db/dialect/mysql.zep b/phalcon/db/dialect/mysql.zep index 81aee9d3913..d4d36e5b5f9 100644 --- a/phalcon/db/dialect/mysql.zep +++ b/phalcon/db/dialect/mysql.zep @@ -385,7 +385,7 @@ class MySQL extends Dialect } /** - * Create a temporary o normal table + * Create a temporary or normal table */ if temporary { let sql = "CREATE TEMPORARY TABLE " . table . " (\n\t"; diff --git a/phalcon/db/dialect/postgresql.zep b/phalcon/db/dialect/postgresql.zep index 2bea71ed137..688471e5e1f 100644 --- a/phalcon/db/dialect/postgresql.zep +++ b/phalcon/db/dialect/postgresql.zep @@ -358,7 +358,7 @@ class Postgresql extends Dialect } /** - * Create a temporary o normal table + * Create a temporary or normal table */ if temporary { let sql = "CREATE TEMPORARY TABLE " . table . " (\n\t"; From 3fa3a6c0887c1ce4dad06679a2707606f29f3df2 Mon Sep 17 00:00:00 2001 From: Serghei Iakovlev Date: Sun, 13 Sep 2015 22:15:03 +0300 Subject: [PATCH 02/50] Update CHANGELOG.md [ci skip] --- CHANGELOG.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7f6a63ca19e..21578b38271 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,7 @@ column definition - Fixed determining of default value for column in `Phalcon\Db\Dialect\MySQL`, `Phalcon\Db\Dialect\Sqlite` and `Phalcon\Db\Dialect\Postgresql` classes -- Now Phalcon\Mvc\Model::__call invokes finders as in __callStatic +- Now `Phalcon\Mvc\Model::__call` invokes finders as in `__callStatic` - Fixed `Phalcon\Db\Dialect\Postgresql::getColumnDefinition` for `BIGINT` and `BOOLEAN` data types - Fixed `BOOLEAN` default value in `Phalcon\Db\Dialect\Postgresql` @@ -73,20 +73,20 @@ belongs to the uniqueId or the whole session data - Fixed generation and validation of default parameters in Volt's macros - Added `Phalcon\Assets\Manager::getCollections()` to return all collections registered [#2488](https://github.com/phalcon/cphalcon/pull/2488) - Now `Phalcon\Mvc\Url::getStatic()` generates URLs from routes -- Introduced `Phalcon\Mvc\EntityInterface` to allow parameters receive both Phalcon\Mvc\Model and `Phalcon\Mvc\Collection` instances +- Introduced `Phalcon\Mvc\EntityInterface` to allow parameters receive both `Phalcon\Mvc\Model` and `Phalcon\Mvc\Collection` instances - Added `Phalcon\Session\Adapter::setName()` to change the session name -- Added BIGINT support in Phalcon\Db +- Added BIGINT support in `Phalcon\Db` - Added new types `Phalcon\Db\Column::BLOB` and `Phalcon\Db\Column::DOUBLE` [#10506](https://github.com/phalcon/cphalcon/pull/10506) - Automatic binding of Large Object data (LOB) in the ORM - Support for BIT types in MySQL with binding as booleans - Added `Phalcon\Flash\Direct::output()` allowing to place flash messages in a specific place of the view [#629](https://github.com/phalcon/cphalcon/pull/629) - Added 'autoescape' option that allows to globally enable autoescape in any Volt template -- Added readAttribute/writeAttribute to `Phalcon\Mvc\Collection\Document` +- Added `readAttribute`/`writeAttribute` to `Phalcon\Mvc\Collection\Document` - Added toArray to `Phalcon\Mvc\Collection\Document` - Global setting `db.force_casting` now forces casting bound parameters to specified bind types - Introduced new placeholders in PHQL enclosed in brackets that allow to set the type: {name:str} or {names:array} - Now you can bind arrays in bound parameters in PHQL -- Global setting orm.cast_on_hydrate allow to cast hydrated attributes to the original types in the mapped tables instead of using strings +- Global setting `orm.cast_on_hydrate` allow to cast hydrated attributes to the original types in the mapped tables instead of using strings - Values in LIMIT/OFFSET clause are now passed using bound parameters in PHQL - Allowing late state binding in both Simple/Complex results to allow override `Mvc\Model::cloneResultMap` - Added method `distinct()` in `Phalcon\Mvc\Model\Criteria` [#10536](https://github.com/phalcon/cphalcon/issues/10536) From 8572ea112706bbede9b44318a72d88b6437141a7 Mon Sep 17 00:00:00 2001 From: Serghei Iakovlev Date: Mon, 21 Sep 2015 01:40:15 +0300 Subject: [PATCH 03/50] Added mixed return type Phalcon\Config::get --- phalcon/config.zep | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phalcon/config.zep b/phalcon/config.zep index 58450bdfdaa..db01cfd93f4 100644 --- a/phalcon/config.zep +++ b/phalcon/config.zep @@ -83,7 +83,7 @@ class Config implements \ArrayAccess, \Countable * echo $config->get('controllersDir', '../app/controllers/'); * */ - public function get(var index, var defaultValue = null) + public function get(var index, var defaultValue = null) -> var { let index = strval(index); From 2c289b426a64f15eec9cbf43d3666a588c259309 Mon Sep 17 00:00:00 2001 From: Serghei Iakovlev Date: Tue, 22 Sep 2015 14:29:46 +0300 Subject: [PATCH 04/50] Added mixed return types to Request --- phalcon/http/request.zep | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/phalcon/http/request.zep b/phalcon/http/request.zep index e95af301359..03334106e71 100755 --- a/phalcon/http/request.zep +++ b/phalcon/http/request.zep @@ -82,7 +82,7 @@ class Request implements RequestInterface, InjectionAwareInterface * $userEmail = $request->get("user_email", "email"); * */ - public function get(string! name = null, var filters = null, var defaultValue = null, boolean notAllowEmpty = false, boolean noRecursive = false) + public function get(string! name = null, var filters = null, var defaultValue = null, boolean notAllowEmpty = false, boolean noRecursive = false) -> var { return this->getHelper(_REQUEST, name, filters, defaultValue, notAllowEmpty, noRecursive); } @@ -99,7 +99,7 @@ class Request implements RequestInterface, InjectionAwareInterface * $userEmail = $request->getPost("user_email", "email"); * */ - public function getPost(string! name = null, var filters = null, var defaultValue = null, boolean notAllowEmpty = false, boolean noRecursive = false) + public function getPost(string! name = null, var filters = null, var defaultValue = null, boolean notAllowEmpty = false, boolean noRecursive = false) -> var { return this->getHelper(_POST, name, filters, defaultValue, notAllowEmpty, noRecursive); } @@ -115,7 +115,7 @@ class Request implements RequestInterface, InjectionAwareInterface * $userEmail = $request->getPut("user_email", "email"); * */ - public function getPut(string! name = null, var filters = null, var defaultValue = null, boolean notAllowEmpty = false, boolean noRecursive = false) + public function getPut(string! name = null, var filters = null, var defaultValue = null, boolean notAllowEmpty = false, boolean noRecursive = false) -> var { var put; @@ -146,7 +146,7 @@ class Request implements RequestInterface, InjectionAwareInterface * $id = $request->getQuery("id", null, 150); * */ - public function getQuery(string! name = null, var filters = null, var defaultValue = null, boolean notAllowEmpty = false, boolean noRecursive = false) + public function getQuery(string! name = null, var filters = null, var defaultValue = null, boolean notAllowEmpty = false, boolean noRecursive = false) -> var { return this->getHelper(_GET, name, filters, defaultValue, notAllowEmpty, noRecursive); } @@ -155,7 +155,7 @@ class Request implements RequestInterface, InjectionAwareInterface * Helper to get data from superglobals, applying filters if needed. * If no parameters are given the superglobal is returned. */ - protected final function getHelper(array source, string! name = null, var filters = null, var defaultValue = null, boolean notAllowEmpty = false, boolean noRecursive = false) + protected final function getHelper(array source, string! name = null, var filters = null, var defaultValue = null, boolean notAllowEmpty = false, boolean noRecursive = false) -> var { var value, filter, dependencyInjector; @@ -191,7 +191,7 @@ class Request implements RequestInterface, InjectionAwareInterface /** * Gets variable from $_SERVER superglobal */ - public function getServer(string! name) + public function getServer(string! name) -> string | null { var serverValue; From a49da4114c705f18a9a383bc7a22dcc475d35329 Mon Sep 17 00:00:00 2001 From: snowair Date: Thu, 24 Sep 2015 11:41:09 +0800 Subject: [PATCH 05/50] Fix: cookie is allways resent after get. --- phalcon/http/response/cookies.zep | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/phalcon/http/response/cookies.zep b/phalcon/http/response/cookies.zep index 8c24e7e5dd9..07827d8e7bb 100644 --- a/phalcon/http/response/cookies.zep +++ b/phalcon/http/response/cookies.zep @@ -148,12 +148,16 @@ class Cookies implements CookiesInterface, InjectionAwareInterface { var dependencyInjector, encryption, cookie; + /** + * Gets cookie from the cookies service. They will be sent with response. + */ if fetch cookie, this->_cookies[name] { return cookie; } /** - * Create the cookie if the it does not exist + * Create the cookie if the it does not exist. + * It's value come from $_COOKIE with request, so it shouldn't be saved to _cookies property, otherwise it will allways be resent after get. */ let cookie = this->_dependencyInjector->get("Phalcon\\Http\\Cookie", [name]), dependencyInjector = this->_dependencyInjector; @@ -175,7 +179,6 @@ class Cookies implements CookiesInterface, InjectionAwareInterface } } - let this->_cookies[name] = cookie; return cookie; } From ec3ef0ec771c612285678529496e26a9b19de45d Mon Sep 17 00:00:00 2001 From: snowair Date: Thu, 24 Sep 2015 13:59:00 +0800 Subject: [PATCH 06/50] fix the indentation --- phalcon/http/response/cookies.zep | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/phalcon/http/response/cookies.zep b/phalcon/http/response/cookies.zep index 07827d8e7bb..4dbc5ad0049 100644 --- a/phalcon/http/response/cookies.zep +++ b/phalcon/http/response/cookies.zep @@ -148,17 +148,17 @@ class Cookies implements CookiesInterface, InjectionAwareInterface { var dependencyInjector, encryption, cookie; - /** - * Gets cookie from the cookies service. They will be sent with response. - */ + /** + * Gets cookie from the cookies service. They will be sent with response. + */ if fetch cookie, this->_cookies[name] { return cookie; } /** - * Create the cookie if the it does not exist. - * It's value come from $_COOKIE with request, so it shouldn't be saved to _cookies property, otherwise it will allways be resent after get. - */ + * Create the cookie if the it does not exist. + * It's value come from $_COOKIE with request, so it shouldn't be saved to _cookies property, otherwise it will allways be resent after get. + */ let cookie = this->_dependencyInjector->get("Phalcon\\Http\\Cookie", [name]), dependencyInjector = this->_dependencyInjector; From eb7c5d06ffe58a9167f4d3fe89f9793997c7e0fa Mon Sep 17 00:00:00 2001 From: Serghei Iakovlev Date: Mon, 28 Sep 2015 00:13:53 +0300 Subject: [PATCH 07/50] Update di.zep --- phalcon/di.zep | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/phalcon/di.zep b/phalcon/di.zep index e6634057097..d9cd8d0ef92 100755 --- a/phalcon/di.zep +++ b/phalcon/di.zep @@ -178,7 +178,7 @@ class Di implements DiInterface /** * Returns a service definition without resolving */ - public function getRaw(string! name) + public function getRaw(string! name) -> var { var service; @@ -205,9 +205,8 @@ class Di implements DiInterface /** * Resolves the service based on its configuration - * @returm mixed */ - public function get(string! name, parameters = null) + public function get(string! name, parameters = null) -> var { var service, instance, reflection, eventsManager; @@ -368,11 +367,8 @@ class Di implements DiInterface * * var_dump($di["request"]); * - * - * @param string name - * @return mixed */ - public function offsetGet(string! name) -> boolean + public function offsetGet(string! name) -> var { return this->getShared(name); } @@ -390,9 +386,8 @@ class Di implements DiInterface * * @param string method * @param array arguments - * @return mixed */ - public function __call(string! method, arguments = null) + public function __call(string! method, arguments = null) -> var { var instance, possibleService, services, definition; From 4d6f1e1547e57870c026fd82b377f5d53b9e1c32 Mon Sep 17 00:00:00 2001 From: Serghei Iakovlev Date: Tue, 29 Sep 2015 16:48:39 +0300 Subject: [PATCH 08/50] Update di.zep --- phalcon/di.zep | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phalcon/di.zep b/phalcon/di.zep index d9cd8d0ef92..1506f575e98 100755 --- a/phalcon/di.zep +++ b/phalcon/di.zep @@ -387,7 +387,7 @@ class Di implements DiInterface * @param string method * @param array arguments */ - public function __call(string! method, arguments = null) -> var + public function __call(string! method, arguments = null) -> var|null { var instance, possibleService, services, definition; From 17493b8078f657fc11eaf031153181429ef074f2 Mon Sep 17 00:00:00 2001 From: dreamsxin Date: Wed, 30 Sep 2015 09:07:52 +0800 Subject: [PATCH 09/50] Fix #10829 --- phalcon/session/adapter/redis.zep | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phalcon/session/adapter/redis.zep b/phalcon/session/adapter/redis.zep index 251fa096eb8..d3c1a64ea69 100644 --- a/phalcon/session/adapter/redis.zep +++ b/phalcon/session/adapter/redis.zep @@ -22,7 +22,7 @@ namespace Phalcon\Session\Adapter; use Phalcon\Session\Adapter; use Phalcon\Session\AdapterInterface; use Phalcon\Cache\Backend\Redis; -use Phalcon\Cache\Frontend\Data as FrontendData; +use Phalcon\Cache\Frontend\None as FrontendNone; /** * Phalcon\Session\Adapter\Redis @@ -78,7 +78,7 @@ class Redis extends Adapter implements AdapterInterface } let this->_redis = new Redis( - new FrontendData(["lifetime": this->_lifetime]), + new FrontendNone(["lifetime": this->_lifetime]), options ); From c1cadf36936ca7dc5269e23d173a1ec26f84f3c0 Mon Sep 17 00:00:00 2001 From: Serghei Iakovlev Date: Wed, 30 Sep 2015 21:29:33 +0300 Subject: [PATCH 10/50] Fixed logger doc --- phalcon/logger.zep | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phalcon/logger.zep b/phalcon/logger.zep index 487ef00071b..08abcb54f62 100644 --- a/phalcon/logger.zep +++ b/phalcon/logger.zep @@ -29,7 +29,7 @@ namespace Phalcon; * * $logger = new \Phalcon\Logger\Adapter\File("app/logs/test.log"); * $logger->log("This is a message"); - * $logger->log("This is an error", Phalcon\Logger::ERROR); + * $logger->log(\Phalcon\Logger::ERROR, "This is an error"); * $logger->error("This is another error"); * */ From 5460d71851d68b75c148f537e91abfebba8fe013 Mon Sep 17 00:00:00 2001 From: Serghei Iakovlev Date: Wed, 30 Sep 2015 21:53:31 +0300 Subject: [PATCH 11/50] Update file.zep --- phalcon/logger/adapter/file.zep | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phalcon/logger/adapter/file.zep b/phalcon/logger/adapter/file.zep index 81301f4f4f3..5a50212381b 100644 --- a/phalcon/logger/adapter/file.zep +++ b/phalcon/logger/adapter/file.zep @@ -33,7 +33,7 @@ use Phalcon\Logger\Formatter\Line as LineFormatter; * * $logger = new \Phalcon\Logger\Adapter\File("app/logs/test.log"); * $logger->log("This is a message"); - * $logger->log("This is an error", \Phalcon\Logger::ERROR); + * $logger->log(\Phalcon\Logger::ERROR, "This is an error"); * $logger->error("This is another error"); * $logger->close(); * From 5336ab7c1650450d4b5f5c9eab0bbadd5471e2ee Mon Sep 17 00:00:00 2001 From: Serghei Iakovlev Date: Wed, 30 Sep 2015 21:54:08 +0300 Subject: [PATCH 12/50] Update stream.zep --- phalcon/logger/adapter/stream.zep | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phalcon/logger/adapter/stream.zep b/phalcon/logger/adapter/stream.zep index a8ea153de33..c18b5c259aa 100644 --- a/phalcon/logger/adapter/stream.zep +++ b/phalcon/logger/adapter/stream.zep @@ -33,7 +33,7 @@ use Phalcon\Logger\Formatter\Line as LineFormatter; * * $logger = new \Phalcon\Logger\Adapter\Stream("php://stderr"); * $logger->log("This is a message"); - * $logger->log("This is an error", \Phalcon\Logger::ERROR); + * $logger->log(\Phalcon\Logger::ERROR, "This is an error"); * $logger->error("This is another error"); * */ From 9090a03e0721e597bbc4dff8e9df1baff7a9508a Mon Sep 17 00:00:00 2001 From: Serghei Iakovlev Date: Wed, 30 Sep 2015 21:55:06 +0300 Subject: [PATCH 13/50] Update syslog.zep --- phalcon/logger/adapter/syslog.zep | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phalcon/logger/adapter/syslog.zep b/phalcon/logger/adapter/syslog.zep index 507e9ca5ee8..b7f1a46263e 100644 --- a/phalcon/logger/adapter/syslog.zep +++ b/phalcon/logger/adapter/syslog.zep @@ -35,7 +35,7 @@ use Phalcon\Logger\Formatter\Syslog as SyslogFormatter; * 'facility' => LOG_MAIL * )); * $logger->log("This is a message"); - * $logger->log("This is an error", \Phalcon\Logger::ERROR); + * $logger->log(\Phalcon\Logger::ERROR, "This is an error"); * $logger->error("This is another error"); * */ From 54415843e17e1157bc3417784cc3f51b3895c107 Mon Sep 17 00:00:00 2001 From: Andres Gutierrez Date: Thu, 1 Oct 2015 10:14:13 -0500 Subject: [PATCH 14/50] Updating version to 2.0.9, using latest Zephir --- CHANGELOG.md | 3 +++ build/64bits/phalcon.zep.c | 2 +- config.json | 2 +- ext/phalcon/acl/adapter.zep.c | 3 --- ext/phalcon/db/profiler/item.zep.h | 4 ++-- ext/phalcon/db/rawvalue.zep.c | 4 ---- ext/phalcon/di.zep.c | 9 ++------- ext/phalcon/http/response/cookies.zep.c | 3 +-- ext/phalcon/logger/item.zep.c | 6 ------ ext/phalcon/session/adapter/redis.zep.c | 18 ++++++++++-------- ext/phalcon/version.zep.c | 2 +- ext/php_phalcon.h | 2 +- phalcon/version.zep | 2 +- 13 files changed, 23 insertions(+), 37 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3375bdc888f..c5b5ea1c97d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +# [2.0.9](https://github.com/phalcon/cphalcon/releases/tag/phalcon-v2.0.8) (2015-10-17 +- Fixed bug that double serializes data using Redis adapter + # [2.0.8](https://github.com/phalcon/cphalcon/releases/tag/phalcon-v2.0.8) (2015-09-19) - Added `Phalcon\Security\Random::base58` - to generate a random base58 string - Added `Phalcon\Logger\Adapter::isTransaction()` to check whether the logger is currently in transaction diff --git a/build/64bits/phalcon.zep.c b/build/64bits/phalcon.zep.c index 148cef29977..8ab8a3604ab 100644 --- a/build/64bits/phalcon.zep.c +++ b/build/64bits/phalcon.zep.c @@ -11199,7 +11199,7 @@ static const unsigned char tolower_map[256] = { static int zephir_has_constructor_ce(const zend_class_entry *ce) { - while (ce) { + while (ce != NULL) { if (ce->constructor) { return 1; } diff --git a/config.json b/config.json index 8c37b43620d..8204191db54 100644 --- a/config.json +++ b/config.json @@ -10,7 +10,7 @@ "name": "phalcon", "description": "Web framework delivered as a C-extension for PHP", "author": "Phalcon Team and contributors", - "version": "2.0.8", + "version": "2.0.9", "verbose": true, "optimizer-dirs": [ "optimizers" diff --git a/ext/phalcon/acl/adapter.zep.c b/ext/phalcon/acl/adapter.zep.c index 8ba37a8b253..fcf885ac71a 100644 --- a/ext/phalcon/acl/adapter.zep.c +++ b/ext/phalcon/acl/adapter.zep.c @@ -70,7 +70,6 @@ ZEPHIR_INIT_CLASS(Phalcon_Acl_Adapter) { /** * Role which the list is checking if it's allowed to certain resource/access - * @var mixed */ PHP_METHOD(Phalcon_Acl_Adapter, getActiveRole) { @@ -81,7 +80,6 @@ PHP_METHOD(Phalcon_Acl_Adapter, getActiveRole) { /** * Resource which the list is checking if some role can access it - * @var mixed */ PHP_METHOD(Phalcon_Acl_Adapter, getActiveResource) { @@ -92,7 +90,6 @@ PHP_METHOD(Phalcon_Acl_Adapter, getActiveResource) { /** * Active access which the list is checking if some role can access it - * @var mixed */ PHP_METHOD(Phalcon_Acl_Adapter, getActiveAccess) { diff --git a/ext/phalcon/db/profiler/item.zep.h b/ext/phalcon/db/profiler/item.zep.h index dccba4e6d5b..8e21ab80b61 100644 --- a/ext/phalcon/db/profiler/item.zep.h +++ b/ext/phalcon/db/profiler/item.zep.h @@ -20,11 +20,11 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_db_profiler_item_setsqlstatement, 0, 0, 1 ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_db_profiler_item_setsqlvariables, 0, 0, 1) - ZEND_ARG_INFO(0, sqlVariables) + ZEND_ARG_ARRAY_INFO(0, sqlVariables, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_db_profiler_item_setsqlbindtypes, 0, 0, 1) - ZEND_ARG_INFO(0, sqlBindTypes) + ZEND_ARG_ARRAY_INFO(0, sqlBindTypes, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_db_profiler_item_setinitialtime, 0, 0, 1) diff --git a/ext/phalcon/db/rawvalue.zep.c b/ext/phalcon/db/rawvalue.zep.c index 2e769732a97..3225b55035c 100644 --- a/ext/phalcon/db/rawvalue.zep.c +++ b/ext/phalcon/db/rawvalue.zep.c @@ -48,8 +48,6 @@ ZEPHIR_INIT_CLASS(Phalcon_Db_RawValue) { /** * Raw value without quoting or formating - * - * @var string */ PHP_METHOD(Phalcon_Db_RawValue, getValue) { @@ -60,8 +58,6 @@ PHP_METHOD(Phalcon_Db_RawValue, getValue) { /** * Raw value without quoting or formating - * - * @var string */ PHP_METHOD(Phalcon_Db_RawValue, __toString) { diff --git a/ext/phalcon/di.zep.c b/ext/phalcon/di.zep.c index a0f37a908dd..cdf979bc534 100644 --- a/ext/phalcon/di.zep.c +++ b/ext/phalcon/di.zep.c @@ -411,7 +411,6 @@ PHP_METHOD(Phalcon_Di, getService) { /** * Resolves the service based on its configuration - * @returm mixed */ PHP_METHOD(Phalcon_Di, get) { @@ -464,7 +463,7 @@ PHP_METHOD(Phalcon_Di, get) { ZEPHIR_CONCAT_SVS(_3, "Service '", name, "' wasn't found in the dependency injection container"); ZEPHIR_CALL_METHOD(NULL, _2, "__construct", NULL, 9, _3); zephir_check_call_status(); - zephir_throw_exception_debug(_2, "phalcon/di.zep", 230 TSRMLS_CC); + zephir_throw_exception_debug(_2, "phalcon/di.zep", 229 TSRMLS_CC); ZEPHIR_MM_RESTORE(); return; } @@ -708,9 +707,6 @@ PHP_METHOD(Phalcon_Di, offsetSet) { * * var_dump($di["request"]); * - * - * @param string name - * @return mixed */ PHP_METHOD(Phalcon_Di, offsetGet) { @@ -771,7 +767,6 @@ PHP_METHOD(Phalcon_Di, offsetUnset) { * * @param string method * @param array arguments - * @return mixed */ PHP_METHOD(Phalcon_Di, __call) { @@ -838,7 +833,7 @@ PHP_METHOD(Phalcon_Di, __call) { ZEPHIR_CONCAT_SVS(_5, "Call to undefined method or service '", method, "'"); ZEPHIR_CALL_METHOD(NULL, _1, "__construct", NULL, 9, _5); zephir_check_call_status(); - zephir_throw_exception_debug(_1, "phalcon/di.zep", 428 TSRMLS_CC); + zephir_throw_exception_debug(_1, "phalcon/di.zep", 423 TSRMLS_CC); ZEPHIR_MM_RESTORE(); return; diff --git a/ext/phalcon/http/response/cookies.zep.c b/ext/phalcon/http/response/cookies.zep.c index 952aa60c0bc..db84bd36021 100644 --- a/ext/phalcon/http/response/cookies.zep.c +++ b/ext/phalcon/http/response/cookies.zep.c @@ -304,7 +304,6 @@ PHP_METHOD(Phalcon_Http_Response_Cookies, get) { zephir_check_call_status(); } } - zephir_update_property_array(this_ptr, SL("_cookies"), name, cookie TSRMLS_CC); RETURN_CCTOR(cookie); } @@ -397,7 +396,7 @@ PHP_METHOD(Phalcon_Http_Response_Cookies, send) { zephir_check_call_status(); if (!(zephir_is_true(_0))) { _1 = zephir_fetch_nproperty_this(this_ptr, SL("_cookies"), PH_NOISY_CC); - zephir_is_iterable(_1, &_3, &_2, 0, 0, "phalcon/http/response/cookies.zep", 236); + zephir_is_iterable(_1, &_3, &_2, 0, 0, "phalcon/http/response/cookies.zep", 239); for ( ; zephir_hash_get_current_data_ex(_3, (void**) &_4, &_2) == SUCCESS ; zephir_hash_move_forward_ex(_3, &_2) diff --git a/ext/phalcon/logger/item.zep.c b/ext/phalcon/logger/item.zep.c index 59238352c41..df992b18e7f 100644 --- a/ext/phalcon/logger/item.zep.c +++ b/ext/phalcon/logger/item.zep.c @@ -56,8 +56,6 @@ ZEPHIR_INIT_CLASS(Phalcon_Logger_Item) { /** * Log type - * - * @var integer */ PHP_METHOD(Phalcon_Logger_Item, getType) { @@ -68,8 +66,6 @@ PHP_METHOD(Phalcon_Logger_Item, getType) { /** * Log message - * - * @var string */ PHP_METHOD(Phalcon_Logger_Item, getMessage) { @@ -80,8 +76,6 @@ PHP_METHOD(Phalcon_Logger_Item, getMessage) { /** * Log timestamp - * - * @var integer */ PHP_METHOD(Phalcon_Logger_Item, getTime) { diff --git a/ext/phalcon/session/adapter/redis.zep.c b/ext/phalcon/session/adapter/redis.zep.c index 848b155427b..86ba88c79cd 100644 --- a/ext/phalcon/session/adapter/redis.zep.c +++ b/ext/phalcon/session/adapter/redis.zep.c @@ -110,14 +110,16 @@ PHP_METHOD(Phalcon_Session_Adapter_Redis, __construct) { ZEPHIR_INIT_NVAR(_0); object_init_ex(_0, phalcon_cache_backend_redis_ce); ZEPHIR_INIT_VAR(_1); - object_init_ex(_1, phalcon_cache_frontend_data_ce); - ZEPHIR_INIT_VAR(_2); - zephir_create_array(_2, 1, 0 TSRMLS_CC); - ZEPHIR_OBS_VAR(_3); - zephir_read_property_this(&_3, this_ptr, SL("_lifetime"), PH_NOISY_CC); - zephir_array_update_string(&_2, SL("lifetime"), &_3, PH_COPY | PH_SEPARATE); - ZEPHIR_CALL_METHOD(NULL, _1, "__construct", NULL, 312, _2); - zephir_check_call_status(); + object_init_ex(_1, phalcon_cache_frontend_none_ce); + if (zephir_has_constructor(_1 TSRMLS_CC)) { + ZEPHIR_INIT_VAR(_2); + zephir_create_array(_2, 1, 0 TSRMLS_CC); + ZEPHIR_OBS_VAR(_3); + zephir_read_property_this(&_3, this_ptr, SL("_lifetime"), PH_NOISY_CC); + zephir_array_update_string(&_2, SL("lifetime"), &_3, PH_COPY | PH_SEPARATE); + ZEPHIR_CALL_METHOD(NULL, _1, "__construct", NULL, 0, _2); + zephir_check_call_status(); + } ZEPHIR_CALL_METHOD(NULL, _0, "__construct", NULL, 316, _1, options); zephir_check_call_status(); zephir_update_property_this(this_ptr, SL("_redis"), _0 TSRMLS_CC); diff --git a/ext/phalcon/version.zep.c b/ext/phalcon/version.zep.c index 220f54ab4c5..2d5923f0027 100644 --- a/ext/phalcon/version.zep.c +++ b/ext/phalcon/version.zep.c @@ -97,7 +97,7 @@ PHP_METHOD(Phalcon_Version, _getVersion) { ZVAL_LONG(_0, 0); zephir_array_fast_append(return_value, _0); ZEPHIR_INIT_NVAR(_0); - ZVAL_LONG(_0, 8); + ZVAL_LONG(_0, 9); zephir_array_fast_append(return_value, _0); ZEPHIR_INIT_NVAR(_0); ZVAL_LONG(_0, 4); diff --git a/ext/php_phalcon.h b/ext/php_phalcon.h index 43bb13d7e64..92b3dbede83 100644 --- a/ext/php_phalcon.h +++ b/ext/php_phalcon.h @@ -11,7 +11,7 @@ #include "kernel/globals.h" #define PHP_PHALCON_NAME "phalcon" -#define PHP_PHALCON_VERSION "2.0.8" +#define PHP_PHALCON_VERSION "2.0.9" #define PHP_PHALCON_EXTNAME "phalcon" #define PHP_PHALCON_AUTHOR "Phalcon Team and contributors" #define PHP_PHALCON_ZEPVERSION "0.8.0a" diff --git a/phalcon/version.zep b/phalcon/version.zep index f422a9e94c1..80fa5a71945 100644 --- a/phalcon/version.zep +++ b/phalcon/version.zep @@ -80,7 +80,7 @@ class Version */ protected static function _getVersion() -> array { - return [2, 0, 8, 4, 0]; + return [2, 0, 9, 4, 0]; } /** From f27c7f1a4fc62d2251f5eb9e83a2fa2fec05ec11 Mon Sep 17 00:00:00 2001 From: Serghei Iakovlev Date: Wed, 30 Sep 2015 11:36:41 +0300 Subject: [PATCH 15/50] Added console:boot event In order to allow the developer to perform initialization actions --- CHANGELOG.md | 3 ++- phalcon/cli/console.zep | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c5b5ea1c97d..66b5070364d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ -# [2.0.9](https://github.com/phalcon/cphalcon/releases/tag/phalcon-v2.0.8) (2015-10-17 +# [2.0.9](https://github.com/phalcon/cphalcon/releases/tag/phalcon-v2.0.9) (2015-??-??) - Fixed bug that double serializes data using Redis adapter +- Added `console:boot` event to allow the developer to perform initialization actions # [2.0.8](https://github.com/phalcon/cphalcon/releases/tag/phalcon-v2.0.8) (2015-09-19) - Added `Phalcon\Security\Random::base58` - to generate a random base58 string diff --git a/phalcon/cli/console.zep b/phalcon/cli/console.zep index 89abe49b787..bbfbc2e8da0 100644 --- a/phalcon/cli/console.zep +++ b/phalcon/cli/console.zep @@ -154,6 +154,15 @@ class Console implements InjectionAwareInterface, EventsAwareInterface let eventsManager = this->_eventsManager; + /** + * Call boot event, this allow the developer to perform initialization actions + */ + if typeof eventsManager == "object" { + if eventsManager->fire("console:boot", this) === false { + return false; + } + } + let router = dependencyInjector->getShared("router"); if !count(arguments) && this->_arguments { From 425abc4d9111a1e1f907bfad280c2f98665418a4 Mon Sep 17 00:00:00 2001 From: Green Cat Date: Tue, 6 Oct 2015 10:09:14 +0100 Subject: [PATCH 16/50] Removes duplicate use statement in router --- phalcon/mvc/router.zep | 1 - 1 file changed, 1 deletion(-) diff --git a/phalcon/mvc/router.zep b/phalcon/mvc/router.zep index b2af3d23209..4379504db38 100755 --- a/phalcon/mvc/router.zep +++ b/phalcon/mvc/router.zep @@ -23,7 +23,6 @@ use Phalcon\DiInterface; use Phalcon\Mvc\Router\Route; use Phalcon\Mvc\Router\Exception; use Phalcon\Http\RequestInterface; -use Phalcon\Events\ManagerInterface; use Phalcon\Mvc\Router\GroupInterface; use Phalcon\Mvc\Router\RouteInterface; use Phalcon\Di\InjectionAwareInterface; From 60cbfa44140c135d31f67d5cdddb0376fa3726be Mon Sep 17 00:00:00 2001 From: Green Cat Date: Thu, 8 Oct 2015 12:48:55 +0200 Subject: [PATCH 17/50] Removes duplicate use statement in response --- phalcon/http/response.zep | 1 - 1 file changed, 1 deletion(-) diff --git a/phalcon/http/response.zep b/phalcon/http/response.zep index e859e2644f2..fab37d1572c 100644 --- a/phalcon/http/response.zep +++ b/phalcon/http/response.zep @@ -27,7 +27,6 @@ use Phalcon\Mvc\UrlInterface; use Phalcon\Mvc\ViewInterface; use Phalcon\Http\Response\Headers; use Phalcon\Di\InjectionAwareInterface; -use Phalcon\Mvc\ViewInterface; /** * Phalcon\Http\Response From 413722cfa4064d250b98e94599df83843d89b8fc Mon Sep 17 00:00:00 2001 From: Stanislav Kiryukhin Date: Fri, 2 Oct 2015 13:22:54 +0300 Subject: [PATCH 18/50] #10992 - Added implementation options "allowEmpty" --- CHANGELOG.md | 1 + phalcon/mvc/model/validator/ip.zep | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 66b5070364d..c40033fdd93 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # [2.0.9](https://github.com/phalcon/cphalcon/releases/tag/phalcon-v2.0.9) (2015-??-??) - Fixed bug that double serializes data using Redis adapter - Added `console:boot` event to allow the developer to perform initialization actions +- Added implementation options `allowEmpty` for `Phalcon\Mvc\Model\Validator\Ip` # [2.0.8](https://github.com/phalcon/cphalcon/releases/tag/phalcon-v2.0.8) (2015-09-19) - Added `Phalcon\Security\Random::base58` - to generate a random base58 string diff --git a/phalcon/mvc/model/validator/ip.zep b/phalcon/mvc/model/validator/ip.zep index e358e66e469..a96a3ac11e5 100644 --- a/phalcon/mvc/model/validator/ip.zep +++ b/phalcon/mvc/model/validator/ip.zep @@ -92,6 +92,10 @@ class Ip extends Validator implements ValidatorInterface let allowPrivate = this->getOption("allowPrivate") ? 0 : FILTER_FLAG_NO_PRIV_RANGE; let allowReserved = this->getOption("allowReserved") ? 0 : FILTER_FLAG_NO_RES_RANGE; + if this->getOption("allowEmpty", false) && empty value { + return true; + } + let options = [ "options": [ "default": false From fac1ef7a167243fae3b35bbd0d6466a9e340bc1f Mon Sep 17 00:00:00 2001 From: Serghei Iakovlev Date: Fri, 9 Oct 2015 14:06:31 +0300 Subject: [PATCH 19/50] Fixed issue #11014 --- phalcon/mvc/model.zep | 1 - 1 file changed, 1 deletion(-) diff --git a/phalcon/mvc/model.zep b/phalcon/mvc/model.zep index 1a85d64a9bd..162281583e6 100644 --- a/phalcon/mvc/model.zep +++ b/phalcon/mvc/model.zep @@ -40,7 +40,6 @@ use Phalcon\Mvc\Model\Relation; use Phalcon\Mvc\Model\RelationInterface; use Phalcon\Mvc\Model\BehaviorInterface; use Phalcon\Mvc\Model\Exception; -use Phalcon\Mvc\Model\MetadataInterface; use Phalcon\Mvc\Model\MessageInterface; use Phalcon\Events\ManagerInterface as EventsManagerInterface; From 271598202e1373197e0df05a4bcd1b631304cfab Mon Sep 17 00:00:00 2001 From: Serghei Iakovlev Date: Sun, 4 Oct 2015 15:32:37 +0300 Subject: [PATCH 20/50] Fixed issue #10997 --- phalcon/db/adapter/pdo/sqlite.zep | 32 ++++++++++++++++++++++--------- phalcon/db/dialect/sqlite.zep | 20 +++++++++++++++++++ 2 files changed, 43 insertions(+), 9 deletions(-) diff --git a/phalcon/db/adapter/pdo/sqlite.zep b/phalcon/db/adapter/pdo/sqlite.zep index d034023f6e8..b83a6de3148 100644 --- a/phalcon/db/adapter/pdo/sqlite.zep +++ b/phalcon/db/adapter/pdo/sqlite.zep @@ -300,29 +300,43 @@ class Sqlite extends PdoAdapter implements AdapterInterface */ public function describeIndexes(table, schema = null) -> { - var indexes, index, keyName, indexObjects, name, indexColumns, columns, - describe_index; + var indexes, index, keyName, indexObjects, name, columns, describeIndex, indexSql; let indexes = []; - for index in this->fetchAll(this->_dialect->describeIndexes(table, schema), Db::FETCH_NUM) { + for index in this->fetchAll(this->_dialect->describeIndexes(table, schema), Db::FETCH_ASSOC) { + let keyName = index["name"]; - let keyName = index[1]; if !isset indexes[keyName] { let columns = []; } else { let columns = indexes[keyName]; } - for describe_index in this->fetchAll(this->_dialect->describeIndex(keyName), Db::FETCH_NUM) { - let columns[] = describe_index[2]; + for describeIndex in this->fetchAll(this->_dialect->describeIndex(keyName), Db::FETCH_ASSOC) { + let columns[] = describeIndex["name"]; } - let indexes[keyName] = columns; + if (isset(indexes[keyName])) { + let indexes[keyName] = []; + } + + let indexes[keyName]["columns"] = columns; + let indexSql = this->fetchColumn(this->_dialect->listIndexesSql(table, schema, keyName)); + + if index["unique"] { + if preg_match("# UNIQUE #i", indexSql) { + let indexes[keyName]["type"] = "UNIQUE"; + } else { + let indexes[keyName]["type"] = "PRIMARY"; + } + } else { + let indexes[keyName]["type"] = null; + } } let indexObjects = []; - for name, indexColumns in indexes { - let indexObjects[name] = new Index(name, indexColumns); + for name, index in indexes { + let indexObjects[name] = new Index(name, index["columns"], index["type"]); } return indexObjects; diff --git a/phalcon/db/dialect/sqlite.zep b/phalcon/db/dialect/sqlite.zep index 3de5c35882e..96e74de2d03 100644 --- a/phalcon/db/dialect/sqlite.zep +++ b/phalcon/db/dialect/sqlite.zep @@ -471,6 +471,26 @@ class Sqlite extends Dialect return "SELECT tbl_name FROM sqlite_master WHERE type = 'view' ORDER BY tbl_name"; } + /** + * Generates the SQL to list query of indexes + * + * + * print_r($dialect->listIndexesSql("blog")) + * + */ + public function listIndexesSql(string! table, string schema = null, string keyName = null) -> string + { + var sql; + + let sql = "SELECT sql FROM sqlite_master WHERE type = 'index' AND tbl_name = '". table ."' COLLATE NOCASE"; + + if keyName { + let sql .= " AND name = '". keyName ."' COLLATE NOCASE"; + } + + return sql; + } + /** * Generates SQL to query indexes on a table */ From c8455b232b73b8ae0b4799474e89e3bdb391dbb0 Mon Sep 17 00:00:00 2001 From: Serghei Iakovlev Date: Sun, 4 Oct 2015 17:42:33 +0300 Subject: [PATCH 21/50] Added tests for SQLite indexes --- unit-tests/DbDescribeTest.php | 54 +++++++++++++--------- unit-tests/schemas/sqlite/phalcon_test.sql | 14 +++++- 2 files changed, 44 insertions(+), 24 deletions(-) diff --git a/unit-tests/DbDescribeTest.php b/unit-tests/DbDescribeTest.php index d6893b0ce46..58d01885d21 100644 --- a/unit-tests/DbDescribeTest.php +++ b/unit-tests/DbDescribeTest.php @@ -755,22 +755,24 @@ public function testDbSqlite() //List tables $expectedTables = array ( - 0 => 'customers', - 1 => 'm2m_parts', - 2 => 'm2m_robots', - 3 => 'm2m_robots_parts', - 4 => 'parts', - 5 => 'personas', - 6 => 'personnes', - 7 => 'prueba', - 8 => 'robots', - 9 => 'robots_parts', - 10 => 'sqlite_sequence', - 11 => 'subscriptores', - 12 => 'tipo_documento', + 0 => 'COMPANY', + 1 => 'customers', + 2 => 'm2m_parts', + 3 => 'm2m_robots', + 4 => 'm2m_robots_parts', + 5 => 'parts', + 6 => 'personas', + 7 => 'personnes', + 8 => 'prueba', + 9 => 'robots', + 10 => 'robots_parts', + 11 => 'sqlite_sequence', + 12 => 'subscriptores', + 13 => 'tipo_documento', ); $tables = $connection->listTables(); + $this->assertEquals($tables, $expectedTables); $tables = $connection->listTables('public'); @@ -790,22 +792,28 @@ public function testDbSqlite() $describe = $connection->describeColumns('personas', 'main'); $this->assertEquals($describe, $expectedDescribe); - //Indexes ps. sqlite's integer primary key autoincrement is not listed in indexes + //Indexes $expectedIndexes = array( - 'robots_parts_parts_id' => Phalcon\Db\Index::__set_state(array( - '_name' => 'robots_parts_parts_id', - '_columns' => array('parts_id') - )), - 'robots_parts_robots_id' => Phalcon\Db\Index::__set_state(array( - '_name' => 'robots_parts_robots_id', - '_columns' => array('robots_id') + 'sqlite_autoindex_COMPANY_1' => Phalcon\Db\Index::__set_state(array( + '_name' => 'sqlite_autoindex_COMPANY_1', + '_columns' => array('ID'), + '_type' => 'PRIMARY' + )), + 'salary_index' => Phalcon\Db\Index::__set_state(array( + '_name' => 'salary_index', + '_columns' => array('SALARY') + )), + 'name_index' => Phalcon\Db\Index::__set_state(array( + '_name' => 'name_index', + '_columns' => array('NAME'), + '_type' => 'UNIQUE' )) ); - $describeIndexes = $connection->describeIndexes('robots_parts'); + $describeIndexes = $connection->describeIndexes('COMPANY'); $this->assertEquals($describeIndexes, $expectedIndexes); - $describeIndexes = $connection->describeIndexes('robots_parts', 'main'); + $describeIndexes = $connection->describeIndexes('company', 'main'); $this->assertEquals($describeIndexes, $expectedIndexes); //References diff --git a/unit-tests/schemas/sqlite/phalcon_test.sql b/unit-tests/schemas/sqlite/phalcon_test.sql index 3c134caecc9..c85eac553e9 100644 --- a/unit-tests/schemas/sqlite/phalcon_test.sql +++ b/unit-tests/schemas/sqlite/phalcon_test.sql @@ -6499,4 +6499,16 @@ CREATE INDEX `personnes_cupo` ON `personnes` (`cupo`); CREATE INDEX `prueba_estado` ON `prueba` (`estado`); CREATE INDEX `robots_parts_robots_id` on `robots_parts` (`robots_id`); CREATE INDEX `robots_parts_parts_id` on `robots_parts` (`parts_id`); -COMMIT; + +CREATE TABLE COMPANY ( + ID INT PRIMARY KEY NOT NULL, + NAME TEXT NOT NULL, + AGE INT NOT NULL, + ADDRESS CHAR(50), + SALARY REAL +); + +CREATE INDEX salary_index ON COMPANY (salary); +CREATE UNIQUE INDEX name_index ON COMPANY (name); + +COMMIT; \ No newline at end of file From 35b72ff4050d429983a1b59c3dcc0b375f378005 Mon Sep 17 00:00:00 2001 From: Serghei Iakovlev Date: Sun, 4 Oct 2015 18:11:36 +0300 Subject: [PATCH 22/50] Updated CHANGELOG [ci skip] --- CHANGELOG.md | 2 ++ phalcon/db/dialect/sqlite.zep | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c40033fdd93..72dc79bc189 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ - Fixed bug that double serializes data using Redis adapter - Added `console:boot` event to allow the developer to perform initialization actions - Added implementation options `allowEmpty` for `Phalcon\Mvc\Model\Validator\Ip` +- Fixed SQLite bug[#10997] related to setting of index type +- Added `Phalcon\Db\Dialect\Sqlite::listIndexesSql` - to generate the SQL to get query list of indexes # [2.0.8](https://github.com/phalcon/cphalcon/releases/tag/phalcon-v2.0.8) (2015-09-19) - Added `Phalcon\Security\Random::base58` - to generate a random base58 string diff --git a/phalcon/db/dialect/sqlite.zep b/phalcon/db/dialect/sqlite.zep index 96e74de2d03..158252293da 100644 --- a/phalcon/db/dialect/sqlite.zep +++ b/phalcon/db/dialect/sqlite.zep @@ -472,7 +472,7 @@ class Sqlite extends Dialect } /** - * Generates the SQL to list query of indexes + * Generates the SQL to get query list of indexes * * * print_r($dialect->listIndexesSql("blog")) From 15a295220cf9a7fdbe3f157362d95135bd517dad Mon Sep 17 00:00:00 2001 From: Serghei Iakovlev Date: Sun, 4 Oct 2015 18:48:08 +0300 Subject: [PATCH 23/50] Escape table & keyName in Sqlite::listIndexesSql --- phalcon/db/dialect/sqlite.zep | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/phalcon/db/dialect/sqlite.zep b/phalcon/db/dialect/sqlite.zep index 158252293da..7763a5092f7 100644 --- a/phalcon/db/dialect/sqlite.zep +++ b/phalcon/db/dialect/sqlite.zep @@ -480,12 +480,12 @@ class Sqlite extends Dialect */ public function listIndexesSql(string! table, string schema = null, string keyName = null) -> string { - var sql; + string sql; - let sql = "SELECT sql FROM sqlite_master WHERE type = 'index' AND tbl_name = '". table ."' COLLATE NOCASE"; + let sql = "SELECT sql FROM sqlite_master WHERE type = 'index' AND tbl_name = ". this->escape(table) ." COLLATE NOCASE"; if keyName { - let sql .= " AND name = '". keyName ."' COLLATE NOCASE"; + let sql .= " AND name = ". this->escape(keyName) ." COLLATE NOCASE"; } return sql; From cb8453b1eec8d70728edd3f8b6e38ad1fa7f6ad0 Mon Sep 17 00:00:00 2001 From: Serghei Iakovlev Date: Mon, 19 Oct 2015 01:12:47 +0300 Subject: [PATCH 24/50] Amended Router Mvc Test --- unit-tests/RouterMvcTest.php | 75 +++++++++++++++--------------------- 1 file changed, 32 insertions(+), 43 deletions(-) diff --git a/unit-tests/RouterMvcTest.php b/unit-tests/RouterMvcTest.php index 53a22e886ee..b4dc35c09a7 100644 --- a/unit-tests/RouterMvcTest.php +++ b/unit-tests/RouterMvcTest.php @@ -757,9 +757,11 @@ public function _testHostnameRegexRouter() } - public function testHostnameRouteGroup() + /** + * @dataProvider hostnamedRoutesProvider + */ + public function testHostnameRouteGroup($actualHost, $expectedHost, $controller) { - Phalcon\Mvc\Router\Route::reset(); $di = new Phalcon\DI(); @@ -788,31 +790,17 @@ public function testHostnameRouteGroup() $router->mount($group); - $routes = array( - array( - 'hostname' => 'localhost', - 'controller' => 'posts3' - ), - array( - 'hostname' => 'my.phalconphp.com', - 'controller' => 'posts' - ), - array( - 'hostname' => null, - 'controller' => 'posts3' - ) - ); - - foreach ($routes as $route) { - $_SERVER['HTTP_HOST'] = $route['hostname']; - $router->handle('/edit'); - $this->assertEquals($router->getControllerName(), $route['controller']); - } + $_SERVER['HTTP_HOST'] = $actualHost; + $router->handle('/edit'); + $this->assertEquals($router->getControllerName(), $controller); + $this->assertEquals($router->getMatchedRoute()->getHostname(), $expectedHost); } - public function testHostnameRegexRouteGroup() + /** + * @dataProvider hostnamedRegexRoutesProvider + */ + public function testHostnameRegexRouteGroup($actualHost, $expectedHost, $controller) { - Phalcon\Mvc\Router\Route::reset(); $di = new Phalcon\DI(); @@ -841,26 +829,27 @@ public function testHostnameRegexRouteGroup() $router->mount($group); - $routes = array( - array( - 'hostname' => 'localhost', - 'controller' => 'posts3' - ), - array( - 'hostname' => 'my.phalconphp.com', - 'controller' => 'posts' - ), - array( - 'hostname' => null, - 'controller' => 'posts3' - ) - ); + $_SERVER['HTTP_HOST'] = $actualHost; + $router->handle('/edit'); + $this->assertEquals($router->getControllerName(), $controller); + $this->assertEquals($router->getMatchedRoute()->getHostname(), $expectedHost); + } - foreach ($routes as $route) { - $_SERVER['HTTP_HOST'] = $route['hostname']; - $router->handle('/edit'); - $this->assertEquals($router->getControllerName(), $route['controller']); - } + public function hostnamedRegexRoutesProvider() + { + return array( + array('localhost', null, 'posts3'), + array('my.phalconphp.com', '([a-z]+).phalconphp.com', 'posts'), + array(null, null, 'posts3'), + ); } + public function hostnamedRoutesProvider() + { + return array( + array('localhost', null, 'posts3'), + array('my.phalconphp.com', 'my.phalconphp.com', 'posts'), + array(null, null, 'posts3'), + ); + } } From 2df9582e12596aceac22faea73049e1d5ff51852 Mon Sep 17 00:00:00 2001 From: Serghei Iakovlev Date: Wed, 21 Oct 2015 13:48:22 +0300 Subject: [PATCH 25/50] Small fixes in Sqlite::describeIndexes --- phalcon/db/adapter/pdo/sqlite.zep | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/phalcon/db/adapter/pdo/sqlite.zep b/phalcon/db/adapter/pdo/sqlite.zep index b83a6de3148..3e4c072aa5f 100644 --- a/phalcon/db/adapter/pdo/sqlite.zep +++ b/phalcon/db/adapter/pdo/sqlite.zep @@ -294,9 +294,13 @@ class Sqlite extends PdoAdapter implements AdapterInterface /** * Lists table indexes * - * @param string table - * @param string schema - * @return Phalcon\Db\IndexInterface[] + * + * print_r($connection->describeIndexes('robots_parts')); + * + * + * @param string table + * @param string schema + * @return \Phalcon\Db\IndexInterface[] */ public function describeIndexes(table, schema = null) -> { @@ -307,19 +311,19 @@ class Sqlite extends PdoAdapter implements AdapterInterface let keyName = index["name"]; if !isset indexes[keyName] { + let indexes[keyName] = []; + } + + if !isset indexes[keyName]["columns"] { let columns = []; } else { - let columns = indexes[keyName]; + let columns = indexes[keyName]["columns"]; } for describeIndex in this->fetchAll(this->_dialect->describeIndex(keyName), Db::FETCH_ASSOC) { let columns[] = describeIndex["name"]; } - if (isset(indexes[keyName])) { - let indexes[keyName] = []; - } - let indexes[keyName]["columns"] = columns; let indexSql = this->fetchColumn(this->_dialect->listIndexesSql(table, schema, keyName)); From 1ffa9a7a0990177d1e2a40153b03f24d2e979fe8 Mon Sep 17 00:00:00 2001 From: Serghei Iakovlev Date: Wed, 21 Oct 2015 12:13:14 +0300 Subject: [PATCH 26/50] Fixed issue #11036 --- phalcon/db/adapter/pdo/mysql.zep | 51 ++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/phalcon/db/adapter/pdo/mysql.zep b/phalcon/db/adapter/pdo/mysql.zep index 3b4616e5a36..58e769eb845 100644 --- a/phalcon/db/adapter/pdo/mysql.zep +++ b/phalcon/db/adapter/pdo/mysql.zep @@ -21,6 +21,8 @@ namespace Phalcon\Db\Adapter\Pdo; use Phalcon\Db; use Phalcon\Db\Column; +use Phalcon\Db\Index; +use Phalcon\Db\IndexInterface; use Phalcon\Db\AdapterInterface; use Phalcon\Db\Adapter\Pdo as PdoAdapter; @@ -336,4 +338,53 @@ class Mysql extends PdoAdapter implements AdapterInterface return columns; } + + /** + * Lists table indexes + * + * + * print_r($connection->describeIndexes('robots_parts')); + * + * + * @param string table + * @param string schema + * @return \Phalcon\Db\IndexInterface[] + */ + public function describeIndexes(string! table, schema = null) -> + { + var indexes, index, keyName, indexObjects, columns, name; + + let indexes = []; + for index in this->fetchAll(this->_dialect->describeIndexes(table, schema), Db::FETCH_ASSOC) { + let keyName = index["Key_name"]; + + if !isset indexes[keyName] { + let indexes[keyName] = []; + } + + if !isset indexes[keyName]["columns"] { + let columns = []; + } else { + let columns = indexes[keyName]["columns"]; + } + + let columns[] = index["Column_name"]; + let indexes[keyName]["columns"] = columns; + + if keyName == "PRIMARY" { + let indexes[keyName]["type"] = "PRIMARY"; + } elseif index["Non_unique"] == 0 { + let indexes[keyName]["type"] = "UNIQUE"; + } else { + let indexes[keyName]["type"] = null; + } + } + + let indexObjects = []; + for name, index in indexes { + let indexObjects[name] = new Index(name, index["columns"], index["type"]); + } + + return indexObjects; + } } From 3a8f73bbe02679fe1dd49fd1cc6c935cce0c503d Mon Sep 17 00:00:00 2001 From: Serghei Iakovlev Date: Wed, 21 Oct 2015 12:39:44 +0300 Subject: [PATCH 27/50] Added tests for MySQL indexes --- unit-tests/DbDescribeTest.php | 24 ++++++++++++++++++++++- unit-tests/schemas/mysql/phalcon_test.sql | 11 +++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/unit-tests/DbDescribeTest.php b/unit-tests/DbDescribeTest.php index 58d01885d21..285740df5e9 100644 --- a/unit-tests/DbDescribeTest.php +++ b/unit-tests/DbDescribeTest.php @@ -554,6 +554,7 @@ public function testDbMysql() 'albums', 'artists', 'customers', + 'issue_11036', 'issue_1534', 'issue_2019', 'm2m_parts', @@ -605,7 +606,8 @@ public function testDbMysql() $expectedIndexes = array( 'PRIMARY' => Phalcon\Db\Index::__set_state(array( '_name' => 'PRIMARY', - '_columns' => array('id') + '_columns' => array('id'), + '_type' => 'PRIMARY', )), 'robots_id' => Phalcon\Db\Index::__set_state(array( '_name' => 'robots_id', @@ -623,6 +625,26 @@ public function testDbMysql() $describeIndexes = $connection->describeIndexes('robots_parts', 'phalcon_test'); $this->assertEquals($describeIndexes, $expectedIndexes); + //Indexes + $expectedIndexes = array( + 'PRIMARY' => Phalcon\Db\Index::__set_state(array( + '_name' => 'PRIMARY', + '_columns' => array('id'), + '_type' => 'PRIMARY', + )), + 'issue_11036_token_UNIQUE' => Phalcon\Db\Index::__set_state(array( + '_name' => 'issue_11036_token_UNIQUE', + '_columns' => array('token'), + '_type' => 'UNIQUE' + )) + ); + + $describeIndexes = $connection->describeIndexes('issue_11036'); + $this->assertEquals($describeIndexes, $expectedIndexes); + + $describeIndexes = $connection->describeIndexes('issue_11036', 'phalcon_test'); + $this->assertEquals($describeIndexes, $expectedIndexes); + //References $expectedReferences = array( 'robots_parts_ibfk_1' => Phalcon\Db\Reference::__set_state(array( diff --git a/unit-tests/schemas/mysql/phalcon_test.sql b/unit-tests/schemas/mysql/phalcon_test.sql index d358ac0f3a7..398eb793646 100644 --- a/unit-tests/schemas/mysql/phalcon_test.sql +++ b/unit-tests/schemas/mysql/phalcon_test.sql @@ -412,6 +412,17 @@ CREATE TABLE IF NOT EXISTS `issue_2019` ( PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +DROP TABLE IF EXISTS `issue_11036`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `issue_11036` ( + `id` int(11) unsigned NOT NULL AUTO_INCREMENT, + `token` varchar(100) NOT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `issue_11036_token_UNIQUE` (`token`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; +/*!40101 SET character_set_client = @saved_cs_client */; + /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; /*!40101 SET SQL_MODE=@OLD_SQL_MODE */; From 71345a456fcdb9a44298cfc17d404c5028051012 Mon Sep 17 00:00:00 2001 From: Serghei Iakovlev Date: Wed, 21 Oct 2015 12:41:34 +0300 Subject: [PATCH 28/50] Updated CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 72dc79bc189..140390d4e6b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - Added implementation options `allowEmpty` for `Phalcon\Mvc\Model\Validator\Ip` - Fixed SQLite bug[#10997] related to setting of index type - Added `Phalcon\Db\Dialect\Sqlite::listIndexesSql` - to generate the SQL to get query list of indexes +- Fixed MySQL bug[#11036] related to setting of index type # [2.0.8](https://github.com/phalcon/cphalcon/releases/tag/phalcon-v2.0.8) (2015-09-19) - Added `Phalcon\Security\Random::base58` - to generate a random base58 string From 0c5a01210dbab83baa861e8ec84424dbd767b5f8 Mon Sep 17 00:00:00 2001 From: Sid Roberts Date: Thu, 22 Oct 2015 10:26:12 +0100 Subject: [PATCH 29/50] Fixed typo in Db\Dialect (filed -> field). --- phalcon/db/dialect.zep | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/phalcon/db/dialect.zep b/phalcon/db/dialect.zep index ef0190b08bd..a9c3e72a4aa 100644 --- a/phalcon/db/dialect.zep +++ b/phalcon/db/dialect.zep @@ -818,18 +818,18 @@ abstract class Dialect implements DialectInterface */ protected final function getSqlExpressionGroupBy(var expression, string escapeChar = null, bindCounts = null) -> string { - var filed, fields; + var field, fields; if typeof expression == "array" { let fields = []; - for filed in expression { - if unlikely typeof filed != "array" { + for field in expression { + if unlikely typeof field != "array" { throw new Exception("Invalid SQL-GROUP-BY expression"); } - let fields[] = this->getSqlExpression(filed, escapeChar, bindCounts); + let fields[] = this->getSqlExpression(field, escapeChar, bindCounts); } let fields = join(", ", fields); @@ -858,24 +858,24 @@ abstract class Dialect implements DialectInterface */ protected final function getSqlExpressionOrderBy(var expression, string escapeChar = null, bindCounts = null) -> string { - var filed, fields, type, fieldSql = null; + var field, fields, type, fieldSql = null; if typeof expression == "array" { let fields = []; - for filed in expression { + for field in expression { - if unlikely typeof filed != "array" { + if unlikely typeof field != "array" { throw new Exception("Invalid SQL-ORDER-BY expression"); } - let fieldSql = this->getSqlExpression(filed[0], escapeChar, bindCounts); + let fieldSql = this->getSqlExpression(field[0], escapeChar, bindCounts); /** * In the numeric 1 position could be a ASC/DESC clause */ - if fetch type, filed[1] && type != "" { + if fetch type, field[1] && type != "" { let fieldSql .= " " . type; } From c98d9faec841ba0ebb39bbde700b7577a4683d46 Mon Sep 17 00:00:00 2001 From: Sid Roberts Date: Thu, 22 Oct 2015 10:27:15 +0100 Subject: [PATCH 30/50] Removed redundant type-checking code from `Db\Dialect::getSqlExpressionHaving()`. --- phalcon/db/dialect.zep | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/phalcon/db/dialect.zep b/phalcon/db/dialect.zep index a9c3e72a4aa..74ec3b6eed8 100644 --- a/phalcon/db/dialect.zep +++ b/phalcon/db/dialect.zep @@ -844,13 +844,9 @@ abstract class Dialect implements DialectInterface /** * Resolve a HAVING clause */ - protected final function getSqlExpressionHaving(var expression, string escapeChar = null, bindCounts = null) -> string + protected final function getSqlExpressionHaving(array expression, string escapeChar = null, bindCounts = null) -> string { - if typeof expression == "array" { - return "HAVING " . this->getSqlExpression(expression, escapeChar, bindCounts); - } - - throw new Exception("Invalid SQL-HAVING expression"); + return "HAVING " . this->getSqlExpression(expression, escapeChar, bindCounts); } /** From 56f95835fadbc2ddf3778e83e0c3eaf8aa46fd9f Mon Sep 17 00:00:00 2001 From: Sid Roberts Date: Thu, 22 Oct 2015 10:09:18 +0100 Subject: [PATCH 31/50] Added another example to Mvc\Url::get() (phalcon/docs#432) --- phalcon/mvc/url.zep | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/phalcon/mvc/url.zep b/phalcon/mvc/url.zep index 9c81a343213..347376ace7a 100644 --- a/phalcon/mvc/url.zep +++ b/phalcon/mvc/url.zep @@ -170,6 +170,12 @@ class Url implements UrlInterface, InjectionAwareInterface * * //Generate a URL for a predefined route * echo $url->get(array('for' => 'blog-post', 'title' => 'some-cool-stuff', 'year' => '2015')); + * + * // Generate a URL with GET arguments (/show/products?id=1&name=Carrots) + * echo $url->get('show/products', array('id' => 1, 'name' => 'Carrots')); + * + * // Generate an absolute URL by setting the third parameter as false. + * echo $url->get('https://phalconphp.com/', null, false); * */ public function get(var uri = null, var args = null, var local = null, var baseUri = null) -> string From d120eb77273888d3cdf25c89fad3c788664aedcf Mon Sep 17 00:00:00 2001 From: Sid Roberts Date: Thu, 22 Oct 2015 10:31:38 +0100 Subject: [PATCH 32/50] Added stricter type-checking to `Db\Dialect::getSqlExpressionHaving()`. --- phalcon/db/dialect.zep | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phalcon/db/dialect.zep b/phalcon/db/dialect.zep index 74ec3b6eed8..d6e96797b68 100644 --- a/phalcon/db/dialect.zep +++ b/phalcon/db/dialect.zep @@ -844,7 +844,7 @@ abstract class Dialect implements DialectInterface /** * Resolve a HAVING clause */ - protected final function getSqlExpressionHaving(array expression, string escapeChar = null, bindCounts = null) -> string + protected final function getSqlExpressionHaving(array! expression, string escapeChar = null, bindCounts = null) -> string { return "HAVING " . this->getSqlExpression(expression, escapeChar, bindCounts); } From cd73ca713f9db711d87a5feae8b3af8d50a05d6a Mon Sep 17 00:00:00 2001 From: Eugene Smirnov Date: Thu, 22 Oct 2015 23:50:59 +0300 Subject: [PATCH 33/50] Fixed notice in query builder paginator when totalQuery result is empty --- phalcon/paginator/adapter/querybuilder.zep | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phalcon/paginator/adapter/querybuilder.zep b/phalcon/paginator/adapter/querybuilder.zep index d63d32b204c..c17e38691cd 100644 --- a/phalcon/paginator/adapter/querybuilder.zep +++ b/phalcon/paginator/adapter/querybuilder.zep @@ -177,7 +177,7 @@ class QueryBuilder extends Adapter implements AdapterInterface */ let result = totalQuery->execute(), row = result->getFirst(), - rowcount = intval(row->rowcount), + rowcount = row ? intval(row->rowcount) : 0, totalPages = intval(ceil(rowcount / limit)); if numberPage < totalPages { From 660596b48d37c1cc88aece0d58d1e0b0aee445ee Mon Sep 17 00:00:00 2001 From: Serghei Iakovlev Date: Fri, 23 Oct 2015 00:53:26 +0300 Subject: [PATCH 34/50] Update Phalcon\Queue\Beanstalk\Job doc for getters --- phalcon/queue/beanstalk/job.zep | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/phalcon/queue/beanstalk/job.zep b/phalcon/queue/beanstalk/job.zep index da30d82cf6e..63031519649 100644 --- a/phalcon/queue/beanstalk/job.zep +++ b/phalcon/queue/beanstalk/job.zep @@ -28,8 +28,14 @@ use Phalcon\Queue\Beanstalk; */ class Job { + /** + * @var string + */ protected _id { get }; + /** + * @var mixed + */ protected _body { get }; protected _queue; From cd1152a6ac1f827d0109003e38104a96896c26e2 Mon Sep 17 00:00:00 2001 From: Nochum Sossonko Date: Fri, 23 Oct 2015 14:08:45 -0400 Subject: [PATCH 35/50] #11042 - Fix setting relation should not always cause dirty state change --- phalcon/mvc/model.zep | 8 ++++++-- unit-tests/ModelsRelationsTest.php | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/phalcon/mvc/model.zep b/phalcon/mvc/model.zep index 162281583e6..217b4e231f9 100644 --- a/phalcon/mvc/model.zep +++ b/phalcon/mvc/model.zep @@ -4089,17 +4089,21 @@ abstract class Model implements EntityInterface, ModelInterface, ResultInterface public function __set(string property, value) { var lowerProperty, related, modelName, manager, lowerKey, - relation, referencedModel, key, item; + relation, referencedModel, key, item, dirtyState; /** * Values are probably relationships if they are objects */ if typeof value == "object" { if value instanceof ModelInterface { + let dirtyState = this->_dirtyState; + if (value->getDirtyState() != dirtyState) { + let dirtyState = self::DIRTY_STATE_TRANSIENT; + } let lowerProperty = strtolower(property), this->{lowerProperty} = value, this->_related[lowerProperty] = value, - this->_dirtyState = self::DIRTY_STATE_TRANSIENT; + this->_dirtyState = dirtyState; return value; } } diff --git a/unit-tests/ModelsRelationsTest.php b/unit-tests/ModelsRelationsTest.php index 146852d505e..2e3fd1216fe 100644 --- a/unit-tests/ModelsRelationsTest.php +++ b/unit-tests/ModelsRelationsTest.php @@ -75,6 +75,7 @@ public function testModelsMysql() $this->_executeTestsNormal($di); $this->_executeTestsRenamed($di); $this->_testIssue938($di); + $this->_testIssue11042(); } public function testModelsPostgresql() @@ -94,6 +95,7 @@ public function testModelsPostgresql() $this->_executeTestsNormal($di); $this->_executeTestsRenamed($di); + $this->_testIssue11042(); } @@ -115,6 +117,7 @@ public function testModelsSqlite() $this->_executeTestsNormal($di); $this->_executeTestsRenamed($di); $this->_testIssue938($di); + $this->_testIssue11042(); } public function _executeTestsNormal($di) @@ -367,4 +370,20 @@ protected function _testIssue938($di) $this->assertEquals($rp[$i]->robots_id, $robot->id); } } + + protected function _testIssue11042() + { + $robot = RelationsRobots::findFirst(); + $this->assertNotEquals($robot, false); + $this->assertEquals($robot->getDirtyState(), $robot::DIRTY_STATE_PERSISTENT); + + $robotsParts = $robot->getRelationsRobotsParts(); + $this->assertEquals($robot->getDirtyState(), $robot::DIRTY_STATE_PERSISTENT); + + $robot = RelationsRobots::findFirst(); + $this->assertNotEquals($robot, false); + + $robotsParts = $robot->relationsRobotsParts; + $this->assertEquals($robot->getDirtyState(), $robot::DIRTY_STATE_PERSISTENT); + } } From 6da308e9d44ba061c089ea6d832a246148fe0191 Mon Sep 17 00:00:00 2001 From: Serghei Iakovlev Date: Sun, 18 Oct 2015 15:31:54 +0300 Subject: [PATCH 36/50] Added missed RouteInterface::setHostname, RouteInterface::getHostname --- CHANGELOG.md | 1 + phalcon/mvc/router/routeinterface.zep | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 140390d4e6b..a0516f36157 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - Fixed SQLite bug[#10997] related to setting of index type - Added `Phalcon\Db\Dialect\Sqlite::listIndexesSql` - to generate the SQL to get query list of indexes - Fixed MySQL bug[#11036] related to setting of index type +- Added missed `RouteInterface::setHostname`, `RouteInterface::getHostname` # [2.0.8](https://github.com/phalcon/cphalcon/releases/tag/phalcon-v2.0.8) (2015-09-19) - Added `Phalcon\Security\Random::base58` - to generate a random base58 string diff --git a/phalcon/mvc/router/routeinterface.zep b/phalcon/mvc/router/routeinterface.zep index 3d09b6fb6c8..ff366f52ea7 100644 --- a/phalcon/mvc/router/routeinterface.zep +++ b/phalcon/mvc/router/routeinterface.zep @@ -32,6 +32,16 @@ interface RouteInterface */ public function __construct(string! pattern, var paths = null, var httpMethods = null); + /** + * Sets a hostname restriction to the route + */ + public function setHostname(string hostname) -> ; + + /** + * Returns the hostname restriction if any + */ + public function getHostname() -> string; + /** * Replaces placeholders from pattern returning a valid PCRE regular expression */ From 44e8916f6c9c2a81e6e5fd3a9522f41e80164a3f Mon Sep 17 00:00:00 2001 From: Serghei Iakovlev Date: Tue, 27 Oct 2015 21:58:40 +0200 Subject: [PATCH 37/50] Fixed Filter::sanitize return type --- phalcon/filter.zep | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phalcon/filter.zep b/phalcon/filter.zep index c050465b74a..acc0814cda0 100644 --- a/phalcon/filter.zep +++ b/phalcon/filter.zep @@ -81,7 +81,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) + public function sanitize(var value, var filters, boolean noRecursive = false) -> var { var filter, arrayValue, itemKey, itemValue, sanitizedValue; @@ -125,7 +125,7 @@ class Filter implements FilterInterface /** * Internal sanitize wrapper to filter_var */ - protected function _sanitize(var value, string! filter) + protected function _sanitize(var value, string! filter) -> var { var filterObject; From dd97416b4e04bbee93020c700facb83099ed3c1a Mon Sep 17 00:00:00 2001 From: Serghei Iakovlev Date: Thu, 29 Oct 2015 17:51:45 +0200 Subject: [PATCH 38/50] Update filter.zep --- phalcon/filter.zep | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phalcon/filter.zep b/phalcon/filter.zep index acc0814cda0..4adc34a0073 100644 --- a/phalcon/filter.zep +++ b/phalcon/filter.zep @@ -125,7 +125,7 @@ class Filter implements FilterInterface /** * Internal sanitize wrapper to filter_var */ - protected function _sanitize(var value, string! filter) -> var + protected function _sanitize(var value, string! filter) { var filterObject; From 471760bff152cbd1083d232e26966e4fae1a7685 Mon Sep 17 00:00:00 2001 From: Serghei Iakovlev Date: Sat, 31 Oct 2015 12:00:15 +0200 Subject: [PATCH 39/50] Replaced spaces to tabs --- phalcon/cli/task.zep | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/phalcon/cli/task.zep b/phalcon/cli/task.zep index 3844bd9b3e5..64c59e98d49 100644 --- a/phalcon/cli/task.zep +++ b/phalcon/cli/task.zep @@ -35,7 +35,7 @@ use Phalcon\Di\Injectable; *class HelloTask extends \Phalcon\Cli\Task *{ * - * //This action will be executed by default + * // This action will be executed by default * public function mainAction() * { * @@ -58,8 +58,8 @@ class Task extends Injectable */ public final function __construct() { - if method_exists(this, "onConstruct") { - this->{"onConstruct"}(); - } + if method_exists(this, "onConstruct") { + this->{"onConstruct"}(); + } } } From e4ad6e8ca5521fa019885b7caf40ef9f9cdfdfb1 Mon Sep 17 00:00:00 2001 From: Alex Barinov Date: Tue, 3 Nov 2015 12:47:47 +0500 Subject: [PATCH 40/50] Add 'strict' option in ExclusionIn validator --- phalcon/validation/validator/exclusionin.zep | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/phalcon/validation/validator/exclusionin.zep b/phalcon/validation/validator/exclusionin.zep index f3aad967fd0..25d45a1dce8 100644 --- a/phalcon/validation/validator/exclusionin.zep +++ b/phalcon/validation/validator/exclusionin.zep @@ -46,7 +46,7 @@ class ExclusionIn extends Validator */ public function validate( validation, string! field) -> boolean { - var value, domain, message, label, replacePairs; + var value, domain, message, label, replacePairs, strict; let value = validation->getValue(field); @@ -61,11 +61,20 @@ class ExclusionIn extends Validator if typeof domain != "array" { throw new Exception("Option 'domain' must be an array"); } + + let strict = false; + if this->isSetOption("strict") { + if typeof strict != "boolean" { + throw new Exception("Option 'strict' must be a boolean"); + } + + let strict = this->getOption("strict"); + } /** * Check if the value is contained by the array */ - if in_array(value, domain) { + if in_array(value, domain, strict) { let label = this->getOption("label"); if empty label { From 8c68d90fd158a9d21375b8911263fdf43169f53d Mon Sep 17 00:00:00 2001 From: Alex Barinov Date: Wed, 4 Nov 2015 21:07:12 +0500 Subject: [PATCH 41/50] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a0516f36157..3461f647be2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - Added `Phalcon\Db\Dialect\Sqlite::listIndexesSql` - to generate the SQL to get query list of indexes - Fixed MySQL bug[#11036] related to setting of index type - Added missed `RouteInterface::setHostname`, `RouteInterface::getHostname` +- Added `strict` option for ExclusionIn validator # [2.0.8](https://github.com/phalcon/cphalcon/releases/tag/phalcon-v2.0.8) (2015-09-19) - Added `Phalcon\Security\Random::base58` - to generate a random base58 string From f5466c58a1bda6bad01d0e893f9c1cfd2692ae70 Mon Sep 17 00:00:00 2001 From: Serghei Iakovlev Date: Sun, 8 Nov 2015 02:20:15 +0200 Subject: [PATCH 42/50] Added Text::humanize, Text::underscore --- CHANGELOG.md | 2 + phalcon/text.zep | 26 ++++++++++ tests/unit/Phalcon/Text/TextHumanizeTest.php | 47 +++++++++++++++++++ .../unit/Phalcon/Text/TextUnderscoreTest.php | 47 +++++++++++++++++++ 4 files changed, 122 insertions(+) create mode 100644 tests/unit/Phalcon/Text/TextHumanizeTest.php create mode 100644 tests/unit/Phalcon/Text/TextUnderscoreTest.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 3461f647be2..b54697fa2b0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ - Fixed MySQL bug[#11036] related to setting of index type - Added missed `RouteInterface::setHostname`, `RouteInterface::getHostname` - Added `strict` option for ExclusionIn validator +- Added `Phalcon\Text::underscore` - to make a phrase underscored instead of spaced +- Added `Phalcon\Text::humanize` - to make an underscored or dashed phrase human-readable # [2.0.8](https://github.com/phalcon/cphalcon/releases/tag/phalcon-v2.0.8) (2015-09-19) - Added `Phalcon\Security\Random::base58` - to generate a random base58 string diff --git a/phalcon/text.zep b/phalcon/text.zep index 3496bcadffa..aa867410ce0 100644 --- a/phalcon/text.zep +++ b/phalcon/text.zep @@ -276,4 +276,30 @@ abstract class Text return result; } + + /** + * Makes a phrase underscored instead of spaced + * + * + * echo Phalcon\Text::underscore('look behind'); // 'look_behind' + * echo Phalcon\Text::underscore('Awesome Phalcon'); // 'Awesome_Phalcon' + * + */ + public static function underscore(string! text) -> string + { + return preg_replace("#\s+#", "_", trim(text)); + } + + /** + * Makes an underscored or dashed phrase human-readable + * + * + * echo Phalcon\Text::humanize('start-a-horse'); // 'start a horse' + * echo Phalcon\Text::humanize('five_cats'); // 'five cats' + * + */ + public static function humanize(string! text) -> string + { + return preg_replace("#[_-]+#", " ", trim(text)); + } } diff --git a/tests/unit/Phalcon/Text/TextHumanizeTest.php b/tests/unit/Phalcon/Text/TextHumanizeTest.php new file mode 100644 index 00000000000..6030fe1a700 --- /dev/null +++ b/tests/unit/Phalcon/Text/TextHumanizeTest.php @@ -0,0 +1,47 @@ + + * @author Nikolaos Dimopoulos + * + * The contents of this file are subject to the New BSD License that is + * bundled with this package in the file docs/LICENSE.txt + * + * If you did not receive a copy of the license and are unable to obtain it + * through the world-wide-web, please send an email to license@phalconphp.com + * so that we can send you a copy immediately. + */ + +namespace Phalcon\Tests\unit\Phalcon\Text; + +use \PhalconTest\Text as PhTText; + +class TextHumanizeTest extends Helper\TextBase +{ + /** + * Tests the humanize function + * + * @author Serghei Iakovlev + * @since 2015-11-09 + */ + public function testUnderscore() + { + $this->specify( + "humanize do not an underscored or dashed phrase human-readable", + function () { + expect(PhTText::humanize('start_a_horse'))->equals('start a horse'); + expect(PhTText::humanize("five-cats"))->equals('five cats'); + expect(PhTText::humanize('kittens-are_cats'))->equals('kittens are cats'); + expect(PhTText::humanize(" \t Awesome-Phalcon \t "))->equals('Awesome Phalcon'); + } + ); + } +} diff --git a/tests/unit/Phalcon/Text/TextUnderscoreTest.php b/tests/unit/Phalcon/Text/TextUnderscoreTest.php new file mode 100644 index 00000000000..ec64b4087fd --- /dev/null +++ b/tests/unit/Phalcon/Text/TextUnderscoreTest.php @@ -0,0 +1,47 @@ + + * @author Nikolaos Dimopoulos + * + * The contents of this file are subject to the New BSD License that is + * bundled with this package in the file docs/LICENSE.txt + * + * If you did not receive a copy of the license and are unable to obtain it + * through the world-wide-web, please send an email to license@phalconphp.com + * so that we can send you a copy immediately. + */ + +namespace Phalcon\Tests\unit\Phalcon\Text; + +use \PhalconTest\Text as PhTText; + +class TextUnderscoreTest extends Helper\TextBase +{ + /** + * Tests the uderscore function + * + * @author Serghei Iakovlev + * @since 2015-11-09 + */ + public function testUnderscore() + { + $this->specify( + "underscore do not replace spaces", + function () { + expect(PhTText::underscore('start a horse'))->equals('start_a_horse'); + expect(PhTText::underscore("five\tcats"))->equals('five_cats'); + expect(PhTText::underscore(' look behind '))->equals('look_behind'); + expect(PhTText::underscore(" \t Awesome \t \t Phalcon "))->equals('Awesome_Phalcon'); + } + ); + } +} From 7707552d4f12a34aedd74bb730ac0e022935c239 Mon Sep 17 00:00:00 2001 From: Serghei Iakovlev Date: Sun, 8 Nov 2015 21:03:41 +0200 Subject: [PATCH 43/50] Update routeinterface.zep --- phalcon/mvc/router/routeinterface.zep | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phalcon/mvc/router/routeinterface.zep b/phalcon/mvc/router/routeinterface.zep index ff366f52ea7..027ccdd2258 100644 --- a/phalcon/mvc/router/routeinterface.zep +++ b/phalcon/mvc/router/routeinterface.zep @@ -70,7 +70,7 @@ interface RouteInterface /** * Sets a set of HTTP methods that constraint the matching of the route */ - public function setHttpMethods(var httpMethods) -> string | array; + public function setHttpMethods(var httpMethods) -> ; /** * Returns the route's id From ceb7e5d07fb1077f1ce924ef0bba77e38eab28c0 Mon Sep 17 00:00:00 2001 From: Serghei Iakovlev Date: Mon, 9 Nov 2015 21:15:08 +0200 Subject: [PATCH 44/50] Fixed issue #11109 --- phalcon/db/dialect/oracle.zep | 1 - 1 file changed, 1 deletion(-) diff --git a/phalcon/db/dialect/oracle.zep b/phalcon/db/dialect/oracle.zep index 3fbbaad3d85..f263148bc5b 100644 --- a/phalcon/db/dialect/oracle.zep +++ b/phalcon/db/dialect/oracle.zep @@ -160,7 +160,6 @@ class Oracle extends Dialect throw new Exception("Not implemented yet"); } - /** /** * Generates SQL to delete an index from a table */ From 96941a77cb8aaa731c5a6f8927fb168ca3941695 Mon Sep 17 00:00:00 2001 From: Serghei Iakovlev Date: Mon, 9 Nov 2015 21:21:44 +0200 Subject: [PATCH 45/50] Fixed Serghei email --- tests/PhalconTest/Security/Random.php | 2 +- tests/unit/Phalcon/Security/RandomTest.php | 16 ++++++++-------- .../unit/Phalcon/Text/TextReduceSlashesTest.php | 5 ++--- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/tests/PhalconTest/Security/Random.php b/tests/PhalconTest/Security/Random.php index 28100b9dd7a..096626da1f1 100644 --- a/tests/PhalconTest/Security/Random.php +++ b/tests/PhalconTest/Security/Random.php @@ -9,7 +9,7 @@ * * @copyright (c) 2011-2015 Phalcon Team * @link http://www.phalconphp.com - * @author Serghei Iakovlev + * @author Serghei Iakovlev * * The contents of this file are subject to the New BSD License that is * bundled with this package in the file docs/LICENSE.txt diff --git a/tests/unit/Phalcon/Security/RandomTest.php b/tests/unit/Phalcon/Security/RandomTest.php index 403f1c6ef97..41a0804e53f 100644 --- a/tests/unit/Phalcon/Security/RandomTest.php +++ b/tests/unit/Phalcon/Security/RandomTest.php @@ -9,7 +9,7 @@ * * @copyright (c) 2011-2015 Phalcon Team * @link http://www.phalconphp.com - * @author Serghei Iakovlev + * @author Serghei Iakovlev * * The contents of this file are subject to the New BSD License that is * bundled with this package in the file docs/LICENSE.txt @@ -39,7 +39,7 @@ public function _before() /** * Tests the random number generation * - * @author Serghei Iakovlev + * @author Serghei Iakovlev * @since 2015-08-17 */ public function testRandomNumber() @@ -72,7 +72,7 @@ function () { /** * Tests the random UUID v4 generation * - * @author Serghei Iakovlev + * @author Serghei Iakovlev * @since 2015-08-17 */ public function testRandomUuid() @@ -100,7 +100,7 @@ function () { /** * Tests the random base58 generation * - * @author Serghei Iakovlev + * @author Serghei Iakovlev * @since 2015-08-20 */ public function testRandomBase58() @@ -149,7 +149,7 @@ function () { /** * Tests the random base64 generation * - * @author Serghei Iakovlev + * @author Serghei Iakovlev * @since 2015-08-17 */ public function testRandomBase64() @@ -196,7 +196,7 @@ function () { /** * Tests the random base64 generation * - * @author Serghei Iakovlev + * @author Serghei Iakovlev * @since 2015-08-17 */ public function testRandomBase64Safe() @@ -245,7 +245,7 @@ function () { /** * Tests the random hex generation * - * @author Serghei Iakovlev + * @author Serghei Iakovlev * @since 2015-08-17 */ public function testRandomHex() @@ -289,7 +289,7 @@ function () { /** * Tests the random bytes string generation * - * @author Serghei Iakovlev + * @author Serghei Iakovlev * @since 2015-08-17 */ public function testRandomByte() diff --git a/tests/unit/Phalcon/Text/TextReduceSlashesTest.php b/tests/unit/Phalcon/Text/TextReduceSlashesTest.php index 9779c62affc..e67f8c39231 100644 --- a/tests/unit/Phalcon/Text/TextReduceSlashesTest.php +++ b/tests/unit/Phalcon/Text/TextReduceSlashesTest.php @@ -9,8 +9,7 @@ * * @copyright (c) 2011-2015 Phalcon Team * @link http://www.phalconphp.com - * @author Andres Gutierrez - * @author Nikolaos Dimopoulos + * @author Serghei Iakovlev * * The contents of this file are subject to the New BSD License that is * bundled with this package in the file docs/LICENSE.txt @@ -29,7 +28,7 @@ class TextReduceSlashesTest extends Helper\TextBase /** * Tests the reduce slashes function * - * @author Serghei Iakovlev + * @author Serghei Iakovlev * @since 2015-05-11 */ public function testReduceSlashes() From 788cab8823be7c7eb661c433a640ca50a3204060 Mon Sep 17 00:00:00 2001 From: Serghei Iakovlev Date: Mon, 9 Nov 2015 21:49:08 +0200 Subject: [PATCH 46/50] Fixed issue #11112 [ci skip] --- phalcon/db/adapter/pdo.zep | 2 +- phalcon/db/adapter/pdo/mysql.zep | 24 +++++++++++++++--------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/phalcon/db/adapter/pdo.zep b/phalcon/db/adapter/pdo.zep index f181a2bed0e..bee7c5dbbc5 100644 --- a/phalcon/db/adapter/pdo.zep +++ b/phalcon/db/adapter/pdo.zep @@ -411,7 +411,7 @@ abstract class Pdo extends Adapter * * * $escapedTable = $connection->escapeIdentifier('robots'); - * $escapedTable = $connection->escapeIdentifier(array('store', 'robots')); + * $escapedTable = $connection->escapeIdentifier(['store', 'robots']); * * * @param string identifier diff --git a/phalcon/db/adapter/pdo/mysql.zep b/phalcon/db/adapter/pdo/mysql.zep index 58e769eb845..d7d4f27830e 100644 --- a/phalcon/db/adapter/pdo/mysql.zep +++ b/phalcon/db/adapter/pdo/mysql.zep @@ -33,15 +33,17 @@ use Phalcon\Db\Adapter\Pdo as PdoAdapter; * * * - *$config = array( - * "host" => "192.168.0.11", - * "dbname" => "blog", - * "port" => 3306, - * "username" => "sigma", - * "password" => "secret" - *); + * use Phalcon\Db\Adapter\Pdo\Mysql; * - *$connection = new \Phalcon\Db\Adapter\Pdo\Mysql($config); + * $config = [ + * "host" => "192.168.0.11", + * "dbname" => "blog", + * "port" => 3306, + * "username" => "sigma", + * "password" => "secret" + * ]; + * + * $connection = new Mysql($config); * */ class Mysql extends PdoAdapter implements AdapterInterface @@ -54,8 +56,12 @@ class Mysql extends PdoAdapter implements AdapterInterface /** * Escapes a column/table/schema name * + * + * echo $connection->escapeIdentifier('my_table'); // `my_table` + * echo $connection->escapeIdentifier(['companies', 'name']); // `companies`.`name` + * + * * @param string|array identifier - * @return string */ public function escapeIdentifier(var identifier) -> string { From e90febe1172ecbdff8a097d1035d3c42e674286d Mon Sep 17 00:00:00 2001 From: Serghei Iakovlev Date: Mon, 9 Nov 2015 23:10:53 +0200 Subject: [PATCH 47/50] Fixed issue #11115 [ci skip] --- phalcon/queue/beanstalk.zep | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/phalcon/queue/beanstalk.zep b/phalcon/queue/beanstalk.zep index 442afa65099..38a79af6dd8 100644 --- a/phalcon/queue/beanstalk.zep +++ b/phalcon/queue/beanstalk.zep @@ -22,13 +22,13 @@ namespace Phalcon\Queue; use Phalcon\Queue\Beanstalk\Job; /** -* Phalcon\Queue\Beanstalk -* -* Class to access the beanstalk queue service. -* Partially implements the protocol version 1.2 -* -* @see http://www.igvita.com/2010/05/20/scalable-work-queues-with-beanstalk/ -*/ + * Phalcon\Queue\Beanstalk + * + * Class to access the beanstalk queue service. + * Partially implements the protocol version 1.2 + * + * @link http://www.igvita.com/2010/05/20/scalable-work-queues-with-beanstalk/ + */ class Beanstalk { protected _connection; From 78cfcfc49347c3f9b2857613c7dccc815de06533 Mon Sep 17 00:00:00 2001 From: Serghei Iakovlev Date: Tue, 10 Nov 2015 23:04:48 +0200 Subject: [PATCH 48/50] Amended doc for Phalcon\Security\Random [ci skip] --- phalcon/security/random.zep | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/phalcon/security/random.zep b/phalcon/security/random.zep index 117a62e45b3..329d9c637f7 100644 --- a/phalcon/security/random.zep +++ b/phalcon/security/random.zep @@ -31,6 +31,12 @@ namespace Phalcon\Security; * - openssl * - /dev/urandom * + * A `Phalcon\Security\Random` could be mainly useful for: + * + * - Key generation (e.g. generation of complicated keys) + * - Creating random passwords for new user accounts + * - Encryption systems + * * * $random = new \Phalcon\Security\Random(); * @@ -84,6 +90,9 @@ class Random /** * Generates a random binary string * + * The `Random::bytes` method returns a string and accepts as input an int + * representing the length in bytes to be returned. + * * If $len is not specified, 16 is assumed. It may be larger in future. * The result may contain any byte: "x00" - "xFF". * @@ -91,6 +100,8 @@ class Random * $random = new \Phalcon\Security\Random(); * * $bytes = $random->bytes(); + * var_dump(bin2hex($bytes)); + * // possible ouput: string(32) "00f6c04b144b41fad6a59111c126e1ee" * * * @throws Exception If secure random number generator is not available or unexpected partial read From c641cd605816bb9e53aab31e22feb55381ce479c Mon Sep 17 00:00:00 2001 From: Eugene Smirnov Date: Sun, 25 Oct 2015 22:09:21 +0300 Subject: [PATCH 49/50] Added ability to change document class to be returned in ODM through `class` option --- CHANGELOG.md | 1 + phalcon/mvc/collection.zep | 24 +++-- unit-tests/CollectionsClassChangeTest.php | 92 +++++++++++++++++++ unit-tests/collections/Bookshelf/Books.php | 7 ++ .../collections/Bookshelf/Magazines.php | 7 ++ .../collections/Bookshelf/NotACollection.php | 5 + unit-tests/phpunit.xml | 1 + 7 files changed, 127 insertions(+), 10 deletions(-) create mode 100644 unit-tests/CollectionsClassChangeTest.php create mode 100644 unit-tests/collections/Bookshelf/Books.php create mode 100644 unit-tests/collections/Bookshelf/Magazines.php create mode 100644 unit-tests/collections/Bookshelf/NotACollection.php diff --git a/CHANGELOG.md b/CHANGELOG.md index b54697fa2b0..6089f726bec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ - Added `strict` option for ExclusionIn validator - Added `Phalcon\Text::underscore` - to make a phrase underscored instead of spaced - Added `Phalcon\Text::humanize` - to make an underscored or dashed phrase human-readable +- Added ability to change document class to be returned in ODM through `class` option # [2.0.8](https://github.com/phalcon/cphalcon/releases/tag/phalcon-v2.0.8) (2015-09-19) - Added `Phalcon\Security\Random::base58` - to generate a random base58 string diff --git a/phalcon/mvc/collection.zep b/phalcon/mvc/collection.zep index 0ee8d1c8c67..ee502e71bf0 100644 --- a/phalcon/mvc/collection.zep +++ b/phalcon/mvc/collection.zep @@ -341,7 +341,20 @@ abstract class Collection implements EntityInterface, CollectionInterface, Injec protected static function _getResultset(var params, collection, connection, boolean unique) { var source, mongoCollection, conditions, base, documentsCursor, - fields, skip, limit, sort, document, collections; + fields, skip, limit, sort, document, collections, className; + + /** + * Check if "class" clause was defined + */ + if fetch className, params["class"] { + let base = new {className}(); + + if !(base instanceof CollectionInterface || base instanceof Collection\Document) { + throw new Exception("Object of class '" . className . "' must be an implementation of Phalcon\\Mvc\\CollectionInterface or an instance of Phalcon\\Mvc\\Collection\\Document"); + } + } else { + let base = collection; + } let source = collection->getSource(); if empty source { @@ -397,15 +410,6 @@ abstract class Collection implements EntityInterface, CollectionInterface, Injec documentsCursor->skip(skip); } - /** - * If a group of specific fields are requested we use a Phalcon\Mvc\Collection\Document instead - */ - if isset params["fields"] { - let base = new Document(); - } else { - let base = collection; - } - if unique === true { /** diff --git a/unit-tests/CollectionsClassChangeTest.php b/unit-tests/CollectionsClassChangeTest.php new file mode 100644 index 00000000000..d4792864344 --- /dev/null +++ b/unit-tests/CollectionsClassChangeTest.php @@ -0,0 +1,92 @@ +set('mongo', function(){ + $mongo = new MongoClient(); + return $mongo->phalcon_test; + }); + + $di->set('collectionManager', function(){ + return new Phalcon\Mvc\Collection\Manager(); + }); + } + + public function setUp() { + $book = new Books(); + $book->title = 'book'; + $book->save(); + + $this->_book = $book; + } + + public function testCollectionsClassChange() { + if (!class_exists('Mongo')) { + $this->markTestSkipped("Mongo class does not exist, test skipped"); + return; + } + + $book = Books::findFirst([['_id' => $this->_book->getId()]]); + $this->assertInstanceOf('\Bookshelf\Books', $book); + + $magazine = Books::findFirst([ + ['_id' => $this->_book->getId()], + 'class' => '\Bookshelf\Magazines' + ]); + $this->assertInstanceOf('\Bookshelf\Magazines', $magazine); + + $document = Books::findFirst([ + ['_id' => $this->_book->getId()], + 'class' => '\Phalcon\Mvc\Collection\Document' + ]); + $this->assertInstanceOf('\Phalcon\Mvc\Collection\Document', $document); + } + + public function testCollectionsClassChangeExceptionOnWrongClass() { + if (!class_exists('Mongo')) { + $this->markTestSkipped("Mongo class does not exist, test skipped"); + return; + } + + $this->setExpectedException('Exception', 'must be an implementation of Phalcon\\Mvc\\CollectionInterface'); + + Books::findFirst([ + ['_id' => $this->_book->getId()], + 'class' => '\Bookshelf\NotACollection' + ]); + + } + + public function tearDown() { + $this->_book->delete(); + } + +} \ No newline at end of file diff --git a/unit-tests/collections/Bookshelf/Books.php b/unit-tests/collections/Bookshelf/Books.php new file mode 100644 index 00000000000..775719d8ad5 --- /dev/null +++ b/unit-tests/collections/Bookshelf/Books.php @@ -0,0 +1,7 @@ +unit-tests/CollectionsBehaviorsTest.php unit-tests/CollectionsEventsTest.php unit-tests/CollectionsSerializeTest.php + unit-tests/CollectionsChangeClassTest.php unit-tests/CollectionsTest.php unit-tests/ConfigTest.php unit-tests/ConsoleCliTest.php From c8fdec8e2f8d9dbb9950b98d9acf082b99cbff3e Mon Sep 17 00:00:00 2001 From: Andres Gutierrez Date: Tue, 24 Nov 2015 03:03:47 -0500 Subject: [PATCH 50/50] Regenerating build [ci skip] --- build/32bits/phalcon.zep.c | 27 ++++++++++++++------------- build/32bits/phalcon.zep.h | 4 ++-- build/32bits/php_phalcon.h | 2 +- build/64bits/phalcon.zep.c | 29 +++++++++++++++-------------- build/64bits/phalcon.zep.h | 4 ++-- build/64bits/php_phalcon.h | 2 +- build/safe/phalcon.zep.c | 27 ++++++++++++++------------- build/safe/phalcon.zep.h | 4 ++-- build/safe/php_phalcon.h | 2 +- 9 files changed, 52 insertions(+), 49 deletions(-) diff --git a/build/32bits/phalcon.zep.c b/build/32bits/phalcon.zep.c index 148cef29977..dfd6f432c04 100644 --- a/build/32bits/phalcon.zep.c +++ b/build/32bits/phalcon.zep.c @@ -20252,7 +20252,7 @@ static PHP_METHOD(Phalcon_Di, get) { ZEPHIR_CONCAT_SVS(_3, "Service '", name, "' wasn't found in the dependency injection container"); ZEPHIR_CALL_METHOD(NULL, _2, "__construct", NULL, 9, _3); zephir_check_call_status(); - zephir_throw_exception_debug(_2, "phalcon/di.zep", 230 TSRMLS_CC); + zephir_throw_exception_debug(_2, "phalcon/di.zep", 229 TSRMLS_CC); ZEPHIR_MM_RESTORE(); return; } @@ -20576,7 +20576,7 @@ static PHP_METHOD(Phalcon_Di, __call) { ZEPHIR_CONCAT_SVS(_5, "Call to undefined method or service '", method, "'"); ZEPHIR_CALL_METHOD(NULL, _1, "__construct", NULL, 9, _5); zephir_check_call_status(); - zephir_throw_exception_debug(_1, "phalcon/di.zep", 428 TSRMLS_CC); + zephir_throw_exception_debug(_1, "phalcon/di.zep", 423 TSRMLS_CC); ZEPHIR_MM_RESTORE(); return; @@ -27413,7 +27413,7 @@ static PHP_METHOD(Phalcon_Version, _getVersion) { ZVAL_LONG(_0, 0); zephir_array_fast_append(return_value, _0); ZEPHIR_INIT_NVAR(_0); - ZVAL_LONG(_0, 8); + ZVAL_LONG(_0, 9); zephir_array_fast_append(return_value, _0); ZEPHIR_INIT_NVAR(_0); ZVAL_LONG(_0, 4); @@ -66663,7 +66663,6 @@ static PHP_METHOD(Phalcon_Http_Response_Cookies, get) { zephir_check_call_status(); } } - zephir_update_property_array(this_ptr, SL("_cookies"), name, cookie TSRMLS_CC); RETURN_CCTOR(cookie); } @@ -66745,7 +66744,7 @@ static PHP_METHOD(Phalcon_Http_Response_Cookies, send) { zephir_check_call_status(); if (!(zephir_is_true(_0))) { _1 = zephir_fetch_nproperty_this(this_ptr, SL("_cookies"), PH_NOISY_CC); - zephir_is_iterable(_1, &_3, &_2, 0, 0, "phalcon/http/response/cookies.zep", 236); + zephir_is_iterable(_1, &_3, &_2, 0, 0, "phalcon/http/response/cookies.zep", 239); for ( ; zephir_hash_get_current_data_ex(_3, (void**) &_4, &_2) == SUCCESS ; zephir_hash_move_forward_ex(_3, &_2) @@ -134285,14 +134284,16 @@ static PHP_METHOD(Phalcon_Session_Adapter_Redis, __construct) { ZEPHIR_INIT_NVAR(_0); object_init_ex(_0, phalcon_cache_backend_redis_ce); ZEPHIR_INIT_VAR(_1); - object_init_ex(_1, phalcon_cache_frontend_data_ce); - ZEPHIR_INIT_VAR(_2); - zephir_create_array(_2, 1, 0 TSRMLS_CC); - ZEPHIR_OBS_VAR(_3); - zephir_read_property_this(&_3, this_ptr, SL("_lifetime"), PH_NOISY_CC); - zephir_array_update_string(&_2, SL("lifetime"), &_3, PH_COPY | PH_SEPARATE); - ZEPHIR_CALL_METHOD(NULL, _1, "__construct", NULL, 312, _2); - zephir_check_call_status(); + object_init_ex(_1, phalcon_cache_frontend_none_ce); + if (zephir_has_constructor(_1 TSRMLS_CC)) { + ZEPHIR_INIT_VAR(_2); + zephir_create_array(_2, 1, 0 TSRMLS_CC); + ZEPHIR_OBS_VAR(_3); + zephir_read_property_this(&_3, this_ptr, SL("_lifetime"), PH_NOISY_CC); + zephir_array_update_string(&_2, SL("lifetime"), &_3, PH_COPY | PH_SEPARATE); + ZEPHIR_CALL_METHOD(NULL, _1, "__construct", NULL, 0, _2); + zephir_check_call_status(); + } ZEPHIR_CALL_METHOD(NULL, _0, "__construct", NULL, 316, _1, options); zephir_check_call_status(); zephir_update_property_this(this_ptr, SL("_redis"), _0 TSRMLS_CC); diff --git a/build/32bits/phalcon.zep.h b/build/32bits/phalcon.zep.h index 89cf6505f41..41c7cc4a29f 100644 --- a/build/32bits/phalcon.zep.h +++ b/build/32bits/phalcon.zep.h @@ -9778,11 +9778,11 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_db_profiler_item_setsqlstatement, 0, 0, 1 ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_db_profiler_item_setsqlvariables, 0, 0, 1) - ZEND_ARG_INFO(0, sqlVariables) + ZEND_ARG_ARRAY_INFO(0, sqlVariables, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_db_profiler_item_setsqlbindtypes, 0, 0, 1) - ZEND_ARG_INFO(0, sqlBindTypes) + ZEND_ARG_ARRAY_INFO(0, sqlBindTypes, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_db_profiler_item_setinitialtime, 0, 0, 1) diff --git a/build/32bits/php_phalcon.h b/build/32bits/php_phalcon.h index 4a60e53b947..df53cc57cd7 100644 --- a/build/32bits/php_phalcon.h +++ b/build/32bits/php_phalcon.h @@ -196,7 +196,7 @@ typedef zend_function zephir_fcall_cache_entry; #define PHP_PHALCON_NAME "phalcon" -#define PHP_PHALCON_VERSION "2.0.8" +#define PHP_PHALCON_VERSION "2.0.9" #define PHP_PHALCON_EXTNAME "phalcon" #define PHP_PHALCON_AUTHOR "Phalcon Team and contributors" #define PHP_PHALCON_ZEPVERSION "0.8.0a" diff --git a/build/64bits/phalcon.zep.c b/build/64bits/phalcon.zep.c index 8ab8a3604ab..dfd6f432c04 100644 --- a/build/64bits/phalcon.zep.c +++ b/build/64bits/phalcon.zep.c @@ -11199,7 +11199,7 @@ static const unsigned char tolower_map[256] = { static int zephir_has_constructor_ce(const zend_class_entry *ce) { - while (ce != NULL) { + while (ce) { if (ce->constructor) { return 1; } @@ -20252,7 +20252,7 @@ static PHP_METHOD(Phalcon_Di, get) { ZEPHIR_CONCAT_SVS(_3, "Service '", name, "' wasn't found in the dependency injection container"); ZEPHIR_CALL_METHOD(NULL, _2, "__construct", NULL, 9, _3); zephir_check_call_status(); - zephir_throw_exception_debug(_2, "phalcon/di.zep", 230 TSRMLS_CC); + zephir_throw_exception_debug(_2, "phalcon/di.zep", 229 TSRMLS_CC); ZEPHIR_MM_RESTORE(); return; } @@ -20576,7 +20576,7 @@ static PHP_METHOD(Phalcon_Di, __call) { ZEPHIR_CONCAT_SVS(_5, "Call to undefined method or service '", method, "'"); ZEPHIR_CALL_METHOD(NULL, _1, "__construct", NULL, 9, _5); zephir_check_call_status(); - zephir_throw_exception_debug(_1, "phalcon/di.zep", 428 TSRMLS_CC); + zephir_throw_exception_debug(_1, "phalcon/di.zep", 423 TSRMLS_CC); ZEPHIR_MM_RESTORE(); return; @@ -27413,7 +27413,7 @@ static PHP_METHOD(Phalcon_Version, _getVersion) { ZVAL_LONG(_0, 0); zephir_array_fast_append(return_value, _0); ZEPHIR_INIT_NVAR(_0); - ZVAL_LONG(_0, 8); + ZVAL_LONG(_0, 9); zephir_array_fast_append(return_value, _0); ZEPHIR_INIT_NVAR(_0); ZVAL_LONG(_0, 4); @@ -66663,7 +66663,6 @@ static PHP_METHOD(Phalcon_Http_Response_Cookies, get) { zephir_check_call_status(); } } - zephir_update_property_array(this_ptr, SL("_cookies"), name, cookie TSRMLS_CC); RETURN_CCTOR(cookie); } @@ -66745,7 +66744,7 @@ static PHP_METHOD(Phalcon_Http_Response_Cookies, send) { zephir_check_call_status(); if (!(zephir_is_true(_0))) { _1 = zephir_fetch_nproperty_this(this_ptr, SL("_cookies"), PH_NOISY_CC); - zephir_is_iterable(_1, &_3, &_2, 0, 0, "phalcon/http/response/cookies.zep", 236); + zephir_is_iterable(_1, &_3, &_2, 0, 0, "phalcon/http/response/cookies.zep", 239); for ( ; zephir_hash_get_current_data_ex(_3, (void**) &_4, &_2) == SUCCESS ; zephir_hash_move_forward_ex(_3, &_2) @@ -134285,14 +134284,16 @@ static PHP_METHOD(Phalcon_Session_Adapter_Redis, __construct) { ZEPHIR_INIT_NVAR(_0); object_init_ex(_0, phalcon_cache_backend_redis_ce); ZEPHIR_INIT_VAR(_1); - object_init_ex(_1, phalcon_cache_frontend_data_ce); - ZEPHIR_INIT_VAR(_2); - zephir_create_array(_2, 1, 0 TSRMLS_CC); - ZEPHIR_OBS_VAR(_3); - zephir_read_property_this(&_3, this_ptr, SL("_lifetime"), PH_NOISY_CC); - zephir_array_update_string(&_2, SL("lifetime"), &_3, PH_COPY | PH_SEPARATE); - ZEPHIR_CALL_METHOD(NULL, _1, "__construct", NULL, 312, _2); - zephir_check_call_status(); + object_init_ex(_1, phalcon_cache_frontend_none_ce); + if (zephir_has_constructor(_1 TSRMLS_CC)) { + ZEPHIR_INIT_VAR(_2); + zephir_create_array(_2, 1, 0 TSRMLS_CC); + ZEPHIR_OBS_VAR(_3); + zephir_read_property_this(&_3, this_ptr, SL("_lifetime"), PH_NOISY_CC); + zephir_array_update_string(&_2, SL("lifetime"), &_3, PH_COPY | PH_SEPARATE); + ZEPHIR_CALL_METHOD(NULL, _1, "__construct", NULL, 0, _2); + zephir_check_call_status(); + } ZEPHIR_CALL_METHOD(NULL, _0, "__construct", NULL, 316, _1, options); zephir_check_call_status(); zephir_update_property_this(this_ptr, SL("_redis"), _0 TSRMLS_CC); diff --git a/build/64bits/phalcon.zep.h b/build/64bits/phalcon.zep.h index 89cf6505f41..41c7cc4a29f 100644 --- a/build/64bits/phalcon.zep.h +++ b/build/64bits/phalcon.zep.h @@ -9778,11 +9778,11 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_db_profiler_item_setsqlstatement, 0, 0, 1 ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_db_profiler_item_setsqlvariables, 0, 0, 1) - ZEND_ARG_INFO(0, sqlVariables) + ZEND_ARG_ARRAY_INFO(0, sqlVariables, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_db_profiler_item_setsqlbindtypes, 0, 0, 1) - ZEND_ARG_INFO(0, sqlBindTypes) + ZEND_ARG_ARRAY_INFO(0, sqlBindTypes, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_db_profiler_item_setinitialtime, 0, 0, 1) diff --git a/build/64bits/php_phalcon.h b/build/64bits/php_phalcon.h index 4a60e53b947..df53cc57cd7 100644 --- a/build/64bits/php_phalcon.h +++ b/build/64bits/php_phalcon.h @@ -196,7 +196,7 @@ typedef zend_function zephir_fcall_cache_entry; #define PHP_PHALCON_NAME "phalcon" -#define PHP_PHALCON_VERSION "2.0.8" +#define PHP_PHALCON_VERSION "2.0.9" #define PHP_PHALCON_EXTNAME "phalcon" #define PHP_PHALCON_AUTHOR "Phalcon Team and contributors" #define PHP_PHALCON_ZEPVERSION "0.8.0a" diff --git a/build/safe/phalcon.zep.c b/build/safe/phalcon.zep.c index 148cef29977..dfd6f432c04 100644 --- a/build/safe/phalcon.zep.c +++ b/build/safe/phalcon.zep.c @@ -20252,7 +20252,7 @@ static PHP_METHOD(Phalcon_Di, get) { ZEPHIR_CONCAT_SVS(_3, "Service '", name, "' wasn't found in the dependency injection container"); ZEPHIR_CALL_METHOD(NULL, _2, "__construct", NULL, 9, _3); zephir_check_call_status(); - zephir_throw_exception_debug(_2, "phalcon/di.zep", 230 TSRMLS_CC); + zephir_throw_exception_debug(_2, "phalcon/di.zep", 229 TSRMLS_CC); ZEPHIR_MM_RESTORE(); return; } @@ -20576,7 +20576,7 @@ static PHP_METHOD(Phalcon_Di, __call) { ZEPHIR_CONCAT_SVS(_5, "Call to undefined method or service '", method, "'"); ZEPHIR_CALL_METHOD(NULL, _1, "__construct", NULL, 9, _5); zephir_check_call_status(); - zephir_throw_exception_debug(_1, "phalcon/di.zep", 428 TSRMLS_CC); + zephir_throw_exception_debug(_1, "phalcon/di.zep", 423 TSRMLS_CC); ZEPHIR_MM_RESTORE(); return; @@ -27413,7 +27413,7 @@ static PHP_METHOD(Phalcon_Version, _getVersion) { ZVAL_LONG(_0, 0); zephir_array_fast_append(return_value, _0); ZEPHIR_INIT_NVAR(_0); - ZVAL_LONG(_0, 8); + ZVAL_LONG(_0, 9); zephir_array_fast_append(return_value, _0); ZEPHIR_INIT_NVAR(_0); ZVAL_LONG(_0, 4); @@ -66663,7 +66663,6 @@ static PHP_METHOD(Phalcon_Http_Response_Cookies, get) { zephir_check_call_status(); } } - zephir_update_property_array(this_ptr, SL("_cookies"), name, cookie TSRMLS_CC); RETURN_CCTOR(cookie); } @@ -66745,7 +66744,7 @@ static PHP_METHOD(Phalcon_Http_Response_Cookies, send) { zephir_check_call_status(); if (!(zephir_is_true(_0))) { _1 = zephir_fetch_nproperty_this(this_ptr, SL("_cookies"), PH_NOISY_CC); - zephir_is_iterable(_1, &_3, &_2, 0, 0, "phalcon/http/response/cookies.zep", 236); + zephir_is_iterable(_1, &_3, &_2, 0, 0, "phalcon/http/response/cookies.zep", 239); for ( ; zephir_hash_get_current_data_ex(_3, (void**) &_4, &_2) == SUCCESS ; zephir_hash_move_forward_ex(_3, &_2) @@ -134285,14 +134284,16 @@ static PHP_METHOD(Phalcon_Session_Adapter_Redis, __construct) { ZEPHIR_INIT_NVAR(_0); object_init_ex(_0, phalcon_cache_backend_redis_ce); ZEPHIR_INIT_VAR(_1); - object_init_ex(_1, phalcon_cache_frontend_data_ce); - ZEPHIR_INIT_VAR(_2); - zephir_create_array(_2, 1, 0 TSRMLS_CC); - ZEPHIR_OBS_VAR(_3); - zephir_read_property_this(&_3, this_ptr, SL("_lifetime"), PH_NOISY_CC); - zephir_array_update_string(&_2, SL("lifetime"), &_3, PH_COPY | PH_SEPARATE); - ZEPHIR_CALL_METHOD(NULL, _1, "__construct", NULL, 312, _2); - zephir_check_call_status(); + object_init_ex(_1, phalcon_cache_frontend_none_ce); + if (zephir_has_constructor(_1 TSRMLS_CC)) { + ZEPHIR_INIT_VAR(_2); + zephir_create_array(_2, 1, 0 TSRMLS_CC); + ZEPHIR_OBS_VAR(_3); + zephir_read_property_this(&_3, this_ptr, SL("_lifetime"), PH_NOISY_CC); + zephir_array_update_string(&_2, SL("lifetime"), &_3, PH_COPY | PH_SEPARATE); + ZEPHIR_CALL_METHOD(NULL, _1, "__construct", NULL, 0, _2); + zephir_check_call_status(); + } ZEPHIR_CALL_METHOD(NULL, _0, "__construct", NULL, 316, _1, options); zephir_check_call_status(); zephir_update_property_this(this_ptr, SL("_redis"), _0 TSRMLS_CC); diff --git a/build/safe/phalcon.zep.h b/build/safe/phalcon.zep.h index 89cf6505f41..41c7cc4a29f 100644 --- a/build/safe/phalcon.zep.h +++ b/build/safe/phalcon.zep.h @@ -9778,11 +9778,11 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_db_profiler_item_setsqlstatement, 0, 0, 1 ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_db_profiler_item_setsqlvariables, 0, 0, 1) - ZEND_ARG_INFO(0, sqlVariables) + ZEND_ARG_ARRAY_INFO(0, sqlVariables, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_db_profiler_item_setsqlbindtypes, 0, 0, 1) - ZEND_ARG_INFO(0, sqlBindTypes) + ZEND_ARG_ARRAY_INFO(0, sqlBindTypes, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_db_profiler_item_setinitialtime, 0, 0, 1) diff --git a/build/safe/php_phalcon.h b/build/safe/php_phalcon.h index 4a60e53b947..df53cc57cd7 100644 --- a/build/safe/php_phalcon.h +++ b/build/safe/php_phalcon.h @@ -196,7 +196,7 @@ typedef zend_function zephir_fcall_cache_entry; #define PHP_PHALCON_NAME "phalcon" -#define PHP_PHALCON_VERSION "2.0.8" +#define PHP_PHALCON_VERSION "2.0.9" #define PHP_PHALCON_EXTNAME "phalcon" #define PHP_PHALCON_AUTHOR "Phalcon Team and contributors" #define PHP_PHALCON_ZEPVERSION "0.8.0a"