/** * 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); } } } }
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); }
function __construct($value) { $ref = new ReflectionObject($this); $consts = $ref->getConstants(); if (!in_array($value, $consts, true)) { throw new InvalidArgumentException(); } $this->scalar = $value; }
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(); }
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(); }
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()); } }
/** * @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: '******'name']); } $this->_filename = $filename; } }
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; } }
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; }
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'); }
/** * 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; }
/** * Возвращает название медиа типа по его значению * Название получается автоматически из константы с определением типа * * @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; }
<?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>
/** * prints out information about the $this arg * * @since 9-23-09 * * object info uses the reflection class http://nz.php.net/manual-lookup.php?pattern=oop5.reflection&lang=en * * @todo * - get the parent classes methods and values and stuff, then organize the methods by visible and invisible (private, protected) * - this might be a good way for aIter to display classes also, but just get the properties of the object * * @param string $calling_class the class name of the class that made the call * @return string information about the arg */ function outInfo($calling_class = '') { $this->useName(false); $config = $this->config(); $config->outEnquote(false); $config->outObject(false); $type = $this->type(); $format_handler = new out_format($config); $name = $this->name(); $val = $this->value(); $info_list = array(); $info_type = 'undefined'; switch ($type) { case self::TYPE_NULL: $info_type = 'NULL'; break; case self::TYPE_STRING_VAL: case self::TYPE_STRING_LITERAL: case self::TYPE_STRING_GENERATED: $info_type = 'string'; $info_list[] = sprintf('value: %s', $format_handler->enquote($val)); $info_list[] = sprintf('%d characters', mb_strlen($val)); break; ///case self::TYPE_STRING_EMPTY: break; ///case self::TYPE_STRING_EMPTY: break; case self::TYPE_NUMERIC: if (is_int($val)) { $info_type = 'integer'; } else { if (is_float($val)) { $info_type = 'float'; } } //if/else if $info_list[] = sprintf('value: %s', $val); break; case self::TYPE_ARRAY: $info_type = 'array'; // find out if it is an indexed array... $info_list = array(); $info_list[] = 'length: ' . count($val); if (!empty($val)) { $info_list[] = ctype_digit(join('', array_keys($val))) ? 'keys are numeric' : 'keys are associative'; } //if break; case self::TYPE_OBJECT: $rclass = new ReflectionObject($val); $info_type = $rclass->getName() . ' instance'; $indent = $this->indent; if ($path = $rclass->getFileName()) { $file_map = new out_file($path); $file_map->config($config); $info_list[] = sprintf('%s %s %s', $format_handler->wrap('b', 'Defined:'), $rclass->getName(), $file_map->out(true, false)); } //if $class_name_list = array($rclass->getName()); // get all the classes this object extends... if ($parent_class = $rclass->getParentClass()) { $info_list[] = $format_handler->wrap('b', 'Extends:'); while (!empty($parent_class)) { $class_name_list[] = $parent_class->getName(); $file_map = new out_file($parent_class->getFileName()); $file_map->config($config); $info_list[] = sprintf('%s%s %s', $indent, $parent_class->getName(), $file_map->out(true, false)); $parent_class = $parent_class->getParentClass(); } //while } //if // handle properties... $properties = $rclass->getProperties(); $info_list[] = $format_handler->wrap('b', sprintf('%s (%d):', 'Properties', count($properties))); $prop_val = null; $prop_check = true; foreach ($properties as $property) { // 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(); }
<?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()); }
public static function renderEnum($enumClassName, $name, $prefix) { $enum = new $enumClassName(); $enumObject = new \ReflectionObject($enum); $constants = $enumObject->getConstants(); echo '<select name="' . $prefix . $name . '">'; foreach ($constants as $constant) { echo '<option value="' . $constant . '">' . $constant . '</option>'; } echo '</select>'; }
/** * Check available name for service * @param string $serviceType * @return string * @throw */ protected function checkServiceType($serviceType) { $reflection = new \ReflectionObject($this); $constants = $reflection->getConstants(); if (!in_array($serviceType, $constants)) { throw new RuntimeException('Service type does not supports: ' . $serviceType); } return $serviceType; }
/** * @param $param * @param \ReflectionObject $reflection */ private function buildFromObject($param, $reflection = null) { foreach ($param as $key => $value) { $this->object['Object default'][$key] = $value; } // Get info on the object $this->object['Reflection']['In namespace'] = $reflection->inNamespace() ? 'Yes' : 'No'; if ($reflection->inNamespace()) { $this->object['Class namespace'] = $reflection->getNamespaceName(); } $this->object['Reflection']['Class name'] = $reflection->getName(); $this->object['Reflection']['Is internal'] = $reflection->isInternal() ? 'Yes' : 'No'; $this->object['Reflection']['Is iterable'] = $reflection->isIterateable() ? 'Yes' : 'No'; $this->object['Reflection']['Is abstract'] = $reflection->isAbstract() ? 'Yes' : 'No'; $this->object['Reflection']['Is final'] = $reflection->isFinal() ? 'Yes' : 'No'; $this->object['Reflection']['Is user defined'] = $reflection->isUserDefined() ? 'Yes' : 'No'; $this->object['Reflection']['Is instantiable'] = $reflection->isInstantiable() ? 'Yes' : 'No'; $this->object['Reflection']['Is clonable'] = $reflection->isCloneable() ? 'Yes' : 'No'; $this->object['Reflection']['Is interface'] = $reflection->isInterface() ? 'Yes' : 'No'; $this->object['Reflection']['Class constants'] = !empty($reflection->getConstants()) ? $reflection->getConstants() : 'Class has no constants'; $this->object['Reflection']['Class static properties'] = !empty($reflection->getStaticProperties()) ? $reflection->getStaticProperties() : 'Class has no static properties'; $this->object['Reflection']['Class default properties'] = !empty($reflection->getDefaultProperties()) ? $reflection->getDefaultProperties() : 'Class has no default properties'; if (null === $reflection->getConstructor()) { $this->object['Reflection']['Class construct'] = 'Class has no construct.'; } else { $this->object['Reflection']['Class construct'] = $reflection->getConstructor(); } $this->object['Reflection']['Class interfaces'] = !empty($reflection->getInterfaces()) ? $reflection->getInterfaces() : 'Class implements no interfaces'; $this->object['Reflection']['Class traits'] = !empty($reflection->getTraits()) ? $reflection->getTraits() : 'Class has no traits'; $this->object['Reflection']['Class parent'] = $reflection->getParentClass() !== false ? $reflection->getParentClass() : 'Class has no parent'; if (false === $reflection->getFileName()) { $this->object['Reflection']['Defined in'] = 'Class is internal, no definition to provide.'; } else { $this->object['Reflection']['Defined in'] = $reflection->getFileName(); } if (false === $reflection->getFileName()) { $this->object['Reflection']['Start line'] = 'Class is internal, no start line to provide.'; } else { $this->object['Reflection']['Start line'] = $reflection->getFileName(); } if (false === $reflection->getEndLine()) { $this->object['Reflection']['End line'] = 'Class is internal, no end line to provide.'; } else { $this->object['Reflection']['End line'] = $reflection->getEndLine(); } if (false === $reflection->getDocComment()) { $this->object['Reflection']['Doc comments'] = 'No documents to provide.'; } else { $this->object['Reflection']['Doc comments'] = $reflection->getDocComment(); } // End get info $this->html .= "<span class=\"js-parent-object\">"; if (!empty($this->object['Object default'])) { $this->html .= "<div class=\"js-object-default-tab \"><button class=\"button-reflection button\">Show reflection</button></div>"; $this->html .= "<div class=\"js-object-default \">"; $this->buildFromObjectIterationInformationRecursive($this->object['Object default']); $this->html .= "</div>"; } if ($param instanceof \Closure) { $this->html .= "<div class=\"js-object-default-tab \"><button class=\"button-reflection button\">Show reflection</button></div>"; $this->html .= "<div class=\"js-object-default \">"; $this->html .= "<span class=\"css-type-string\">Nothing here...</span>"; $this->html .= "</div>"; } $this->html .= "<div class=\"js-object-reflection-tab hide\"><button class=\"button-class-default button\">Show default</button></div>"; $this->html .= "<div class=\"js-object-reflection hide\">"; $this->buildFromObjectReflectionInformationRecursive($this->object['Reflection']); $this->html .= "</div>"; $this->html .= "</span>"; $this->object = []; }
/** * Cast a value to object. * * Please note: in a normal array to object cast pre-PHP7, array values with numerical keys are 'lost'. * This method checks whether the array contains numerical keys, if it doesn't it will do a * normal array to object cast. If it does, it will cast each numerically indexes value to a numerical * property, similar to the behaviour in PHP7. * * @static * * @param mixed $value Value to cast. * @param bool $allow_empty (Optional) Whether to allow empty strings/arrays/objects. * * @return object|null */ static function _object($value, $allow_empty = true) { if ($allow_empty === false && (is_string($value) && $value === '')) { return null; } if (is_array($value) === true) { $has_num_keys = false; foreach ($value as $k => $v) { if (is_int($k)) { $has_num_keys = true; break; } } if ($has_num_keys === false) { $value = (object) $value; } else { $new_value = new stdClass(); foreach ($value as $k => $v) { $new_value->{$k} = $v; } $value = $new_value; unset($new_value, $k, $v); } } else { if (is_object($value) !== true) { $value = (object) $value; } } if ($allow_empty === false) { if (PHP_VERSION_ID > 50200) { $obj = new ReflectionObject($value); if (count($obj->getMethods()) + count($obj->getProperties()) + count($obj->getConstants()) === 0) { // No methods, properties or constants found. $value = null; } } else { // PHP <= 5.1. $methods = get_class_methods($value); $properties = get_object_vars($value); if ((is_null($methods) || count($methods) === 0) && (is_null($properties) || count($properties) === 0)) { // No methods or properties found. $value = null; } } } return $value; }
/** */ public function __construct() { $refl = new \ReflectionObject($this); $this->constants = $refl->getConstants(); parent::__construct(new \ArrayIterator($this->constants)); }
private function _reflectionConstants(\ReflectionObject $reflection) { $constants = $reflection->getConstants(); if (count($constants)) { $name = '<span class="d-information" title="Constants defined in this object"></span> '; $name .= '<span class="d-obj-info">Class Constants</span>'; $this->render($constants, $name); } }
private function getAnalyzeHtml_Object($obj, $index) { $reflector = new \ReflectionObject($obj); $result = ''; $result .= '<h4>About</h4>'; $result .= '<table class="aboutTable">'; $result .= '<tbody>'; $result .= '<tr>'; $result .= '<td class="colLeft"><strong>Name</strong></td>'; $result .= '<td class="colRight">' . htmlentities($reflector->getShortName()) . '</td>'; $result .= '</tr>'; $result .= '<tr>'; $result .= '<td class="colLeft"><strong>Namespace</strong></td>'; $result .= '<td class="colRight">' . htmlentities($reflector->getNamespaceName()) . '</td>'; $result .= '</tr>'; $result .= '</tbody>'; $result .= '<tr>'; $result .= '<td class="colLeft"><strong>File</strong></td>'; $result .= '<td class="colRight">' . htmlentities($reflector->getFileName()) . '</td>'; $result .= '</tr>'; $result .= '</tbody>'; $result .= '</table>'; $result .= '<h4>Members</h4>'; $result .= '<ul class="accordion" data-accordion>'; $accId = "objConstants{$index}"; $constants = $reflector->getConstants(); uksort($constants, function ($x, $y) { return strcmp(trim(strtolower($x)), trim(strtolower($y))); }); $content = 'No constants found.'; if (!empty($constants)) { $content = '<table class="memberTable">'; $content .= '<thead>'; $content .= '<tr>'; $content .= '<th class="memberName">Name</th>'; $content .= '<th>Value</th>'; $content .= '</tr>'; $content .= '</thead>'; $content .= '<tbody>'; foreach ($constants as $name => $value) { $content .= '<tr>'; $content .= '<td>' . htmlentities($name) . '</td>'; $content .= '<td>' . htmlentities(var_export($value, true)) . '</td>'; $content .= '</tr>'; } $content .= '</tbody>'; $content .= '</table>'; } $result .= '<li class="accordion-navigation">'; $result .= '<a href="#' . $accId . '" aria-expanded="false">Constants (' . trim(count($constants)) . ')</a>'; $result .= '<div id="' . $accId . '" class="content">' . $content . '</div>'; $result .= '</li>'; $accId = "objMethods{$index}"; $methods = $reflector->getMethods(); usort($methods, function (\ReflectionMethod $x, \ReflectionMethod $y) { return strcmp(trim(strtolower($x->getName())), trim(strtolower($y->getName()))); }); foreach ($methods as $i => $m) { if (!$m->isPublic()) { unset($methods[$i]); } } $content = 'No methods found.'; if (!empty($methods)) { $content = '<table class="memberTable">'; $content .= '<thead>'; $content .= '<tr>'; $content .= '<th class="memberName">Name</th>'; $content .= '</tr>'; $content .= '</thead>'; $content .= '<tbody>'; foreach ($methods as $m) { $content .= '<tr>'; $content .= '<td>' . htmlentities($m->getName()) . '</td>'; $content .= '</tr>'; } $content .= '</tbody>'; $content .= '</table>'; } $result .= '<li class="accordion-navigation">'; $result .= '<a href="#' . $accId . '" aria-expanded="false">Methods (' . trim(count($methods)) . ')</a>'; $result .= '<div id="' . $accId . '" class="content">' . $content . '</div>'; $result .= '</li>'; $accId = "objProperties{$index}"; $properties = $reflector->getProperties(); usort($properties, function (\ReflectionProperty $x, \ReflectionProperty $y) { return strcmp(trim(strtolower($x->getName())), trim(strtolower($y->getName()))); }); foreach ($properties as $i => $p) { if (!$p->isPublic()) { unset($properties[$i]); } } $content = 'No properties found.'; if (!empty($properties)) { $content = '<table class="memberTable">'; $content .= '<thead>'; $content .= '<tr>'; $content .= '<th class="memberName">Name</th>'; $content .= '<th>Current value</th>'; $content .= '</tr>'; $content .= '</thead>'; $content .= '<tbody>'; foreach ($properties as $p) { $content .= '<tr>'; $content .= '<td>' . htmlentities($p->getName()) . '</td>'; $content .= '<td>' . htmlentities(var_export($p->getValue($obj), true)) . '</td>'; $content .= '</tr>'; } $content .= '</tbody>'; $content .= '</table>'; } $result .= '<li class="accordion-navigation">'; $result .= '<a href="#' . $accId . '" aria-expanded="false">Properties (' . trim(count($properties)) . ')</a>'; $result .= '<div id="' . $accId . '" class="content">' . $content . '</div>'; $result .= '</li>'; $result .= '</ul>'; return $result; }
private static function _dump($element, $prevPath = null, $matchPath = null, $level = 0, $showElementType = true) { $br = self::getBreakLine(); $tab = self::getTab(); $tabs = str_repeat($tab, $level); $path = $prevPath; $addLevel = 2; // echo "\n{$tabs}ELEMENT PATH ($path): "; $pKey1 = self::colorContent("{", 'blue'); $pKey2 = self::colorContent("}", 'blue'); if (is_array($element)) { if ($showElementType) { echo "{$br}{$tabs}" . self::colorContent("array (", 'blue'); } foreach ($element as $key => $value) { $newPath = $path . "/{$key}/"; $showValue = self::getShowValue($value); $pKey = self::getPrintableValueType($key); $pPath = self::getPathLink($newPath, $matchPath, $prevPath); $pValue = self::getPrintableValueType($value); $pKey1 = self::getPrintableValueClosure($value, 'open'); $pKey2 = self::getPrintableValueClosure($value, 'close'); echo "{$br}{$tabs}{$tab}[{$pKey}] {$pValue} {$pKey1} {$pPath}"; if ($matchPath && self::_matchPath($matchPath, $newPath)) { self::_dump($value, $newPath, $matchPath, $level + $addLevel, false); echo "{$br}{$tabs}{$tab}{$pKey2}"; } else { echo self::colorContent("{$pKey2}", 'blue'); } } if ($showElementType) { echo "{$br}{$tabs}" . self::colorContent(')', 'blue'); } } else { if (is_object($element)) { if ($showElementType) { echo "{$br}{$tabs}" . self::colorContent(get_class($element) . " {", 'blue'); } $path = $prevPath; //$prevPath . '/' . get_class($element); $r = new ReflectionObject($element); $constants = $r->getConstants(); $pAccess = self::colorContent('const', 'dimgray', 'italic'); foreach ($constants as $name => $value) { echo "{$br}{$tabs}{$tab}{$pAccess} " . self::colorContent($name, 'limegreen') . ' ' . self::getPrintableValueType($value); } $properties = $r->getProperties(ReflectionProperty::IS_PUBLIC | ReflectionProperty::IS_PROTECTED | ReflectionProperty::IS_PRIVATE); foreach ($properties as $property) { $access = $property->isPrivate() ? 'private' : ($property->isProtected() ? 'protected' : 'public'); $static = $property->isStatic() ? 'static ' : ''; if (!$property->isPublic()) { $property->setAccessible(true); } $value = $property->getValue($element); $pAccess = self::colorContent($access, 'dimgray', 'italic'); $pValue = self::getPrintableValueType($value); $pName = self::colorContent('$' . $property->name, 'limegreen'); $newPath = $path . '/' . $property->name . '/'; $pPath = self::getPathLink($newPath, $matchPath, $prevPath); $pKey1 = self::getPrintableValueClosure($value, 'open'); $pKey2 = self::getPrintableValueClosure($value, 'close'); echo "{$br}{$tabs}{$tab}{$static}{$pAccess} {$pName} {$pValue} {$pKey1} {$pPath}"; if ($matchPath && self::_matchPath($matchPath, $newPath)) { self::_dump($value, $newPath, $matchPath, $level + $addLevel, false); echo "{$br}{$tabs}{$tab}{$pKey2}"; } else { echo self::colorContent(" {$pKey2}", 'blue'); } } $methods = $r->getMethods(); foreach ($methods as $method) { $access = $method->isPublic() ? 'public' : ($method->isPrivate() ? 'private' : 'protected'); $pAccess = self::colorContent($access, 'dimgray', 'italic'); echo "{$br}{$tabs}{$tab}{$pAccess} " . self::colorContent("{$method->name}(", 'blue', null, $method->getDocComment()); $tmpParameters = array(); foreach ($method->getParameters() as $parameter) { $tmpParameters[] = self::colorContent("\${$parameter->name}", 'limegreen'); } echo implode(', ', $tmpParameters); echo self::colorContent(")", 'blue'); } if ($showElementType) { echo "{$br}{$tabs}" . self::colorContent('}', 'blue'); } } else { if (is_string($element)) { $string = htmlentities($element); echo "{$br}{$tabs}{$string}"; } else { echo "{$br}{$tabs}{$element}"; } } } }
public function getConstants() { $reflection = new ReflectionObject($this); return $reflection->getConstants(); }
<?php class X { } $rc = new ReflectionObject(new X()); $rc->getConstants('X'); $rc->getConstants(true);
public static function getConditions() { $reflection = new \ReflectionObject(new self()); return array_values($reflection->getConstants()); }
protected static function accessKeys(HermitParam $target) { $ref = new ReflectionObject($target); return array_flip($ref->getConstants()); }
/** Return a list of type options for awards! */ public function otm_type_options($type = null) { $types = new ReflectionObject(new OTMTypes()); foreach ($types->getConstants() as $key => $value) { $selected = ""; if ($type && $type == $value) { $selected = "selected"; } $optionstring .= "<option value='{$value}' {$selected}>{$value}</option>"; } return $optionstring; }