Esempio n. 1
0
 /**
  * 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;
 }
Esempio n. 2
0
 /**
  * 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;
 }
<?php

class A
{
}
$ro = new ReflectionObject(new A());
var_dump($ro->isSubclassOf());
var_dump($ro->isSubclassOf('A', 5));
var_dump($ro->isSubclassOf('X'));
<?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";
Esempio n. 5
0
 /**
  * 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;
     }
 }