-
-
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
[BUG] \Phalcon\DI #1209
Comments
DI is a dependency injection and service resolver component, it does not act as a registry. |
@phalcon |
You can create a real registry: class MyRegistry
{
private $items = array();
public function get($key)
{
return $this->_items[$key];
}
public function set($key, $value)
{
$this->_items[$key] = $value;
}
} Service registration: $di['registry'] = new MyRegistry(); Usage: $registry = $di->getRegistry();
$registry->set('my-record', Records::findFirst());
$record = $registry->get('my-record'); |
But now in view I need. $this->registry->get('identity'); Not beautiful use |
But that would allow a developer to give an incorrect usage to the DI, so in the future we will have false "bugs" or NFR with:
$di->set('x', 'yyy');
|
Well, class MyRegistry
{
private $items = array();
public function __get($key)
{
return $this->_items[$key];
}
public function __set($key, $value)
{
$this->_items[$key] = $value;
}
} and then use
a bit shorter :-) |
Good point — registry and dependency injector are different entities. |
$di->set('ex1', function() {return 'sdgdsg';});
var_dump($di->get('ex1'));
$di->set('ex2', function() {return false;});
var_dump($di->get('ex2')); https://github.com/phalcon/cphalcon/blob/1.3.0/ext/di.c#L113 |
What if we check in Phalcon\DI\Service::resolve() what the service has been resolved to and throw an exception if it is not an object? |
after we create this condition for check resolve it broke my app )) it broke back support need to be in 1.3.0 and important fix |
This condition has not been added yet as far as I know. |
yeap but i only notice about that condition will crash backward compatibility ^_^ |
Yes, need to emit E_DEPRECATED there :-) |
@zaets28rus This has been merged, could you please test and close the issue if everything works for you? |
I've commented on this here: #1935 Can we please have a switch that would allow us to return strings? It's been a disastrous patch, really. |
@phalcon Need your opinion. |
I would like to explain my position once more. I totally understand why you introduced
$di->set('myObj', function ($returnAsJson = false) {
$obj = new Obj;
if ($returnAsJson) {
return $obj->asJson();
}
return $obj;
});
$json = $di->get('myObj', true); And that was great. In my opinion, implementation of Will be happy to hear your opinions. Thanks! |
@phalcon ping |
You can use Phalcon\Registry in case you need a registry |
Hi all)
Bug with boolean and service consruct in di
i am n`t c developer
ovr@663624f
Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.
The text was updated successfully, but these errors were encountered: