当前位置: 首页>>代码示例>>PHP>>正文


PHP Closure::bindTo方法代码示例

本文整理汇总了PHP中Closure::bindTo方法的典型用法代码示例。如果您正苦于以下问题:PHP Closure::bindTo方法的具体用法?PHP Closure::bindTo怎么用?PHP Closure::bindTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Closure的用法示例。


在下文中一共展示了Closure::bindTo方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: __construct

 /**
  * Constructs a test suite, which may contain nested suites and specs. The
  * anonymous function passed to the constructor contains the body of the
  * suite to be ran, and it is bound to the suite.
  *
  * @param string   $title   A title to be associated with the suite
  * @param \Closure $closure The closure to invoke when the suite is ran
  * @param Suite    $parent  An optional parent suite
  */
 public function __construct($title, \Closure $closure, Suite $parent = null)
 {
     $this->title = $title;
     if (version_compare(PHP_VERSION, '5.4.0', ">=")) {
         $this->closure = $closure->bindTo($this);
     } else {
         $this->closure = $closure;
     }
     $this->specs = array();
     $this->suites = array();
     $this->store = array();
     $this->parent = $parent;
 }
开发者ID:ciarand,项目名称:pho,代码行数:22,代码来源:Suite.php

示例2: proceed

 /**
  * Invokes original method and return result from it
  *
  * @return mixed
  */
 public function proceed()
 {
     if (isset($this->advices[$this->current])) {
         /** @var $currentInterceptor \Go\Aop\Intercept\Interceptor */
         $currentInterceptor = $this->advices[$this->current++];
         return $currentInterceptor->invoke($this);
     }
     // Fill the closure only once if it's empty
     if (!$this->closureToCall) {
         $this->closureToCall = $this->reflectionMethod->getClosure($this->instance);
     }
     // Rebind the closure if instance was changed since last time
     if ($this->previousInstance !== $this->instance) {
         $this->closureToCall = $this->closureToCall->bindTo($this->instance, $this->reflectionMethod->class);
         $this->previousInstance = $this->instance;
     }
     $closureToCall = $this->closureToCall;
     $args = $this->arguments;
     switch (count($args)) {
         case 0:
             return $closureToCall();
         case 1:
             return $closureToCall($args[0]);
         case 2:
             return $closureToCall($args[0], $args[1]);
         case 3:
             return $closureToCall($args[0], $args[1], $args[2]);
         case 4:
             return $closureToCall($args[0], $args[1], $args[2], $args[3]);
         case 5:
             return $closureToCall($args[0], $args[1], $args[2], $args[3], $args[4]);
         default:
             return forward_static_call_array($closureToCall, $args);
     }
 }
开发者ID:williamamed,项目名称:Raptor2,代码行数:40,代码来源:ClosureDynamicProceedTrait.php

示例3: get

 public function get()
 {
     if (!$this->closure instanceof \Closure) {
         throw new \RuntimeException("Cannot get a key with an undefined closure");
     }
     if ($this->enabled) {
         $data = $this->predis->get($this->getKeyName($this->key));
     }
     if ($data === null) {
         $boundCallback = $this->closure->bindTo($this);
         $data = $boundCallback();
         if ($this->enabled) {
             $this->predis->setex($this->getKeyName($this->key), $this->ttl, serialize($data));
         }
         if ($this->onMiss instanceof \Closure) {
             call_user_func_array($this->onMiss, [$this, $data]);
         }
         return $data;
     } else {
         $value = unserialize($data);
         if ($this->onHit instanceof \Closure) {
             call_user_func_array($this->onHit, [$this, $value]);
         }
         return $value;
     }
 }
开发者ID:jimbojsb,项目名称:cacheback,代码行数:26,代码来源:Key.php

示例4: discern

 /**
  * Handles the event
  *
  * @param Event $event
  * @return mixed|void
  */
 public function discern(Event $event)
 {
     if ($this->eventInstance && !$event instanceof $this->eventInstance) {
         return;
     }
     $callback = $this->callback->bindTo($this, $this);
     $callback($event);
 }
开发者ID:dlundgren,项目名称:watchtower,代码行数:14,代码来源:GenericCallback.php

示例5: execute

 /**
  * Execute the console command.
  *
  * @param \Symfony\Component\Console\Input\InputInterface   $input
  * @param \Symfony\Component\Console\Output\OutputInterface $output
  *
  * @return mixed
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $inputs = array_merge($input->getArguments(), $input->getOptions());
     $parameters = [];
     foreach ((new ReflectionFunction($this->callback))->getParameters() as $parameter) {
         if (isset($inputs[$parameter->name])) {
             $parameters[$parameter->name] = $inputs[$parameter->name];
         }
     }
     return $this->getInvoker()->call($this->callback->bindTo($this, $this), $parameters);
 }
开发者ID:narrowspark,项目名称:framework,代码行数:19,代码来源:ClosureCommand.php

示例6: __invoke

 /**
  * Runs the stub.
  *
  * @param  string $self   The context form which the stub need to be executed.
  * @param  array  $params The call parameters array.
  * @return mixed          The returned stub result.
  */
 public function __invoke($self, $params)
 {
     if ($this->_closure) {
         if (is_string($self)) {
             $closure = $this->_closure->bindTo(null, $self);
         } else {
             $closure = $this->_closure->bindTo($self, get_class($self));
         }
         return call_user_func_array($closure, $params);
     }
     if (isset($this->_returns[$this->_index])) {
         return $this->_returns[$this->_index++];
     }
     return $this->_returns ? end($this->_returns) : null;
 }
