クラスがコントローラーの定義を満たしているか確認する

@param   \ReflectionClass    $class
確認対象クラス
@param   bool    $throw
もしtrueが設定された場合、コントローラとして利用できない場合に
例外をスローする。

@return  bool
コントローラとして使用可能であればtrue、それ以外の場合はfalseを返す

@throws  Exception\ControllerException
967057
protected function isController(\ReflectionClass $class, bool $throw = true){
        $result     = false;
        $namespace  = $this->kernel->getConfig()->getNameSpace() . "\\Controller\\";

        try{
            if(!$class->isInstantiable()){
                throw new \InvalidArgumentException(
                    "Class '{$class->getName()}' is not instantiable."
                );
            }

            if(0 !== strpos($class->getName(), $namespace)){
                throw new Exception\ControllerException(
                    "Class '{$class}' is not a controller. The controller class"
                    . " must be included in the namespace '{$namespace}'."
                );
            }

            if("Controller" !== substr($class->getShortName(), -10)){
                throw new Exception\ControllerException(
                    "The name of the controller class must end with 'Controller'."
                    . " But {$class->getName()} does not end with 'Controller'."
                );
            }

            $result = true;
        }catch(\Exception $e){
            if($throw){
                throw $e;
            }
        }

        return $result;
    }
755978
public function loadMetadataForClass(\ReflectionClass $class)
    {
        $classMetadata = new MergeableClassMetadata($class->getName());

        foreach ($class->getProperties() as $reflectionProperty) {
            $propertyMetadata = new PropertyMetadata($class->getName(), $reflectionProperty->getName());

            /** @var $annotation \Zicht\Bundle\FileManagerBundle\Annotation\File */
            $annotation = $this->reader->getPropertyAnnotation(
                $reflectionProperty,
                'Zicht\Bundle\FileManagerBundle\Annotation\File'
            );
            if (null !== $annotation) {
                // a "@DefaultValue" annotation was found
                $propertyMetadata->fileManager = $annotation->settings;
            }

            $classMetadata->addPropertyMetadata($propertyMetadata);
        }

        return $classMetadata;
    }
661309
public function actionDisable($class)
    {
        try {
            if (Yii::$app->rhoone->ext->disable($class)) {
                echo "Disabled.";
            } else {
                echo "Failed to disable.";
            }
        } catch (\Exception $ex) {
            throw new Exception($ex->getMessage());
        }
        return 0;
    }
1063987
public static function ThrowIfNotDaftJson(string $class) : string
    {
        if ( ! is_a($class, DaftJson::class, self::IS_A_STRINGS)) {
            throw Exceptions\Factory::DaftObjectNotDaftJsonBadMethodCallException($class);
        }

        return $class;
    }
1227924
public function actionEnable($class)
    {
        try {
            if (Yii::$app->rhoone->ext->enable($class)) {
                echo "Enabled.";
            } else {
                echo "Failed to enable.";
            }
        } catch (\Exception $ex) {
            throw new Exception($ex->getMessage());
        }
        return 0;
    }
998860
public static function get($controllerClass) {
        if (!isset(self::$controllers[$controllerClass])) {
            if (class_exists($controllerClass)) {
                $reflectionClass = new ReflectionClass($controllerClass);
                self::$controllers[$controllerClass] = $reflectionClass->isAbstract()? $controllerClass : (new $controllerClass);
            }
            else {
                self::$controllers[$controllerClass] = null;
            }
        }
        return self::$controllers[$controllerClass];
    }
251262
private function supports(string $class): bool
    {
        $class = new \ReflectionClass($class);

        // We look for at least one non-static property
        do {
            foreach ($class->getProperties() as $property) {
                if (!$property->isStatic()) {
                    return true;
                }
            }
        } while ($class = $class->getParentClass());

        return false;
    }
1178657
public function make($class)
    {
        $controller = $this->container->make($class);
        $controller->setServer($this->makeServer());
        $controller->setView($this->makeView());
        $controller->setSession($this->makeSession());
        $controller->setUrlGenerator($this->makeUrlGenerator());

        return $controller;
    }
852503
public function _action(&$class) {
        ob_start();

        $annotation = Annotation::getClass($class);

        $this->_callAnnotation($class, $annotation, 'class', 'Before');

        if (method_exists($class, 'action' . ucfirst($this->request->action))) {
            $this->_callAnnotation($class, $annotation, 'methods', 'Before');
            $action = 'action' . ucfirst($this->request->action);
            $params = Injector::instance()->getArgsMethod($class, $action);

            $reflectionMethod = new \ReflectionMethod($class, $action);
            $output = $reflectionMethod->invokeArgs($class, $params);
            $this->_callAnnotation($class, $annotation, 'methods', 'After');

            $this->addError('Action "' . $this->request->src . '/' . ucfirst($this->request->controller) . '/action' . ucfirst($this->request->action) . '" called successfully', __FILE__, __LINE__, ERROR_INFORMATION);
        }
        else {
            throw new Exception('The requested "' . $this->request->src . '/' . ucfirst($this->request->controller) . '/action' . ucfirst($this->request->action) . '"  doesn\'t exist');
        }

        $this->_callAnnotation($class, $annotation, 'class', 'After');
        $output = ob_get_contents() . $output;
        ob_get_clean();

        return $output;
    }
244722
public function fileController($route, $class, $method = "")
    {
        $file = "../OxApp/controllers/" . $class . "Controller.php";
        $file = str_replace("\\", "/", $file);
        if (is_readable($file) === false) {
            throw new \Exception($file . ' Controller Not Found');
        } else {
            $class .= "Controller";
            try {
                $this->useMethod($class, $method);
                Router::$route = $route;
                Router::$controller = $class;
                Router::$routeCounts += 1;
            } catch (\RuntimeException $e) {
                throw new \Exception($e);
            }
        }
    }
