Created
May 15, 2017 08:23
-
-
Save linxlad/232225dda78d274d8a5ca18a55b1bc29 to your computer and use it in GitHub Desktop.
Deferred services in Phalcon 3.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$di->set('deferred.classes', $deferred = [ | |
'mail.selected_adapter' => Closure, | |
'mail' => Closure, | |
'db' => Closure, | |
'log' => Closure, | |
]); | |
function resolve($alias) | |
{ | |
if (!$di->has($alias)) { | |
return $di->get($alias); | |
} | |
$deferred = $di->get('deferred.classes'); | |
if (isset($deffered[$alias])) { | |
// Do the binding process manually register using: | |
// $di->set($alias, call_user_func_array($callback, $params)); | |
return $di->get($alias); | |
} | |
throw new RuntimeException('Unable to resolve alias ['.$alias.'].'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment