Skip to content

Instantly share code, notes, and snippets.

@linxlad
Created May 15, 2017 08:23
Show Gist options
  • Save linxlad/232225dda78d274d8a5ca18a55b1bc29 to your computer and use it in GitHub Desktop.
Save linxlad/232225dda78d274d8a5ca18a55b1bc29 to your computer and use it in GitHub Desktop.
Deferred services in Phalcon 3.
<?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