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


PHP ReflectionFunction::getClosureThis方法代码示例

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


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

示例1: wrapClosures

 /**
  * Recursively traverses and wraps all Closure objects within the value.
  *
  * NOTE: THIS MAY NOT WORK IN ALL USE CASES, SO USE AT YOUR OWN RISK.
  *
  * @param mixed $data Any variable that contains closures.
  * @param SerializerInterface $serializer The serializer to use.
  */
 public static function wrapClosures(&$data, SerializerInterface $serializer)
 {
     if ($data instanceof \Closure) {
         // Handle and wrap closure objects.
         $reflection = new \ReflectionFunction($data);
         if ($binding = $reflection->getClosureThis()) {
             self::wrapClosures($binding, $serializer);
             $scope = $reflection->getClosureScopeClass();
             $scope = $scope ? $scope->getName() : 'static';
             $data = $data->bindTo($binding, $scope);
         }
         $data = new SerializableClosure($data, $serializer);
     } elseif (is_array($data) || $data instanceof \stdClass || $data instanceof \Traversable) {
         // Handle members of traversable values.
         foreach ($data as &$value) {
             self::wrapClosures($value, $serializer);
         }
     } elseif (is_object($data) && !$data instanceof \Serializable) {
         // Handle objects that are not already explicitly serializable.
         $reflection = new \ReflectionObject($data);
         if (!$reflection->hasMethod('__sleep')) {
             foreach ($reflection->getProperties() as $property) {
                 if ($property->isPrivate() || $property->isProtected()) {
                     $property->setAccessible(true);
                 }
                 $value = $property->getValue($data);
                 self::wrapClosures($value, $serializer);
                 $property->setValue($data, $value);
             }
         }
     }
 }
开发者ID:betes-curieuses-design,项目名称:ElieJosiePhotographie,代码行数:40,代码来源:Serializer.php

示例2: parse

 public function parse(&$variable)
 {
     if (!$variable instanceof Closure) {
         return false;
     }
     $this->name = 'Closure';
     $reflection = new ReflectionFunction($variable);
     $ret = array('Parameters' => array());
     if ($val = $reflection->getParameters()) {
         foreach ($val as $parameter) {
             // todo http://php.net/manual/en/class.reflectionparameter.php
             $ret['Parameters'][] = $parameter->name;
         }
     }
     if ($val = $reflection->getStaticVariables()) {
         $ret['Uses'] = $val;
     }
     if ($val = $reflection->getClosureThis()) {
         $ret['Uses']['$this'] = $val;
     }
     if ($val = $reflection->getFileName()) {
         $this->value = Kint::shortenPath($val) . ':' . $reflection->getStartLine();
     }
     return $ret;
 }
开发者ID:Tacit007,项目名称:Calenda,代码行数:25,代码来源:closure.php

示例3: isClosureStatic

 private function isClosureStatic(\Closure $closure)
 {
     $closure = @$closure->bindTo(new \stdClass());
     if ($closure === null) {
         return true;
     }
     $rebound = new \ReflectionFunction($closure);
     return $rebound->getClosureThis() === null;
 }
开发者ID:focuslife,项目名称:v0.1,代码行数:9,代码来源:ClosureAnalyzer.php

示例4: isBindable

 /**
  * Checks if callable is bindable.
  *
  * @param \Closure $callable
  * @return bool
  */
 function isBindable(Closure $callable)
 {
     $bindable = false;
     $reflectionFunction = new \ReflectionFunction($callable);
     if ($reflectionFunction->getClosureScopeClass() === null || $reflectionFunction->getClosureThis() !== null) {
         $bindable = true;
     }
     return $bindable;
 }
开发者ID:lunnlew,项目名称:Norma_Code,代码行数:15,代码来源:Macroable.php

示例5: unwrap

 public static function unwrap(\Closure $closure)
 {
     $reflectionFunction = new \ReflectionFunction($closure);
     if (substr($reflectionFunction->getName(), -1) === '}') {
         $vars = $reflectionFunction->getStaticVariables();
         return isset($vars['_callable_']) ? $vars['_callable_'] : $closure;
     } else {
         if ($obj = $reflectionFunction->getClosureThis()) {
             return [$obj, $reflectionFunction->getName()];
         } else {
             if ($class = $reflectionFunction->getClosureScopeClass()) {
                 return [$class->getName(), $reflectionFunction->getName()];
             }
         }
     }
     return $reflectionFunction->getName();
 }
开发者ID:edde-framework,项目名称:edde,代码行数:17,代码来源:CallbackUtils.php

