From 772a002acf0daaa0ad57470694e1e8f08a62a95e Mon Sep 17 00:00:00 2001 From: Fenikkusu Date: Wed, 28 Aug 2019 23:22:12 -0400 Subject: [PATCH] Adding Passback To DIC, Updating Documentation --- CHANGELOG-4.0.md | 1 + phalcon/Di/Service.zep | 5 +++-- tests/unit/Di/ServiceCest.php | 19 +++++++++++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/CHANGELOG-4.0.md b/CHANGELOG-4.0.md index 26eb87ead6c..aea40c3fe7c 100644 --- a/CHANGELOG-4.0.md +++ b/CHANGELOG-4.0.md @@ -8,6 +8,7 @@ - Changed `Phalcon\Flash\Direct` to allow `escaper` in the constructor [#14349](https://github.com/phalcon/cphalcon/issues/14349) - Changed `Phalcon\Flash\Session` to allow `escaper` in the constructor [#14349](https://github.com/phalcon/cphalcon/issues/14349) - Changed `Phalcon\Di\AbstractDIAware` to `Phalcon\Di\AbstractInjectionAware` [#14359](https://github.com/phalcon/cphalcon/issues/14359) +- Changed `Phalcon\Di\Service` to use DI to initialize `string` based services when possible [#14342](https://github.com/phalcon/cphalcon/pull/14342) ## Fixed - Fixed `Phalcon\Helper\Str::includes` to return correct result [#14301](https://github.com/phalcon/cphalcon/issues/14301) diff --git a/phalcon/Di/Service.zep b/phalcon/Di/Service.zep index 07e1bea5036..30bd6445a2b 100644 --- a/phalcon/Di/Service.zep +++ b/phalcon/Di/Service.zep @@ -134,11 +134,12 @@ class Service implements ServiceInterface let definition = this->definition; if typeof definition == "string" { - /** * String definitions can be class names without implicit parameters */ - if class_exists(definition) { + if container !== null { + let instance = container->get(definition, parameters); + } elseif class_exists(definition) { if typeof parameters == "array" && count(parameters) { let instance = create_instance_params( definition, diff --git a/tests/unit/Di/ServiceCest.php b/tests/unit/Di/ServiceCest.php index ce9228cfb0c..72f8853915b 100644 --- a/tests/unit/Di/ServiceCest.php +++ b/tests/unit/Di/ServiceCest.php @@ -61,4 +61,23 @@ function () { $di->getService('notResolved')->isResolved() ); } + + public function testAlias(UnitTester $I) + { + $escaper = new Escaper(); + + $di = new Di(); + + $di->set( + 'resolved', + Escaper::class + ); + + $di->set(Escaper::class, $escaper); + + $I->assertSame( + $escaper, + $di->get('resolved') + ); + } }