public function testHasMethod() { $definitionClass = new ClassDefinition('foo'); $definitionClass->addMethod('doFoo'); $definitionList = new DefinitionList(array($definitionClass)); $this->assertTrue($definitionList->hasMethod('foo', 'doFoo')); $this->assertFalse($definitionList->hasMethod('foo', 'doBar')); $definitionClass->addMethod('doBar'); $this->assertTrue($definitionList->hasMethod('foo', 'doBar')); }
public function testHasMethodAvoidAskingFromDefinitionsWhichDoNotIncludeClass() { $builderDefinition = new BuilderDefinition(); $definitionClass = new ClassDefinition('foo'); $definitionClass->addMethod('doFoo'); $definitionList = new DefinitionList(array($builderDefinition, $definitionClass)); $this->assertTrue($definitionList->hasMethod('foo', 'doFoo')); }
/** * Get an object instance from the defined callback * * @param callable $callback * @param array $params * @param string $alias * @return object * @throws Exception\InvalidCallbackException * @throws Exception\RuntimeException */ protected function createInstanceViaCallback($callback, $params, $alias) { if (!is_callable($callback)) { throw new Exception\InvalidCallbackException('An invalid constructor callback was provided'); } if (is_array($callback)) { $class = is_object($callback[0]) ? $this->getClass($callback[0]) : $callback[0]; $method = $callback[1]; } elseif (is_string($callback) && strpos($callback, '::') !== false) { list($class, $method) = explode('::', $callback, 2); } else { throw new Exception\RuntimeException('Invalid callback type provided to ' . __METHOD__); } $callParameters = array(); if ($this->definitions->hasMethod($class, $method)) { $callParameters = $this->resolveMethodParameters($class, $method, $params, $alias, self::METHOD_IS_INSTANTIATOR, true); } return call_user_func_array($callback, $callParameters); }