コード例 #1
0
ファイル: CallablePromisor.php プロジェクト: cubiche/cubiche
 protected function execute()
 {
     try {
         $this->deferred()->resolve($this->delegate->invokeWith(\func_get_args()));
     } catch (\Exception $e) {
         $this->deferred()->reject($e);
     }
 }
コード例 #2
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);
 }
コード例 #3
0
ファイル: Method.php プロジェクト: cubiche/cubiche
 /**
  * {@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());
 }
コード例 #4
0
ファイル: Timer.php プロジェクト: cubiche/cubiche
 /**
  */
 private function onTick()
 {
     try {
         $this->lastResult = $this->task->__invoke($this);
         ++$this->iterations;
         if ($this->timer->isPeriodic()) {
             $this->deferred()->notify($this->lastResult);
             if ($this->maxIterations() !== null && $this->iterations() >= $this->maxIterations()) {
                 $this->cancel();
             }
         } else {
             $this->deferred()->resolve($this->lastResult);
         }
     } catch (\Exception $e) {
         $this->deferred()->reject($e);
         $this->timer->cancel();
     }
 }
コード例 #5
0
ファイル: LockingMiddleware.php プロジェクト: cubiche/cubiche
 /**
  * Execute the given message... after other running messages are complete.
  *
  * @param mixed    $message
  * @param callable $next
  *
  * @throws \Exception
  */
 public function handle($message, callable $next)
 {
     $this->queue[] = Delegate::fromClosure(function () use($message, $next) {
         return $next($message);
     });
     if ($this->isRunning) {
         return;
     }
     $this->isRunning = true;
     try {
         $this->runQueuedJobs();
     } catch (\Exception $e) {
         $this->isRunning = false;
         $this->queue = [];
         throw $e;
     }
     $this->isRunning = false;
 }
コード例 #6
0
ファイル: PromiseTests.php プロジェクト: cubiche/cubiche
 /**
  * {@inheritdoc}
  */
 protected function notify($state = null)
 {
     $this->notify->__invoke($state);
 }
コード例 #7
0
 /**
  * @return callable
  */
 public function target()
 {
     return $this->callbackDelegate->target();
 }
コード例 #8
0
 /**
  * {@inheritdoc}
  */
 public function equals($a, $b)
 {
     return $this->callbackDelegate->__invoke($a, $b);
 }
コード例 #9
0
 /**
  * {@inheritdoc}
  */
 public function compare($a, $b)
 {
     return $this->direction()->value() * parent::compare($this->selector->__invoke($a), $this->selector->__invoke($b));
 }
コード例 #10
0
 /**
  * @param BinaryConstraintOperator $operator
  */
 protected function visitNotEqualityOperator(BinaryConstraintOperator $operator)
 {
     $this->visitRelationalOperator($operator, Delegate::fromMethod($this->queryBuilder, 'notEqual'));
 }
コード例 #11
0
ファイル: Criteria.php プロジェクト: cubiche/cubiche
 /**
  * @param string $method
  * @param array  $arguments
  *
  * @return mixed
  */
 public static function __callStatic($method, $arguments)
 {
     return Delegate::fromMethod(self::this(), $method)->invokeWith($arguments);
 }
コード例 #12
0
ファイル: Bus.php プロジェクト: cubiche/cubiche
 /**
  * @return Delegate
  */
 private function chainedExecution()
 {
     $middlewares = [];
     foreach ($this->middlewares as $priority => $collection) {
         foreach ($collection as $middleware) {
             $middlewares[] = $middleware;
         }
     }
     $next = Delegate::fromClosure(function ($message) {
         // the final middleware return the same message
         return $message;
     });
     // reverse iteration over middlewares
     /** @var MiddlewareInterface $middleware */
     while ($middleware = array_pop($middlewares)) {
         $next = Delegate::fromClosure(function ($message) use($middleware, $next) {
             return $middleware->handle($message, $next);
         });
     }
     return $next;
 }
コード例 #13
0
ファイル: QueryBuilder.php プロジェクト: cubiche/cubiche
 /**
  * @return static
  */
 public function createQueryBuilder()
 {
     return $this->factory->__invoke();
 }
コード例 #14
0
ファイル: DelegateTests.php プロジェクト: cubiche/cubiche
 /**
  * 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'));
 }
コード例 #15
0
ファイル: DelegateListener.php プロジェクト: cubiche/cubiche
 /**
  * @param callable $callable
  */
 public function __construct($callable)
 {
     parent::__construct($callable);
     $this->callback = $callable;
 }