开发者ID:Ilyes512,项目名称:kahlan,代码行数:22,代码来源:Method.php

示例7: proceed

 /**
  * Invokes original method and return result from it
  *
  * @return mixed
  */
 public function proceed()
 {
     if (isset($this->advices[$this->current])) {
         /** @var $currentInterceptor MethodInterceptor */
         $currentInterceptor = $this->advices[$this->current++];
         return $currentInterceptor->invoke($this);
     }
     // Rebind the closure if scope (class name) was changed since last time
     if ($this->previousScope !== $this->instance) {
         $this->closureToCall = $this->closureToCall->bindTo(null, $this->instance);
         $this->previousScope = $this->instance;
     }
     $closureToCall = $this->closureToCall;
     return $closureToCall($this->arguments);
 }
开发者ID:latamautos,项目名称:goaop,代码行数:20,代码来源:ClosureStaticMethodInvocation.php

示例8: customInit

 /**
  * @return void
  */
 public final function customInit()
 {
     if ($this->customInitClosure instanceof \Closure) {
         $customInitClosure = $this->customInitClosure->bindTo($this, $this);
         $customInitClosure();
     }
 }
开发者ID:phpcrystal,项目名称:phpcrystal,代码行数:10,代码来源:AbstractService.php

示例9: on

 public function on($event, \Closure $callback)
 {
     if (is_string($event)) {
         $this->events[$event] = $callback->bindTo($this, $this);
     }
     return $this;
 }
开发者ID:cyan-framework,项目名称:library,代码行数:7,代码来源:websocket.php

示例10: __construct

 /**
  * Constructs a Spec, to be associated with a particular suite, and ran
  * by the test runner. The closure is bound to the suite.
  *
  * @param string   $title   A title to be associated with the spec
  * @param \Closure $closure The closure to invoke when the spec is called
  * @param Suite    $suite   The suite within which this spec was defined
  */
 public function __construct($title, \Closure $closure = null, Suite $suite)
 {
     $this->title = $title;
     $this->suite = $suite;
     if ($closure) {
         $this->closure = $closure->bindTo($suite);
     }
 }
开发者ID:gsouf,项目名称:pho,代码行数:16,代码来源:Spec.php

示例11: add

 /**
  * Registers a route.
  *
  * @param  string $name
  * @param  \Closure $handler
  *
  * @return Route
  */
 public function add($name, \Closure $handler)
 {
     // Bind the handler to the Router class
     $route = new Route($name, $handler->bindTo($this, $this));
     // Insert the route
     $this->routes[$name] = $route;
     return $route;
 }
开发者ID:domynation,项目名称:domynation-framework,代码行数:16,代码来源:Router.php

示例12: fingerprint

 public function fingerprint(\Closure $fingerprint = null)
 {
     if (func_num_args() > 0) {
         $this->_fingerprint = $fingerprint->bindTo($this);
         return $this;
     }
     return $this->_fingerprint;
 }
开发者ID:jacksleight,项目名称:coast,代码行数:8,代码来源:Session.php

示例13: group

 /**
  * @param string $prefix
  * @param \Closure $closure
  */
 public function group($prefix, \Closure $closure)
 {
     $original = $this->prefix;
     $this->prefix = sprintf('/%s/%s', trim($original, '/'), trim($prefix, '/'));
     $callback = $closure->bindTo($this);
     $callback();
     $this->prefix = $original;
 }
开发者ID:pkdevboxy,项目名称:tez,代码行数:12,代码来源:Router.php

示例14: __construct

 public function __construct(\Closure $closure, Suite $suite)
 {
     $this->suite = $suite;
     if (version_compare(PHP_VERSION, '5.4.0', '>=')) {
         $this->closure = $closure->bindTo($suite);
     } else {
         $this->closure = $closure;
     }
 }
开发者ID:ciarand,项目名称:pho,代码行数:9,代码来源:RunnableSpec.php

示例15: proceed

 /**
  * Invokes original method and return result from it
  *
  * @return mixed
  */
 public function proceed()
 {
     if (isset($this->advices[$this->current])) {
         /** @var $currentInterceptor Interceptor */
         $currentInterceptor = $this->advices[$this->current++];
         return $currentInterceptor->invoke($this);
     }
     // Fill the closure only once if it's empty
     if (!$this->closureToCall) {
         $this->closureToCall = $this->reflectionMethod->getClosure($this->instance);
     }
     // Rebind the closure if instance was changed since last time
     if ($this->previousInstance !== $this->instance) {
         $this->closureToCall = $this->closureToCall->bindTo($this->instance, $this->reflectionMethod->class);
         $this->previousInstance = $this->instance;
     }
     $closureToCall = $this->closureToCall;
     return $closureToCall(...$this->arguments);
 }
开发者ID:quickmobile,项目名称:go-aop-php,代码行数:24,代码来源:ClosureSplatDynamicProceedTrait.php


注:本文中的Closure::bindTo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。