本文整理汇总了PHP中ReflectionExtension::getConstants方法的典型用法代码示例。如果您正苦于以下问题:PHP ReflectionExtension::getConstants方法的具体用法?PHP ReflectionExtension::getConstants怎么用?PHP ReflectionExtension::getConstants使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ReflectionExtension
的用法示例。
在下文中一共展示了ReflectionExtension::getConstants方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getTagsForExtension
/**
* @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;
}
示例2: getConstants
/**
* Returns an associative array containing this extension's constants and
* their values
* @return array<string,mixed>
*/
public function getConstants()
{
if ($this->reflectionSource) {
return $this->reflectionSource->getConstants();
} else {
return parent::getConstants();
}
}
示例3: foreach
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) {
}
}
}
示例4: __invoke
/**
* @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;
}
示例5: introspect
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);
}
示例6: export_ext
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);
}
示例7: export
function export()
{
/**
* 获取所有define常量
*/
$consts = $this->rf_ext->getConstants();
$defines = '';
foreach ($consts as $className => $ref) {
if (!is_numeric($ref)) {
$ref = "'{$ref}'";
}
$defines .= "define('{$className}', {$ref});\n";
}
file_put_contents(OUTPUT_DIR . '/constants.php', "<?php\n" . $defines);
/**
* 获取所有函数
*/
$funcs = $this->rf_ext->getFunctions();
$fdefs = $this->getFunctionsDef($funcs);
file_put_contents(OUTPUT_DIR . '/functions.php', "<?php\n" . $fdefs);
/**
* 获取所有类
*/
$classes = $this->rf_ext->getClasses();
$class_alias = "<?php\n";
foreach ($classes as $className => $ref) {
//命名空间
if (strchr($className, '\\')) {
$this->exportNamespaceClass($className, $ref);
continue;
} else {
$class_alias .= sprintf("\nclass %s extends %s\n{\n\n}\n", $className, self::getNamespaceAlias($className));
}
}
file_put_contents(OUTPUT_DIR . '/classes.php', $class_alias);
}
示例8: gen_extension_markup
function gen_extension_markup(ReflectionExtension $obj, $content, $xml_file)
{
/* {{{ */
global $INFO, $OPTION;
switch ($xml_file) {
case 'ini.xml':
if ($ini = ini_get_all($obj->name)) {
$visibility = array(INI_USER => 'PHP_INI_USER', INI_PERDIR => 'PHP_INI_PERDIR', INI_SYSTEM => 'PHP_INI_SYSTEM', INI_ALL => 'PHP_INI_ALL');
$ident = get_ident_size('INI_ENTRIES', $content);
$markup = "<tbody>" . PHP_EOL;
$markup2 = '';
foreach ($ini as $config => $value) {
$id = "ini." . format_config($config);
$markup .= str_repeat(' ', $ident + 1) . "<row>" . PHP_EOL;
$markup .= str_repeat(' ', $ident + 2) . "<entry><link linkend=\"" . $id . "\">" . $config . "</link></entry>" . PHP_EOL;
$markup .= str_repeat(' ', $ident + 2) . "<entry>" . $value['global_value'] . "</entry>" . PHP_EOL;
$markup .= str_repeat(' ', $ident + 2) . "<entry>" . (isset($visibility[$value['access']]) ? $visibility[$value['access']] : $value['access']) . "</entry>" . PHP_EOL;
$markup .= str_repeat(' ', $ident + 2) . "<entry><!-- leave empty, this will be filled by an automatic script --></entry>" . PHP_EOL;
$markup .= str_repeat(' ', $ident + 1) . "</row>" . PHP_EOL;
$markup2 .= ($markup2 ? str_repeat(' ', $ident) : '') . "<varlistentry xml:id=\"" . $id . "\">" . PHP_EOL;
$markup2 .= str_repeat(' ', $ident + 1) . "<term>" . PHP_EOL;
$markup2 .= str_repeat(' ', $ident + 2) . "<parameter>" . $config . "</parameter>" . PHP_EOL;
$markup2 .= str_repeat(' ', $ident + 2) . "<type>" . get_type_by_string($value['global_value']) . "</type>" . PHP_EOL;
$markup2 .= str_repeat(' ', $ident + 1) . "</term>" . PHP_EOL;
$markup2 .= str_repeat(' ', $ident + 1) . "<listitem>" . PHP_EOL;
$markup2 .= str_repeat(' ', $ident + 2) . "<para>" . PHP_EOL;
$markup2 .= str_repeat(' ', $ident + 3) . PHP_EOL;
$markup2 .= str_repeat(' ', $ident + 2) . "</para>" . PHP_EOL;
$markup2 .= str_repeat(' ', $ident + 1) . "</listitem>" . PHP_EOL;
$markup2 .= str_repeat(' ', $ident) . "</varlistentry>" . PHP_EOL;
}
$markup .= str_repeat(' ', $ident) . "</tbody>";
/* {INI_ENTRIES} */
$content = preg_replace('/\\{INI_ENTRIES\\}/', $markup, $content, 1);
/* {INI_ENTRIES_DESCRIPTION} */
$content = preg_replace('/\\{INI_ENTRIES_DESCRIPTION\\}/', $markup2, $content, 1);
} else {
return false;
/* Abort */
}
break;
case 'constants.xml':
if ($constants = $obj->getConstants()) {
$ident = get_ident_size('CONSTANTS', $content);
$markup = "&extension.constants;" . PHP_EOL;
$markup .= str_repeat(' ', $ident) . "<para>" . PHP_EOL;
$markup .= str_repeat(' ', $ident + 1) . "<variablelist>" . PHP_EOL;
foreach ($constants as $name => $value) {
$markup .= str_repeat(' ', $ident + 2) . '<varlistentry xml:id="constant.' . format_id($name) . '">' . PHP_EOL;
$markup .= str_repeat(' ', $ident + 3) . "<term>" . PHP_EOL;
$markup .= str_repeat(' ', $ident + 4) . "<constant>" . $name . "</constant>" . PHP_EOL;
$markup .= str_repeat(' ', $ident + 4) . "(<type>" . gettype($value) . "</type>)" . PHP_EOL;
$markup .= str_repeat(' ', $ident + 3) . "</term>" . PHP_EOL;
$markup .= str_repeat(' ', $ident + 3) . "<listitem>" . PHP_EOL;
$markup .= str_repeat(' ', $ident + 4) . "<simpara>" . PHP_EOL;
$markup .= str_repeat(' ', $ident + 4) . "</simpara>" . PHP_EOL;
$markup .= str_repeat(' ', $ident + 3) . "</listitem>" . PHP_EOL;
$markup .= str_repeat(' ', $ident + 2) . "</varlistentry>" . PHP_EOL;
}
$markup .= str_repeat(' ', $ident + 1) . "</variablelist>" . PHP_EOL;
$markup .= str_repeat(' ', $ident) . "</para>";
$content = preg_replace('/\\{CONSTANTS\\}/', $markup, $content, 1);
} else {
$content = preg_replace('/\\{CONSTANTS\\}/', '&no.constants;', $content, 1);
}
break;
case 'configure.xml':
$ident = get_ident_size('EXT_INSTALL_MAIN', $content);
$ident2 = get_ident_size('EXT_INSTALL_WIN', $content);
$markup = '';
$markup2 = '';
if ($OPTION['pecl'] === true) {
$markup .= "<para>" . PHP_EOL;
$markup .= str_repeat(' ', $ident + 1) . "&pecl.info;" . PHP_EOL;
$markup .= str_repeat(' ', $ident + 1) . "<link xlink:href=\"&url.pecl.package;{EXT_NAME_ID}\">&url.pecl.package;{EXT_NAME_ID}</link>" . PHP_EOL;
$markup .= str_repeat(' ', $ident) . "</para>" . PHP_EOL;
/*
$markup2 .= "<para>". PHP_EOL;
$markup2 .= str_repeat(' ', $ident2 + 1) ."The latest PECL/{EXT_NAME_ID} Win32 DLL is available here:". PHP_EOL;
$markup2 .= str_repeat(' ', $ident2 + 1) ."<link xlink:href=\"&url.pecl.win.ext;php_{EXT_NAME_ID}.dll\">php_{EXT_NAME_ID}.dll</link>". PHP_EOL;
$markup2 .= str_repeat(' ', $ident2) ."</para>". PHP_EOL;
*/
} else {
$markup .= "<para>" . PHP_EOL;
$markup .= str_repeat(' ', $ident + 1) . "Use <option role=\"configure\">--with-{EXT_NAME_ID}[=DIR]</option> when compiling PHP." . PHP_EOL;
$markup .= str_repeat(' ', $ident) . "</para>" . PHP_EOL;
$markup2 .= "<para>" . PHP_EOL;
$markup2 .= str_repeat(' ', $ident2 + 1) . "Windows users should include <filename>php_{EXT_NAME_ID}.dll</filename> into &php.ini;" . PHP_EOL;
$markup2 .= str_repeat(' ', $ident2) . "</para>" . PHP_EOL;
}
$content = str_replace('{EXT_INSTALL_MAIN}', $markup, $content);
$content = str_replace('{EXT_INSTALL_WIN}', $markup2, $content);
break;
case 'versions.xml':
$version_default = 'PHP 5 >= Unknown';
if ($OPTION['pecl'] === true) {
$version_default = 'PECL {EXT_NAME_ID} >= Unknown';
}
$markup = "";
/* Function list */
//.........这里部分代码省略.........
示例9: fopen
default:
case 3:
$out = fopen($argv[2], "w") or die;
case 2:
$ext = $argv[1];
break;
case 1:
die(sprintf($out, "Usage: %s <ext>\n", $argv[0]));
}
fprintf($out, "<?php\n\n");
$ext = new ReflectionExtension($ext);
$constants = array();
$functions = array();
$structures = array();
// split up by namespace first
foreach ($ext->getConstants() as $constant => $value) {
$ns = ($nsend = strrpos($constant, "\\")) ? substr($constant, 0, $nsend++) : "";
$cn = substr($constant, $nsend);
$constants[$ns][$cn] = $value;
}
foreach ($ext->getFunctions() as $f) {
/* @var $f ReflectionFunction */
$ns = $f->inNamespace() ? $f->getNamespaceName() : "";
$functions[$ns][$f->getShortName()] = $f;
}
foreach ($ext->getClasses() as $c) {
/* @var $c ReflectionClass */
$ns = $c->inNamespace() ? $c->getNamespaceName() : "";
$structures[$ns][$c->getShortName()] = $c;
}
$namespaces = array_unique(array_merge(array_keys($constants), array_keys($functions), array_keys($structures)));
示例10: ReflectionExtension
<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>
示例11: printInfo
public function printInfo()
{
$info = [];
$ion = new \ReflectionExtension('ion');
$info[] = $ion->info();
foreach ($ion->getINIEntries() as $ini => $value) {
$info[] = "ini {$ini} = " . var_export($value, true);
}
foreach ($ion->getConstants() as $constant => $value) {
$info[] = "const {$constant} = " . var_export($value, true);
}
foreach ($ion->getFunctions() as $function) {
$info[] = $this->_scanFunction($function);
}
foreach ($ion->getClasses() as $class) {
$mods = [];
if ($class->isFinal()) {
$mods[] = "final";
}
if ($class->isInterface()) {
$mods[] = "interface";
} elseif ($class->isTrait()) {
$mods[] = "trait";
} else {
if ($class->isAbstract()) {
$mods[] = "abstract";
}
$mods[] = "class";
}
$info[] = implode(' ', $mods) . " {$class->name} {";
if ($class->getParentClass()) {
$info[] = " extends {$class->getParentClass()->name}";
}
foreach ($class->getInterfaceNames() as $interface) {
$info[] = " implements {$interface}";
}
foreach ($class->getTraitNames() as $trait) {
$info[] = " use {$trait}";
}
foreach ($class->getConstants() as $constant => $value) {
$info[] = " const {$class->name}::{$constant} = " . var_export($value, true);
}
foreach ($class->getProperties() as $prop_name => $prop) {
/** @var ReflectionProperty $prop */
$mods = implode(' ', Reflection::getModifierNames($prop->getModifiers()));
if ($prop->class !== $class->name) {
$info[] = " prop {$mods} {$prop->class}::\${$prop->name}";
} else {
$info[] = " prop {$mods} \${$prop->name}";
}
}
foreach ($class->getMethods() as $method) {
$info[] = $this->_scanFunction($method, $class->name);
}
$info[] = "}";
}
echo implode("\n", $info) . "\n";
}
示例12: ReflectionExtension
<?php
$ext = new ReflectionExtension("standard");
$consts = $ext->getConstants();
var_dump($consts["CONNECTION_NORMAL"]);
示例13: array
# Housekeeping.
error_reporting(E_ALL | E_DEPRECATED | E_STRICT);
ini_set('display_errors', 'On');
date_default_timezone_set('UTC');
$blocks = array('extensions' => array(), 'last-modified' => sprintf('" %s, PHP %s', date('r'), PHP_VERSION));
# Parse the configuration file associated with this script.
$configuration = parse_ini_file(__DIR__ . '/syntax.ini', true);
# Process extensions and generate built-in functions, constants, classes and interfaces.
$extensions = array();
foreach ($configuration['extensions'] as $extensionName => $isEnabled) {
if (!$isEnabled) {
continue;
}
try {
$reflect = new ReflectionExtension($extensionName);
$options = array('name' => $reflect->getName(), 'classes' => array(), 'functions' => array_keys($reflect->getFunctions()), 'constants' => array_diff(array_keys($reflect->getConstants()), array('TRUE', 'FALSE', 'NULL')));
foreach ($reflect->getClasses() as $extensionClass) {
$options['classes'][] = $extensionClass->getName();
$options['constants'] = array_unique(array_merge($options['constants'], array_keys($extensionClass->getConstants())));
}
sort($options['classes'], SORT_NATURAL);
sort($options['functions'], SORT_NATURAL);
sort($options['constants'], SORT_NATURAL);
$extensions[$extensionName] = $options;
} catch (ReflectionException $e) {
file_put_contents('php://stderr', sprintf('[ERROR] %s: %s.' . PHP_EOL, $extensionName, rtrim($e->getMessage(), ' ?!.')));
}
}
$blocks['extensions'][] = 'if ! exists("g:php_syntax_extensions_enabled")';
$blocks['extensions'][] = sprintf(' let g:php_syntax_extensions_enabled = ["%s"]', implode('", "', array_map('strtolower', array_keys($extensions))));
$blocks['extensions'][] = 'endif';
示例14: ReflectionExtension
<?php
## Использование отражения библиотеки.
$consts = [];
foreach (get_loaded_extensions() as $name) {
$ext = new ReflectionExtension($name);
$consts = array_merge($consts, $ext->getConstants());
}
echo "<pre>" . var_export($consts, true) . "</pre>";
示例15: _getExtension
/**
* 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;
}