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


PHP ReflectionFunction::getClosureScopeClass方法代码示例

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


在下文中一共展示了ReflectionFunction::getClosureScopeClass方法的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: 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

示例3: hash

 /**
  * Hash anything, return the unique identity.
  *
  * @param $object
  * @return string
  */
 protected function hash($object)
 {
     array_walk_recursive($object, function (&$item) {
         if ($item instanceof \Closure) {
             $reflection = new \ReflectionFunction($item);
             $item = serialize($reflection->getClosureScopeClass()) . $reflection->getNumberOfParameters() . $reflection->getNamespaceName() . $reflection->getStartLine() . $reflection->getEndLine();
         }
     });
     return md5(serialize($object));
 }
开发者ID:sandeeprajoria,项目名称:Housekeeper,代码行数:16,代码来源:AbstractCacheManager.php

示例4: hash

 /**
  * Hash anything (except PDO connection stuff, for now).
  *
  * @param mixed $object
  * @return string
  */
 public static function hash($object)
 {
     $object = is_array($object) ? $object : [$object];
     array_walk_recursive($object, function ($item) {
         if ($item instanceof \Closure) {
             $reflection = new \ReflectionFunction($item);
             // Unique and fast.
             $item = serialize($reflection->getClosureScopeClass()) . $reflection->getNumberOfParameters() . $reflection->getNamespaceName() . $reflection->getStartLine() . $reflection->getEndLine();
         }
     });
     return md5(serialize($object));
 }
开发者ID:aaronjan,项目名称:housekeeper,代码行数:18,代码来源:SmartHasher.php

示例5: fromReflection

 /**
  * Creates a ClosureLocation and seeds it with all the data that can be gleaned from the closure's reflection
  *
  * @param \ReflectionFunction $reflection The reflection of the closure that this ClosureLocation should represent
  *
  * @return ClosureLocation
  */
 public static function fromReflection(\ReflectionFunction $reflection)
 {
     $location = new self();
     $location->directory = dirname($reflection->getFileName());
     $location->file = $reflection->getFileName();
     $location->function = $reflection->getName();
     $location->line = $reflection->getStartLine();
     // @codeCoverageIgnoreStart
     if (version_compare(PHP_VERSION, '5.4', '>=')) {
         $closureScopeClass = $reflection->getClosureScopeClass();
         $location->closureScopeClass = $closureScopeClass ? $closureScopeClass->getName() : null;
     }
     // @codeCoverageIgnoreEnd
     return $location;
 }
开发者ID:rodrigopbel,项目名称:ong,代码行数:22,代码来源:ClosureLocation.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 (!$this->location['class']) {
         /** @var \ReflectionClass $closureScopeClass */
         $closureScopeClass = $this->reflection->getClosureScopeClass();
         $this->location['class'] = $closureScopeClass ? $closureScopeClass->getName() : null;
     }
 }
开发者ID:ngitimfoyo,项目名称:Nyari-AppPHP,代码行数:15,代码来源:ClosureLocatorVisitor.php

示例7: 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

示例8: 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

示例9: getControllerName

 /**
  * @param callable $listener
  *
  * @return string
  */
 private function getControllerName($listener) : string
 {
     if (is_array($listener)) {
         if (is_string($listener[0])) {
             return $listener[0] . '::' . $listener[1];
         } else {
             return get_class($listener[0]) . '::' . $listener[1];
         }
     } elseif (is_string($listener)) {
         return $listener;
     } else {
         $reflection = new \ReflectionFunction($listener);
         return $reflection->getClosureScopeClass()->getName() . '::' . 'closure[' . $reflection->getStartLine() . ':' . $reflection->getEndLine() . ']';
     }
 }
开发者ID:cawaphp,项目名称:module-clockwork,代码行数:20,代码来源:Module.php

示例10: function

<?php

$c = function () {
    var_dump($this);
};
$d = $c->bindTo(new stdClass());
$d();
$rm = new ReflectionFunction($d);
var_dump($rm->getClosureScopeClass()->name);
//dummy sope is Closure
//should have the same effect
$d = $c->bindTo(new stdClass(), NULL);
$d();
$rm = new ReflectionFunction($d);
var_dump($rm->getClosureScopeClass()->name);
//dummy sope is Closure
echo "Done.\n";
开发者ID:badlamer,项目名称:hhvm,代码行数:17,代码来源:closure_042.php

示例11: getClosure

<?php

$closure = function ($param) {
    return "this is a closure";
};
$rf = new ReflectionFunction($closure);
var_dump($rf->getClosureScopeClass());
class A
{
    public static function getClosure()
    {
        return function ($param) {
            return "this is a closure";
        };
    }
}
$closure = A::getClosure();
$rf = new ReflectionFunction($closure);
var_dump($rf->getClosureScopeClass());
echo "Done!\n";
开发者ID:badlamer,项目名称:hhvm,代码行数:20,代码来源:ReflectionFunction_getClosureScopeClass.php


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