Skip to content

Instantly share code, notes, and snippets.

@matej21
Last active December 14, 2015 11:28
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save matej21/5079124 to your computer and use it in GitHub Desktop.
<?php
public function createComponent($name)
{
$ucname = ucfirst($name);
$method = 'createComponent' . $ucname;
if ($ucname !== $name && method_exists($this, $method)) {
$reflection = $this->getReflection()->getMethod($method);
if($reflection->getName() !== $method) {
return;
}
$parameters = $reflection->parameters;
$args = array();
if (($first = reset($parameters)) && !$first->className) {
$args[] = $name;
}
$args = Nette\DI\Helpers::autowireArguments($reflection, $args, $this->context);
$component = call_user_func_array(array($this, $method), $args);
if (!$component instanceof Nette\ComponentModel\IComponent && !isset($this->components[$name])) {
throw new Nette\UnexpectedValueException("Method $reflection did not return or create the desired component.");
}
return $component;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment