Esempio n. 1
0
 /**
  * {@inheritdoc}
  */
 public function resolve(MessageInterface $message)
 {
     $nameOfMessage = $this->nameOfMessageResolver->resolve($message);
     $handler = $this->getHandlerFor($nameOfMessage);
     $handlerMethodName = $this->getHandlerMethodFor($nameOfMessage);
     if (!method_exists($handler, $handlerMethodName)) {
         throw NotFoundException::methodForObject($handler, $handlerMethodName);
     }
     return Delegate::fromMethod($handler, $handlerMethodName);
 }
Esempio n. 2
0
 /**
  * {@inheritdoc}
  */
 public function apply($value)
 {
     if (!is_object($value)) {
         throw new \RuntimeException('Trying to call method of non-object');
     }
     if (!method_exists($value, $this->name)) {
         throw new \RuntimeException(\sprintf('Undefined method %s::%s', \get_class($value), $this->name));
     }
     $method = Delegate::fromMethod($value, $this->name);
     if ($method->reflection()->isPrivate() || $method->reflection()->isProtected()) {
         throw new \RuntimeException(\sprintf('Trying to call non-public method %s::%s', \get_class($value), $this->name));
     }
     return $method->invokeWith($this->args());
 }
Esempio n. 3
0
 /**
  * @param BinaryConstraintOperator $operator
  */
 protected function visitNotEqualityOperator(BinaryConstraintOperator $operator)
 {
     $this->visitRelationalOperator($operator, Delegate::fromMethod($this->queryBuilder, 'notEqual'));
 }
Esempio n. 4
0
 /**
  * @param string $method
  * @param array  $arguments
  *
  * @return mixed
  */
 public static function __callStatic($method, $arguments)
 {
     return Delegate::fromMethod(self::this(), $method)->invokeWith($arguments);
 }
Esempio n. 5
0
 /**
  * Test reflection method.
  */
 public function testReflection()
 {
     $this->given($closure = function ($value = null) {
         return $value;
     })->when($reflection = Delegate::fromClosure($closure)->reflection())->then()->object($reflection)->isEqualTo(new \ReflectionFunction($closure));
     $this->when($reflection = Delegate::fromMethod($this, 'sampleMethod')->reflection())->then()->object($reflection)->isEqualTo(new \ReflectionMethod($this, 'sampleMethod'));
     $this->given($foo = new FooCallable())->when($reflection = (new Delegate($foo))->reflection())->then()->object($reflection)->isEqualTo(new \ReflectionMethod($foo, '__invoke'));
     $this->when($reflection = Delegate::fromStaticMethod(self::class, 'sampleStaticMethod')->reflection())->then()->object($reflection)->isEqualTo(new \ReflectionMethod(self::class . '::sampleStaticMethod'));
 }