示例6: afterTraverse

 public function afterTraverse(array $nodes)
 {
     if ($this->location['class']) {
         $this->location['class'] = $this->location['namespace'] . '\\' . $this->location['class'];
         $this->location['method'] = "{$this->location['class']}::{$this->location['function']}";
     } elseif ($this->location['trait']) {
         $this->location['trait'] = $this->location['namespace'] . '\\' . $this->location['trait'];
         $this->location['method'] = "{$this->location['trait']}::{$this->location['function']}";
         // If the closure was declared in a trait, then we will do a best
         // effort guess on the name of the class that used the trait. It's
         // actually impossible at this point to know for sure what it is.
         if ($closureScope = $this->reflection->getClosureScopeClass()) {
             $this->location['class'] = $closureScope ? $closureScope->getName() : null;
         } elseif ($closureThis = $this->reflection->getClosureThis()) {
             $this->location['class'] = get_class($closureThis);
         }
     }
 }
开发者ID:cruni505,项目名称:prestomed,代码行数:18,代码来源:ClosureLocatorVisitor.php

示例7: setCode

 /**
  * Sets the code to execute when running this command.
  *
  * If this method is used, it overrides the code defined
  * in the execute() method.
  *
  * @param callable $code A callable(InputInterface $input, OutputInterface $output)
  *
  * @return Command The current instance
  *
  * @throws \InvalidArgumentException
  *
  * @see execute()
  *
  * @api
  */
 public function setCode($code)
 {
     if (!is_callable($code)) {
         throw new \InvalidArgumentException('Invalid callable provided to Command::setCode.');
     }
     if ($code instanceof \Closure) {
         $r = new \ReflectionFunction($code);
         if (null === $r->getClosureThis()) {
             $code = \Closure::bind($code, $this);
         }
     }
     $this->code = $code;
     return $this;
 }
开发者ID:yonetici,项目名称:pimcore-coreshop-demo,代码行数:30,代码来源:Command.php

示例8: setCode

 /**
  * Sets the code to execute when running this command.
  *
  * If this method is used, it overrides the code defined
  * in the execute() method.
  *
  * @param callable $code A callable(InputInterface $input, OutputInterface $output)
  *
  * @return Command The current instance
  *
  * @throws InvalidArgumentException
  *
  * @see execute()
  */
 public function setCode(callable $code)
 {
     if ($code instanceof \Closure) {
         $r = new \ReflectionFunction($code);
         if (null === $r->getClosureThis()) {
             $code = \Closure::bind($code, $this);
         }
     }
     $this->code = $code;
     return $this;
 }
开发者ID:blazarecki,项目名称:symfony,代码行数:25,代码来源:Command.php

示例9: isBinded

 private function isBinded($closure)
 {
     $reflection = new \ReflectionFunction($closure);
     $bind = $reflection->getClosureThis();
     if (is_object($bind)) {
         return $bind;
     }
     return false;
 }
开发者ID:kijtra,项目名称:multiget,代码行数:9,代码来源:Multiget.php

示例10: foo

<?php

class StaticExample
{
    static function foo()
    {
        var_dump("Static Example class, Hello World!");
    }
}
class Example
{
    public $bar = 42;
    public function foo()
    {
        var_dump("Example class, bar: " . $this->bar);
    }
}
// Initialize classes
$class = new ReflectionClass('Example');
$staticclass = new ReflectionClass('StaticExample');
$object = new Example();
$method = $staticclass->getMethod('foo');
$closure = $method->getClosure();
$rf = new ReflectionFunction($closure);
var_dump($rf->getClosureThis());
$method = $class->getMethod('foo');
$closure = $method->getClosure($object);
$rf = new ReflectionFunction($closure);
var_dump($rf->getClosureThis());
echo "Done!\n";
开发者ID:badlamer,项目名称:hhvm,代码行数:30,代码来源:ReflectionMethod_getClosureThis.php

示例11: setCode

 /**
  * Sets the code to execute when running this command.
  *
  * If this method is used, it overrides the code defined
  * in the execute() method.
  *
  * @param callable $code A callable(InputInterface $input, OutputInterface $output)
  *
  * @return Command The current instance
  *
  * @throws InvalidArgumentException
  *
  * @see execute()
  */
 public function setCode(callable $code)
 {
     if ($code instanceof \Closure) {
         $r = new \ReflectionFunction($code);
         if (null === $r->getClosureThis()) {
             if (PHP_VERSION_ID < 70000) {
                 // Bug in PHP5: https://bugs.php.net/bug.php?id=64761
                 // This means that we cannot bind static closures and therefore we must
                 // ignore any errors here.  There is no way to test if the closure is
                 // bindable.
                 $code = @\Closure::bind($code, $this);
             } else {
                 $code = \Closure::bind($code, $this);
             }
         }
     }
     $this->code = $code;
     return $this;
 }
开发者ID:symfony,项目名称:symfony,代码行数:33,代码来源:Command.php


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