File indexing completed on 2024-05-05 18:01:10

0001 <?php
0002 /** @noinspection PhpUnused */
0003 /** @noinspection PhpIncludeInspection */
0004 
0005 /**
0006  * Flooer Framework
0007  *
0008  * LICENSE: BSD License (2 Clause)
0009  *
0010  * @category    Flooer
0011  * @package     Flooer_Application
0012  * @subpackage  Dispatch
0013  * @author      Akira Ohgaki <akiraohgaki@gmail.com>
0014  * @copyright   Akira Ohgaki
0015  * @license     https://opensource.org/licenses/BSD-2-Clause  BSD License (2 Clause)
0016  * @link        https://github.com/akiraohgaki/flooer
0017  */
0018 
0019 require_once 'Flooer/Filter.php';
0020 require_once 'Flooer/Controller.php';
0021 
0022 /**
0023  * Usage
0024  *
0025  * $dispatch = new Flooer_Application_Dispatch($application);
0026  * $dispatch->setBaseDir('../application/controllers');
0027  * $dispatch->dispatch();
0028  */
0029 
0030 /**
0031  * Dispatcher class of application
0032  *
0033  * @category    Flooer
0034  * @package     Flooer_Application
0035  * @subpackage  Dispatch
0036  * @author      Akira Ohgaki <akiraohgaki@gmail.com>
0037  */
0038 class Flooer_Application_Dispatch
0039 {
0040 
0041     /**
0042      * Application environment object
0043      *
0044      * @var     Flooer_Application
0045      */
0046     protected $_application = null;
0047 
0048     /**
0049      * Configuration options
0050      *
0051      * @var     array
0052      */
0053     protected $_config = array(
0054         'limitMethod'          => true,
0055         'filterInput'          => true,
0056         'filterOutput'         => true,
0057         'sendResponse'         => true,
0058         'renderView'           => true,
0059         'renderErrorPage'      => true,
0060         'writeLog'             => true,
0061         'allowedMethod'        => 'GET, POST, PUT, DELETE',
0062         'baseDir'              => null,
0063         'defaultController'    => 'Index',
0064         'defaultAction'        => 'Index',
0065         'errorController'      => 'Error',
0066         'errorAction'          => 'Error',
0067         'errorMethod'          => 'catch',
0068         'layoutView'           => 'layout',
0069         'controllerFileSuffix' => '.php',
0070         'viewFileSuffix'       => '.html',
0071         'controllerConfig'     => array(),
0072     );
0073 
0074     /**
0075      * Dispatch status
0076      *
0077      * @var     bool
0078      */
0079     protected $_status = false;
0080 
0081     /**
0082      * Constructor
0083      *
0084      * @param Flooer_Application &$application
0085      * @param array               $config
0086      *
0087      * @return  void
0088      */
0089     public function __construct(Flooer_Application &$application, array $config = null)
0090     {
0091         ob_start();
0092         $this->_application =& $application;
0093         if ($config) {
0094             $this->_config = $config + $this->_config;
0095         }
0096     }
0097 
0098     /**
0099      * Destructor
0100      *
0101      * @return  void
0102      */
0103     public function __destruct()
0104     {
0105         if (ob_get_level()) {
0106             ob_end_flush();
0107         }
0108     }
0109 
0110     /**
0111      * Dispatch to a page script or an action controller
0112      *
0113      * Flooer Framework have an additional support to PUT, DELETE
0114      * and more methods but those HTTP methods are not supported
0115      * on a lot of web browsers, so Flooer Framework accept the
0116      * request method emulation on POST method
0117      * with 'X-HTTP-Method-Override' request header
0118      * or 'method' request parameter.
0119      *
0120      * @param string $filename
0121      *
0122      * @return  void
0123      * @throws Flooer_Exception
0124      */
0125     public function dispatch($filename = null)
0126     {
0127         if ($this->_status) {
0128             trigger_error(
0129                 'Dispatch is already running', E_USER_NOTICE
0130             );
0131         }
0132         $this->_status = true;
0133         // Request method check
0134         if ($this->_config['limitMethod']) {
0135             $this->limitMethod();
0136         }
0137         // Input filtering
0138         if ($this->_config['filterInput']) {
0139             $this->filterInput();
0140         }
0141         // Dispatch to a page script
0142         if ($filename) {
0143             // Render the page script
0144             try {
0145                 $this->renderPage($filename);
0146             } // Error handling
0147             catch (Flooer_Exception $exception) {
0148                 $this->_application->setResource('exception', $exception);
0149                 if ($this->_config['writeLog'] && $this->_application->getResource('log') && $this->_application->getResource('log') instanceof Flooer_Log) {
0150                     $this->writeLog();
0151                 }
0152                 if ($this->_config['renderErrorPage']) {
0153                     $this->renderErrorPage();
0154                 }
0155             }
0156         } // Dispatch to an action controller
0157         else {
0158             // Detect a meta-parameters
0159             if ($this->_application->getResource('request')->controller) {
0160                 $controller = $this->_application->getResource('request')->controller;
0161             } else {
0162                 $controller = $this->_config['defaultController'];
0163             }
0164             if ($this->_application->getResource('request')->action) {
0165                 $action = $this->_application->getResource('request')->action;
0166             } else {
0167                 $action = $this->_config['defaultAction'];
0168             }
0169             if ($this->_application->getResource('request')->getMethod() == 'POST') {
0170                 if ($this->_application->getResource('request')->method) {
0171                     $method = $this->_application->getResource('request')->method;
0172                 } else {
0173                     $method = $this->_application->getResource('request')->getMethod(true);
0174                 }
0175             } else {
0176                 $method = $this->_application->getResource('request')->getMethod();
0177             }
0178             // Execute the action and render the view
0179             try {
0180                 $this->executeAction($controller, $action, $method);
0181                 if ($this->_config['renderView'] && $this->_application->getResource('view') && $this->_application->getResource('view') instanceof Flooer_View) {
0182                     $this->renderView($controller, $action);
0183                 }
0184             } // Error handling
0185             catch (Flooer_Exception $exception) {
0186                 $this->_application->setResource('exception', $exception);
0187                 if ($this->_config['writeLog'] && $this->_application->getResource('log') && $this->_application->getResource('log') instanceof Flooer_Log) {
0188                     $this->writeLog();
0189                 }
0190                 // Execute the error action and render the view
0191                 try {
0192                     $this->executeAction(
0193                         $this->_config['errorController'], $this->_config['errorAction'], $this->_config['errorMethod']
0194                     );
0195                     if ($this->_config['renderView'] && $this->_application->getResource('view') && $this->_application->getResource('view') instanceof Flooer_View) {
0196                         $this->renderView(
0197                             $this->_config['errorController'], $this->_config['errorAction']
0198                         );
0199                     }
0200                 } // If error happened again, render a default error page
0201                 catch (Flooer_Exception $exception) {
0202                     $this->_application->setResource('exception', $exception);
0203                     if ($this->_config['writeLog'] && $this->_application->getResource('log') && $this->_application->getResource('log') instanceof Flooer_Log) {
0204                         $this->writeLog();
0205                     }
0206                     if ($this->_config['renderErrorPage']) {
0207                         $this->renderErrorPage();
0208                     }
0209                 }
0210             }
0211         }
0212         // Output filtering
0213         if ($this->_config['filterOutput']) {
0214             $this->filterOutput();
0215         }
0216         // Send a response
0217         if ($this->_config['sendResponse']) {
0218             $this->sendResponse();
0219         }
0220     }
0221 
0222     /**
0223      * Request limits to an allowed request method
0224      *
0225      * @return  void
0226      */
0227     public function limitMethod()
0228     {
0229         if ($this->_application->getResource('request')->getMethod() == 'HEAD') {
0230             $this->_application->getResource('response')->setBody('');
0231             $this->_application->getResource('response')->send();
0232             exit;
0233         } else {
0234             if ($this->_application->getResource('request')->getMethod() == 'OPTIONS') {
0235                 $this->_application->getResource('response')->setHeader(
0236                     'Allow', $this->_config['allowedMethod']
0237                 );
0238                 $this->_application->getResource('response')->setBody(
0239                     'Allow: ' . $this->_config['allowedMethod']
0240                 );
0241                 $this->_application->getResource('response')->send();
0242                 exit;
0243             } else {
0244                 if (!in_array(
0245                     $this->_application->getResource('request')
0246                                        ->getMethod(true), explode(',', str_replace(' ', '', $this->_config['allowedMethod']))
0247                 )) {
0248                     $this->_application->getResource('response')->setStatus(405);
0249                     $this->_application->getResource('response')->setBody(
0250                         'Method Not Allowed'
0251                     );
0252                     $this->_application->getResource('response')->send();
0253                     exit;
0254                 }
0255             }
0256         }
0257     }
0258 
0259     /**
0260      * Input filtering
0261      *
0262      * @return  void
0263      */
0264     public function filterInput()
0265     {
0266         $filter = new Flooer_Filter(
0267             array(
0268                 'convertEncoding' => $this->_application->getConfig('mbstringSupport'),
0269                 'convertNewline'  => true,
0270                 'stripNull'       => true,
0271                 'stripSlashes'    => $this->_application->getConfig('magicQuotesSupport'),
0272                 'trimWhitespace'  => true,
0273                 'encoding'        => $this->_application->getConfig('encoding'),
0274                 'newline'         => $this->_application->getConfig('newline'),
0275             )
0276         );
0277         $request = $this->_application->getResource('request');
0278         $filter->filter($request);
0279         $this->_application->setResource('request', $request);
0280         if ($this->_application->getResource('cookie') && $this->_application->getResource('cookie') instanceof Flooer_Http_Cookie) {
0281             $cookie = $this->_application->getResource('cookie');
0282             $filter->filter($cookie);
0283             $this->_application->setResource('cookie', $cookie);
0284         }
0285         if ($this->_application->getResource('server') && $this->_application->getResource('server') instanceof Flooer_Http_Server) {
0286             $server = $this->_application->getResource('server');
0287             $filter->filter($server);
0288             $this->_application->setResource('server', $server);
0289         }
0290     }
0291 
0292     /**
0293      * Render a page
0294      *
0295      * @param string $filename
0296      *
0297      * @return  void
0298      * @throws  Flooer_Exception
0299      */
0300     public function renderPage($filename)
0301     {
0302         if (is_file($filename)) {
0303             try {
0304                 ob_start();
0305                 include $filename;
0306                 $this->_application->getResource('response')->setBody(ob_get_contents());
0307                 ob_end_clean();
0308                 if (!$this->_application->getResource('response')->getHeader('Content-Type')) {
0309                     $type = $this->_application->getResource('response')->detectContentType($filename);
0310                     if ($type) {
0311                         $this->_application->getResource('response')->setHeader(
0312                             'Content-Type', $type
0313                         );
0314                     }
0315                 }
0316             } catch (Flooer_Exception $exception) {
0317                 ob_clean();
0318                 $this->_application->getResource('response')->setStatus(500);
0319                 throw $exception;
0320             } catch (Exception $exception) {
0321                 ob_clean();
0322                 $this->_application->getResource('response')->setStatus(500);
0323                 throw new Flooer_Exception(
0324                     $exception->getMessage(), $exception->getCode(), $exception->getFile(), $exception->getLine()
0325                 );
0326             }
0327 
0328             return;
0329         }
0330         $this->_application->getResource('response')->setStatus(404);
0331         $message = "Page script file ($filename) not found";
0332         if (in_array($this->_application->getConfig('environment'), array('production', 'staging'))) {
0333             $message = 'Not Found';
0334         }
0335         throw new Flooer_Exception(
0336             $message, LOG_NOTICE
0337         );
0338     }
0339 
0340     /**
0341      * Write a log and/or send an email notification
0342      *
0343      * @return  void
0344      */
0345     public function writeLog()
0346     {
0347         $message = $this->_application->getResource('exception')->getMessage();
0348         $code = $this->_application->getResource('exception')->getCode();
0349         $file = $this->_application->getResource('exception')->getFile();
0350         $line = $this->_application->getResource('exception')->getLine();
0351         $uri = $this->_application->getResource('request')->getUri();
0352         $this->_application->getResource('log')->log(
0353             "$message; $file($line); $uri", $code
0354         );
0355     }
0356 
0357     /**
0358      * Render a default error page
0359      *
0360      * @return  void
0361      * @throws Flooer_Exception
0362      * @throws Flooer_Exception
0363      */
0364     public function renderErrorPage()
0365     {
0366         $this->renderPage(
0367             dirname(__FILE__) . '/pages/error.phtml'
0368         );
0369     }
0370 
0371     /**
0372      * Execute an action
0373      *
0374      * @param string $controller
0375      * @param string $action
0376      * @param string $method
0377      *
0378      * @return  void
0379      * @throws  Flooer_Exception
0380      */
0381     public function executeAction($controller, $action, $method)
0382     {
0383         $previousException = null;
0384         if ($this->_application->getResource('exception') && $this->_application->getResource('exception') instanceof Flooer_Exception) {
0385             $previousException = $this->_application->getResource('exception');
0386         }
0387         $controller = ucfirst(strtolower($controller));
0388         $controller = str_replace('controller', 'Controller', $controller);
0389         $action = ucfirst(strtolower($action));
0390         $method = strtolower($method);
0391         if (is_file(
0392             $this->_config['baseDir'] . '/' . $controller . $this->_config['controllerFileSuffix']
0393         )) {
0394             include_once $this->_config['baseDir'] . '/' . $controller . $this->_config['controllerFileSuffix'];
0395             if (class_exists($controller, false)) {
0396                 $controllerInstance = new $controller($this->_config['controllerConfig']);
0397                 if ($controllerInstance instanceof Flooer_Controller) {
0398                     if (method_exists($controllerInstance, $method . $action)) {
0399                         foreach ($this->_application->getResources() as $key => $value) {
0400                             // A resources should be an object.
0401                             $controllerInstance->$key = $value;
0402                         }
0403                         try {
0404                             $controllerInstance->execute($method . $action);
0405                         } catch (Flooer_Exception $exception) {
0406                             ob_clean();
0407                             if (!$this->_application->getResource('response')->getStatus()) {
0408                                 $this->_application->getResource('response')->setStatus(500);
0409                             }
0410                             throw $exception;
0411                         } catch (Exception $exception) {
0412                             ob_clean();
0413                             if (!$this->_application->getResource('response')->getStatus()) {
0414                                 $this->_application->getResource('response')->setStatus(500);
0415                             }
0416                             throw new Flooer_Exception(
0417                                 $exception->getMessage(), $exception->getCode(), $exception->getFile(), $exception->getLine()
0418                             );
0419                         }
0420 
0421                         return;
0422                     }
0423                     $this->_application->getResource('response')->setStatus(404);
0424                     $message = "Unknown action ($action)";
0425                     if (in_array($this->_application->getConfig('environment'), array('production', 'staging'))) {
0426                         $message = 'Not Found';
0427                     }
0428                     throw new Flooer_Exception(
0429                         $message, LOG_NOTICE, null, null, $previousException
0430                     );
0431                 }
0432                 $this->_application->getResource('response')->setStatus(500);
0433                 $message = "Invalid controller ($controller)";
0434                 if (in_array($this->_application->getConfig('environment'), array('production', 'staging'))) {
0435                     $message = 'Internal Server Error';
0436                 }
0437                 throw new Flooer_Exception(
0438                     $message, LOG_ERR, null, null, $previousException
0439                 );
0440             }
0441             $this->_application->getResource('response')->setStatus(500);
0442             $message = "Invalid controller ($controller)";
0443             if (in_array($this->_application->getConfig('environment'), array('production', 'staging'))) {
0444                 $message = 'Internal Server Error';
0445             }
0446             throw new Flooer_Exception(
0447                 $message, LOG_ERR, null, null, $previousException
0448             );
0449         }
0450         $this->_application->getResource('response')->setStatus(404);
0451         $message = "Unknown controller ($controller)";
0452         if (in_array($this->_application->getConfig('environment'), array('production', 'staging'))) {
0453             $message = 'Not Found';
0454         }
0455         throw new Flooer_Exception(
0456             $message, LOG_NOTICE, null, null, $previousException
0457         );
0458     }
0459 
0460     /**
0461      * Render a view
0462      *
0463      * @param string $controller
0464      * @param string $action
0465      *
0466      * @return  void
0467      * @throws  Flooer_Exception
0468      */
0469     public function renderView($controller, $action)
0470     {
0471         $controller = strtolower($controller);
0472         $action = strtolower($action);
0473         $file = $this->_application->getResource('view')->getFile();
0474         if (!$file) {
0475             if (is_file(
0476                 $this->_application->getResource('view')
0477                                    ->getBaseDir() . '/' . $this->_config['layoutView'] . $this->_config['viewFileSuffix']
0478             )) {
0479                 $file = $this->_config['layoutView'] . $this->_config['viewFileSuffix'];
0480             } else {
0481                 if (is_file(
0482                     $this->_application->getResource('view')
0483                                        ->getBaseDir() . '/' . $controller . $this->_config['viewFileSuffix']
0484                 )) {
0485                     $file = $controller . $this->_config['viewFileSuffix'];
0486                 } else {
0487                     $file = $controller . '/' . $action . $this->_config['viewFileSuffix'];
0488                 }
0489             }
0490         }
0491         if (is_file(
0492             $this->_application->getResource('view')->getBaseDir() . '/' . $file
0493         )) {
0494             try {
0495                 $this->_application->getResource('response')->setBody(
0496                     $this->_application->getResource('view')->render($file)
0497                 );
0498                 if (!$this->_application->getResource('response')->getHeader('Content-Type')) {
0499                     $type = $this->_application->getResource('response')->detectContentType($file);
0500                     if ($type) {
0501                         $this->_application->getResource('response')->setHeader(
0502                             'Content-Type', $type
0503                         );
0504                     }
0505                 }
0506             } catch (Flooer_Exception $exception) {
0507                 ob_clean();
0508                 $this->_application->getResource('response')->setStatus(500);
0509                 throw $exception;
0510             } catch (Exception $exception) {
0511                 ob_clean();
0512                 $this->_application->getResource('response')->setStatus(500);
0513                 throw new Flooer_Exception(
0514                     $exception->getMessage(), $exception->getCode(), $exception->getFile(), $exception->getLine()
0515                 );
0516             }
0517 
0518             return;
0519         }
0520         $this->_application->getResource('response')->setStatus(404);
0521         $message = 'View script file (' . $this->_application->getResource('view')
0522                                                              ->getBaseDir() . '/' . $file . ') not found';
0523         if (in_array($this->_application->getConfig('environment'), array('production', 'staging'))) {
0524             $message = 'Not Found';
0525         }
0526         throw new Flooer_Exception(
0527             $message, LOG_NOTICE
0528         );
0529     }
0530 
0531     /**
0532      * Output filtering
0533      *
0534      * @return  void
0535      */
0536     public function filterOutput()
0537     {
0538         $filter = new Flooer_Filter(
0539             array(
0540                 'convertEncoding' => $this->_application->getConfig('mbstringSupport'),
0541                 'convertNewline'  => true,
0542                 'stripNull'       => true,
0543                 'stripSlashes'    => false,
0544                 'trimWhitespace'  => true,
0545                 'encoding'        => $this->_application->getConfig('encoding'),
0546                 'newline'         => $this->_application->getConfig('newline'),
0547             )
0548         );
0549         $body = $this->_application->getResource('response')->getBody();
0550         $filter->filter($body);
0551         $this->_application->getResource('response')->setBody($body);
0552     }
0553 
0554     /**
0555      * Send a response
0556      *
0557      * @return  void
0558      */
0559     public function sendResponse()
0560     {
0561         $this->_application->getResource('response')->send();
0562     }
0563 
0564     /**
0565      * Get an application environment object
0566      *
0567      * @return  Flooer_Application
0568      */
0569     public function getApplication()
0570     {
0571         return $this->_application;
0572     }
0573 
0574     /**
0575      * Set an executable flag for limitMethod()
0576      *
0577      * @param bool $bool
0578      *
0579      * @return  void
0580      */
0581     public function setLimitMethod($bool)
0582     {
0583         $this->_config['limitMethod'] = $bool;
0584     }
0585 
0586     /**
0587      * Get an executable flag for limitMethod()
0588      *
0589      * @return  bool
0590      */
0591     public function getLimitMethod()
0592     {
0593         return $this->_config['limitMethod'];
0594     }
0595 
0596     /**
0597      * Set an executable flag for filterInput()
0598      *
0599      * @param bool $bool
0600      *
0601      * @return  void
0602      */
0603     public function setFilterInput($bool)
0604     {
0605         $this->_config['filterInput'] = $bool;
0606     }
0607 
0608     /**
0609      * Get an executable flag for filterInput()
0610      *
0611      * @return  bool
0612      */
0613     public function getFilterInput()
0614     {
0615         return $this->_config['filterInput'];
0616     }
0617 
0618     /**
0619      * Set an executable flag for filterOutput()
0620      *
0621      * @param bool $bool
0622      *
0623      * @return  void
0624      */
0625     public function setFilterOutput($bool)
0626     {
0627         $this->_config['filterOutput'] = $bool;
0628     }
0629 
0630     /**
0631      * Get an executable flag for filterOutput()
0632      *
0633      * @return  bool
0634      */
0635     public function getFilterOutput()
0636     {
0637         return $this->_config['filterOutput'];
0638     }
0639 
0640     /**
0641      * Set an executable flag for sendResponse()
0642      *
0643      * @param bool $bool
0644      *
0645      * @return  void
0646      */
0647     public function setSendResponse($bool)
0648     {
0649         $this->_config['sendResponse'] = $bool;
0650     }
0651 
0652     /**
0653      * Get an executable flag for sendResponse()
0654      *
0655      * @return  bool
0656      */
0657     public function getSendResponse()
0658     {
0659         return $this->_config['sendResponse'];
0660     }
0661 
0662     /**
0663      * Set an executable flag for renderView()
0664      *
0665      * @param bool $bool
0666      *
0667      * @return  void
0668      */
0669     public function setRenderView($bool)
0670     {
0671         $this->_config['renderView'] = $bool;
0672     }
0673 
0674     /**
0675      * Get an executable flag for renderView()
0676      *
0677      * @return  bool
0678      */
0679     public function getRenderView()
0680     {
0681         return $this->_config['renderView'];
0682     }
0683 
0684     /**
0685      * Set an executable flag for renderErrorPage()
0686      *
0687      * @param bool $bool
0688      *
0689      * @return  void
0690      */
0691     public function setRenderErrorPage($bool)
0692     {
0693         $this->_config['renderErrorPage'] = $bool;
0694     }
0695 
0696     /**
0697      * Get an executable flag for renderErrorPage()
0698      *
0699      * @return  bool
0700      */
0701     public function getRenderErrorPage()
0702     {
0703         return $this->_config['renderErrorPage'];
0704     }
0705 
0706     /**
0707      * Set an executable flag for writeLog()
0708      *
0709      * @param bool $bool
0710      *
0711      * @return  void
0712      */
0713     public function setWriteLog($bool)
0714     {
0715         $this->_config['writeLog'] = $bool;
0716     }
0717 
0718     /**
0719      * Get an executable flag for writeLog()
0720      *
0721      * @return  bool
0722      */
0723     public function getWriteLog()
0724     {
0725         return $this->_config['writeLog'];
0726     }
0727 
0728     /**
0729      * Set an allowed method
0730      *
0731      * @param string $allowedMethod Comma-separated list
0732      *
0733      * @return  void
0734      */
0735     public function setAllowedMethod($allowedMethod)
0736     {
0737         $this->_config['allowedMethod'] = $allowedMethod;
0738     }
0739 
0740     /**
0741      * Get an allowed method
0742      *
0743      * @return  string
0744      */
0745     public function getAllowedMethod()
0746     {
0747         return $this->_config['allowedMethod'];
0748     }
0749 
0750     /**
0751      * Set the path of a base directory
0752      *
0753      * @param string $path
0754      *
0755      * @return  void
0756      */
0757     public function setBaseDir($path)
0758     {
0759         $this->_config['baseDir'] = $path;
0760     }
0761 
0762     /**
0763      * Get the path of a base directory
0764      *
0765      * @return  string
0766      */
0767     public function getBaseDir()
0768     {
0769         return $this->_config['baseDir'];
0770     }
0771 
0772     /**
0773      * Set a default controller name
0774      *
0775      * @param string $controller
0776      *
0777      * @return  void
0778      */
0779     public function setDefaultController($controller)
0780     {
0781         $this->_config['defaultController'] = $controller;
0782     }
0783 
0784     /**
0785      * Get a default controller name
0786      *
0787      * @return  string
0788      */
0789     public function getDefaultController()
0790     {
0791         return $this->_config['defaultController'];
0792     }
0793 
0794     /**
0795      * Set a default action name
0796      *
0797      * @param string $action
0798      *
0799      * @return  void
0800      */
0801     public function setDefaultAction($action)
0802     {
0803         $this->_config['defaultAction'] = $action;
0804     }
0805 
0806     /**
0807      * Get a default action name
0808      *
0809      * @return  string
0810      */
0811     public function getDefaultAction()
0812     {
0813         return $this->_config['defaultAction'];
0814     }
0815 
0816     /**
0817      * Set an error controller name
0818      *
0819      * @param string $controller
0820      *
0821      * @return  void
0822      */
0823     public function setErrorController($controller)
0824     {
0825         $this->_config['errorController'] = $controller;
0826     }
0827 
0828     /**
0829      * Get an error controller name
0830      *
0831      * @return  string
0832      */
0833     public function getErrorController()
0834     {
0835         return $this->_config['errorController'];
0836     }
0837 
0838     /**
0839      * Set an error action name
0840      *
0841      * @param string $action
0842      *
0843      * @return  void
0844      */
0845     public function setErrorAction($action)
0846     {
0847         $this->_config['errorAction'] = $action;
0848     }
0849 
0850     /**
0851      * Get an error action name
0852      *
0853      * @return  string
0854      */
0855     public function getErrorAction()
0856     {
0857         return $this->_config['errorAction'];
0858     }
0859 
0860     /**
0861      * Set an error method name
0862      *
0863      * @param string $method
0864      *
0865      * @return  void
0866      */
0867     public function setErrorMethod($method)
0868     {
0869         $this->_config['errorMethod'] = $method;
0870     }
0871 
0872     /**
0873      * Get an error method name
0874      *
0875      * @return  string
0876      */
0877     public function getErrorMethod()
0878     {
0879         return $this->_config['errorMethod'];
0880     }
0881 
0882     /**
0883      * Set a view name for layout
0884      *
0885      * @param string $layout
0886      *
0887      * @return  void
0888      */
0889     public function setLayoutView($layout)
0890     {
0891         $this->_config['layoutView'] = $layout;
0892     }
0893 
0894     /**
0895      * Get a view name for layout
0896      *
0897      * @return  string
0898      */
0899     public function getLayoutView()
0900     {
0901         return $this->_config['layoutView'];
0902     }
0903 
0904     /**
0905      * Set a controller file suffix
0906      *
0907      * @param string $suffix
0908      *
0909      * @return  void
0910      */
0911     public function setControllerFileSuffix($suffix)
0912     {
0913         $this->_config['controllerFileSuffix'] = $suffix;
0914     }
0915 
0916     /**
0917      * Get a controller file suffix
0918      *
0919      * @return  string
0920      */
0921     public function getControllerFileSuffix()
0922     {
0923         return $this->_config['controllerFileSuffix'];
0924     }
0925 
0926     /**
0927      * Set a view file suffix
0928      *
0929      * @param string $suffix
0930      *
0931      * @return  void
0932      */
0933     public function setViewFileSuffix($suffix)
0934     {
0935         $this->_config['viewFileSuffix'] = $suffix;
0936     }
0937 
0938     /**
0939      * Get a view file suffix
0940      *
0941      * @return  string
0942      */
0943     public function getViewFileSuffix()
0944     {
0945         return $this->_config['viewFileSuffix'];
0946     }
0947 
0948     /**
0949      * Set a configuration options for a controller class
0950      *
0951      * @param array $config
0952      *
0953      * @return  void
0954      */
0955     public function setControllerConfig(array $config)
0956     {
0957         $this->_config['controllerConfig'] = $config;
0958     }
0959 
0960     /**
0961      * Get a configuration options for a controller class
0962      *
0963      * @return  array
0964      */
0965     public function getControllerConfig()
0966     {
0967         return $this->_config['controllerConfig'];
0968     }
0969 
0970 }