Example #1
0
 /**
  * Checks if a view exists by file, method, or both.
  * 
  * @access protected
  * @final
  * @param array|string $args Can be either the name of the view or an array with name and controller defined
  * @param string $controller The name of the controller where the view is located, if left blank assumes the current controller
  * @param mixed $checkmethod Indicates whether to check if the method exists, file exists, or both
  * @return boolean true if the view exists and boolean false if not
  */
 protected final function _viewExists($args, $controller = "", $checkmethod = false)
 {
     $args = func_get_args();
     if (count($args) < 1 || count($args) > 4) {
         return false;
     }
     if (count($args) == 1 && is_array($args[0])) {
         $args = $args[0];
     } else {
         $checkmethod = false;
         if (is_bool($args[count($args) - 1]) === true || $args[count($args) - 1] == 'both') {
             $checkmethod = array_pop($args);
         }
         $args = array_combine(array_merge(array_slice(array('name', 'controller', 'branch'), 0, count($args)), (array) 'checkmethod'), array_merge($args, (array) $checkmethod));
         unset($checkmethod);
     }
     // call hook
     Hook::call('Controller.viewExists.before', array(&$args));
     if (empty($args['name'])) {
         return false;
     }
     if (empty($args['controller'])) {
         $args['controller'] = $this->params['controller'];
     }
     if (empty($args['branch']) && Reg::hasVal('Branch.name')) {
         $args['branch'] = Reg::get('Branch.name');
     }
     if (!empty($args['branch']) && $args['branch'] == Reg::get('System.rootIdentifier')) {
         unset($args['branch']);
     }
     if (!isset($args['checkmethod'])) {
         $args['checkmethod'] = false;
     }
     if ($args['name'][0] != '_' && (!isset($this->bounceback['check']) || $this->bounceback['check'] != $args['controller']) && !in_array($args['controller'], $this->notAView)) {
         if ($args['checkmethod'] === true) {
             $load['name'] = Config::uriToClass(Config::fileToClass($args['controller']));
             if (!empty($args['branch'])) {
                 $load['branch'] = Config::uriToClass(Config::fileToClass($args['branch']));
             }
             $load['type'] = 'Controller';
             $load = implode('_', $load);
             if (is_callable(array($load, Config::uriToMethod(Config::fileToMethod($args['name'])))) && method_exists($load, Config::uriToMethod(Config::fileToMethod($args['name'])))) {
                 $return = true;
             } else {
                 $return = false;
             }
         } else {
             $path = Reg::get("Path.physical") . ($args['branch'] ? "/branches/" . Config::uriToFile(Config::classToFile($args['branch'])) : "") . "/views/" . Config::uriToFile(Config::classToFile($args['controller'])) . "/" . Config::uriToFile(Config::methodToFile($args['name'])) . ".php";
             // call hook
             Hook::call('Controller.viewExists.setPath', array(&$args, &$path));
             if (file_exists($path)) {
                 if ($args['checkmethod'] == 'both') {
                     $load['name'] = Config::uriToClass(Config::fileToClass($args['controller']));
                     if (!empty($args['branch'])) {
                         $load['branch'] = Config::uriToClass(Config::fileToClass($args['branch']));
                     }
                     $load['type'] = 'Controller';
                     $load = implode('_', $load);
                     if (is_callable(array($load, Config::uriToMethod(Config::fileToMethod($args['name'])))) && method_exists($load, Config::uriToMethod(Config::fileToMethod($args['name'])))) {
                         $return = true;
                     } else {
                         $return = false;
                     }
                 } else {
                     $return = true;
                 }
             } else {
                 $return = false;
             }
             unset($path);
         }
     } else {
         $return = false;
     }
     // call hook
     Hook::call('Controller.viewExists.after', array(&$return));
     return $return;
 }