Created
March 23, 2015 14:54
-
-
Save devosc/1e292b202683b32af4eb to your computer and use it in GitHub Desktop.
Scoped Hydration Callbacks
This file contains hidden or 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
protected function hydrate(Config $config, $service) | |
{ | |
foreach($config->calls() as $method => $value) { | |
if (is_string($method)) { | |
if (Args::PROPERTY == $method[0]) { | |
$service->{substr($method, 1)} = $this->resolve($value); | |
continue; | |
} | |
$service->$method($this->resolve($value)); | |
continue; | |
} | |
if (is_array($value)) { | |
list($method, $args) = $value; | |
if (!is_string($method)) { | |
$this->invoke($method, $args); | |
continue; | |
} | |
is_string($args) ? $this->invoke($value) : $this->invoke([$service, $method], $args); | |
continue; | |
} | |
if ($value instanceof Closure) { | |
$this->invoke(Closure::bind($value, $service, $service)); | |
continue; | |
} | |
$this->resolve($value); | |
} | |
return $service; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment