Beispiel #1
0
 public function __construct(Request $request, Response $response)
 {
     $this->request = $request;
     $this->response = $response;
     // @TODO: Clean this up - we should instantiate a default model.
     $modelName = ucfirst(strtolower(Inflector::singularize(str_replace('Controller', '', get_class($this)))));
     if (class_exists($modelName)) {
         $this->{$modelName} = new $modelName();
     }
 }
 /**
  * Creates the controller to perform rendering on the error response.
  * If the error is a CakeException it will be converted to either a 400 or a 500
  * code error depending on the code used to construct the error.
  *
  * @param Exception $exception Exception
  */
 public function __construct(Exception $exception, Application $app)
 {
     $this->_app = $app;
     $this->controller = new Controller($app['request'], $app['response']);
     if (method_exists($this->controller, 'appError')) {
         $this->controller->appError($exception);
         return;
     }
     $exceptionName = explode('\\', str_replace('Exception', '', get_class($exception)));
     $exceptionName = array_pop($exceptionName);
     $method = $template = Inflector::variable($exceptionName);
     $code = $exception->getCode();
     $methodExists = method_exists($this, $method);
     if ($exception instanceof PrimerException && !$methodExists) {
         $method = '_primerError';
         if (empty($template) || $template === 'internalError') {
             $template = 'error500';
         }
     } else {
         if ($exception instanceof PDOException) {
             $method = 'pdoError';
             $template = 'pdo_error';
             $code = 500;
         } else {
             if (!$methodExists) {
                 $method = 'error500';
                 if ($code >= 400 && $code < 500) {
                     $method = 'error400';
                 }
             }
         }
     }
     $isNotDebug = !$this->_app['config']['app.debug'];
     if ($isNotDebug && $method === '_primerError') {
         $method = 'error400';
     }
     if ($isNotDebug && $code == 500) {
         $method = 'error500';
     }
     $this->template = $template;
     $this->method = $method;
     $this->error = $exception;
 }
Beispiel #3
0
 public static function getModelName($string = null)
 {
     $string = $string ?: get_called_class();
     return Inflector::classify($string);
 }
Beispiel #4
0
 /**
  * Returns the default table name for a model
  * Ex: User model returns 'users'
  *
  * @return string
  */
 public static function getTableName($class = null)
 {
     $class = $class ?: get_called_class();
     return Inflector::tableize($class);
 }