コード例 #1
0
ファイル: Reflection.php プロジェクト: alterphp/components
 public function callStaticMethod($class, $method, array $args = [])
 {
     $refl = new \reflectionClass($class);
     // Check that method is static AND public
     if ($refl->hasMethod($method) && $refl->getMethod($method)->isStatic() && $refl->getMethod($method)->isPublic()) {
         return call_user_func_array($class . '::' . $method, $args);
     }
     throw new \RuntimeException(sprintf('Invalid static method call for class %s and method %s', $class, $method));
 }
コード例 #2
0
ファイル: object.php プロジェクト: xihewang/atoum
 protected static function canInstanciateClass($class)
 {
     $reflection = new \reflectionClass($class);
     if ($reflection->hasMethod('__construct') === false) {
         return true;
     }
     $constructor = $reflection->getMethod('__construct');
     if ($constructor->isPublic() === false) {
         throw new provider\object\exceptions\privateConstructor('Could not instanciate an object from ' . $class . ' because ' . $class . '::__construct() is private');
     }
     if ($constructor->getNumberOfRequiredParameters() > 0) {
         throw new provider\object\exceptions\mandatoryArgument('Could not instanciate an object from ' . $class . ' because ' . $class . '::__construct() has at least one mandatory argument');
     }
     return true;
 }