File indexing completed on 2024-12-22 05:33:09
0001 <?php 0002 0003 /** 0004 * Flooer Framework 0005 * 0006 * LICENSE: BSD License (2 Clause) 0007 * 0008 * @category Flooer 0009 * @package Flooer_Controller 0010 * @author Akira Ohgaki <akiraohgaki@gmail.com> 0011 * @copyright Akira Ohgaki 0012 * @license https://opensource.org/licenses/BSD-2-Clause BSD License (2 Clause) 0013 * @link https://github.com/akiraohgaki/flooer 0014 */ 0015 0016 /** 0017 * Usage 0018 * 0019 * class Controller extends Flooer_Controller 0020 * { 0021 * public function action() 0022 * { 0023 * } 0024 * } 0025 * $controller = new Controller(); 0026 * $controller->execute('action'); 0027 */ 0028 0029 /** 0030 * Action controller class 0031 * 0032 * @category Flooer 0033 * @package Flooer_Controller 0034 * @author Akira Ohgaki <akiraohgaki@gmail.com> 0035 */ 0036 abstract class Flooer_Controller 0037 { 0038 0039 /** 0040 * Configuration options 0041 * 0042 * @var array 0043 */ 0044 protected $_config = array(); 0045 0046 /** 0047 * Constructor 0048 * 0049 * @param array $config 0050 * @return void 0051 */ 0052 public function __construct(array $config = null) 0053 { 0054 if ($config) { 0055 $this->_config = $config + $this->_config; 0056 } 0057 } 0058 0059 /** 0060 * Magic method for undefined methods 0061 * 0062 * @param string $method 0063 * @param array $arguments 0064 * @return void 0065 */ 0066 public function __call($method, array $arguments) 0067 { 0068 trigger_error( 0069 "Method ($method) does not exist", 0070 E_USER_ERROR 0071 ); 0072 } 0073 0074 /** 0075 * Execute an action 0076 * 0077 * @param string $action 0078 * @return void 0079 */ 0080 public function execute($action) 0081 { 0082 $this->construct(); 0083 $this->$action(); 0084 $this->destruct(); 0085 } 0086 0087 /** 0088 * Alternative constructor 0089 * 0090 * @return void 0091 */ 0092 public function construct() 0093 { 0094 } 0095 0096 /** 0097 * Alternative destructor 0098 * 0099 * @return void 0100 */ 0101 public function destruct() 0102 { 0103 } 0104 0105 }