/**
  * {@inheritDoc}
  */
 public function locateIdentifier(Reflector $reflector, Identifier $identifier)
 {
     try {
         $closureData = $this->closureAnalyzer->analyze($this->closure);
     } catch (ClosureAnalysisException $closureAnalysisException) {
         if (stripos($closureAnalysisException->getMessage(), 'Two closures were declared on the same line') !== false) {
             throw TwoClosuresOneLine::fromClosureAnalysisException($closureAnalysisException);
         }
         throw $closureAnalysisException;
     }
     if (!isset($closureData['ast']) || !$closureData['ast'] instanceof ClosureNode) {
         return null;
     }
     $locatedSource = new LocatedSource('<?php ' . $closureData['code'], $closureData['reflection']->getFileName());
     $namespaceNode = null;
     if (isset($closureData['location']['namespace'])) {
         $namespaceNode = new Namespace_(new Name($closureData['location']['namespace']));
     }
     return $this->conversionStrategy->__invoke($reflector, $closureData['ast'], $locatedSource, $namespaceNode);
 }
Пример #2
0
 /**
  * @inheritDoc
  */
 public function getData(\Closure $closure, $forSerialization = false)
 {
     // Use the closure analyzer to get data about the closure.
     $data = $this->analyzer->analyze($closure);
     // If the closure data is getting retrieved solely for the purpose of
     // serializing the closure, then make some modifications to the data.
     if ($forSerialization) {
         // If there is no reference to the binding, don't serialize it.
         if (!$data['hasThis']) {
             $data['binding'] = null;
         }
         // Remove data about the closure that does not get serialized.
         $data = array_intersect_key($data, self::$dataToKeep);
         // Wrap any other closures within the context.
         foreach ($data['context'] as &$value) {
             if ($value instanceof \Closure) {
                 $value = $value === $closure ? self::RECURSION : new SerializableClosure($value, $this);
             }
         }
     }
     return $data;
 }