Skip to content

Instantly share code, notes, and snippets.

@devosc
Created March 23, 2015 14:54
Show Gist options
  • Save devosc/1e292b202683b32af4eb to your computer and use it in GitHub Desktop.
Save devosc/1e292b202683b32af4eb to your computer and use it in GitHub Desktop.
Scoped Hydration Callbacks
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