39241
public static function autoload($class)
  {
    if(substr($class, 0, strlen(__CLASS__)) != __CLASS__) return;

    try
    {
      self::loadClass($class);

      return TRUE;
    }
    catch(Exception $e)
    {
      return FALSE;
    }
  }
970106
private static function getInstance($class)
    {
        //get the backtrace
        $trace = debug_backtrace();
        $args = array();
        
        //the 2nd line is the caller method
        if (isset($trace[1]['args']) && count($trace[1]['args']) > 1) {
            //get the args
            $args = $trace[1]['args'];
            //shift out the class name
            array_shift($args);
            //then maybe it's the 3rd line?
        } else if (isset($trace[2]['args']) && count($trace[2]['args']) > 0) {
            //get the args
            $args = $trace[2]['args'];
        }
        
        //if there's no args or there's no construct to accept the args
        if (count($args) === 0 || !method_exists($class, '__construct')) {
            //just return the instantiation
            return new $class;
        }
        
        //at this point, we need to vitually call the class
        $reflect = new \ReflectionClass($class);
        
        try { //to return the instantiation
            return $reflect->newInstanceArgs($args);
        } catch (\ReflectionException $e) {
            //trigger error
            Exception::i()
                ->setMessage(self::ERROR_REFLECTION)
                ->addVariable($class)
                ->addVariable('new')
                ->trigger();
        }
    }
173239
public function addClass($class)
    {
        if (is_array($class)) {
            $class = implode(' ', $class);
        }

        if (!$this->class) {
            $this->class = [];
        }

        if (is_string($this->class)) {
            throw new Exception(['Property $class should always be array', 'object' => $this, 'class' => $this->class]);
        }

        $this->class = array_merge($this->class, explode(' ', $class));

        return $this;
    }
21263
public function loadClass( $class ) {

		if ( ! isset( $this->class_map[ $class ] ) )
			return FALSE;

		return $this->loader->loadFile( $this->class_map[ $class ] );
	}
245832
protected function assertClass($class)
    {
        if (!preg_match('/^([a-zA-Z_]\w*\\\\)*[a-zA-Z_]\w*$/', $class)) {
            throw new \UnexpectedValueException("Can't route to controller '$class': invalid classname");
        }
        
        if (!class_exists($class)) {
            throw new \UnexpectedValueException("Can't route to controller '$class': class not exists");
        }

        $refl = new \ReflectionClass($class);
        $realClass = $refl->getName();
        
        if ($realClass !== $class) {
            throw new \UnexpectedValueException("Can't route to controller '$class': case mismatch with '$realClass'");
        }
    }
806790
public function loadMetadataForClass(\ReflectionClass $class)
    {
        $classMetadata = new ClassMetadata($class->getName());

        foreach ($class->getMethods(\ReflectionMethod::IS_PUBLIC) as $reflectionMethod) {
            if (false === strpos($reflectionMethod->getName(), 'Action')) {
                continue;
            }

            if ($reflectionMethod->isAbstract()) {
                continue;
            }

            $methodMetadata = new ActionMetadata($class->getName(), $reflectionMethod->getName());

            $annotations = $this->reader->getMethodAnnotations($reflectionMethod);

            foreach ($annotations as $annotation) {
                if ($annotation instanceof \BackBee\Rest\Controller\Annotations\QueryParam) {
                    $data = array(
                        'name' => $annotation->name,
                        'key' => $annotation->key ? $annotation->key : $annotation->name,
                        'default' => $annotation->default,
                        'description' => $annotation->description,
                        'requirements' => $annotation->requirements,
                    );

                    $methodMetadata->queryParams[] = $data;
                } elseif ($annotation instanceof \BackBee\Rest\Controller\Annotations\RequestParam) {
                    $data = array(
                        'name' => $annotation->name,
                        'key' => $annotation->key ? $annotation->key : $annotation->name,
                        'default' => $annotation->default,
                        'description' => $annotation->description,
                        'requirements' => $annotation->requirements,
                    );

                    $methodMetadata->requestParams[] = $data;
                } elseif ($annotation instanceof \BackBee\Rest\Controller\Annotations\Pagination) {
                    $methodMetadata->default_start = $annotation->default_start;
                    $methodMetadata->default_count = $annotation->default_count;
                    $methodMetadata->max_count = $annotation->max_count;
                    $methodMetadata->min_count = $annotation->min_count;
                } elseif ($annotation instanceof \BackBee\Rest\Controller\Annotations\ParamConverter) {
                    $methodMetadata->param_converter_bag[] = $annotation;
                } elseif ($annotation instanceof \BackBee\Rest\Controller\Annotations\Security) {
                    $methodMetadata->security[] = $annotation;
                }
            }

            $classMetadata->addMethodMetadata($methodMetadata);
        }

        return $classMetadata;
    }
1056319
protected function isAction(\ReflectionMethod $method, bool $throw = true){
        $result = false;

        try{
            if(!$method->isPublic()){
                throw new Exception\ActionException();
            }

            if($method->isAbstract()){
                throw new Exception\ActionException();
            }

            if($method->isStatic()){
                throw new Exception\ActionException();
            }

            if(0 === strpos($method->getName(), "__")){
                throw new Exception\ActionException();
            }

            $result = true;
        }catch(Exception\ActionException $e){
            if($throw){
                throw $e;
            }
        }

        return $result;
    }