/** * @return void */ protected function _generateFileStructure() { $classes = $this->_extension->getClassNames(); foreach ($classes as $class) { $reflectionClass = new \ReflectionClass($class); $output = "<?php\n\n"; $output .= $this->_exportNamespace($reflectionClass); $output .= $this->_exportDefinition($reflectionClass); $output .= "\n{\n\n"; $output .= $this->_exportClassConstants($reflectionClass); $output .= $this->_exportClassProperties($reflectionClass); $output .= $this->_exportClassMethods($reflectionClass); $output .= "}"; $dir_class = str_replace('\\', DIRECTORY_SEPARATOR, $reflectionClass->getNamespaceName()); $dir = $this->_targetDir . DIRECTORY_SEPARATOR . $this->_extension->getVersion() . DIRECTORY_SEPARATOR . $dir_class; if (!is_dir($dir)) { mkdir($dir, 0777, true); } $file = str_replace('\\', DIRECTORY_SEPARATOR, $class) . '.php'; $path = $this->_targetDir . DIRECTORY_SEPARATOR . $this->_extension->getVersion() . DIRECTORY_SEPARATOR . $file; $fp = fopen($path, 'w+'); fputs($fp, $output); fclose($fp); } }
public function testExtension() { if (!extension_loaded('hstore')) { return; } $r = new \ReflectionExtension('hstore'); $this->assertContains('Intaro\\HStore\\Coder', $r->getClassNames()); }
public function getClasses() { $res = []; foreach (parent::getClassNames() as $val) { $res[$val] = new ClassType($val); } return $res; }
/** * Returns an array containing all names of all classes of this extension * @return string[] */ public function getClassNames() { if ($this->reflectionSource) { return $this->reflectionSource->getClassNames(); } else { return parent::getClassNames(); } }
public function getClasses() { $res = array(); foreach (parent::getClassNames() as $val) { $res[$val] = new ClassReflection($val); } return $res; }
/** * @param string[] $extensionNames * @return string[] * @throws UnknownExtensionException if the extension cannot be found */ public function __invoke(array $extensionNames) : array { $definedSymbols = []; foreach ($extensionNames as $extensionName) { try { $extensionReflection = new \ReflectionExtension($extensionName); $definedSymbols = array_merge($definedSymbols, array_keys($extensionReflection->getConstants()), array_keys($extensionReflection->getFunctions()), $extensionReflection->getClassNames()); } catch (\Exception $e) { throw new UnknownExtensionException($e->getMessage()); } } return $definedSymbols; }
/** * Returns default colophons. * @param string profiler | bluescreen * @return array */ public static function getDefaultColophons($sender) { if ($sender === 'profiler') { $arr[] = 'Elapsed time: ' . sprintf('%0.3f', (microtime(TRUE) - Debug::$time) * 1000) . ' ms'; foreach ((array) self::$counters as $name => $value) { if (is_array($value)) { $value = implode(', ', $value); } $arr[] = htmlSpecialChars($name) . ' = <strong>' . htmlSpecialChars($value) . '</strong>'; } $autoloaded = class_exists('AutoLoader', FALSE) ? AutoLoader::$count : 0; $s = '<span>' . count(get_included_files()) . '/' . $autoloaded . ' files</span>, '; $exclude = array('stdClass', 'Exception', 'ErrorException', 'Traversable', 'IteratorAggregate', 'Iterator', 'ArrayAccess', 'Serializable', 'Closure'); foreach (get_loaded_extensions() as $ext) { $ref = new ReflectionExtension($ext); $exclude = array_merge($exclude, $ref->getClassNames()); } $classes = array_diff(get_declared_classes(), $exclude); $intf = array_diff(get_declared_interfaces(), $exclude); $func = get_defined_functions(); $func = (array) @$func['user']; $consts = get_defined_constants(TRUE); $consts = array_keys((array) @$consts['user']); foreach (array('classes', 'intf', 'func', 'consts') as $item) { $s .= '<span ' . (${$item} ? 'title="' . implode(", ", ${$item}) . '"' : '') . '>' . count(${$item}) . ' ' . $item . '</span>, '; } $arr[] = $s; } if ($sender === 'bluescreen') { $arr[] = 'PHP ' . PHP_VERSION; if (isset($_SERVER['SERVER_SOFTWARE'])) { $arr[] = htmlSpecialChars($_SERVER['SERVER_SOFTWARE']); } //$arr[] = 'Nette Framework ' . Framework::VERSION . ' (revision ' . Framework::REVISION . ')'; $arr[] = 'Report generated at ' . @strftime('%c', Debug::$time); // intentionally @ } return $arr; }
<?php $ereg = new ReflectionExtension('ereg'); var_dump($ereg->getClassNames()); ?> ==DONE==
<?php $extension = new ReflectionExtension('ctype'); var_dump($extension->getClassNames()); ?> ==DONE==
/** * Get all info about function * @param string|function $extensionName Function or function name * @return array|bool */ protected static function _getExtension($extensionName) { if (!extension_loaded($extensionName)) { return false; } $ext = new ReflectionExtension($extensionName); $result = array(); $result['name'] = $ext->name; $result['version'] = $ext->getVersion(); if ($constants = $ext->getConstants()) { $result['constants'] = $constants; } if ($classesName = $ext->getClassNames()) { $result['classesName'] = $classesName; } if ($functions = $ext->getFunctions()) { $result['functions'] = $functions; } if ($dependencies = $ext->getDependencies()) { $result['dependencies'] = $dependencies; } if ($INIEntries = $ext->getINIEntries()) { $result['INIEntries'] = $INIEntries; } $functions = $ext->getFunctions(); if (is_array($functions) && count($functions) > 0) { $result['functions'] = array(); foreach ($functions as $function) { $funcName = $function->getName(); $result['functions'][$funcName] = self::_getFunction($funcName); } } return $result; }
/** * This method reads all available classes and interfaces and checks whether * this type belongs to an extension or is internal. All internal and extension * classes are collected in an internal data structure. * * @return array(string=>string) */ private static function _initTypeToExtension() { // Skip when already done. if (self::$_typeNameToExtension !== null) { return self::$_typeNameToExtension; } self::$_typeNameToExtension = array('iterator' => '+standard'); $extensionNames = get_loaded_extensions(); $extensionNames = array_map('strtolower', $extensionNames); foreach ($extensionNames as $extensionName) { $extension = new ReflectionExtension($extensionName); $classNames = $extension->getClassNames(); $classNames = array_map('strtolower', $classNames); foreach ($classNames as $className) { self::$_typeNameToExtension[$className] = '+' . $extensionName; } } return self::$_typeNameToExtension; }
<pre> <?php // Создание экземпляра класса ReflectionProperty $ext = new ReflectionExtension('standard'); // Вывод основной информации printf("Имя : %s\n" . "Версия : %s\n" . "Функции : [%d] %s\n" . "Константы : [%d] %s\n" . "Директивы INI : [%d] %s\n" . "Классы : [%d] %s\n", $ext->getName(), $ext->getVersion() ? $ext->getVersion() : 'NO_VERSION', sizeof($ext->getFunctions()), var_export($ext->getFunctions(), 1), sizeof($ext->getConstants()), var_export($ext->getConstants(), 1), sizeof($ext->getINIEntries()), var_export($ext->getINIEntries(), 1), sizeof($ext->getClassNames()), var_export($ext->getClassNames(), 1)); ?> </pre>
public static function ListPackage() { foreach (get_loaded_extensions() as $ext) { $reflection = new ReflectionExtension($ext); foreach ($reflection->getClassNames() as $class) { echo $reflection->getName() . ': ' . $class . "\n"; } } }
/** * Test that each classes are defined in reference * * @depends testReference * @group reference * @return void */ public function testGetClassesFromExtension() { if (is_null($this->ref)) { return; } foreach ($this->ref['extensions'] as $extname => $opt) { if ('internal' == $extname) { // only Core is a valid extension name for API reflection continue; } $extension = new ReflectionExtension($extname); $classes = $extension->getClassNames(); foreach ($classes as $classname) { if (class_exists($classname)) { if (!in_array($classname, $this->ignoredclasses)) { $this->assertArrayHasKey($classname, $this->ref['classes'], "Defined class '{$classname}' not known in Reference."); } } else { if (!in_array($classname, $this->ignoredinterfaces)) { $this->assertArrayHasKey($classname, $this->ref['interfaces'], "Defined interface '{$classname}' not known in Reference."); } } } } }
__toString(){return'Extension '.$this->getName();}function getClasses(){$res=array();foreach(parent::getClassNames()as$val){$res[$val]=new ClassType($val);}return$res;}function
/** * Test that each class constants are defined in reference * * @depends testReference * @group reference * @return void */ public function testGetClassConstantsFromExtension() { if (!in_array(self::$ext, self::$extensions)) { $this->assertFalse(false); return; } $extname = self::$ext; $extension = new \ReflectionExtension($extname); $classes = array_unique($extension->getClassNames()); $this->assertTrue(is_array($classes)); $classconstants = self::$obj->getClassConstants(); foreach ($classes as $classname) { $class = new \ReflectionClass($classname); if ($class->getName() != $classname) { /* Skip class alias */ continue; } $parent = $class->getParentClass(); if ($parent) { $constants = array(); } else { $constants = $class->getConstants(); } if (!array_key_exists($classname, $classconstants)) { $classconstants[$classname] = array(); } foreach ($constants as $constantname => $constantvalue) { $this->assertArrayHasKey($constantname, $classconstants[$classname], "Defined class constant '{$classname}::{$constantname}' not known in Reference."); } } }
<?php $extName = "Git"; $extension = new ReflectionExtension($extName); $classes = $extension->getClassNames(); foreach ($classes as $class) { $ref = new ReflectionClass($class); $methods = $ref->getMethods(); $namespace = array(); if (strpos($ref->getName(), "\\") !== false) { $tmp = explode("\\", $ref->getName()); $className = array_pop($tmp); $name = strtolower($className); $namespace = $tmp; $nameSpace = join("\\\\", $namespace) . "\\\\"; $nameSpace2 = join("\\", $namespace) . "\\"; } else { $className = $ref->getName(); $name = strtolower($className); } //if(!is_dir("class/" . $name)){ @mkdir("class/" . $name, 0766); file_put_contents("class/" . $name . "/" . "index.rst", <<<EOS {$nameSpace}{$className} =========================== .. toctree:: :maxdepth: 1 :glob:
/** * Returns default colophons. * @param string profiler | bluescreen * @return array */ public static function getDefaultColophons($sender) { if ($sender === 'profiler') { $arr[] = 'Elapsed time: <b>' . number_format((microtime(TRUE) - Debug::$time) * 1000, 1, '.', ' ') . '</b> ms | Allocated memory: <b>' . number_format(memory_get_peak_usage() / 1000, 1, '.', ' ') . '</b> kB'; foreach ((array) self::$counters as $name => $value) { if (is_array($value)) { $value = implode(', ', $value); } $arr[] = htmlSpecialChars($name) . ' = <strong>' . htmlSpecialChars($value) . '</strong>'; } $autoloaded = class_exists('AutoLoader', FALSE) ? AutoLoader::$count : 0; $s = '<span>' . count(get_included_files()) . '/' . $autoloaded . ' files</span>, '; $exclude = array('stdClass', 'Exception', 'ErrorException', 'Traversable', 'IteratorAggregate', 'Iterator', 'ArrayAccess', 'Serializable', 'Closure'); foreach (get_loaded_extensions() as $ext) { $ref = new ReflectionExtension($ext); $exclude = array_merge($exclude, $ref->getClassNames()); } $classes = array_diff(get_declared_classes(), $exclude); $intf = array_diff(get_declared_interfaces(), $exclude); $func = get_defined_functions(); $func = (array) @$func['user']; $consts = get_defined_constants(TRUE); $consts = array_keys((array) @$consts['user']); foreach (array('classes', 'intf', 'func', 'consts') as $item) { $s .= '<span ' . (${$item} ? 'title="' . implode(", ", ${$item}) . '"' : '') . '>' . count(${$item}) . ' ' . $item . '</span>, '; } $arr[] = $s; } if ($sender === 'bluescreen') { $arr[] = 'Report generated at ' . @date('Y/m/d H:i:s', Debug::$time); // intentionally @ if (isset($_SERVER['HTTP_HOST'], $_SERVER['REQUEST_URI'])) { $url = (isset($_SERVER['HTTPS']) && strcasecmp($_SERVER['HTTPS'], 'off') ? 'https://' : 'http://') . htmlSpecialChars($_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); $arr[] = '<a href="' . $url . '">' . $url . '</a>'; } $arr[] = 'PHP ' . htmlSpecialChars(PHP_VERSION); if (isset($_SERVER['SERVER_SOFTWARE'])) { $arr[] = htmlSpecialChars($_SERVER['SERVER_SOFTWARE']); } $arr[] = htmlSpecialChars(Framework::NAME . ' ' . Framework::VERSION) . ' <i>(revision ' . htmlSpecialChars(Framework::REVISION) . ')</i>'; } return $arr; }
<?php $standard = new ReflectionExtension('standard'); var_dump($standard->getClassNames()); ?> ==DONE==