当前位置: 首页>>代码示例>>PHP>>正文


PHP Exception::handle方法代码示例

本文整理汇总了PHP中Exception::handle方法的典型用法代码示例。如果您正苦于以下问题:PHP Exception::handle方法的具体用法?PHP Exception::handle怎么用?PHP Exception::handle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Exception的用法示例。


在下文中一共展示了Exception::handle方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: initialize2

 /**
  * undocumented 
  *
  * @author Joshua Davey
  */
 public function initialize2()
 {
     array_shift($_SERVER['argv']);
     $args = $_SERVER['argv'];
     $scriptName = false;
     $commandName = false;
     // get list of available consoles
     $scriptNames = array('create', 'delete', 'test', 'migrate');
     while (true) {
         // reset console
         $scriptName = false;
         // check to see if the console exists in the args
         if (isset($args[0])) {
             $scriptName = array_shift($args);
         }
         // if the command requires to be in the application's root path then check it.
         // If we aren't in the applicatin's root path then tell the user and exit
         if ($scriptName != 'make') {
             if (!file_exists(realpath('application/vendor/Madeam.php'))) {
                 console\CLI::outError('Please point Madeam Console to the root directory of your application.');
                 exit;
             }
         }
         try {
             $scriptClassName = 'Console_Script_' . ucfirst($scriptName);
             $script = new $scriptClassName();
             break;
         } catch (exception\AutoloadFail $e) {
             if ($scriptName === false) {
                 // ask them for the script of the console they'd like to use
                 console\CLI::outMenu('Scripts', $scriptNames);
                 $scriptName = console\CLI::getCommand('script');
             }
             // by entering a console name at this point it means they've tried entering one that doesn't exist.
             // prompt them with an saying please try again.
             if ($scriptName !== false) {
                 console\CLI::outError("Sorry the script you entered does not exist.");
             }
         }
     }
     // get list of commands for this script
     $commandNames = array();
     $classReflection = new \ReflectionClass($script);
     foreach ($classReflection->getMethods(\ReflectionMethod::IS_PUBLIC) as $mehodReflection) {
         $commandNames[] = $mehodReflection->getName();
     }
     do {
         // by entering a console name at this point it means they've tried entering one that doesn't exist.
         // prompt them with an saying please try again.
         if ($commandName !== false) {
             console\CLI::outError("Sorry the command you entered does not exist.");
         }
         // reset command
         $commandName = false;
         // check to see if the command exists in the args
         if (isset($args[0])) {
             $commandName = array_shift($args);
         }
         if ($commandName == null) {
             console\CLI::outMenu('Commands', $commandNames);
             $commandName = console\CLI::getCommand('command');
         }
     } while (!in_array($commandName, $commandNames));
     try {
         return $script->{$commandName}($this->parseArguments($args));
     } catch (Exception $e) {
         Exception::handle($e);
     }
     // unset arguments -- they are only for first time use
     $args = array();
 }
开发者ID:joshdavey,项目名称:madeam,代码行数:76,代码来源:Console.php

示例2: control

 /**
  * undocumented 
  *
  * @author Joshua Davey
  * @param array $request
  */
 public static function control($request)
 {
     // because we allow controllers to be grouped into sub folders we need to recognize this when
     // someone tries to access them. For example if someone wants to access the 'admin/index' controller
     // they should be able to just type in 'admin' because 'index' is the default controller in that
     // group of controllers. To make this possible we check to see if a directory exists that is named
     // the same as the controller being called and then append the default controller name to the end
     // so 'admin' becomes 'admin/index' if the admin directory exists.
     // note: there is a consequence for this feature which means if you have a directory named 'admin'
     // you can't have a controller named 'Controller_Admin'
     if (is_dir('application/controllers/' . ucfirst($request['_controller']))) {
         $request['_controller'] .= '/' . 'index';
     }
     // set controller's class
     $controllerClassNodes = explode('/', $request['_controller']);
     foreach ($controllerClassNodes as &$node) {
         $node = Inflector::camelize($node);
     }
     $controllerClassNodes[count($controllerClassNodes) - 1] = ucfirst($controllerClassNodes[count($controllerClassNodes) - 1]);
     // set controller class
     $controllerClass = implode('\\', $controllerClassNodes) . 'Controller';
     try {
         $controller = new $controllerClass();
     } catch (Exception\AutoloadFail $e) {
         if (is_dir(self::$pathToProject . 'application/views/' . $request['_controller'])) {
             $view = $request['_controller'] . '/' . $request['_action'];
             $request['_controller'] = 'app';
             $controller = new \AppController();
             $controller->view($view);
         } elseif (is_file(self::$pathToProject . 'application/views/' . $request['_controller'] . '/' . $request['_action'] . '.' . $request['_format'])) {
             $view = $request['_controller'];
             $request['_action'] = $request['_controller'];
             $request['_controller'] = 'app';
             $controller = new \AppController();
             $controller->view($view);
         } else {
             // no controller or view found = critical error.
             //header("HTTP/1.1 404 Not Found");
             Exception::handle($e, array('message' => 'Missing Controller <strong>' . $controllerClass . "</strong> \n Create File: <strong>application/controllers/" . str_replace('_', DS, $controllerClass) . ".php</strong> \n <code>&lt;?php \n class {$controllerClass} extends AppController {\n\n  &nbsp; public function " . Inflector::camelize(lcfirst($request['_action'])) . "Action() {\n &nbsp;&nbsp;&nbsp; \n &nbsp; }\n\n   }</code>"));
             return;
         }
     }
     try {
         // process request
         $response = $controller->process($request);
         // delete controller
         unset($controller);
         // return response
         return $response;
     } catch (controller\exception\MissingAction $e) {
         //header("HTTP/1.1 404 Not Found");
         Exception::handle($e);
         return;
     } catch (controller\exception\MissingView $e) {
         header("HTTP/1.1 404 Not Found");
         Exception::handle($e);
         return;
     }
 }
开发者ID:joshdavey,项目名称:madeam,代码行数:65,代码来源:Framework.php


注:本文中的Exception::handle方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。