本文整理汇总了PHP中ReflectionObject::getConstants方法的典型用法代码示例。如果您正苦于以下问题:PHP ReflectionObject::getConstants方法的具体用法?PHP ReflectionObject::getConstants怎么用?PHP ReflectionObject::getConstants使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ReflectionObject
的用法示例。
在下文中一共展示了ReflectionObject::getConstants方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setCreationParams
/**
* Set the creation parameters
*
* @param array $creationParams
* @return void
*/
public function setCreationParams(array $creationParams)
{
if (empty($creationParams)) {
return;
}
$r = new ReflectionObject($this);
$class = $r->getName();
$constants = $r->getConstants();
$parameterConstants = array_filter(array_keys($constants), array($this, '_getParameterConstants'));
$supportedParameters = array();
for ($i = 0, $n = count($parameterConstants); $i < $n; $i++) {
$constant = $parameterConstants[$i];
$supportedParameters[] = constant($class . '::' . $constant);
}
if (empty($supportedParameters)) {
return;
}
foreach ($creationParams as $param => $value) {
if (in_array($param, $supportedParameters)) {
$method = 'set' . ucfirst($param);
if (method_exists($this, $method)) {
$this->{$method}($value);
}
}
}
}
示例2: __construct
public function __construct()
{
$reflection = new \ReflectionObject($this);
$this->values = $reflection->getConstants();
$names = array_keys($this->values);
$this->names = array_combine($names, $names);
$this->valuesAsNames = array_combine($this->value, $names);
}
示例3: ReflectionObject
function __construct($value)
{
$ref = new ReflectionObject($this);
$consts = $ref->getConstants();
if (!in_array($value, $consts, true)) {
throw new InvalidArgumentException();
}
$this->scalar = $value;
}
示例4: __construct
public function __construct()
{
/**
* Populate our valid log levels by Reflecting on the
* constants exposed in the Psr\Log\LogLevel class
*/
$t = new LogLevel();
$r = new \ReflectionObject($t);
$this->aValidLogLevels = $r->getConstants();
}
示例5: __construct
public function __construct()
{
// populate our array of valid LogLevels using Reflection
/**
* @var $t LogLevel
*/
$t = new LogLevel();
$r = new \ReflectionObject($t);
$this->_aValidLogLevels = $r->getConstants();
}
示例6: testAddingValidHandler
public function testAddingValidHandler()
{
/**
* @var $t \Talkback\Log\LogLevel
*/
$t = new LogLevel();
$r = new \ReflectionObject($t);
$aLogLevels = $r->getConstants();
$obj = Logger::getLogger('test3');
$aBuildLevels = array();
foreach ($aLogLevels as $LogLevel) {
$aBuildLevels[] = $LogLevel;
$obj->addChannel($aBuildLevels, ChannelFactory::Basic());
}
}
示例7: __construct
/**
* @param null $filename optional filename (path + filename)
* @throws \Talkback\Exception\InvalidArgumentException
*/
public function __construct($filename = null)
{
/**
* Populate our valid log levels by Reflecting on the
* constants exposed in the Psr\Log\LogLevel class
*/
$t = new LogLevel();
$r = new \ReflectionObject($t);
$this->_aValidLogLevels = $r->getConstants();
// Set our filename
if (!is_null($filename)) {
if (file_exists($filename) && !is_writable($filename)) {
$processUser = posix_getpwuid(posix_geteuid());
throw new InvalidArgumentException('logfile must be writeable by user: ' . $processUser['name']);
}
$this->_filename = $filename;
}
}
示例8: get
public static function get($native, $type = self::STRING)
{
switch ($type) {
case self::FILEPATH:
return Filepath::fromNative($native);
break;
case self::STRING:
return StringLiteral::fromNative($native);
break;
case self::URL:
return Url::fromNative($native);
break;
default:
$oReflection = new \ReflectionObject(new self());
$allowedTypes = array_keys($oReflection->getConstants());
throw new InvalidNativeArgumentException($type, $allowedTypes);
break;
}
}
示例9: update
public static function update($status, $to_job_id, $namespace)
{
\Resque::setBackend('127.0.0.1:6379');
if (!empty($namespace)) {
\Resque_Redis::prefix($namespace);
}
$job = new \Resque_Job_Status($to_job_id);
if (!$job->get()) {
throw new \RuntimeException("Job {$to_job_id} was not found");
}
$class = new \ReflectionObject($job);
foreach ($class->getConstants() as $constant_value) {
if ($constant_value == $status) {
$job->update($status);
return true;
}
}
return false;
}
示例10: api
public function api($var)
{
if (is_object($var)) {
$class = get_class($var);
$obj = $var;
} else {
if (!class_exists($var)) {
throw new \Exception('Class [' . $var . '] doesn\'t exist');
}
$class = $var;
try {
$obj = new $class();
} catch (\Exception $e) {
throw new \Exception('Debug::api could not instantiate [' . $var . '], send it an object.');
}
}
$reflection = new \ReflectionObject($obj);
$properties = array();
foreach (array('public' => \ReflectionProperty::IS_PUBLIC, 'protected' => \ReflectionProperty::IS_PROTECTED, 'private' => \ReflectionProperty::IS_PRIVATE) as $access => $rule) {
$vars = $reflection->getProperties($rule);
foreach ($vars as $refProp) {
$property = $refProp->getName();
$refProp->setAccessible(true);
$value = $refProp->getValue($obj);
$type = gettype($value);
if (is_object($value)) {
$value = get_class($value);
} elseif (is_array($value)) {
$value = 'array[' . count($value) . ']';
}
$properties[$access][$property] = compact('value', 'type');
}
}
$constants = $reflection->getConstants();
$methods = array();
foreach (array('public' => \ReflectionMethod::IS_PUBLIC, 'protected' => \ReflectionMethod::IS_PROTECTED, 'private' => \ReflectionMethod::IS_PRIVATE) as $access => $rule) {
$refMethods = $reflection->getMethods($rule);
foreach ($refMethods as $refMethod) {
$refParams = $refMethod->getParameters();
$params = array();
foreach ($refParams as $refParam) {
$params[] = $refParam->getName();
}
/*
$required = $refMethod->getNumberOfRequiredParameters();
$requiredParams = array();
for ($i=0;$i<$required;$i++) {
$requiredParams[] = array_shift($params);
}*/
$method_name = $refMethod->getName();
$string = $access . ' function ' . $method_name . '(';
$paramString = '';
foreach ($params as $p) {
$paramString .= '$' . $p . ', ';
}
$paramString = substr($paramString, 0, -2);
$string .= $paramString;
$string .= ')';
$comment = $refMethod->getDocComment();
$comment = trim(preg_replace('/^(\\s*\\/\\*\\*|\\s*\\*{1,2}\\/|\\s*\\* ?)/m', '', $comment));
$comment = str_replace("\r\n", "\n", $comment);
$commentParts = explode('@', $comment);
$description = array_shift($commentParts);
$tags = array();
foreach ($commentParts as $part) {
$tagArr = explode(' ', $part, 2);
if ($tagArr[0] == 'param') {
$paramArr = preg_split("/[\\s\t]+/", $tagArr[1]);
$type = array_shift($paramArr);
if (empty($type)) {
$type = array_shift($paramArr);
}
$name = array_shift($paramArr);
$info = implode(' ', $paramArr);
$tags['param'][$name] = compact('type', 'info');
} else {
$tags[$tagArr[0]] = isset($tagArr[1]) ? $tagArr[1] : '';
}
}
$methods[$access][$string] = compact('description', 'tags');
}
}
return compact('properties', 'constants', 'methods');
}
示例11: setLevel
/**
* mainly used for logging/debugging - sets the log level
*
* @param $level string one of \Psr\Log\LogLevel constants
*
* @throws \Talkback\Exception\InvalidArgumentException
*/
public function setLevel($level)
{
$t = new LogLevel();
$r = new \ReflectionObject($t);
$aLevels = $r->getConstants();
$level = strtolower($level);
if (!in_array($level, $aLevels)) {
throw new InvalidArgumentException('setLevel($level) must be set with a \\Psr\\Log\\LogLevel const value');
}
$this->level = $level;
}
示例12: GetMediaTypeName
/**
* Возвращает название медиа типа по его значению
* Название получается автоматически из константы с определением типа
*
* @param $iType
* @return null|string
*/
public function GetMediaTypeName($iType)
{
$oRefl = new ReflectionObject($this);
foreach ($oRefl->getConstants() as $sName => $mValue) {
if (strpos($sName, 'MEDIA_TYPE_') === 0 and $mValue == $iType) {
return strtolower(substr($sName, strlen('MEDIA_TYPE_')));
}
}
return null;
}
示例13: ReflectionObject
<?php
/*
This is a page that enables the user to import more data into the application.
*/
require_once "include_files.php";
$t = new db_enum_ttype();
$r = new ReflectionObject($t);
$ttypeList = $r->getConstants();
?>
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function()
{
// do stuff when the submit button is clicked
$('form[name="myform"]').submit(function(e)
{
if(confirm("Are you sure you want to proceed with upload?")){
// disable the submit button
$('input[type="submit"]').attr('disabled', true);
// submit the form
return true;
}else{return false;}
});
});
</script>
</head>
<body>
示例14: outInfo
//.........这里部分代码省略.........
// setAccessible only around >5.3...
if (method_exists($property, 'setAccessible')) {
$property->setAccessible(true);
$prop_val = $property->getValue($val);
} else {
if ($property->isPublic()) {
$prop_val = $property->getValue($val);
} else {
$prop_val = $format_handler->wrap('i', 'Not Accessible');
$prop_check = false;
}
//if/else
}
//if/else
if (is_array($prop_val)) {
$prop_val = $format_handler->escapeArray(trim($this->aIter($prop_val, 2, false)));
} else {
if ($prop_check) {
$arg_map = new out_arg('', $prop_val);
$prop_val = $arg_map->defaultValue();
}
//if
}
//if/else
$info_list[] = sprintf('%s%s %s = %s', $indent, $format_handler->wrap('span', join(' ', Reflection::getModifierNames($property->getModifiers())), out_config::COLOR_MODIFIER), $format_handler->wrap('span', $property->getName(), out_config::COLOR_PARAM), $prop_val);
}
//foreach
// handle methods...
$methods = $rclass->getMethods();
$info_list[] = $format_handler->wrap('b', sprintf('%s (%d):', 'Methods', count($methods)));
$method_list = array();
$only_public_methods = empty($calling_class) ? true : !in_array($calling_class, $class_name_list);
foreach ($methods as $method) {
// we only want to show methods the person can use...
if ($only_public_methods && !$method->isPublic()) {
continue;
}
//if
$method_comment = $method->getDocComment();
$params = $method->getParameters();
$param_list = array();
foreach ($params as $param) {
$param_type = '';
if (!empty($method_comment)) {
$match = array();
if (preg_match(sprintf('#\\*\\s*@param\\s+(\\S+)\\s+\\$%s#iu', preg_quote($param->getName())), $method_comment, $match)) {
$param_type = $format_handler->wrap('span', $match[1], out_config::COLOR_TYPE) . ' ';
}
//if
}
//if
$param_str = $format_handler->wrap('span', sprintf('%s$%s', $param_type, $param->getName()), out_config::COLOR_PARAM);
if ($param->isDefaultValueAvailable()) {
$arg_map = new out_arg('', $param->getDefaultValue());
$param_str .= ' = ' . $arg_map->defaultValue();
}
//if
$param_list[] = $param_str;
}
//foreach
// see if we can get a return type for the method...
$method_return_type = '';
if (!empty($method_comment)) {
$match = array();
if (preg_match('#\\*\\s*@return\\s+(\\S+)#iu', $method_comment, $match)) {
$method_return_type = ' ' . $format_handler->wrap('span', $match[1], out_config::COLOR_TYPE);
}
//if
}
//if
$method_list[$method->getName()] = sprintf('%s%s%s %s(%s)', $indent, $format_handler->wrap('span', join(' ', Reflection::getModifierNames($method->getModifiers())), out_config::COLOR_MODIFIER), $method_return_type, $method->getName(), join(', ', $param_list));
}
//foreach
ksort($method_list);
$info_list = array_merge($info_list, array_values($method_list));
// handle constants...
$constants = $rclass->getConstants();
$info_list[] = $format_handler->wrap('b', sprintf('%s (%d):', 'Constants', count($constants)));
foreach ($constants as $const_name => $const_val) {
$info_list[] = sprintf('%s%s = %s', $indent, $format_handler->wrap('span', $const_name, out_config::COLOR_PARAM), $const_val);
}
//foreach
break;
case self::TYPE_BOOLEAN:
$info_type = 'boolean';
$info_list[] = sprintf('value: %s', $this->defaultValue());
break;
case self::TYPE_BREAK:
$info_type = 'break';
$info_list[] = sprintf('lines: %d', $this->name());
break;
case self::TYPE_UNDEFINED:
default:
$type = 'undefined';
break;
}
//switch
$this->printValue(sprintf("%s (%s)\r\n%s", $format_handler->wrap('b', $name), $info_type, empty($info_list) ? '' : join("\r\n", $info_list) . "\r\n"));
return $this->outAll();
}
示例15: array
<?php
class C
{
const a = 'hello from C';
}
class D extends C
{
}
class E extends D
{
}
class F extends E
{
const a = 'hello from F';
}
class X
{
}
$classes = array("C", "D", "E", "F", "X");
foreach ($classes as $class) {
echo "Reflecting on instance of class {$class}: \n";
$rc = new ReflectionObject(new $class());
var_dump($rc->getConstants());
}