Permalink
Browse files

Don't use reflection when it is not necessary.

  • Loading branch information...
markstory committed Jan 19, 2014
1 parent 197d475 commit 2d7e291a6767f02af84ae46be24c0fb827c93bbd
Showing with 10 additions and 6 deletions.
  1. +10 −6 src/View/Input/InputRegistry.php
@@ -88,7 +88,7 @@ public function __construct(StringTemplate $templates, array $widgets = null) {
* @return void
*/
public function add(array $widgets) {
- $this->_widgets = array_merge($this->_widgets, $widgets);
+ $this->_widgets = $widgets + $this->_widgets;
}
/**
@@ -140,12 +140,16 @@ protected function _resolveWidget($widget) {
if ($className === false || !class_exists($className)) {
throw new \RuntimeException(sprintf('Unable to locate widget class "%s"', $class));
}
- $reflection = new ReflectionClass($className);
- $arguments = [$this->_templates];
- foreach ($widget as $requirement) {
- $arguments[] = $this->get($requirement);
+ if (count($widget)) {
+ $reflection = new ReflectionClass($className);
+ $arguments = [$this->_templates];
+ foreach ($widget as $requirement) {
+ $arguments[] = $this->get($requirement);
+ }
+ $instance = $reflection->newInstanceArgs($arguments);
+ } else {
+ $instance = new $className($this->_templates);
}
- $instance = $reflection->newInstanceArgs($arguments);
if (!($instance instanceof InputInterface)) {
throw new \RuntimeException(sprintf('"%s" does not implement the InputInterface', $className));
}

0 comments on commit 2d7e291

Please sign in to comment.