/** * @return array */ protected function getTagsForExtension($name) { if (!extension_loaded($name)) { return array(); } $tags = array(); $module = new \ReflectionExtension($name); // Export constants. foreach ($module->getConstants() as $name => $value) { $tags[] = new Tag($name, 'constant', Tag::DEFINITION); } // Export functions. foreach ($module->getFunctions() as $function) { $tags[] = new Tag($function->getName(), 'function', TAG::DEFINITION); } // Export classes. foreach ($module->getClasses() as $class) { $tags[] = new Tag($class->getName(), 'class', TAG::DEFINITION); foreach ($class->getMethods() as $method) { $tags[] = new Tag(sprintf('%s::%s', $class->getName(), $method->getName()), 'function', TAG::DEFINITION); } foreach ($class->getProperties() as $property) { $tags[] = new Tag(sprintf('%s::%s', $class->getName(), $property->getName()), 'variable', TAG::DEFINITION); } foreach ($class->getConstants() as $constant => $value) { $tags[] = new Tag(sprintf('%s::%s', $class->getName(), $constant), 'constant', TAG::DEFINITION); } } return $tags; }
public function prepare_storage() { // Generate tables midgard_storage::create_base_storage(); // And update as necessary $re = new ReflectionExtension('midgard2'); $classes = $re->getClasses(); foreach ($classes as $refclass) { if ($refclass->isAbstract() || $refclass->isInterface()) { continue; } $type = $refclass->getName(); if (!is_subclass_of($type, 'MidgardDBObject')) { continue; } if (midgard_storage::class_storage_exists($type)) { // FIXME: Skip updates until http://trac.midgard-project.org/ticket/1426 is fixed continue; if (!midgard_storage::update_class_storage($type)) { $this->markTestSkipped('Could not update ' . $type . ' tables in test database'); } continue; } if (!midgard_storage::create_class_storage($type)) { $this->markTestSkipped('Could not create ' . $type . ' tables in test database'); } } // And update as necessary return; if (!midgard_user::auth('root', 'password')) { echo "auth failed\n"; $this->markTestSkipped('Could not authenticate as ROOT'); } }
/** * Exports all PHP files for this extension * * @param string $directory * @param bool $create_sub_directories * * @throws \Exception * @throws \InvalidArgumentException */ public function exportFiles($directory, $create_sub_directories = true) { $dir = realpath($directory); if (empty($dir) || !file_exists($dir)) { throw new \InvalidArgumentException("Directory does not exist: {$directory}"); } foreach ($this->_extension->getClasses() as $class) { $reflection_class = new ReflectionClass($class); $current_dir = $dir; if ($create_sub_directories) { $namespaces = explode('\\', $class->getNamespaceName()); array_shift($namespaces); $sub_dirs = join(DIRECTORY_SEPARATOR, $namespaces); if (!empty($sub_dirs)) { $current_dir = $dir . DIRECTORY_SEPARATOR . $sub_dirs; if (!file_exists($current_dir) && !@mkdir($current_dir, 0755, true)) { throw new \Exception('Could not create sub directories: ' . $sub_dirs); } } } $filename = $reflection_class->getClassName() . '.php'; $file_path = $current_dir . DIRECTORY_SEPARATOR . $filename; $result = file_put_contents($file_path, $reflection_class->exportCode()); if ($result === false) { throw new \Exception('Could not create file: ' . $file_path); } } }
/** * @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); } }
protected function initialize() { parent::initialize(); $versionParser = new VersionParser(); try { $prettyVersion = PHP_VERSION; $version = $versionParser->normalize($prettyVersion); } catch (\UnexpectedValueException $e) { $prettyVersion = preg_replace('#^(.+?)(-.+)?$#', '$1', PHP_VERSION); $version = $versionParser->normalize($prettyVersion); } $php = new MemoryPackage('php', $version, $prettyVersion); $php->setDescription('The PHP interpreter'); parent::addPackage($php); foreach (get_loaded_extensions() as $name) { if (in_array($name, array('standard', 'Core'))) { continue; } $reflExt = new \ReflectionExtension($name); try { $prettyVersion = $reflExt->getVersion(); $version = $versionParser->normalize($prettyVersion); } catch (\UnexpectedValueException $e) { $prettyVersion = '0'; $version = $versionParser->normalize($prettyVersion); } $ext = new MemoryPackage('ext-' . $name, $version, $prettyVersion); $ext->setDescription('The ' . $name . ' PHP extension'); parent::addPackage($ext); } }
/** * 欢迎页面 */ public function welcomeOp() { /** * 管理员信息 */ $model_admin = Model('admin'); $tmp = $this->getAdminInfo(); $condition['admin_id'] = $tmp['id']; $admin_info = $model_admin->infoAdmin($condition); $admin_info['admin_login_time'] = date('Y-m-d H:i:s', $admin_info['admin_login_time'] == '' ? time() : $admin_info['admin_login_time']); /** * 系统信息 */ $version = C('version'); $setup_date = C('setup_date'); $statistics['os'] = PHP_OS; $statistics['web_server'] = $_SERVER['SERVER_SOFTWARE']; $statistics['php_version'] = PHP_VERSION; $statistics['sql_version'] = Db::getServerInfo(); $statistics['shop_version'] = $version; $statistics['setup_date'] = substr($setup_date, 0, 10); // 运维舫 c extension try { $r = new ReflectionExtension('shopnc'); $statistics['php_version'] .= ' / ' . $r->getVersion(); } catch (ReflectionException $ex) { } Tpl::output('statistics', $statistics); Tpl::output('admin_info', $admin_info); Tpl::showpage('welcome'); }
public function testExtension() { if (!extension_loaded('hstore')) { return; } $r = new \ReflectionExtension('hstore'); $this->assertContains('Intaro\\HStore\\Coder', $r->getClassNames()); }
public function __construct() { parent::__construct(); foreach (get_loaded_extensions() as $ext) { $re = new \ReflectionExtension($ext); $extensions = $this->append(NULL, array($ext, $re)); $this->addFunctions($extensions, $re->getFunctions()); $this->addClasses($extensions, $re->getClasses()); } }
public static function tExtension($test, $ext) { try { $ref = new ReflectionExtension($ext); $v = $ref->getVersion(); self::setTestData($test, '%s found%s', $ref->getName(), $v ? ' v' . $v : ''); return true; } catch (ReflectionException $e) { self::setTestData($test, $e->getMessage()); } return false; }
/** * Constructor. */ protected function __construct() { $this->memcached = new \Memcached(); $this->memcached->addServer(Config::getCacheHost(), Config::getCachePort()); $this->memcached->setOption(\Memcached::OPT_PREFIX_KEY, Config::getCachePrefix()); //determine if deleteMulti() is supported if (defined('HHVM_VERSION')) { $this->hasMultiDelete = false; } else { $ext = new \ReflectionExtension('memcached'); $this->hasMultiDelete = version_compare($ext->getVersion(), '2.0.0', '>='); } }
/** * @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; }
function __construct(SymbolTable $symbolTable, \Guardrail\Output\OutputInterface $output) { parent::__construct($symbolTable, $output); foreach (get_loaded_extensions() as $extension) { try { $reflectedExtension = new \ReflectionExtension($extension); foreach ($reflectedExtension->getConstants() as $constant => $value) { $this->reflectedConstants[$constant] = true; } } catch (\ReflectionException $e) { } } }
protected function getIcuVersion() { if (defined('INTL_ICU_VERSION')) { $version = INTL_ICU_VERSION; } else { $reflector = new \ReflectionExtension('intl'); ob_start(); $reflector->info(); $output = strip_tags(ob_get_clean()); preg_match('/^ICU version +(?:=> )?(.*)$/m', $output, $matches); $version = $matches[1]; } return $version; }
private static function mustHaveExtension($ext) { if (!extension_loaded($ext)) { echo "ERROR: The PHP extension '{$ext}' is not installed. You must " . "install it to run aphlict on this machine.\n"; exit(1); } $extension = new ReflectionExtension($ext); foreach ($extension->getFunctions() as $function) { $function = $function->name; if (!function_exists($function)) { echo "ERROR: The PHP function {$function}() is disabled. You must " . "enable it to run aphlict on this machine.\n"; exit(1); } } }
private static function mustHaveExtension($ext) { if (!extension_loaded($ext)) { echo pht("ERROR: The PHP extension '%s' is not installed. You must " . "install it to run Aphlict on this machine.", $ext) . "\n"; exit(1); } $extension = new ReflectionExtension($ext); foreach ($extension->getFunctions() as $function) { $function = $function->name; if (!function_exists($function)) { echo pht('ERROR: The PHP function %s is disabled. You must ' . 'enable it to run Aphlict on this machine.', $function . '()') . "\n"; exit(1); } } }
public function getFunctions() { foreach ($res = parent::getFunctions() as $key => $val) { $res[$key] = new FunctionReflection($key); } return $res; }
/** * @return array */ public function opcodeCacheData() { $cacheData = array(); foreach (static::$opcacheExtenstions as $name => $data) { list($title, $iniSetting) = $data; if ($this->hasCache($name, $iniSetting)) { $cacheData['title'] = $title; $cacheData['name'] = $name; $ref = new \ReflectionExtension($name); $cacheData['version'] = $ref->getVersion(); $cacheData['settings'] = $ref->getINIEntries(); break; } } return $cacheData; }
function expectArgumentError($message) { try { $extension = new \ReflectionExtension('functional'); $extensionFunctions = array_keys($extension->getFunctions()); $isDefinedInExtension = F\every($this->functions, function ($function) use($extensionFunctions) { return in_array($function, $extensionFunctions, true); }); if ($isDefinedInExtension) { $this->setExpectedException('PHPUnit_Framework_Error_Warning', $message); } else { $this->setExpectedException('Functional\\Exceptions\\InvalidArgumentException', $message); } } catch (\ReflectionException $e) { $this->setExpectedException('Functional\\Exceptions\\InvalidArgumentException', $message); } }
private function getTypes() { $mgdschemas = array(); $re = new \ReflectionExtension('midgard2'); $classes = $re->getClasses(); foreach ($classes as $refclass) { $parent_class = $refclass->getParentClass(); if (!$parent_class) { continue; } if ($parent_class->getName() != 'midgard_object') { continue; } $mgdschemas[$include_views][] = $refclass->getName(); } return $mgdschemas; }
public function getClasses() { $classes = parent::getClasses(); $result = array(); foreach ($classes as $class) { $result[] = new MyReflectionClass($class->getName()); } return $result; }
protected function getIcuVersion() { static $icuVersion = null; if (defined('INTL_ICU_VERSION')) { return INTL_ICU_VERSION; } if ($icuVersion === null) { $icuVersion = 0; $ext = new ReflectionExtension('intl'); ob_start(); $ext->info(); $info = ob_get_contents(); if (preg_match('/ICU Version => (.*)/i', $info, $match)) { $icuVersion = $match[1]; } ob_end_clean(); } return $icuVersion; }
protected function getIntlExtensionIcuVersion() { if (isset(self::$icuVersion)) { return self::$icuVersion; } if (!$this->isIntlExtensionLoaded()) { throw new \RuntimeException('The intl extension is not available'); } if (defined('INTL_ICU_VERSION')) { return INTL_ICU_VERSION; } $reflector = new \ReflectionExtension('intl'); ob_start(); $reflector->info(); $output = ob_get_clean(); preg_match('/^ICU version => (.*)$/m', $output, $matches); self::$icuVersion = $matches[1]; return self::$icuVersion; }
public function get_mgdschema_classes() { static $mgdschemas = array(); if (empty($mgdschemas)) { // Get the classes from PHP5 reflection $re = new ReflectionExtension('midgard2'); $classes = $re->getClasses(); foreach ($classes as $refclass) { $parent_class = $refclass->getParentClass(); if (!$parent_class) { continue; } if ($parent_class->getName() == 'midgard_object') { $mgdschemas[] = $refclass->getName(); } } } return $mgdschemas; }
public function introspect(\ReflectionExtension $extension) { $classes = $functions = $constants = array(); foreach ($extension->getClasses() as $class) { assert($class instanceof \ReflectionClass); $phpClass = PhpClass::fromReflection($class); $classes[] = $phpClass; } foreach ($extension->getFunctions() as $function) { assert($function instanceof \ReflectionFunction); $phpFunction = PhpFunction::fromReflection($function); $functions[] = $phpFunction; } foreach ($extension->getConstants() as $name => $value) { $phpConstant = new PhpConstant($name); $phpConstant->setValue($value); $constants[] = $phpConstant; } return array('classes' => $classes, 'functions' => $functions, 'constants' => $constants); }
/** * Get all this extensions classes * * @return Nerd\Design\Collection Enumerable array of extension classes */ public function getClasses() { if ($this->classes === null) { $classes = parent::getClasses(); foreach ($classes as $key => $class) { $classes[$key] = new Klass($class->getName()); } $this->classes = new Collection($classes); } return $this->classes; }
public function getClasses() { $phpReflections = parent::getClasses(); $zendReflections = array(); while ($phpReflections && ($phpReflection = array_shift($phpReflections))) { $zendReflections[] = new ZendL_Reflection_Class($phpReflection->getName()); unset($phpReflection); } unset($phpReflections); return $zendReflections; }
public function __construct($locale = 'en') { $this->setName('Locales'); $this->addRequirement(class_exists('Locale'), 'intl extension should be available', 'Install and enable the <strong>intl</strong> extension (used for validators).'); if (class_exists('Collator')) { $this->addRecommendation(null !== new \Collator('fr'), 'intl extension should be correctly configured', 'The intl extension does not behave properly. This problem is typical on PHP 5.3.X x64 WIN builds.'); } if (class_exists('Locale')) { if (defined('INTL_ICU_VERSION')) { $version = INTL_ICU_VERSION; } else { $reflector = new \ReflectionExtension('intl'); ob_start(); $reflector->info(); $output = strip_tags(ob_get_clean()); preg_match('/^ICU version +(?:=> )?(.*)$/m', $output, $matches); $version = $matches[1]; } $this->addRecommendation(version_compare($version, '4.0', '>='), 'intl ICU version should be at least 4+', 'Upgrade your <strong>intl</strong> extension with a newer ICU version (4+).'); } }
function export_ext($ext) { $rf_ext = new ReflectionExtension($ext); $funcs = $rf_ext->getFunctions(); $classes = $rf_ext->getClasses(); $consts = $rf_ext->getConstants(); $version = $rf_ext->getVersion(); $defines = ''; $sp4 = str_repeat(' ', 4); $fdefs = getFuncDef($funcs, $version); $class_def = ''; foreach ($consts as $k => $v) { if (!is_numeric($v)) { $v = "'{$v}'"; } $defines .= "define('{$k}',{$v});\n"; } foreach ($classes as $k => $v) { $prop_str = ''; $props = $v->getProperties(); array_walk($props, function ($v, $k) { global $prop_str, $sp4; $modifiers = implode(' ', Reflection::getModifierNames($v->getModifiers())); $prop_str .= "{$sp4}/**\n{$sp4}*@var \$" . $v->name . " " . $v->class . "\n{$sp4}*/\n{$sp4} {$modifiers} \$" . $v->name . ";\n\n"; }); if ($v->getParentClass()) { $k .= ' extends ' . $v->getParentClass()->name; } $modifier = 'class'; if ($v->isInterface()) { $modifier = 'interface'; } $mdefs = getMethodsDef($v->getMethods(), $version); $class_def .= sprintf("/**\n*@since %s\n*/\n%s %s{\n%s%s\n}\n", $version, $modifier, $k, $prop_str, $mdefs); } if (!file_exists('./ext')) { mkdir('./ext', 777, TRUE); } file_put_contents("./ext/" . $ext . ".php", "<?php\n" . $defines . $fdefs . $class_def); }
/** * Prepares a mgd2 database */ function openpsa_prepare_database($config) { if (!$config->create_blobdir()) { throw new Exception("Failed to create file attachment storage directory to {$config->blobdir}:" . midgard_connection::get_instance()->get_error_string()); } // Create storage if (!midgard_storage::create_base_storage()) { if (midgard_connection::get_instance()->get_error_string() != 'MGD_ERR_OK') { throw new Exception("Failed to create base database structures" . midgard_connection::get_instance()->get_error_string()); } } $re = new ReflectionExtension('midgard2'); $classes = $re->getClasses(); foreach ($classes as $refclass) { if (!$refclass->isSubclassOf('midgard_object')) { continue; } $type = $refclass->getName(); midgard_storage::create_class_storage($type); midgard_storage::update_class_storage($type); } }
/** * Get extension class reflection objects * * @param string $reflectionClass Name of reflection class to use * @return array Array of Zend_Reflection_Class objects */ public function getClasses($reflectionClass = 'Zend_Reflection_Class') { $phpReflections = parent::getClasses(); $zendReflections = array(); while ($phpReflections && ($phpReflection = array_shift($phpReflections))) { $instance = new $reflectionClass($phpReflection->getName()); if (!$instance instanceof Zend_Reflection_Class) { throw new Zend_Reflection_Exception('Invalid reflection class provided; must extend Zend_Reflection_Class'); } $zendReflections[] = $instance; unset($phpReflection); } unset($phpReflections); return $zendReflections; }