/** * 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; }
/** @inheritdoc */ public function generate(array $replacements, $autoloader) { ReflectionEngine::init(new Locator($autoloader)); foreach ($replacements as $replacement) { $fullPath = $this->vendorDir . '/' . $replacement['package'] . '/proxy/' . str_replace('\\', '/', $replacement['originalFullyQualifiedType']) . ".php"; $this->filesystem->put($fullPath, $this->buildClass($replacement)); } }
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; }
/** * File namespace constructor * * @param string $fileName Name of the file * @param string $namespaceName Name of the namespace * @param Namespace_|null $namespaceNode Optional AST-node for this namespace block */ public function __construct($fileName, $namespaceName, Namespace_ $namespaceNode = null) { if (!$namespaceNode) { $namespaceNode = ReflectionEngine::parseFileNamespace($fileName, $namespaceName); } $this->namespaceNode = $namespaceNode; $this->fileName = $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; }
/** * Initializes reflection instance for the method node * * @param string $className Name of the class * @param string $methodName Name of the method * @param ClassMethod $classMethodNode AST-node for method * @param ReflectionClass $declaringClass Optional declaring class */ public function __construct($className, $methodName, ClassMethod $classMethodNode = null, ReflectionClass $declaringClass = null) { //for some reason, ReflectionMethod->getNamespaceName in php always returns '', so we shouldn't use it too $this->className = $className; $this->declaringClass = $declaringClass; $this->functionLikeNode = $classMethodNode ?: ReflectionEngine::parseClassMethod($className, $methodName); // Let's unset original read-only properties to have a control over them via __get unset($this->name, $this->class); }
/** * Initializes reflection instance * * @param string|object $argument Class name or instance of object * @param ClassLike $classLikeNode AST node for class */ public function __construct($argument, ClassLike $classLikeNode = null) { $fullClassName = is_object($argument) ? get_class($argument) : $argument; $namespaceParts = explode('\\', $fullClassName); $this->className = array_pop($namespaceParts); // Let's unset original read-only property to have a control over it via __get unset($this->name); $this->namespaceName = join('\\', $namespaceParts); $this->classLikeNode = $classLikeNode ?: ReflectionEngine::parseClass($fullClassName); }
/** * Initializes a reflection for the property * * @param string $className Name of the class with properties * @param string $propertyName Name of the property to reflect * @param Property $propertyType Property type definition node * @param PropertyProperty $propertyNode Concrete property definition (value, name) */ public function __construct($className, $propertyName, Property $propertyType = null, PropertyProperty $propertyNode = null) { $this->className = $className; if (!$propertyType || !$propertyNode) { list($propertyType, $propertyNode) = ReflectionEngine::parseClassProperty($className, $propertyName); } $this->propertyTypeNode = $propertyType; $this->propertyNode = $propertyNode; // Let's unset original read-only properties to have a control over them via __get unset($this->name, $this->class); }
<?php /** * Parser Reflection API * * @copyright Copyright 2015, Lisachenko Alexander <*****@*****.**> * * This source file is subject to the license that is bundled * with this source code in the file LICENSE. */ use Go\ParserReflection\Locator\ComposerLocator; use Go\ParserReflection\ReflectionEngine; /** * This file is used for automatic configuration of Go\ParserReflection\ReflectionEngine class */ ReflectionEngine::init(new ComposerLocator());
/** * 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); }
/** * 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); }
/** * Adds a relation. * * @param integer $class_id Class ID. * @param string $related_class Related class. * @param integer $relation_type Relation type. * @param boolean $is_internal Is internal. * @param array $old_relations Old relations. * * @return string */ protected function addRelation($class_id, $related_class, $relation_type, $is_internal, array $old_relations) { $insert_sql = ' INSERT INTO ClassRelations (ClassId, RelatedClass, RelatedClassId, RelationType) VALUES (:class_id, :related_class, :related_class_id, :relation_type)'; $update_sql = ' UPDATE ClassRelations SET RelationType = :relation_type WHERE ClassId = :class_id AND RelatedClassId = :related_class_id'; if ($is_internal) { $related_class_id = 0; } else { $related_class_file = realpath(ReflectionEngine::locateClassFile($related_class)); $sql = 'SELECT Id FROM Classes WHERE FileId = :file_id AND Name = :name'; $related_class_id = $this->db->fetchValue($sql, array('file_id' => $this->processFile($related_class_file), 'name' => $related_class)); } $this->db->perform(in_array($related_class, $old_relations) ? $update_sql : $insert_sql, array('class_id' => $class_id, 'related_class' => $related_class, 'related_class_id' => $related_class_id, 'relation_type' => $relation_type)); return $related_class; }
/** * 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); } }
/** * This method is called before the first test of this test class is run. * * @since Method available since Release 3.4.0 */ public static function setUpBeforeClass() { ReflectionEngine::init(new ComposerLocator()); }