From bbddaef07955be31abff447262588d013b995dd7 Mon Sep 17 00:00:00 2001 From: Nikolaos Dimopoulos Date: Fri, 12 Jan 2024 18:03:50 -0600 Subject: [PATCH 1/5] removing cache from injectable --- phalcon/Di/Di.zep | 16 +++++++-------- phalcon/Di/Injectable.zep | 42 ++++++++++++++++++++++++++++++--------- 2 files changed, 41 insertions(+), 17 deletions(-) diff --git a/phalcon/Di/Di.zep b/phalcon/Di/Di.zep index c7c1851d88..9cddb5964f 100644 --- a/phalcon/Di/Di.zep +++ b/phalcon/Di/Di.zep @@ -340,6 +340,14 @@ class Di implements DiInterface return instance; } + /** + * Check whether the DI contains a service by a name + */ + public function has(string! name) -> bool + { + return isset this->services[name]; + } + /** * Loads services from a Config object. */ @@ -441,14 +449,6 @@ class Di implements DiInterface this->loadFromConfig(services); } - /** - * Check whether the DI contains a service by a name - */ - public function has(string! name) -> bool - { - return isset this->services[name]; - } - /** * Allows to obtain a shared service using the array syntax * diff --git a/phalcon/Di/Injectable.zep b/phalcon/Di/Injectable.zep index fdca331f6a..77c64f5053 100644 --- a/phalcon/Di/Injectable.zep +++ b/phalcon/Di/Injectable.zep @@ -62,36 +62,60 @@ abstract class Injectable extends stdClass implements InjectionAwareInterface let container = this->getDI(); if propertyName === "di" { - let this->{"di"} = container; - return container; } +// if propertyName === "di" { +// let this->{"di"} = container; +// +// return container; +// } +// /** * Accessing the persistent property will create a session bag on any class */ if propertyName === "persistent" { - let this->{"persistent"} = container->get( + return container->get( "sessionBag", [ get_class(this), container ] ); - - return this->{"persistent"}; } +// /** +// * Accessing the persistent property will create a session bag on any class +// */ +// if propertyName === "persistent" { +// let this->{"persistent"} = container->get( +// "sessionBag", +// [ +// get_class(this), +// container +// ] +// ); +// +// return this->{"persistent"}; +// } + /** * Fallback to the PHP userland if the cache is not available */ if container->has(propertyName) { - let service = container->getShared(propertyName); - let this->{propertyName} = service; - - return service; + return container->getShared(propertyName); } +// /** +// * Fallback to the PHP userland if the cache is not available +// */ +// if container->has(propertyName) { +// let service = container->getShared(propertyName); +// let this->{propertyName} = service; +// +// return service; +// } +// /** * A notice is shown if the property is not defined and isn't a valid service */ From af7ad6cd4d32a288b635d9ae8b2c2803cd502a6e Mon Sep 17 00:00:00 2001 From: Nikolaos Dimopoulos Date: Fri, 12 Jan 2024 18:15:22 -0600 Subject: [PATCH 2/5] Revert "removing cache from injectable" This reverts commit 6c280f9e208d8f20c24c8d1770f4407cacee9a80. --- phalcon/Di/Di.zep | 16 +++++++-------- phalcon/Di/Injectable.zep | 42 +++++++++------------------------------ 2 files changed, 17 insertions(+), 41 deletions(-) diff --git a/phalcon/Di/Di.zep b/phalcon/Di/Di.zep index 9cddb5964f..c7c1851d88 100644 --- a/phalcon/Di/Di.zep +++ b/phalcon/Di/Di.zep @@ -340,14 +340,6 @@ class Di implements DiInterface return instance; } - /** - * Check whether the DI contains a service by a name - */ - public function has(string! name) -> bool - { - return isset this->services[name]; - } - /** * Loads services from a Config object. */ @@ -449,6 +441,14 @@ class Di implements DiInterface this->loadFromConfig(services); } + /** + * Check whether the DI contains a service by a name + */ + public function has(string! name) -> bool + { + return isset this->services[name]; + } + /** * Allows to obtain a shared service using the array syntax * diff --git a/phalcon/Di/Injectable.zep b/phalcon/Di/Injectable.zep index 77c64f5053..fdca331f6a 100644 --- a/phalcon/Di/Injectable.zep +++ b/phalcon/Di/Injectable.zep @@ -62,60 +62,36 @@ abstract class Injectable extends stdClass implements InjectionAwareInterface let container = this->getDI(); if propertyName === "di" { + let this->{"di"} = container; + return container; } -// if propertyName === "di" { -// let this->{"di"} = container; -// -// return container; -// } -// /** * Accessing the persistent property will create a session bag on any class */ if propertyName === "persistent" { - return container->get( + let this->{"persistent"} = container->get( "sessionBag", [ get_class(this), container ] ); - } -// /** -// * Accessing the persistent property will create a session bag on any class -// */ -// if propertyName === "persistent" { -// let this->{"persistent"} = container->get( -// "sessionBag", -// [ -// get_class(this), -// container -// ] -// ); -// -// return this->{"persistent"}; -// } + return this->{"persistent"}; + } /** * Fallback to the PHP userland if the cache is not available */ if container->has(propertyName) { - return container->getShared(propertyName); + let service = container->getShared(propertyName); + let this->{propertyName} = service; + + return service; } -// /** -// * Fallback to the PHP userland if the cache is not available -// */ -// if container->has(propertyName) { -// let service = container->getShared(propertyName); -// let this->{propertyName} = service; -// -// return service; -// } -// /** * A notice is shown if the property is not defined and isn't a valid service */ From b59ca0bbb759cfe0e8c0cd13b19ff4ebbacc5fda Mon Sep 17 00:00:00 2001 From: Nikolaos Dimopoulos Date: Thu, 18 Jan 2024 07:58:28 -0600 Subject: [PATCH 3/5] added return types --- phalcon/Cache/AbstractCache.zep | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phalcon/Cache/AbstractCache.zep b/phalcon/Cache/AbstractCache.zep index 53c8a3ac5a..06cd30a711 100644 --- a/phalcon/Cache/AbstractCache.zep +++ b/phalcon/Cache/AbstractCache.zep @@ -144,7 +144,7 @@ abstract class AbstractCache implements CacheInterface * @throws InvalidArgumentException MUST be thrown if the $key string is * not a legal value. */ - protected function doGet(string key, var defaultValue = null) + protected function doGet(string key, var defaultValue = null) -> var { this->checkKey(key); @@ -154,7 +154,7 @@ abstract class AbstractCache implements CacheInterface /** * Obtains multiple cache items by their unique keys. */ - protected function doGetMultiple(var keys, var defaultValue = null) + protected function doGetMultiple(var keys, var defaultValue = null) -> array { var element, results; From e9f66f731b9f8f3d62770e0bd04733ab3ec4f670 Mon Sep 17 00:00:00 2001 From: Nikolaos Dimopoulos Date: Thu, 18 Jan 2024 08:28:48 -0600 Subject: [PATCH 4/5] fixing toArray to ignore getters for 'source' field --- phalcon/Mvc/Model.zep | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/phalcon/Mvc/Model.zep b/phalcon/Mvc/Model.zep index c0532165cf..9276217bcd 100644 --- a/phalcon/Mvc/Model.zep +++ b/phalcon/Mvc/Model.zep @@ -3328,7 +3328,10 @@ abstract class Model extends AbstractInjectionAware implements EntityInterface, */ let method = "get" . camelize(attributeField); - if true === useGetter && method_exists(this, method) { + /** + * Do not use the getter if the field name is `source` (getSource) + */ + if true === useGetter && "getSource" !== method && method_exists(this, method) { let data[attributeField] = this->{method}(); } elseif isset(this->{attributeField}) { let data[attributeField] = this->{attributeField}; From d2ea714ba9e526854371012c390489c0127847a6 Mon Sep 17 00:00:00 2001 From: Nikolaos Dimopoulos Date: Thu, 18 Jan 2024 08:28:54 -0600 Subject: [PATCH 5/5] updating changelog --- CHANGELOG-5.0.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG-5.0.md b/CHANGELOG-5.0.md index b9082a9885..c47eb143ca 100644 --- a/CHANGELOG-5.0.md +++ b/CHANGELOG-5.0.md @@ -12,6 +12,7 @@ - Fixed `Phalcon\Db\Adapter\Pdo\Postgresql::describeColumns()` to return the correct string back [#16371](https://github.com/phalcon/cphalcon/issues/16371) - Fixed `Phalcon/Filter/Validation::validate()` and `Phalcon/Filter/Validation/ValidationInterface::validate()` to return also `bool` [#16337](https://github.com/phalcon/cphalcon/issues/16337) +- Fixed `Phalcon\Mvc\Model::toArray` to ignore getters when the field name is `source`. [#16514](https://github.com/phalcon/cphalcon/issues/16514) ### Removed