function classData(ReflectionClass $class) { $details = ""; $name = $class->getName(); if ($class->isUserDefined()) { $details .= "{$name} is user defined \n"; } if ($class->isInternal()) { $details .= "{$name} is built-in\n"; } if ($class->isInternal()) { $details .= "{$name} is interface \n"; } if ($class->isAbstract()) { $details .= "{$name} is a final class\n"; } if ($class->isFinal()) { $details .= "{$name} is a final class\n"; } if ($class->isInstantiable()) { $details .= "{$name} can be instantiated\n"; } else { $details .= "{$name} can not be instantiated\n"; } return $details; }
/** * @param $rpcRequest \RpcGateway\Request * @throws \Exception */ protected function throwErrorIfRpcRequestIsInvalid($rpcRequest) { $serviceMethodName = $rpcRequest->getMethodName(); // create a PHP compatible version of the requested service class $serviceClassName = $this->getServiceClassNamespace() . str_replace(Request::METHOD_DELIMITER, '_', $rpcRequest->getClassName()); try { class_exists($serviceClassName); } catch (\Exception $exception) { throw new \Exception("Invalid rpc.method [" . $rpcRequest->getMethod() . "] (not found) at " . __METHOD__); } $serviceClassReflection = new \ReflectionClass($serviceClassName); if ($serviceClassReflection->isAbstract() || $serviceClassReflection->isInterface() || $serviceClassReflection->isInternal()) { throw new \Exception("Invalid rpc.class [" . $rpcRequest->getMethod() . "] at " . __METHOD__); } if ($serviceClassReflection->hasMethod($serviceMethodName) !== true) { throw new \Exception("Invalid rpc.method [" . $rpcRequest->getMethod() . "] (not found) at " . __METHOD__); } $serviceMethodReflection = $serviceClassReflection->getMethod($serviceMethodName); if ($serviceMethodReflection->isAbstract() || $serviceMethodReflection->isConstructor() || $serviceMethodReflection->isStatic() || !$serviceMethodReflection->isPublic()) { throw new \Exception("Invalid rpc.method [" . $rpcRequest->getMethod() . "] (not invokable) at " . __METHOD__); } $argsExpectedMin = $serviceMethodReflection->getNumberOfRequiredParameters(); $argsExpectedMax = $serviceMethodReflection->getNumberOfParameters(); $argsOptional = $argsExpectedMax - $argsExpectedMin; $argsGiven = count($rpcRequest->getParams()); if ($argsGiven < $argsExpectedMin || $argsGiven > $argsExpectedMax) { $msg = 'Invalid rpc.method [' . $rpcRequest->getMethod() . ']' . " Wrong number of parameters:" . " " . $argsGiven . " given" . " (required: " . $argsExpectedMin . " optional: " . $argsOptional . ")" . " expectedMin: " . $argsExpectedMin . " expectedMax: " . $argsExpectedMax; throw new Exception($msg); } }
public function isPhpClass() { try { $r = new \ReflectionClass($this->name); return $r->isInternal(); } catch (\ReflectionException $e) { return false; } }
private function isPhpClass(Link $link) { $className = $link->getDestination(); if (!class_exists($className, false)) { return false; } $classReflection = new \ReflectionClass($link->getDestination()); return $classReflection->isInternal(); }
/** * @return string[] internal symbols */ public function internalSymbolsProvider() { $allSymbols = array_merge(get_declared_classes(), get_declared_interfaces(), get_declared_traits()); $indexedSymbols = array_combine($allSymbols, $allSymbols); return array_map(function ($symbol) { return [$symbol]; }, array_filter($indexedSymbols, function ($symbol) { $reflection = new PhpReflectionClass($symbol); return $reflection->isInternal(); })); }
protected function _fillClassPathInfo($serialized) { $classes = self::extractSerializedClasses($serialized); $this->class_paths = array(); foreach ($classes as $class) { $reflect = new ReflectionClass($class); if ($reflect->isInternal()) { throw new lmbException("Class '{$class}' can't be serialized since it's an iternal PHP class, consider omitting object of this class by providing custom __sleep, __wakeup handlers"); } $this->class_paths[] = self::getClassPath($reflect); } }
/** * @param Identifier $identifier * * @return null|string */ private function getInternalReflectionClassName(Identifier $identifier) { if (!$identifier->isClass()) { return null; } $name = $identifier->getName(); if (!(class_exists($name, false) || interface_exists($name, false) || trait_exists($name, false))) { return null; // not an available internal class } $reflection = new \ReflectionClass($name); return $reflection->isInternal() ? $reflection->getName() : null; }
/** * Checks if the given class is located in the vendor directory. * * For convenience, it is also possible to pass an object whose * class is then checked. * * @param string|object $classNameOrObject * @return boolean * @throws \InvalidArgumentException If no valid class name or object is passed. */ public static function isVendorClass($classNameOrObject) { $className = is_object($classNameOrObject) ? get_class($classNameOrObject) : $classNameOrObject; if (!class_exists($className)) { $message = '"' . $className . '" is not the name of a loadable class.'; throw new \InvalidArgumentException($message); } $reflection = new \ReflectionClass($className); if ($reflection->isInternal()) { return false; } return static::isVendorFile($reflection->getFileName()); }
protected function processElementsItems() { $items = []; foreach (array_merge(get_declared_classes(), get_declared_interfaces(), get_declared_traits()) as $name) { $reflection = new \ReflectionClass($name); if ($reflection->isInternal() || mb_substr($name, 0, 11) === 'FixinTools\\') { continue; } $items[$reflection->name] = new Item($this, $reflection); } ksort($items); $this->items = $items; }
/** * @param array $data * @return mixed * @throws \Exception * @todo refactor this out somewhere once we start implementing in new formats */ protected function arrayToObject(array $data) { $reflection = new \ReflectionClass($data['className']); if (false === $reflection->isInternal()) { $object = $reflection->newInstanceWithoutConstructor(); } else { $object = $reflection->newInstance(); } $breadth = array(); $object = $this->extractAndSetSingleDepthProperties($data, $breadth, $reflection, $object); $object = $this->extractAndSetMultipleDepthProperties($breadth, $reflection, $object); return $object; }
function addClasses($parent, array $classes) { foreach ($classes as $rc) { if (is_string($rc)) { $rc = new \ReflectionClass($rc); } if (!$rc->isInternal()) { return; } $class = $this->append($parent, array($rc->getName(), $rc)); $this->addFunctions($class, $rc->getMethods()); } }
public function getParentClass() { if (!$this->getParent()) { return; } // Return internal objects Reflection if (class_exists($this->getParent(), false)) { $reflection = new \ReflectionClass($this->getParent()); if ($reflection->isInternal()) { return $reflection; } } return $this->index->getClass($this->getParent()); }
private function isCloneable($class) { if (!is_string($class) || in_array($class, self::$nonCloneableClasses) || false !== strpos($class, '[')) { // partial mock return false; } $rClass = new \ReflectionClass($class); // native php objects may not be cloneable, and we cannot rely on any // custom __clone implementation (ex: Symfony's Request object) if ($rClass->isInternal() || $rClass->hasMethod('__clone')) { self::$nonCloneableClasses[] = $class; return false; } return true; }
public function testLoad() { $name = $this->getClassName(); $this->assertTrue(class_exists($name)); $r = new \ReflectionClass($name); if ($r->isInstantiable() && !$r->isInternal()) { try { $class = $r->newInstanceWithoutConstructor(); $this->assertInstanceOf($name, $class); $this->assertInstanceOf('PHPJ\\Lang\\Object', $class); } catch (\ReflectionException $e) { $this->markTestSkipped($e->getMessage()); } } }
protected function load($dir, $name = '') { $old_classes = array_flip(get_declared_classes()); $this->load_dir($dir, $name); $new_classes = get_declared_classes(); foreach ($new_classes as $class) { // check if this is an abstract class, or bultin class $ref_class = new ReflectionClass($class); if ($ref_class->isAbstract()) { continue; } if ($ref_class->isInternal()) { continue; } if (!isset($old_classes[$class])) { $this->handle($class); } } }
/** * Execute the command * @param array $args Arguments gived to the command * @return array Response */ public function execute($args = array()) { $class = $args[0]; $internal = isset($args[1]) ? $args[1] : false; try { $reflection = new \ReflectionClass($class); } catch (\Exception $e) { return array('error' => $e->getMessage()); } if ($internal && !$reflection->isInternal()) { return array(); } $ctor = $reflection->getConstructor(); $args = array(); if (!is_null($ctor)) { $args = $this->getMethodArguments($ctor); } return array('methods' => array('constructor' => array('has' => !is_null($ctor), 'args' => $args))); }
public function generate() { $this->notifyBeforeGenerate(); $formatter = $this->formatter; $allFunctions = get_defined_functions(); foreach ($allFunctions['internal'] as $functionName) { $function = new \ReflectionFunction($functionName); $this->notifyGenerateFunction($function, $this->formatter->formatFunction($function)); } # Mix classes/interfaces/etc. $classes = array_merge(get_declared_classes(), get_declared_interfaces()); foreach ($classes as $name) { $class = new \ReflectionClass($name); if (!$class->isInternal()) { continue; } $this->notifyGenerateClass($class, $formatter->formatClass($class)); } $this->notifyAfterGenrate(); }
function initLogger() { $loggerName = "log"; // Iterate over all declared classes $classes = get_declared_classes(); foreach ($classes as $class) { $reflection = new ReflectionClass($class); // If the class is internally defined by PHP or has no property called "logger", skip it. if ($reflection->isInternal() || !$reflection->hasProperty($loggerName)) { continue; } // Get information regarding the "logger" property of this class. $property = new ReflectionProperty($class, $loggerName); // If the "logger" property is not static or not public, then it is not the one we are interested in. Skip this class. if (!$property->isStatic() || !$property->isPublic()) { continue; } // Initialize the logger for this class. $reflection->setStaticPropertyValue($loggerName, getLogger()); } }
public final function createTestDoubleFor($class_name, array $interfaces = array(), array $traits = array(), $method_checker = null) { FBMock_Utils::assertString($class_name); $this->assertAllowed(); if (!class_exists($class_name) && !interface_exists($class_name)) { throw new FBMock_TestDoubleException("Attempting to mock {$class_name} but {$class_name} isn't loaded."); } $mock_class_name = FBMock_Utils::mockClassNameFor($class_name, $interfaces, $traits); $ref_class = new ReflectionClass($class_name); if ($ref_class->isInternal() && !FBMock_Utils::isHHVM()) { throw new FBMock_TestDoubleException("Trying to mock PHP internal class {$class_name}. Mocking of internal " . "classes is only supported in HHVM."); } if (!class_exists($mock_class_name, $autoload = false)) { $class_generator_class = FBMock_Config::get()->getClassGenerator(); $class_generator = new $class_generator_class(); $code = $class_generator->generateCode($ref_class, $mock_class_name, $interfaces, $traits, $method_checker); eval($code); } $mock_object = (new ReflectionClass($mock_class_name))->newInstanceWithoutConstructor(); return $mock_object; }
protected function loadReflectables() { $data = array_merge(get_declared_classes(), get_declared_interfaces()); foreach ($data as $class) { $r = new \ReflectionClass($class); if (!$r->isInternal()) { continue; } $name = strtolower($r->name); if (!isset($this->methods[$name])) { $this->methods[$name] = ['extends' => [], 'methods' => []]; // TODO: load methods } do { $this->methods[$name]['extends'][] = strtolower($r->name); foreach ($r->getInterfaceNames() as $iname) { $this->methods[$name]['extends'][] = strtolower($iname); } } while ($r = $r->getParentClass()); $this->methods[$name]['extends'] = array_unique($this->methods[$name]['extends']); } }
/** * Check whether it is allowed to clean given class static variables * * @param ReflectionClass $reflectionClass * @return bool */ protected static function _isClassCleanable(ReflectionClass $reflectionClass) { // 1. do not process php internal classes if ($reflectionClass->isInternal()) { return false; } // 2. do not process blacklisted classes from integration framework foreach (self::$_classesToSkip as $notCleanableClass) { if ($reflectionClass->getName() == $notCleanableClass || is_subclass_of($reflectionClass->getName(), $notCleanableClass)) { return false; } } // 3. process only files from specific folders $fileName = $reflectionClass->getFileName(); if ($fileName) { $fileName = str_replace('\\', '/', $fileName); foreach (self::$_cleanableFolders as $directory) { if (stripos($fileName, $directory) !== false) { return true; } } } return false; }
/** * creates a link to a type (class, interface or trait) * @param ClassDoc|InterfaceDoc|TraitDoc|ClassDoc[]|InterfaceDoc[]|TraitDoc[]|string|string[] $types * @param string $title a title to be used for the link TODO check whether [[yii\...|Class]] is supported * @param BaseDoc $context * @param array $options additional HTML attributes for the link. * @return string */ public function createTypeLink($types, $context = null, $title = null, $options = []) { if (!is_array($types)) { $types = [$types]; } if (count($types) > 1) { $title = null; } $links = []; foreach ($types as $type) { $postfix = ''; if (is_string($type)) { if (!empty($type) && substr_compare($type, '[]', -2, 2) === 0) { $postfix = '[]'; $type = substr($type, 0, -2); } if ($type === '$this' && $context instanceof TypeDoc) { $title = '$this'; $type = $context; } elseif (($t = $this->apiContext->getType(ltrim($type, '\\'))) !== null) { $type = $t; } elseif ($type[0] !== '\\' && ($t = $this->apiContext->getType($this->resolveNamespace($context) . '\\' . ltrim($type, '\\'))) !== null) { $type = $t; } else { ltrim($type, '\\'); } } if (is_string($type)) { $linkText = ltrim($type, '\\'); if ($title !== null) { $linkText = $title; $title = null; } $phpTypes = ['callable', 'array', 'string', 'boolean', 'integer', 'float', 'object', 'resource', 'null', 'false', 'true']; $phpTypeAliases = ['true' => 'boolean', 'false' => 'boolean']; // check if it is PHP internal class if ((class_exists($type, false) || interface_exists($type, false) || trait_exists($type, false)) && ($reflection = new \ReflectionClass($type)) && $reflection->isInternal()) { $links[] = $this->generateLink($linkText, 'http://www.php.net/class.' . strtolower(ltrim($type, '\\')), $options) . $postfix; } elseif (in_array($type, $phpTypes)) { if (isset($phpTypeAliases[$type])) { $type = $phpTypeAliases[$type]; } $links[] = $this->generateLink($linkText, 'http://www.php.net/language.types.' . strtolower(ltrim($type, '\\')), $options) . $postfix; } else { $links[] = $type; } } elseif ($type instanceof BaseDoc) { $linkText = $type->name; if ($title !== null) { $linkText = $title; $title = null; } $links[] = $this->generateLink($linkText, $this->generateApiUrl($type->name), $options) . $postfix; } } return implode('|', $links); }
protected function _getInstance($mockName, $constructorArgs = null) { $r = new \ReflectionClass($mockName); if (null === $r->getConstructor()) { $return = new $mockName(); return $return; } if ($constructorArgs !== null) { return $r->newInstanceArgs($constructorArgs); } $isInternal = $r->isInternal(); $child = $r; while (!$isInternal && ($parent = $child->getParentClass())) { $isInternal = $parent->isInternal(); $child = $parent; } try { if (version_compare(PHP_VERSION, '5.4') < 0 || $isInternal) { $return = unserialize(sprintf('%s:%d:"%s":0:{}', version_compare(PHP_VERSION, '5.4', '>') && $r->implementsInterface('Serializable') ? 'C' : 'O', strlen($mockName), $mockName)); } else { $return = $r->newInstanceWithoutConstructor(); } } catch (\Exception $ex) { $internalMockName = $mockName . '_Internal'; if (!class_exists($internalMockName)) { eval("class {$internalMockName} extends {$mockName} {" . 'public function __construct() {}' . '}'); } $return = new $internalMockName(); } return $return; }
{ const START = 0; private static $c = Counter::START; /** * Invoke counter * * @access public * @return int */ public function count() { return self::$c++; } } $class = new ReflectionClass('Counter'); printf("===> The %s%s%s %s '%s' [extends %s]" . " declared in %s" . " lines %d to %d" . " having the modifiers %d [%s]<br/>", $class->isInternal() ? 'internal' : 'user-defined', $class->isAbstract() ? ' abstract' : '', $class->isFinal() ? ' final' : '', $class->isInterface() ? 'interface' : 'class', $class->getName(), var_export($class->getParentClass(), 1), $class->getFileName(), $class->getStartLine(), $class->getEndline(), $class->getModifiers(), implode(' ', Reflection::getModifierNames($class->getModifiers()))); // output: ===> The user-defined class 'Counter' [extends ReflectionClass::__set_state(array( 'name' => 'Object', ))] declared in /home/cg/root/main.php lines 15 to 31 having the modifiers 524288 [] printf("===> Documentation:%s<br/>", var_export($class->getDocComment(), 1)); // output: ===> Documentation:'/** * A counter class */' printf("===> Implements:%s<br/>", var_export($class->getInterfaces(), 1)); // output: ===> Implements:array ( 'NSerializable' => ReflectionClass::__set_state(array( 'name' => 'NSerializable', )), ) printf("===> Constants: %s<br/>", var_export($class->getConstants(), 1)); // output: ===> Constants: array ( 'START' => 0, ) printf("===> Properties: %s<br/>", var_export($class->getProperties(), 1)); // output: ===> Properties: array ( 0 => ReflectionProperty::__set_state(array( 'name' => 'c', 'class' => 'Counter', )), ) printf("===> Methods: %s<br/>", var_export($class->getMethods(), 1)); // output: ===> Methods: array ( 0 => ReflectionMethod::__set_state(array( 'name' => 'count', 'class' => 'Counter', )), ) if ($class->isInstantiable()) { $counter = $class->newInstance(); echo '===> $counter is instance? '; echo $class->isInstance($counter) ? 'yes' : 'no';
/** * Returns a proxy class object for the specified original class. * * If no such proxy class has been created yet by this renderer, * this function will create one and register it for later use. * * If the class is not proxable, FALSE will be returned * * @param string $fullClassName Name of the original class * @return \TYPO3\Flow\Object\Proxy\ProxyClass|boolean */ public function getProxyClass($fullClassName) { if (interface_exists($fullClassName) || in_array('TYPO3\\Flow\\Tests\\BaseTestCase', class_parents($fullClassName))) { return FALSE; } if (class_exists($fullClassName) === FALSE) { return FALSE; } $classReflection = new \ReflectionClass($fullClassName); if ($classReflection->isInternal() === TRUE) { return FALSE; } $proxyAnnotation = $this->reflectionService->getClassAnnotation($fullClassName, 'TYPO3\\Flow\\Annotations\\Proxy'); if ($proxyAnnotation !== NULL && $proxyAnnotation->enabled === FALSE) { return FALSE; } if (in_array(substr($fullClassName, 0, 14), $this->blacklistedSubPackages)) { return FALSE; } if (!isset($this->proxyClasses[$fullClassName])) { $this->proxyClasses[$fullClassName] = new ProxyClass($fullClassName); $this->proxyClasses[$fullClassName]->injectReflectionService($this->reflectionService); } return $this->proxyClasses[$fullClassName]; }
print "\n"; print "--- isFinal() ---\n"; var_dump($rb->isFinal()); print "\n"; print "--- isInstance() ---\n"; var_dump($rb->isInstance(new B())); var_dump($rb->isInstance(new C())); print "\n"; print "--- isInstantiable() ---\n"; var_dump($rb->isInstantiable()); print "\n"; print "--- isInterface() ---\n"; var_dump($rb->isInterface()); print "\n"; print "--- isInternal() ---\n"; var_dump($rb->isInternal()); print "\n"; print "--- isIterateable() ---\n"; var_dump($rb->isIterateable()); print "\n"; print "--- isSubclassOf() ---\n"; var_dump($rb->isSubclassOf('A')); var_dump($rb->isSubclassOf('C')); print "\n"; print "--- isUserDefined() ---\n"; var_dump($rb->isUserDefined()); print "\n"; print "--- newInstance() ---\n"; var_dump($rb->newInstance()); print "\n"; print "--- newInstanceArgs() ---\n";
/** * Show reflection * * Show reflection * * <code> * Panda_Debug::reflect('BEAR_Form'); // Class * Panda_Debug::reflect($obj); // Objecy * Panda_Debug::reflect('p'); // Function * </code> * * @param string $target target * @param boll $cehckParent check parent class * * @return void */ public static function reflect($target, $cehckParent = false) { if (is_object($target)) { $target = get_class($target); } switch (true) { case function_exists($target): $ref = new ReflectionFunction($target); $info['name'] = $ref->isInternal() ? 'The internal ' : 'The user-defined '; $info['name'] .= $targetName = $ref->getName(); $info['declare in'] = $ref->getFileName() . ' lines ' . $ref->getStartLine() . ' to ' . $ref->getEndline(); $info['Documentation'] = $ref->getDocComment(); $statics = $ref->getStaticVariables(); if ($statics) { $info['Static variables'] = $statics; } $type = 'function'; break; case class_exists($target, false): $ref = new ReflectionClass($target); $type = 'class'; $info['name'] = $ref->isInternal() ? 'The internal ' : 'The user-defined '; $info['name'] .= $ref->isAbstract() ? ' abstract ' : ''; $info['name'] .= $ref->isFinal() ? ' final ' : ''; $info['name'] .= $ref->isInterface() ? 'interface ' : 'class '; $info['name'] .= $targetName = $ref->getName(); $info['declare in'] = $ref->getFileName() . ' lines ' . $ref->getStartLine() . ' to ' . $ref->getEndline(); $info['modifiers'] = Reflection::getModifierNames($ref->getModifiers()); $info['Documentation'] = $ref->getDocComment(); $info['Implements'] = $ref->getInterfaces(); $info['Constants'] = $ref->getConstants(); foreach ($ref->getProperties() as $prop) { // ReflectionProperty クラスのインスタンスを生成する $propRef = new ReflectionProperty($targetName, $prop->name); if ($propRef->isPublic()) { $porps[] = $prop->name; } } // $info['Public Properties'] = $porps; foreach ($ref->getMethods() as $method) { $methodRef = new ReflectionMethod($targetName, $method->name); if ($methodRef->isPublic() || $method->isStatic()) { $final = $method->isFinal() ? 'final ' : ''; $pubic = $method->isPublic() ? 'public ' : ''; $static = $method->isStatic() ? ' static ' : ''; $methods[] = sprintf("%s%s%s %s", $final, $pubic, $static, $method->name); } } $info['Public Methods'] = $methods; if ($ref->isInstantiable() && is_object($target)) { $info['isInstance ?'] = $ref->isInstance($target) ? 'yes' : 'no'; } if ($parent) { $info['parent'] .= $ref->getParentClass(); } break; default: $type = 'Invalid Object/Class'; $targetName = $target; $info = null; break; } print_a($info, "show_objects:1;label: Reflection of {$type} '{$targetName}'"); }
function generate_class_tests($file, $dest_path, $class) { global $verbose; include_once $file; $x = new ReflectionClass("{$class}"); if ($x->isAbstract() || $x->isInternal() || $x->isInterface()) { if ($verbose) { echo "Class {$class} is internal, abstract, or an interface ... skipping.\n"; } return; } $class_test_file = true; $old_dest_file = path($dest_path, "class.{$class}.phpt"); $dest_file = path($dest_path, "{$class}.phpt"); if (file_exists($old_dest_file) && !file_exists($dest_file)) { echo "svn mv {$old_dest_file} {$dest_file}\n"; return; } if (file_exists($dest_file)) { if (zesk::getb('force-create') || zesk::getb('force-create-classes')) { if ($verbose) { echo "Overwriting destination file {$dest_file} due to force flags...\n"; } } else { if ($verbose) { echo "Skipping because destination file {$dest_file} exists ...\n"; } // Set flag so file is not generated, but static function tests are $class_test_file = false; } } $contents = test_file_header($file, $dest_file, false); $functions = extract_class_functions($x, $class); $exclude_functions = array(); $has_non_static_methods = false; foreach ($functions as $method => $params) { if (in_array($method, $exclude_functions)) { continue; } $param_list = array(); foreach ($params as $k => $v) { $param_list[] = '$' . $k; $contents[] = '$' . $k . ' = ' . PHP::dump($v) . ";"; } if (begins($method, "new ")) { $prefix = '$testx = '; $has_non_static_methods = true; } else { if (begins($method, "::")) { $method_name = str_replace('::', '', $method); $method_object = $x->getMethod($method_name); $methodParams = $method_object->getParameters(); generate_static_class_method_test($file, $dest_path, $class, $method_name, $methodParams); continue; } else { if (begins($method, "->")) { $prefix = '$testx'; $has_non_static_methods = true; } else { continue; } } } $contents[] = $prefix . $method . '(' . implode(", ", $param_list) . ');'; $contents[] = ""; } if (!$class_test_file) { return; } if (!$has_non_static_methods) { return; } $contents[] = "echo basename(__FILE__) . \": success\\n\";"; if (!zesk::getb('dry-run')) { file_put_contents($dest_file, implode("\n", $contents)); chmod($dest_file, 0775); echo "Wrote {$dest_file} ...\n"; } else { echo "Would write {$dest_file} ...\n"; } }
/** * Resolve depend from class * @param \ReflectionClass $class * @return EntityClass */ private function _resolveDepend(\ReflectionClass $class) { if ($class->isInternal()) { $this->addDepends($class->getExtensionName()); return new EntityClass($class->getName()); } elseif (isset($this->classes[$class->getName()])) { return $this->classes[$class->getName()]; } else { // todo: log the problem $file = $this->files[$class->getFileName()] = new EntityFile($class->getFileName(), $this); $file->scan(); $this->_addEntities($file); } }
private function getClassInfo($fqcn) { $classData = $this->getEmptyClassData($fqcn); if (empty($fqcn)) { return $classData; } try { $reflectionClass = new \ReflectionClass($fqcn); } catch (\Exception $e) { return $classData; } if ($reflectionClass->isInternal()) { $fqcn = $reflectionClass->getName(); if (array_key_exists($fqcn, $this->coreIndex['classes'])) { return $this->coreIndex['classes'][$reflectionClass->getName()]; } else { return $classData; } } $classContent = array(); $classData['file'] = $reflectionClass->getFileName(); $classData['startLine'] = $reflectionClass->getStartLine(); $docComment = $reflectionClass->getDocComment(); if (!$docComment) { $docComment = ""; } preg_match("/(\\\\)?(\\w+)\$/", $reflectionClass->name, $classNameMatches); $classData['docComment'] = $this->trimDocComment($docComment); $classContent = $this->getClassContent($reflectionClass->getFileName(), $fqcn); $classData['namespaces']['file'] = $reflectionClass->getNamespaceName(); $parsedClassData = $this->parseClass($classData['file']); $className = $classNameMatches[2]; $classData['namespaces'] = $parsedClassData['namespaces']; $classData['className'] = $className; $this->classes[] = $className; if (array_key_exists($className, $this->class_fqcn)) { if (is_array($this->class_fqcn[$className]) && !in_array($fqcn, $this->class_fqcn[$className])) { $this->class_fqcn[$className][] = $fqcn; } elseif (is_string($this->class_fqcn[$className]) && $this->class_fqcn[$className] != $fqcn) { $fqcns = array(); $fqcns[] = $this->class_fqcn[$className]; $fqcns[] = $fqcn; $this->class_fqcn[$className] = $fqcns; } } else { $this->class_fqcn[$className] = $fqcn; } $this->getConstantData($reflectionClass, $classData); $classMethods = $reflectionClass->getMethods(); foreach ($classMethods as $reflectionMethod) { if ($reflectionMethod->class === $fqcn) { $this->getMethodData($reflectionMethod, $classContent, $classData); } } $classProperties = $reflectionClass->getProperties(); foreach ($classProperties as $classProperty) { if ($classProperty->class == $fqcn) { $this->getPropertyData($classProperty, $classData); } } $classData['parentclass'] = ""; $parentClass = $reflectionClass->getParentClass(); //if($parentClass && !$parentClass->isInternal() ){ if ($parentClass) { $classData['parentclass'] = $parentClass->getName(); } $classData['interfaces'] = $reflectionClass->getInterfaceNames(); $classData['classname'] = $className; return $classData; }