-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Phalcon\Registry #1935
Phalcon\Registry #1935
Conversation
Good idea. |
Benchmark results: Phalcon\Registry vs Read Test (
Read Test via explicit
Read Test using References (
Read Test (using ArrayAccess interface)
Write Test (
Write Test (ArrayAccess)
|
Question... Is this much different than Phalcon\Config? If so, how? I haven't used Phalcon much yet, but it seems like Phalcon\Config is somewhat used as a registry. |
@jymboche Yes, they are similar, however, there are a few differences:
|
With the latest optimizations (f2130da): Read Test
Read Test (
Read Test (reference)
Read Test (ArrayAccess)
Write Test
Write Test (ArrayAccess)
|
Having just recompiled Phalcon v1.3.0 I have started running into this: Phalcon\DI\Service::resolve(): Usage of Phalcon\DI to store non-objects is deprecated, please use Phalcon\Registry instead I am using Phalcon\Di to set Closures that perform certain tasks. Sometimes, the result of And it worked great. OK, I could split my $reg = new Phalcon\Registry;
$reg->reverse = function($el) {
return strrev($el);
}; I could revisit all my DI closures, make them set What's the harm in allowing to return strings, anyway? I am hoping that there's a way out of this and I won't have to rewrite two thirds of my app......... :( Thanks. |
Why you can't invoke the closure in the Registry? $str = $reg->reverse(); |
Because of this: echo $reg->reverse('zxcv');
PHP Fatal error: Call to undefined method Phalcon\Registry::reverse() |
But even if that worked - I think that |
Added that in #2105 |
Thanks! Can that DI error be removed, please? See my comment here: |
An awful idea. A registry is a global static object that moves through whole app. This component will make a lot of code untestable and generally should not exist (it was HUGE pain in ZF1 and was removed in ZF2). I don't understand either idea of putting closures into a registry. Would be the same as making them global, named functions. |
Fortunately, @phalcon has |
See #1209
A registry is a container for storing objects and values in the application space. By storing the value in a registry, the same object is always available throughout the application.
In addition to ArrayAccess, Phalcon\Registry implements ArrayAccess, Countable, Serializable and Iterator interfaces. For PHP 5.4 and higher, JsonSerializable interface is implemented.
Phalcon\Registry is very fast (it is typically faster than any userspace implementation of the registry); however, this comes at a price: Phalcon\Registry is a final class and cannot be inherited from.
Though Phalcon\Registry exposes methods like
__get()
,offsetGet()
,count()
etc, it is not recommended to invoke them manually (these method exists mainly to match the interfaces the registry implements):$registry->__get('property')
is several times slower than$registry->property
.Internally all the magic methods (and interfaces except JsonSerializable) are implemented using object handlers or similar techniques: this allows to bypass relatively slow method calls.