本文整理汇总了PHP中ReflectionObject::getInterfaceNames方法的典型用法代码示例。如果您正苦于以下问题:PHP ReflectionObject::getInterfaceNames方法的具体用法?PHP ReflectionObject::getInterfaceNames怎么用?PHP ReflectionObject::getInterfaceNames使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ReflectionObject
的用法示例。
在下文中一共展示了ReflectionObject::getInterfaceNames方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getHandler
public function getHandler($obj)
{
if (!is_object($obj)) {
return $this->getHandlerByName(gettype($obj));
}
$class = get_class($obj);
$handler = null;
$ex = null;
while (true) {
try {
$handler = $this->getHandlerByName($class);
return $handler;
} catch (\Exception $e) {
if (!$ex) {
$ex = $e;
}
$class = get_parent_class($class);
if (!$class) {
break;
}
}
}
$rObj = new \ReflectionObject($obj);
$interfaces = $rObj->getInterfaceNames();
foreach ($interfaces as $interface) {
try {
$handler = $this->getHandlerByName($interface);
return $handler;
} catch (\Exception $e) {
continue;
}
}
throw $ex;
}
示例2: testSerializable
/**
* Method that checks if the current instance implementing Serializable interface
*/
public function testSerializable()
{
if ($this instanceof \Serializable) {
echo get_class($this), ' implements `Serializable` interface now!', PHP_EOL;
$reflection = new \ReflectionObject($this);
var_dump($reflection->getInterfaceNames(), $reflection->getTraitNames());
} else {
echo get_class($this), ' does not implement `Serializable` interface', PHP_EOL;
}
}
示例3: testSerializable
/**
* Method that checks if the current instance implementing Serializable interface
*/
public function testSerializable()
{
if ($this instanceof \Serializable) {
echo get_class($this), ' implements `Serializable` interface now!', PHP_EOL;
$reflection = new \ReflectionObject($this);
echo "List of interfaces:", PHP_EOL;
foreach ($reflection->getInterfaceNames() as $interfaceName) {
echo '-> ', $interfaceName, PHP_EOL;
}
echo "List of traits:", PHP_EOL;
foreach ($reflection->getTraitNames() as $traitName) {
echo '-> ', $traitName, PHP_EOL;
}
} else {
echo get_class($this), ' does not implement `Serializable` interface', PHP_EOL;
}
}
示例4: typedGetTransformer
protected function typedGetTransformer($name, $type)
{
$transformer = $this->getTransformer($name);
if (!$transformer instanceof $type) {
$reflection = new \ReflectionObject($transformer);
throw new \InvalidArgumentException(sprintf("The transformer '%s' doesn't implement %s but is implements %s", $name, $type, implode(",", $reflection->getInterfaceNames())));
}
return $transformer;
}
示例5: dumpServerMemory
public function dumpServerMemory($outputFolder, $maxNesting, $maxStringSize)
{
gc_disable();
if (!file_exists($outputFolder)) {
mkdir($outputFolder, 0777, true);
}
$this->server->getLogger()->notice("[Dump] After the memory dump is done, the server might crash");
$obData = fopen($outputFolder . "/objects.js", "wb+");
$staticProperties = [];
$data = [];
$objects = [];
$refCounts = [];
$this->continueDump($this->server, $data, $objects, $refCounts, 0, $maxNesting, $maxStringSize);
do {
$continue = false;
foreach ($objects as $hash => $object) {
if (!is_object($object)) {
continue;
}
$continue = true;
$className = get_class($object);
$objects[$hash] = true;
$reflection = new \ReflectionObject($object);
$info = ["information" => "{$hash}@{$className}", "properties" => []];
if ($reflection->getParentClass()) {
$info["parent"] = $reflection->getParentClass()->getName();
}
if (count($reflection->getInterfaceNames()) > 0) {
$info["implements"] = implode(", ", $reflection->getInterfaceNames());
}
foreach ($reflection->getProperties() as $property) {
if ($property->isStatic()) {
continue;
}
if (!$property->isPublic()) {
$property->setAccessible(true);
}
$this->continueDump($property->getValue($object), $info["properties"][$property->getName()], $objects, $refCounts, 0, $maxNesting, $maxStringSize);
}
fwrite($obData, "{$hash}@{$className}: " . json_encode($info, JSON_UNESCAPED_SLASHES) . "\n");
if (!isset($objects["staticProperties"][$className])) {
$staticProperties[$className] = [];
foreach ($reflection->getProperties() as $property) {
if (!$property->isStatic() or $property->getDeclaringClass()->getName() !== $className) {
continue;
}
if (!$property->isPublic()) {
$property->setAccessible(true);
}
$this->continueDump($property->getValue($object), $staticProperties[$className][$property->getName()], $objects, $refCounts, 0, $maxNesting, $maxStringSize);
}
}
}
echo "[Dump] Wrote " . count($objects) . " objects\n";
} while ($continue);
file_put_contents($outputFolder . "/staticProperties.js", json_encode($staticProperties, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT));
file_put_contents($outputFolder . "/serverEntry.js", json_encode($data, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT));
file_put_contents($outputFolder . "/referenceCounts.js", json_encode($refCounts, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT));
echo "[Dump] Finished!\n";
gc_enable();
$this->server->forceShutdown();
}
示例6: dump
//.........这里部分代码省略.........
if(isset($var['fw1recursionsentinel'])) {
echo "(Recursion)";
}
$aclass = (($c > 0) && array_key_exists(0, $var) && array_key_exists($c - 1, $var)) ? 'array' : 'struct';
$var['fw1recursionsentinel'] = TRUE;
echo "$tabs<table class=\"dump ${aclass} depth${depth}\">$tabs<thead><tr><th colspan=\"2\">" . ($label != '' ? $label . ' - ' : '') . "array" . ($c > 0 ? "" : " [empty]") . "</th></tr></thead>$tabs<tbody>";
foreach ($var as $index => $aval) {
if ($index === 'fw1recursionsentinel')
continue;
echo "$tabs<tr><td class=\"key\">" . $he($index) . "</td><td class=\"value\"><div>";
$this->dump($aval, $limit, '', $depth);
echo "</div></td></tr>";
$printCount++;
if (($limit > 0) && ($printCount >= $limit) && ($aclass === 'array'))
break;
}
echo "$tabs</tbody>$tabs</table>";
// unset($var['fw1recursionsentinel']);
} elseif (is_string($var)) {
echo $var === '' ? '[EMPTY STRING]' : htmlentities($var);
} elseif (is_bool($var)) {
echo $var ? "TRUE" : "FALSE";
} elseif (is_callable($var) || (is_object($var) && is_subclass_of($var, 'ReflectionFunctionAbstract'))) {
$echoFunction($var, $tabs, $limit, $label, $depth);
} elseif (is_float($var)) {
echo "(float) " . htmlentities($var);
} elseif (is_int($var)) {
echo "(int) " . htmlentities($var);
} elseif (is_null($var)) {
echo "NULL";
} elseif (is_object($var)) {
$ref = new \ReflectionObject($var);
$parent = $ref->getParentClass();
$interfaces = implode("<br/>implements ", $ref->getInterfaceNames());
/*
try {
$serial = serialize($var);
} catch (\Exception $e) {
$serial = 'hasclosure' . $ref->getName();
}
$objHash = 'o' . md5($serial);
*/
$objHash = spl_object_hash($var);
$refHash = 'r' . md5($ref);
echo "$tabs<table class=\"dump object depth${depth}\"" . (isset($seen[$refHash]) ? "" : "id=\"$refHash\"") . ">$tabs<thead>$tabs<tr><th colspan=\"2\">" . ($label != '' ? $label . ' - ' : '') . "object " . htmlentities($ref->getName()) . ($parent ? "<br/>extends " .$parent->getName() : "") . ($interfaces !== '' ? "<br/>implements " . $interfaces : "") . "</th></tr>$tabs<tbody>";
if (isset($seen[$objHash])) {
echo "$tabs<tr><td colspan=\"2\"><a href=\"#$refHash\">[see above for details]</a></td></tr>";
} else {
$seen[$objHash] = TRUE;
$constants = $ref->getConstants();
if (count($constants) > 0) {
echo "$tabs<tr><td class=\"key\">CONSTANTS</td><td class=\"values\"><div>$tabs<table class=\"dump object\">";
foreach ($constants as $constant => $cval) {
echo "$tabs<tr><td class=\"key\">" . htmlentities($constant) . "</td><td class=\"value constant\"><div>";
$this->dump($cval, $limit, '', $depth + 1);
echo "</div></td></tr>";
}
echo "$tabs</table>$tabs</div></td></tr>";
}
$properties = $ref->getProperties();
if (count($properties) > 0) {
echo "$tabs<tr><td class=\"key\">PROPERTIES</td><td class=\"values\"><div>$tabs<table class=\"dump object\">";
foreach ($properties as $property) {
echo "$tabs<tr><td class=\"key\">" . htmlentities(implode(' ', \Reflection::getModifierNames($property->getModifiers()))) . " " . $he($property->getName()) . "</td><td class=\"value property\"><div>";
$wasHidden = $property->isPrivate() || $property->isProtected();
$property->setAccessible(TRUE);
示例7: dump
//.........这里部分代码省略.........
}
$aclass = $c > 0 && array_key_exists(0, $var) && array_key_exists($c - 1, $var) ? 'array' : 'struct';
$var['fw1recursionsentinel'] = true;
echo "{$tabs}<table class=\"dump {$aclass}\">{$tabs}<thead><tr><th colspan=\"2\">" . ($label != '' ? $label . ' - ' : '') . "array" . ($c > 0 ? "" : " [empty]") . "</th></tr></thead>{$tabs}<tbody>";
foreach ($var as $index => $aval) {
if ($index === 'fw1recursionsentinel') {
continue;
}
echo "{$tabs}<tr><td class=\"key\">" . $he($index) . "</td><td class=\"value\">";
$this->dump($aval, $limit, '', $depth);
echo "</td></tr>";
$printCount++;
if ($limit > 0 && $printCount >= $limit && $aclass === 'array') {
break;
}
}
echo "{$tabs}</tbody>{$tabs}</table>";
// unset($var['fw1recursionsentinel']);
} elseif (is_string($var)) {
echo $var === '' ? '[EMPTY STRING]' : htmlentities($var);
} elseif (is_bool($var)) {
echo $var ? "TRUE" : "FALSE";
} elseif (is_callable($var) || is_object($var) && is_subclass_of($var, 'ReflectionFunctionAbstract')) {
$echoFunction($var, $tabs, $label);
} elseif (is_float($var)) {
echo "(float) " . htmlentities($var);
} elseif (is_int($var)) {
echo "(int) " . htmlentities($var);
} elseif (is_null($var)) {
echo "NULL";
} elseif (is_object($var)) {
$ref = new \ReflectionObject($var);
$parent = $ref->getParentClass();
$interfaces = implode("<br/>implements ", $ref->getInterfaceNames());
try {
$serial = serialize($var);
} catch (\Exception $e) {
$serial = 'hasclosure' . $ref->getName();
}
$objHash = 'o' . md5($serial);
$refHash = 'r' . md5($ref);
echo "{$tabs}<table class=\"dump object\"" . (isset($seen[$refHash]) ? "" : "id=\"{$refHash}\"") . ">{$tabs}<thead>{$tabs}<tr><th colspan=\"2\">" . ($label != '' ? $label . ' - ' : '') . "object " . htmlentities($ref->getName()) . ($parent ? "<br/>extends " . $parent->getName() : "") . ($interfaces !== '' ? "<br/>implements " . $interfaces : "") . "</th></tr>{$tabs}<tbody>";
if (isset($seen[$objHash])) {
echo "{$tabs}<tr><td colspan=\"2\"><a href=\"#{$refHash}\">[see above for details]</a></td></tr>";
} else {
$seen[$objHash] = TRUE;
$constants = $ref->getConstants();
if (count($constants) > 0) {
echo "{$tabs}<tr><td class=\"key\">CONSTANTS</td><td class=\"values\">{$tabs}<table class=\"dump object\">";
foreach ($constants as $constant => $cval) {
echo "{$tabs}<tr><td class=\"key\">" . htmlentities($constant) . "</td><td class=\"value constant\">";
$this->dump($cval, $limit, '', $depth);
echo "</td></tr>";
}
echo "{$tabs}</table>{$tabs}</td></tr>";
}
$properties = $ref->getProperties();
if (count($properties) > 0) {
echo "{$tabs}<tr><td class=\"key\">PROPERTIES</td><td class=\"values\">{$tabs}<table class=\"dump object\">";
foreach ($properties as $property) {
echo "{$tabs}<tr><td class=\"key\">" . htmlentities(implode(' ', \Reflection::getModifierNames($property->getModifiers()))) . " " . $he($property->getName()) . "</td><td class=\"value property\">";
$wasHidden = $property->isPrivate() || $property->isProtected();
$property->setAccessible(TRUE);
$this->dump($property->getValue($var), $limit, '', $depth);
if ($wasHidden) {
$property->setAccessible(FALSE);
示例8: _reflectionInterfaces
private function _reflectionInterfaces(\ReflectionObject $reflection)
{
$interfaces = $reflection->getInterfaceNames();
if (count($interfaces)) {
$name = '<span class="d-information" title="Interfaces that this object implements"></span> ';
$name .= '<span class="d-obj-info">Interfaces</span>';
$inamesstr = implode(', ', $interfaces);
$this->render($inamesstr, $name);
}
}
示例9: dump
/**
* cfdump-style debugging output
* @param $var The variable to output.
* @param $limit Maximum recursion depth for arrays (default 0 = all)
* @param $label text to display in complex data type header
* @param $depth Current depth (default 0)
*/
public static function dump(&$var, $limit = 0, $label = '', $depth = 0) {
if (!is_int($depth))
$depth = 0;
if (!is_int($limit))
$limit = 0;
if (($limit > 0) && ($depth >= $limit))
return;
static $seen = array();
$he = function ($s) { return htmlentities($s); };
$tabs = "\n" . str_repeat("\t", $depth);
$depth++;
$printCount = 0;
self::dumpCssJs();
if (is_array($var)) {
// It turns out that identity (===) in PHP isn't actually identity. It's more like "do you look similar enough to fool an untrained observer?". Lame!
// $label = $label === '' ? (($var === $_POST) ? '$_POST' : (($var === $_GET) ? '$_GET' : (($var === $_COOKIE) ? '$_COOKIE' : (($var === $_ENV) ? '$_ENV' : (($var === $_FILES) ? '$_FILES' : (($var === $_REQUEST) ? '$_REQUEST' : (($var === $_SERVER) ? '$_SERVER' : (isset($_SESSION) && ($var === $_SESSION) ? '$_SESSION' : '')))))))) : $label;
$c = count($var);
if(isset($var['fw1recursionsentinel'])) {
echo "(Recursion)";
}
$aclass = (($c > 0) && array_key_exists(0, $var) && array_key_exists($c - 1, $var)) ? 'array' : 'struct';
$var['fw1recursionsentinel'] = true;
echo "$tabs<table class=\"dump ${aclass} depth${depth}\">$tabs<thead><tr><th colspan=\"2\">" . ($label != '' ? $label . ' - ' : '') . "array" . ($c > 0 ? "" : " [empty]") . "</th></tr></thead>$tabs<tbody>";
foreach ($var as $index => $aval) {
if ($index === 'fw1recursionsentinel')
continue;
echo "$tabs<tr><td class=\"key\">" . $he($index) . "</td><td class=\"value\"><div>";
self::dump($aval, $limit, '', $depth);
echo "</div></td></tr>";
$printCount++;
if (($limit > 0) && ($printCount >= $limit) && ($aclass === 'array'))
break;
}
echo "$tabs</tbody>$tabs</table>";
// unset($var['fw1recursionsentinel']);
} elseif (is_string($var)) {
echo $var === '' ? '[EMPTY STRING]' : htmlentities($var);
} elseif (is_bool($var)) {
echo $var ? "TRUE" : "FALSE";
} elseif (is_callable($var) || (is_object($var) && is_subclass_of($var, 'ReflectionFunctionAbstract'))) {
self::dumpFunction($var, $tabs, $limit, $label, $depth);
} elseif (is_resource($var)) {
echo "(Resource)";
} elseif (is_float($var)) {
echo "(float) " . htmlentities($var);
} elseif (is_int($var)) {
echo "(int) " . htmlentities($var);
} elseif (is_null($var)) {
echo "NULL";
} elseif (is_object($var)) {
$ref = new \ReflectionObject($var);
$parent = $ref->getParentClass();
$interfaces = implode("<br/>implements ", $ref->getInterfaceNames());
$objHash = spl_object_hash($var);
$refHash = 'r' . md5($ref);
$objClassName = $ref->getName();
if ($objClassName === 'SimpleXMLElement') {
echo "$tabs<table class=\"dump xml depth${depth}\">$tabs<thead>$tabs<tr><th colspan=\"2\">" . ($label != '' ? $label . ' - ' : '') . "xml element</th></tr>$tabs<tbody>";
self::trKeyValue('Name', $var->getName());
// echo "<tr><td class=\"key\">Name</td><td class=\"value\">" . htmlentities($var->getName()) . "</td></tr>\n";
$attribs = array();
foreach ($var->attributes() as $attribName => $attribValue) {
$attribs[$attribName] = $attribValue;
}
if (count($attribs) > 0) {
echo "$tabs<tr><td class=\"key\">Attributes</td><td class=\"values\"><div>$tabs<table class=\"dump xml attributes\"><tbody>";
foreach ($attribs as $attribName => $attribValue) {
self::trKeyValue($attribName, $attribValue);
}
echo "$tabs</tbody></table>$tabs</div></td></tr>";
}
$xmlText = trim((string) $var);
if ($xmlText !== '') {
self::trKeyValue('Text', $xmlText);
}
if ($var->count() > 0) {
echo "$tabs<tr><td class=\"key\">Children</td><td class=\"values\"><div>$tabs<table class=\"dump xml children\"><tbody>";
$childNum = 0;
foreach ($var->children() as $child) {
echo "$tabs<tr><td class=\"key\">" . $childNum . "</td><td class=\"value child\"><div>";
self::dump($child, $limit, '', $depth + 1);
echo "</div></td></tr>";
$childNum++;
}
echo "$tabs</tbody></table>$tabs</div></td></tr>";
}
} else {
echo "$tabs<table class=\"dump object depth${depth}\"" . (isset($seen[$refHash]) ? "" : "id=\"$refHash\"") . ">$tabs<thead>$tabs<tr><th colspan=\"2\">" . ($label != '' ? $label . ' - ' : '') . "object " . htmlentities($objClassName) . ($parent ? "<br/>extends " .$parent->getName() : "") . ($interfaces !== '' ? "<br/>implements " . $interfaces : "") . "</th></tr>$tabs<tbody>";
if (isset($seen[$objHash])) {
echo "$tabs<tr><td colspan=\"2\"><a href=\"#$refHash\">[see above for details]</a></td></tr>";
} else {
$seen[$objHash] = TRUE;
$constants = $ref->getConstants();
//.........这里部分代码省略.........