本文整理汇总了PHP中ReflectionObject::isSubclassOf方法的典型用法代码示例。如果您正苦于以下问题:PHP ReflectionObject::isSubclassOf方法的具体用法?PHP ReflectionObject::isSubclassOf怎么用?PHP ReflectionObject::isSubclassOf使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ReflectionObject
的用法示例。
在下文中一共展示了ReflectionObject::isSubclassOf方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: add
/**
* Add new element.
*
* @param RenderableInterface $element
* @return $this
* @throws ReactorException
*/
public function add(RenderableInterface $element)
{
$reflector = new \ReflectionObject($element);
$allowed = false;
foreach ($this->allowed as $class) {
if ($reflector->isSubclassOf($class) || get_class($element) == $class) {
$allowed = true;
break;
}
}
if (!$allowed) {
$type = get_class($element);
throw new ReactorException("Elements with type '{$type}' are not allowed.");
}
$this->elements[] = $element;
return $this;
}
示例2: isExpectedException
/**
* Returns true if the {@link java.lang.reflect.Method Method} definition on
* the service is specified to throw the exception contained in the
* InvocationTargetException or false otherwise. NOTE we do not check that the
* type is serializable here. We assume that it must be otherwise the
* application would never have been allowed to run.
*
* @param MappedMethod serviceIntfMethod the method from the RPC request
* @param Exception cause the exception that the method threw
* @return boolean true if the exception's type is in the method's signature
*/
private static function isExpectedException(MappedMethod $serviceIntfMethod, Exception $cause)
{
assert($serviceIntfMethod != null);
assert($cause != null);
/*Class[]*/
$exceptionsThrown = $serviceIntfMethod->getExceptionTypes();
if (count($exceptionsThrown) <= 0) {
// The method is not specified to throw any exceptions
//
return false;
}
$causeType = new ReflectionObject($cause);
// $cause.getClass();
foreach ($exceptionsThrown as $exceptionThrown) {
assert($exceptionThrown != null);
//$exceptionThrown = new SimpleMappedClass();
if ($causeType->getFileName() == $exceptionThrown->getReflectionClass()->getFileName() && $causeType->getName() == $exceptionThrown->getReflectionClass()->getName() || $causeType->isSubclassOf($exceptionThrown->getReflectionClass()->getName())) {
//.isAssignableFrom(causeType)) {
return true;
}
}
return false;
}
示例3: ReflectionObject
<?php
class A
{
}
$ro = new ReflectionObject(new A());
var_dump($ro->isSubclassOf());
var_dump($ro->isSubclassOf('A', 5));
var_dump($ro->isSubclassOf('X'));
示例4: ReflectionObject
<?php
class C
{
}
$ro = new ReflectionObject(new C());
echo "\n\nTest bad arguments:\n";
try {
var_dump($ro->isSubclassOf());
} catch (Exception $e) {
echo $e->getMessage() . "\n";
}
try {
var_dump($ro->isSubclassOf('C', 'C'));
} catch (Exception $e) {
echo $e->getMessage() . "\n";
}
try {
var_dump($ro->isSubclassOf(null));
} catch (Exception $e) {
echo $e->getMessage() . "\n";
}
try {
var_dump($ro->isSubclassOf('ThisClassDoesNotExist'));
} catch (Exception $e) {
echo $e->getMessage() . "\n";
}
try {
var_dump($ro->isSubclassOf(2));
} catch (Exception $e) {
echo $e->getMessage() . "\n";
示例5: LoadCodeFile
/**
* LoadCodeFile() - Loads an extension/plugin into the core.
*
* WARNING: This function is PHP5 only. A replacement could be designed for PHP4, requiring a bit of
* of code magic regarding object reflexion.
*
* LoadCodeFile loads any PHP file into PHP via include().
* It expects an $object variable to be set by the codefile in order to process with further registration.
* Specifications for the different kind of $objects are available in the development wiki.
* -1 return code for "FILE NOT FOUND"
* -2 return code for "INCORRECT/INEXISTANT OBJECT VARIABLE"
*
* @param $filepath string Path of the file to include
*/
function LoadCodeFile($filepath)
{
if (defined('BB_DEBUG')) {
$this->DebugOutput("LoadCodeFile(): Attempting to load '{$filepath}'");
}
clearstatcache();
if (file_exists($filepath)) {
// Loads the plugin/extension
include_once $filepath;
if (!$object) {
return -2;
}
// BAD BAD BAD BAD BAD !
if (defined('BB_DEBUG')) {
$this->DebugOutput("LoadCodeFile(): Loaded file '{$filepath}'");
}
// Create some reflexion objects in order to check the inheritance of the new $object
$cmdexts = new ReflectionClass(bbCommandExtension);
$dataexts = new ReflectionClass(bbDataExtension);
$reflexion = new ReflectionObject($object);
// Switch to the appropriate register procedure.
if ($reflexion->isSubclassOf($cmdexts)) {
$this->RegisterCommandExtension($object);
} else {
if ($reflexion->isSubclassOf($dataexts)) {
$this->RegisterDataExtension($object);
}
}
} else {
return -1;
}
}