Esempio n. 1
0
 /**
  * This method may transform the supplied source and return a new replacement for it
  *
  * @param StreamMetaData $metadata Metadata for source
  * @return boolean Return false if transformation should be stopped
  */
 public function transform(StreamMetaData $metadata)
 {
     $totalTransformations = 0;
     $fileName = $metadata->uri;
     $astTree = ReflectionEngine::parseFile($fileName, $metadata->source);
     $parsedSource = new ReflectionFile($fileName, $astTree);
     // Check if we have some new aspects that weren't loaded yet
     $unloadedAspects = $this->aspectLoader->getUnloadedAspects();
     if (!empty($unloadedAspects)) {
         $this->loadAndRegisterAspects($unloadedAspects);
     }
     $advisors = $this->container->getByTag('advisor');
     $namespaces = $parsedSource->getFileNamespaces();
     $lineOffset = 0;
     foreach ($namespaces as $namespace) {
         $classes = $namespace->getClasses();
         foreach ($classes as $class) {
             // Skip interfaces and aspects
             if ($class->isInterface() || in_array(Aspect::class, $class->getInterfaceNames())) {
                 continue;
             }
             $wasClassProcessed = $this->processSingleClass($advisors, $metadata, $class, $lineOffset);
             $totalTransformations += (int) $wasClassProcessed;
         }
         $wasFunctionsProcessed = $this->processFunctions($advisors, $metadata, $namespace);
         $totalTransformations += (int) $wasFunctionsProcessed;
     }
     // If we return false this will indicate no more transformation for following transformers
     return $totalTransformations > 0;
 }
 protected function setUp()
 {
     $fileName = stream_resolve_include_path(__DIR__ . self::STUB_FILE);
     $fileNode = ReflectionEngine::parseFile($fileName);
     $reflectionFile = new ReflectionFile($fileName, $fileNode);
     $this->parsedRefFile = $reflectionFile;
     include_once $fileName;
 }
 protected function setUp()
 {
     $this->originalRefClass = $refClass = new \ReflectionClass(self::STUB_CLASS);
     $fileName = $refClass->getFileName();
     $fileNode = ReflectionEngine::parseFile($fileName);
     $reflectionFile = new ReflectionFile($fileName, $fileNode);
     $parsedClass = $reflectionFile->getFileNamespace($refClass->getNamespaceName())->getClass($refClass->getName());
     $this->parsedRefClass = $parsedClass;
 }
 protected function setUp()
 {
     $fileName = stream_resolve_include_path(__DIR__ . self::STUB_FILE);
     $fileNode = ReflectionEngine::parseFile($fileName);
     $reflectionFile = new ReflectionFile($fileName, $fileNode);
     $parsedFileNamespace = $reflectionFile->getFileNamespace('Go\\ParserReflection\\Stub');
     $this->parsedRefFileNamespace = $parsedFileNamespace;
     include_once $fileName;
 }
 /**
  * ReflectionFile constructor.
  *
  * @param string $fileName Name of the file to reflect
  * @param null|array|Node[] $topLevelNodes Optional corresponding list of AST nodes for that file
  */
 public function __construct($fileName, $topLevelNodes = null)
 {
     $this->fileName = $fileName;
     $this->topLevelNodes = $topLevelNodes ?: ReflectionEngine::parseFile($fileName);
 }
Esempio n. 6
0
 /**
  * ReflectionFile constructor.
  *
  * @param string $fileName Name of the file to reflect
  * @param null|array|Node[] $topLevelNodes Optional corresponding list of AST nodes for that file
  */
 public function __construct($fileName, $topLevelNodes = null)
 {
     $fileName = PathResolver::realpath($fileName);
     $this->fileName = $fileName;
     $this->topLevelNodes = $topLevelNodes ?: ReflectionEngine::parseFile($fileName);
 }
 /**
  * Tests specific features of PHP5.6 and newer, for example, array constants, etc
  */
 public function testGettersPHP56()
 {
     if (PHP_VERSION_ID < 50600) {
         $this->markTestSkipped("Can not test new features on old version of PHP");
     }
     $fileName = stream_resolve_include_path(__DIR__ . self::STUB_FILE56);
     $fileNode = ReflectionEngine::parseFile($fileName);
     $reflectionFile = new ReflectionFile($fileName, $fileNode);
     include_once $fileName;
     $parsedFileNamespace = $reflectionFile->getFileNamespace('Go\\ParserReflection\\Stub');
     foreach ($parsedFileNamespace->getClasses() as $parsedRefClass) {
         $this->performGeneralMethodComparison($parsedRefClass);
     }
 }