├── License.md ├── README.md ├── framework ├── Yaf │ ├── .settings │ │ └── org.eclipse.php.core.prefs │ ├── Action │ │ └── Abstract.php │ ├── Application.php │ ├── Bootstrap │ │ └── Abstract.php │ ├── Config │ │ ├── Abstract.php │ │ ├── Exception.php │ │ ├── Ini.php │ │ └── Simple.php │ ├── Controller │ │ └── Abstract.php │ ├── Dispatcher.php │ ├── Exception.php │ ├── Exception │ │ ├── DispatchFailed.php │ │ ├── LoadFailed.php │ │ ├── LoadFailed │ │ │ ├── Action.php │ │ │ ├── Controller.php │ │ │ ├── Module.php │ │ │ └── View.php │ │ ├── RouterFailed.php │ │ ├── StartupError.php │ │ └── TypeError.php │ ├── G.php │ ├── Loader.php │ ├── Plugin │ │ └── Abstract.php │ ├── Registry.php │ ├── Request │ │ ├── Abstract.php │ │ ├── Exception.php │ │ ├── Http.php │ │ └── Simple.php │ ├── Response │ │ ├── Abstract.php │ │ ├── Cli.php │ │ ├── Exception.php │ │ └── Http.php │ ├── Route │ │ ├── Exception.php │ │ ├── Interface.php │ │ ├── Map.php │ │ ├── Regex.php │ │ ├── Rewrite.php │ │ ├── Simple.php │ │ ├── Static.php │ │ └── Supervar.php │ ├── Router.php │ ├── Session.php │ └── View │ │ ├── Interface.php │ │ └── Simple.php ├── Yaf_Namespace │ ├── Action │ │ └── Abstract.php │ ├── Application.php │ ├── Bootstrap │ │ └── Abstract.php │ ├── Config │ │ ├── Abstract.php │ │ ├── Exception.php │ │ ├── Ini.php │ │ └── Simple.php │ ├── Controller │ │ └── Abstract.php │ ├── Dispatcher.php │ ├── Exception.php │ ├── Exception │ │ ├── DispatchFailed.php │ │ ├── LoadFailed │ │ │ ├── Action.php │ │ │ ├── Controller.php │ │ │ ├── LoadFailed.php │ │ │ ├── Module.php │ │ │ └── View.php │ │ ├── RouterFailed.php │ │ ├── StartupError.php │ │ └── TypeError.php │ ├── G.php │ ├── Loader.php │ ├── Plugin │ │ └── Abstract.php │ ├── Registry.php │ ├── Request │ │ ├── Abstract.php │ │ ├── Exception.php │ │ ├── Http.php │ │ └── Simple.php │ ├── Response │ │ ├── Abstract.php │ │ ├── Cli.php │ │ ├── Exception.php │ │ └── Http.php │ ├── Route │ │ ├── Exception.php │ │ ├── Interface.php │ │ ├── Map.php │ │ ├── Regex.php │ │ ├── Rewrite.php │ │ ├── Simple.php │ │ ├── Static.php │ │ └── Supervar.php │ ├── Router.php │ ├── Session.php │ └── View │ │ ├── Interface.php │ │ └── Simple.php └── loader.php ├── sample ├── .htaccess ├── application │ ├── Bootstrap.php │ ├── controllers │ │ ├── Error.php │ │ └── Index.php │ ├── library │ │ ├── A.php │ │ ├── A │ │ │ └── B.php │ │ └── Yaf │ │ │ └── TEST.php │ ├── modules │ │ ├── Index │ │ │ ├── controllers │ │ │ │ ├── Action.php │ │ │ │ └── Index.php │ │ │ ├── models │ │ │ │ └── User.php │ │ │ └── views │ │ │ │ └── Index │ │ │ │ └── Index. │ │ └── Test │ │ │ ├── controllers │ │ │ ├── Action.php │ │ │ └── Index.php │ │ │ ├── models │ │ │ └── User.php │ │ │ └── views │ │ │ └── Index │ │ │ └── Index. │ ├── plugins │ │ └── User.php │ └── views │ │ ├── error │ │ └── error.phtml │ │ ├── index │ │ └── index.phtml │ │ └── test │ │ └── index.phtml ├── conf │ └── application.ini ├── framework ├── index.php └── public │ └── images │ └── logo.jpg └── tests ├── bootstrap.php ├── bootstrap_yaf_so.php ├── framework └── Yaf │ ├── ApplicationTest.php │ ├── Config │ ├── IniTest.php │ ├── SimpleTest.php │ └── _files │ │ ├── allsections.ini │ │ ├── circular.ini │ │ ├── config.ini │ │ ├── empty.ini │ │ ├── invalid.ini │ │ ├── multipleinheritance.ini │ │ ├── nosections.ini │ │ ├── separator.ini │ │ ├── testCase010.ini │ │ ├── testCase018.ini │ │ ├── testCase030.ini │ │ ├── testCase032.ini │ │ ├── zf2843.ini │ │ ├── zf5800.ini │ │ ├── zf6508.ini │ │ └── zf8159.ini │ ├── DispatcherTest.php │ ├── ExceptionTest.php │ ├── Loader │ └── testCase027.php │ ├── Loader2.php │ ├── LoaderTest.php │ ├── RegistryTest.php │ ├── Request │ └── SimpleTest.php │ ├── Response │ ├── CliTest.php │ └── HttpTest.php │ ├── Route │ ├── MapTest.php │ ├── RegexpTest.php │ ├── RewriteTest.php │ ├── SimpleTest.php │ ├── StaticTest.php │ └── SupervarTest.php │ ├── RouterTest.php │ ├── SessionTest.php │ ├── View │ ├── SimpleTest.php │ ├── errorinview.php │ ├── recursiveRender.php │ ├── testCase033.php │ └── testCase041.php │ ├── _files │ ├── application.ini │ ├── application_rewrite.ini │ ├── route_rewrite.ini │ ├── route_simple.ini │ ├── simple.ini │ ├── testCase013.ini │ ├── testCase020.php │ ├── testCase021.php │ └── testCase042.php │ └── notes.txt ├── phpunit.xml ├── runtests.sh └── testApp ├── _files ├── application.ini ├── application_rewrite.ini ├── route_rewrite.ini └── route_simple.ini ├── application ├── Bootstrap.php ├── controllers │ ├── Error.php │ ├── Index.php │ └── Testview.php ├── library │ ├── A.php │ ├── A │ │ └── B.php │ └── Yaf │ │ └── TEST.php ├── modules │ ├── Index │ │ ├── controllers │ │ │ ├── Action.php │ │ │ └── Index.php │ │ ├── models │ │ │ └── User.php │ │ └── views │ │ │ └── Index │ │ │ └── Index. │ ├── Test │ │ ├── controllers │ │ │ ├── Action.php │ │ │ └── Index.php │ │ ├── models │ │ │ └── User.php │ │ └── views │ │ │ └── Index │ │ │ └── Index. │ └── Testview │ │ ├── controllers │ │ ├── Action.php │ │ └── Controller.php │ │ ├── models │ │ └── User.php │ │ └── views │ │ └── Index │ │ └── Index. ├── plugins │ └── User.php └── views │ ├── error │ └── error.phtml │ ├── index │ └── index.phtml │ └── test │ ├── exit.phtml │ ├── index.phtml │ ├── testCase029.phtml │ ├── testCase038.phtml │ └── testCase039.phtml ├── conf └── application.ini └── public └── images └── logo.jpg /License.md: -------------------------------------------------------------------------------- 1 | License: 2 | Same as yaf (http://pecl.php.net/package/yaf) -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | #YAF ported to php to extend portability 2 | 3 | [YAF](http://pecl.php.net/package/yaf) is a php framework written in C and available as an extension. 4 | 5 | This project is a php equivalent of the C code making your code portable to any server which runs php. 6 | Please note that this project is not intended to be a replacement for the Yaf extension, should consider it 7 | an extension for making your code portable to other servers where the yaf extension is not installed or not possible to 8 | install at the moment.... 9 | Yaf C extension installed is aprox. 10 times faster then this Php equivalent....So you should consider making everything possible 10 | to install the C extension. 11 | 12 | If you have a php project which is written using YAF and you have no controll on the hosting, or your hosting would not want 13 | to install the YAf extension, then your code will not work. 14 | Using this project the code will work, but of course at much lower speed. At least the portability of your project will increase and can run on most servers (php 5.2 is required). 15 | 16 | Diferences: 17 | 18 | Instead of 19 | $app->getDispatcher()->setErrorHandler("error_handler", E_RECOVERABLE_ERROR); 20 | should be used: 21 | $app->getDispatcher()->setErrorHandler("error_handler", E_RECOVERABLE_ERROR|E_USER_ERROR); 22 | as from php E_RECOVERABLE_ERROR cannot be triggered. 23 | Do not use Yaf\ENVIRON use instead \Yaf\Application::app()->environ() or \Yaf\G::iniGet('yaf.environ') 24 | 25 | 26 | ## INSTALL 27 | 28 | Copy framework folder into your project folder. 29 | Edit index.php and add this code after APPLICATION_PATH is defined: 30 | 31 | if (!extension_loaded('yaf')) { 32 | //we should load the framework from classes 33 | include(APPLICATION_PATH . '/framework/loader.php'); 34 | } 35 | 36 | ## BENCHMARK 37 | 38 | ab -n 1000 -c 10 http://localhost/work/yaf/testApp/ 39 | On my pc yaf php ported is 10 times slower. 40 | 41 | 42 | ## TESTING 43 | - require php >= 5.3 to run the test 44 | - for testing you need to have yaf be loaded as a dynamic extension from command line 45 | - starting php 5.3 dl() cannot be used when php is loaded from modules. Only command line or Fast CGI mode will 46 | work. 47 | - to run the tests go to /tests/ directory and execute 48 | - ./runtests.sh - when testing the php framework 49 | - ./runtests.sh yaf - when testing with yaf.so extension 50 | 51 | 52 | -------------------------------------------------------------------------------- /framework/Yaf/.settings/org.eclipse.php.core.prefs: -------------------------------------------------------------------------------- 1 | #Fri Jul 27 06:19:23 EEST 2012 2 | eclipse.preferences.version=1 3 | include_path=0;/yaf 4 | use_asp_tags_as_php=false 5 | -------------------------------------------------------------------------------- /framework/Yaf/Action/Abstract.php: -------------------------------------------------------------------------------- 1 | _controller; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /framework/Yaf/Bootstrap/Abstract.php: -------------------------------------------------------------------------------- 1 | _readonly; 25 | } 26 | abstract public function toArray(); 27 | } -------------------------------------------------------------------------------- /framework/Yaf/Config/Exception.php: -------------------------------------------------------------------------------- 1 | setErrorNo($errtype); 12 | $app->setErrorMsg($errmsg); 13 | } 14 | trigger_error($errmsg, $errtype); 15 | } 16 | } -------------------------------------------------------------------------------- /framework/Yaf/Exception/DispatchFailed.php: -------------------------------------------------------------------------------- 1 | true, 11 | 'catchException' => false, 12 | 'autoload_started' => 0, 13 | 'configs' => null, 14 | 'directory' => null, 15 | 'local_library' => null, 16 | 'ext' => Yaf_Router::YAF_DEFAULT_EXT, 17 | 'view_ext' => Yaf_Loader::YAF_DEFAULT_VIEW_EXT, 18 | 'default_module' => Yaf_Router::YAF_ROUTER_DEFAULT_MODULE, 19 | 'default_controller' => Yaf_Router::YAF_ROUTER_DEFAULT_CONTROLLER, 20 | 'default_action' => Yaf_Router::YAF_ROUTER_DEFAULT_ACTION, 21 | 'bootstrap' => Yaf_Bootstrap_Abstract::YAF_DEFAULT_BOOTSTRAP, 22 | 'modules' => null, 23 | 'default_route' => null 24 | ); 25 | //missing globals to check 26 | //local_namespace 27 | protected static $_ini = array( 28 | 'yaf.library' => '', 29 | 'yaf.action_prefer' => false, 30 | 'yaf.lowcase_path' => false, 31 | 'yaf.use_spl_autoload' => false, 32 | 'yaf.forward_limit' => '5', 33 | 'yaf.name_suffix' => true, 34 | 'yaf.name_separator' => '', 35 | 'yaf.cache_config' => false, 36 | 'yaf.st_compatible' => false, 37 | 'yaf.environ' => 'product', 38 | 'yaf.use_namespace' => false 39 | ); 40 | 41 | public static function iniSet($key, $value) 42 | { 43 | self::$_ini[$key] = $value; 44 | } 45 | 46 | public static function iniGet($key) 47 | { 48 | if (($iniValue = ini_get($key))!==false) { 49 | //we have ini set from php 50 | if ($iniValue == '0') { 51 | $value = false; 52 | } elseif ($iniValue == '1') { 53 | $value = true; 54 | } else { 55 | $value = $iniValue; 56 | } 57 | self::iniSet($key, $value); 58 | return $value; 59 | } else { 60 | if (isset(self::$_ini[$key])) { 61 | return self::$_ini[$key]; 62 | } 63 | } 64 | return null; 65 | } 66 | 67 | public static function set($key, $value) 68 | { 69 | self::$_globals[$key] = $value; 70 | } 71 | 72 | public static function get($key) 73 | { 74 | if (isset(self::$_globals[$key])) { 75 | return self::$_globals[$key]; 76 | } 77 | return null; 78 | } 79 | 80 | 81 | public static function isAbsolutePath($path) 82 | { 83 | if ( 84 | substr($path, 0, 1) == "/" 85 | || 86 | ( 87 | (strpos($path, ":") !== false) 88 | && 89 | (strpos(PHP_OS, "WIN") !== FALSE) 90 | ) 91 | ) { 92 | return true; 93 | } else { 94 | return false; 95 | } 96 | } 97 | } -------------------------------------------------------------------------------- /framework/Yaf/Plugin/Abstract.php: -------------------------------------------------------------------------------- 1 | method = $method; 36 | if ($module!=null || $action!=null || $controller!=null) { 37 | $this->setActionName($action); 38 | $this->setControllerName($controller); 39 | $this->setModuleName($module); 40 | $this->setRouted(true); 41 | } else { 42 | if ($module == null) { 43 | $this->setModuleName(Yaf_G::get('default_module')); 44 | } 45 | if ($controller == null) { 46 | $this->setControllerName(Yaf_G::get('default_controller')); 47 | } 48 | if ($action == null) { 49 | $this->setActionName(Yaf_G::get('default_action')); 50 | } 51 | } 52 | 53 | if ($params) { 54 | $this->setParam($params); 55 | } 56 | } 57 | 58 | private function __clone() 59 | { 60 | //close is not possible to do 61 | } 62 | 63 | } -------------------------------------------------------------------------------- /framework/Yaf/Response/Abstract.php: -------------------------------------------------------------------------------- 1 | _body .= (string) $body; 37 | return $this; 38 | } 39 | 40 | /** 41 | * Clear the entire body 42 | * 43 | * @return boolean 44 | */ 45 | public function clearBody() 46 | { 47 | $this->_body = ''; 48 | return true; 49 | } 50 | 51 | /** 52 | * Clear headers 53 | * 54 | * @return Yaf_Response_Abstract 55 | */ 56 | public function clearHeaders() 57 | { 58 | $this->_headers = array(); 59 | return $this; 60 | } 61 | 62 | private function __clone() 63 | { 64 | //close is not possible 65 | } 66 | 67 | public function __construct() 68 | { 69 | } 70 | 71 | public function __destruct() 72 | { 73 | } 74 | /** 75 | * Return the body content 76 | * 77 | * @return string 78 | */ 79 | public function getBody() 80 | { 81 | return $this->_body; 82 | } 83 | /** 84 | * Return array of headers; see {@link $_headers} for format 85 | * 86 | * @return array 87 | */ 88 | public function getHeader() 89 | { 90 | return $this->_headers; 91 | } 92 | /** 93 | * Prepend content the body 94 | * 95 | * @param string $body 96 | * @return Yaf_Response_Abstract 97 | */ 98 | public function prependBody($body) 99 | { 100 | $this->_body = $body . $this->_body; 101 | return $this; 102 | } 103 | /** 104 | * Send the response, including all headers 105 | * 106 | * @return void 107 | */ 108 | public function response() 109 | { 110 | if ($this->_sendheader == true) { 111 | $this->sendHeaders(); 112 | } 113 | echo $this->_body; 114 | } 115 | 116 | private function setAllHeaders() 117 | { 118 | //did not found what should this do 119 | } 120 | /** 121 | * Set body content 122 | * 123 | * @param string $body 124 | * @return Yaf_Response_Abstract 125 | */ 126 | public function setBody($body) 127 | { 128 | $this->_body = (string) $body; 129 | return $this; 130 | } 131 | 132 | /** 133 | * Set a header 134 | * 135 | * If $replace is true, replaces any headers already defined with that 136 | * $name. 137 | * 138 | * @param string $name 139 | * @param string $value 140 | * @param boolean $replace 141 | * @return Yaf_Response_Abstract 142 | */ 143 | public function setHeader($name, $value, $replace = false) 144 | { 145 | $name = $this->_normalizeHeader($name); 146 | $value = (string) $value; 147 | 148 | if ($replace) { 149 | foreach ($this->_headers as $key => $header) { 150 | if ($name == $header['name']) { 151 | unset($this->_headers[$key]); 152 | } 153 | } 154 | } 155 | 156 | $this->_headers[] = array( 157 | 'name' => $name, 158 | 'value' => $value, 159 | 'replace' => $replace 160 | ); 161 | 162 | return $this; 163 | } 164 | 165 | /** 166 | * Set redirect URL 167 | * 168 | * Sets Location header. Forces replacement of any prior redirects. 169 | * 170 | * @param string $url 171 | * @return Yaf_Response_Abstract 172 | */ 173 | public function setRedirect($url) 174 | { 175 | $this->setHeader('Location', $url, true); 176 | return $this; 177 | } 178 | 179 | /** 180 | * Magic __toString functionality 181 | * 182 | * Returns response value as string 183 | * using output buffering. 184 | * 185 | * @return string 186 | */ 187 | public function __toString() 188 | { 189 | ob_start(); 190 | $this->response(); 191 | return ob_get_clean(); 192 | } 193 | 194 | 195 | 196 | //method added to be possible 197 | /** 198 | * Normalize a header name 199 | * 200 | * Normalizes a header name to X-Capitalized-Names 201 | * 202 | * @param string $name 203 | * @return string 204 | */ 205 | protected function _normalizeHeader($name) 206 | { 207 | $filtered = str_replace(array('-', '_'), ' ', (string) $name); 208 | $filtered = ucwords(strtolower($filtered)); 209 | $filtered = str_replace(' ', '-', $filtered); 210 | return $filtered; 211 | } 212 | 213 | /** 214 | * Send all headers 215 | * 216 | * Sends any headers specified. 217 | * If an {@link setHttpResponseCode() HTTP response code} 218 | * has been specified, it is sent with the first header. 219 | * 220 | * @return Yaf_Response_Abstract 221 | */ 222 | protected function sendHeaders() 223 | { 224 | foreach ($this->_headers as $header) { 225 | header( 226 | $header['name'] . ': ' . $header['value'], 227 | $header['replace'] 228 | ); 229 | } 230 | return $this; 231 | } 232 | 233 | } 234 | -------------------------------------------------------------------------------- /framework/Yaf/Response/Cli.php: -------------------------------------------------------------------------------- 1 | _body; 19 | } 20 | } -------------------------------------------------------------------------------- /framework/Yaf/Response/Exception.php: -------------------------------------------------------------------------------- 1 | $code) || (599 < $code)) { 22 | throw new Yaf_Response_Exception('Invalid HTTP response code'); 23 | } 24 | 25 | $this->_responseCode = $code; 26 | return $this; 27 | } 28 | 29 | /** 30 | * Retrieve HTTP response code 31 | * 32 | * @return int 33 | */ 34 | public function getResponseCode() 35 | { 36 | return $this->_responseCode; 37 | } 38 | 39 | /** 40 | * Send all headers 41 | * 42 | * Sends any headers specified. 43 | * If an {@link setResponseCode() HTTP response code} 44 | * has been specified, it is sent with the first header. 45 | * 46 | * @return Yaf_Response_Http 47 | */ 48 | protected function sendHeaders() 49 | { 50 | $httpCodeSent = false; 51 | 52 | foreach ($this->_headers as $header) { 53 | if (!$httpCodeSent && $this->_responseCode) { 54 | header( 55 | $header['name'] . ': ' . $header['value'], 56 | $header['replace'], $this->_responseCode 57 | ); 58 | $httpCodeSent = true; 59 | } else { 60 | header( 61 | $header['name'] . ': ' . $header['value'], 62 | $header['replace'] 63 | ); 64 | } 65 | } 66 | 67 | /*if (!$httpCodeSent) { 68 | header('HTTP/1.1 ' . $this->_responseCode); 69 | $httpCodeSent = true; 70 | }*/ 71 | 72 | return $this; 73 | } 74 | 75 | /** 76 | * Set redirect URL 77 | * 78 | * Sets Location header. Forces replacement of any prior redirects. 79 | * 80 | * @param string $url 81 | * @return Yaf_Response_Abstract 82 | */ 83 | public function setRedirect($url) 84 | { 85 | $this->setHeader('Location', $url, true) 86 | ->setResponseCode(302); 87 | return $this; 88 | } 89 | } -------------------------------------------------------------------------------- /framework/Yaf/Route/Exception.php: -------------------------------------------------------------------------------- 1 | _ctlPrefer = $controller_prefer; 19 | } 20 | if (is_string($delimiter) && $delimiter!='') { 21 | $this->_delimiter = $delimiter; 22 | } 23 | 24 | } 25 | /** 26 | * Processes a request and sets its controller and action. If 27 | * no route was possible, default route is set. 28 | * 29 | * @param Yaf_Request_Abstract 30 | * @return Yaf_Request_Abstract|boolean 31 | */ 32 | 33 | public function route(Yaf_Request_Abstract $request) 34 | { 35 | $requestUri = $request->getRequestUri(); 36 | $baseuri = $request->getBaseUri(); 37 | if ( 38 | $requestUri!='' 39 | && $baseuri!='' 40 | && stripos($requestUri, $baseuri)===0 41 | ) { 42 | $path = substr($requestUri, strlen($baseuri)); 43 | } else { 44 | $path = $requestUri; 45 | } 46 | $path = trim(urldecode($path), Yaf_Router::URI_DELIMITER); 47 | $rest = ''; 48 | if (is_string($this->_delimiter) && $this->_delimiter!='') { 49 | if (($queryStringPos = strpos($path, $this->_delimiter))!==false) { 50 | $rest = substr( 51 | $path, 52 | $queryStringPos+strlen($this->_delimiter), 53 | strlen($path)-1 54 | ); 55 | $path = substr( 56 | $path, 57 | 0, 58 | $queryStringPos 59 | ); 60 | } 61 | } 62 | $route = ''; 63 | if ($path != '' && $path!='/') { 64 | $route = str_replace( 65 | Yaf_Router::URI_DELIMITER, 66 | '_', 67 | trim($path, Yaf_Router::URI_DELIMITER) 68 | ); 69 | } 70 | if ($route!='') { 71 | if ($this->_ctlPrefer == true) { 72 | $request->setControllerName($route); 73 | } else { 74 | $request->setActionName($route); 75 | } 76 | } 77 | $params = array(); 78 | if ($rest!=null && trim($rest)!='') { 79 | $path = explode( 80 | Yaf_Router::URI_DELIMITER, 81 | trim($rest, Yaf_Router::URI_DELIMITER) 82 | ); 83 | if (($numSegs = count($path))!=0) { 84 | for ($i = 0; $i < $numSegs; $i = $i + 2) { 85 | $key = urldecode($path[$i]); 86 | $val = isset($path[$i + 1]) ? 87 | urldecode($path[$i + 1]) : null; 88 | $params[$key] = (isset($params[$key]) 89 | ? (array_merge((array) $params[$key], array($val))) 90 | : $val); 91 | } 92 | } 93 | $request->setParam($params); 94 | } 95 | 96 | return true; 97 | } 98 | /** 99 | * used to create routes on the fly from config 100 | * 101 | * @param array $config 102 | */ 103 | public static function getInstance(array $config) 104 | { 105 | $controllerPrefer = false; 106 | if ( 107 | isset($config['controllerPrefer']) 108 | && 109 | is_bool($config['controllerPrefer']) 110 | ) { 111 | $controllerPrefer = $config['controllerPrefer']; 112 | } 113 | $delimiter = '#!'; 114 | if (isset($config['delimiter'])) { 115 | $delimiter = $config['delimiter']; 116 | } 117 | return new self( 118 | $controllerPrefer, $delimiter 119 | ); 120 | } 121 | } -------------------------------------------------------------------------------- /framework/Yaf/Route/Regex.php: -------------------------------------------------------------------------------- 1 | _route = $match; 59 | $this->_default = (array) $route; 60 | $this->_maps = (array) $map; 61 | $this->_verify = $verify; 62 | } 63 | 64 | /** 65 | * Matches a user submitted path with a previously defined route. 66 | * Assigns and returns an array of defaults on a successful match. 67 | * 68 | * @param string $path Path used to match against this routing map 69 | * @return array|false An array of assigned values or a false on a mismatch 70 | */ 71 | public function route(Yaf_Request_Abstract $request) 72 | { 73 | $requestUri = $request->getRequestUri(); 74 | $baseuri = $request->getBaseUri(); 75 | if ( 76 | $requestUri!='' 77 | && $baseuri!='' 78 | && stripos($requestUri, $baseuri)!==false 79 | ) { 80 | $path = substr($requestUri, strlen($baseuri)); 81 | } else { 82 | $path = $requestUri; 83 | } 84 | $path = urldecode($path); 85 | $res = preg_match($this->_route, $path, $values); 86 | 87 | if ($res === 0) { 88 | return false; 89 | } 90 | 91 | $values = $this->_getMappedValues($values); 92 | 93 | if (isset($this->_default['module'])) { 94 | $request->setModuleName($this->_default['module']); 95 | } 96 | if (isset($this->_default['controller'])) { 97 | $request->setControllerName($this->_default['controller']); 98 | } 99 | if (isset($this->_default['action'])) { 100 | $request->setActionName($this->_default['action']); 101 | } 102 | $request->setParam($values); 103 | 104 | return true; 105 | } 106 | 107 | /** 108 | * Uses user provided map array which consists 109 | * of index => name parameter mapping. If map is not found, 110 | * it returns nothing. 111 | * 112 | * @param array $values Indexed or associative array of values to map 113 | * @return array An array of mapped values 114 | */ 115 | protected function _getMappedValues($values) 116 | { 117 | $return = array(); 118 | foreach ($values as $key => $value) { 119 | if (is_int($key)) { 120 | if (array_key_exists($key, $this->_maps)) { 121 | $index = $this->_maps[$key]; 122 | $return[$index] = $values[$key]; 123 | } 124 | } else { 125 | $return[$key] = $values[$key]; 126 | } 127 | } 128 | return $return; 129 | } 130 | } 131 | -------------------------------------------------------------------------------- /framework/Yaf/Route/Rewrite.php: -------------------------------------------------------------------------------- 1 | _route = $match; 48 | $this->_default = (array) $route; 49 | $this->_verify = $verify; 50 | } 51 | 52 | /** 53 | * Matches a user submitted path with a previously defined route. 54 | * Assigns and returns an array of defaults on a successful match. 55 | * 56 | * @param string $path Path used to match against this routing map 57 | * @return array|false An array of assigned values or a false on a mismatch 58 | */ 59 | public function route(Yaf_Request_Abstract $request) 60 | { 61 | $requestUri = $request->getRequestUri(); 62 | $baseuri = $request->getBaseUri(); 63 | if ( 64 | $requestUri!='' 65 | && $baseuri!='' 66 | && stripos($requestUri, $baseuri)!==false 67 | ) { 68 | $path = substr($requestUri, strlen($baseuri)); 69 | } else { 70 | $path = $requestUri; 71 | } 72 | $path = trim(urldecode($path), Yaf_Router::URI_DELIMITER); 73 | 74 | $values = $this->_match($path); 75 | if ($values == null) { 76 | return false; 77 | } 78 | 79 | if (isset($this->_default['module'])) { 80 | $request->setModuleName($this->_default['module']); 81 | } 82 | if (isset($this->_default['controller'])) { 83 | $request->setControllerName($this->_default['controller']); 84 | } 85 | if (isset($this->_default['action'])) { 86 | $request->setActionName($this->_default['action']); 87 | } 88 | $request->setParam($values); 89 | 90 | return true; 91 | } 92 | 93 | /** 94 | * @todo this method can be write differently with (P< style match 95 | * Matches a user submitted path with parts defined by a map. Assigns and 96 | * returns an array of variables on a successful match. 97 | * 98 | * @param string $path Path used to match against this routing map 99 | * @return array|false An array of assigned values or a false on a mismatch 100 | */ 101 | protected function _match($path) 102 | { 103 | $staticCount = 0; 104 | $pathStaticCount = 0; 105 | $values = array(); 106 | $matchedPath = ''; 107 | $parts = array(); 108 | $variables = array(); 109 | $wildcardData = array(); 110 | 111 | if ($this->_route !== '') { 112 | foreach ( 113 | explode( 114 | Yaf_Router::URI_DELIMITER, trim( 115 | $this->_route, Yaf_Router::URI_DELIMITER 116 | ) 117 | ) as $pos => $part 118 | ) { 119 | if ( 120 | substr($part, 0, 1) == Yaf_Router::URI_VARIABLE 121 | && substr($part, 1, 1) != Yaf_Router::URI_VARIABLE 122 | ) { 123 | $name = substr($part, 1); 124 | $parts[$pos] = null; 125 | $variables[$pos] = $name; 126 | } else { 127 | if (substr($part, 0, 1) == Yaf_Router::URI_VARIABLE) { 128 | $part = substr($part, 1); 129 | } 130 | 131 | $parts[$pos] = $part; 132 | 133 | if ($part !== '*') { 134 | $staticCount++; 135 | } 136 | } 137 | } 138 | } 139 | if ($path !== '') { 140 | $pathMatch = explode(Yaf_Router::URI_DELIMITER, $path); 141 | foreach ($pathMatch as $pos => $pathPart) { 142 | // Path is longer than a route, it's not a match 143 | if (!array_key_exists($pos, $parts)) { 144 | return false; 145 | } 146 | 147 | $matchedPath .= $pathPart . Yaf_Router::URI_DELIMITER; 148 | 149 | // If it's a wildcard, get the rest of URL as 150 | // wildcard data and stop matching 151 | if ($parts[$pos] == '*') { 152 | $count = count($pathMatch); 153 | for ($i = $pos; $i < $count; $i+=2) { 154 | $var = urldecode($pathMatch[$i]); 155 | if ( 156 | !isset($wildcardData[$var]) 157 | && !isset($this->_default[$var]) 158 | && !isset($values[$var]) 159 | ) { 160 | $wildcardData[$var] = 161 | (isset($pathMatch[$i+1])) ? 162 | urldecode($pathMatch[$i+1]) : 163 | null; 164 | } 165 | } 166 | 167 | $matchedPath = implode( 168 | Yaf_Router::URI_DELIMITER, $pathMatch 169 | ); 170 | break; 171 | } 172 | 173 | $name = isset($variables[$pos]) ? $variables[$pos] : null; 174 | $pathPart = urldecode($pathPart); 175 | 176 | $part = $parts[$pos]; 177 | 178 | if (substr($part, 0, 2) === '@@') { 179 | $part = substr($part, 1); 180 | } 181 | 182 | // If it's a static part, match directly 183 | if ($name === null && $part != $pathPart) { 184 | return false; 185 | } 186 | 187 | // If it's a variable with requirement, 188 | // match a regex. If not - everything matches 189 | if ( 190 | $part !== null 191 | && !preg_match('#^' . $part . '$#' . 'iu', $pathPart) 192 | ) { 193 | return false; 194 | } 195 | 196 | // If it's a variable store it's value for later 197 | if ($name !== null) { 198 | $values[$name] = $pathPart; 199 | } else { 200 | $pathStaticCount++; 201 | } 202 | } 203 | } 204 | 205 | // Check if all static mappings have been matched 206 | if ($staticCount != $pathStaticCount) { 207 | return false; 208 | } 209 | $return = $values + $wildcardData; 210 | 211 | 212 | // Check if all map variables have been initialized 213 | foreach ($variables as $var) { 214 | if (!array_key_exists($var, $return)) { 215 | return false; 216 | } elseif ($return[$var] == '' || $return[$var] === null) { 217 | // Empty variable? Replace with the default value. 218 | $return[$var] = $this->_default[$var]; 219 | } 220 | } 221 | if ($values == null && $wildcardData == null && $staticCount!=0) { 222 | $return = $return + $this->_default; 223 | } 224 | return $return; 225 | 226 | } 227 | } 228 | -------------------------------------------------------------------------------- /framework/Yaf/Route/Simple.php: -------------------------------------------------------------------------------- 1 | _module = $module; 26 | $this->_controller = $controller; 27 | $this->_action = $action; 28 | } 29 | } 30 | /** 31 | * Processes a request and sets its controller and action. If 32 | * no route was possible, default route is set. 33 | * 34 | * @param Yaf_Request_Abstract 35 | * @return Yaf_Request_Abstract|boolean 36 | */ 37 | 38 | public function route(Yaf_Request_Abstract $request) 39 | { 40 | $module = isset($_GET[$this->_module]) 41 | ?$_GET[$this->_module]:null; 42 | $controller = isset($_GET[$this->_controller]) 43 | ?$_GET[$this->_controller]:null; 44 | $action = isset($_GET[$this->_action]) 45 | ?$_GET[$this->_action]:null; 46 | if ($module == null && $controller == null && $action == null) { 47 | return false; 48 | } else { 49 | if ($module!=null) { 50 | $request->setModuleName($module); 51 | } 52 | if ($controller!=null) { 53 | $request->setControllerName($controller); 54 | } 55 | if ($action!=null) { 56 | $request->setActionName($action); 57 | } 58 | } 59 | return true; 60 | } 61 | /** 62 | * used to create routes on the fly from config 63 | * 64 | * @param array $config 65 | */ 66 | public static function getInstance(array $config) 67 | { 68 | if (!isset($config['module']) || !is_string($config['module'])) { 69 | return null; 70 | } elseif ( 71 | !isset($config['controller']) 72 | || !is_string($config['controller']) 73 | ) { 74 | return null; 75 | } elseif (!isset($config['action']) || !is_string($config['action'])) { 76 | return null; 77 | } else { 78 | return new self( 79 | $config['module'], $config['controller'], $config['action'] 80 | ); 81 | } 82 | } 83 | } -------------------------------------------------------------------------------- /framework/Yaf/Route/Static.php: -------------------------------------------------------------------------------- 1 | getRequestUri(); 37 | $baseuri = $request->getBaseUri(); 38 | if ( 39 | $requestUri!='' 40 | && $baseuri!='' 41 | && stripos($requestUri, $baseuri)===0 42 | ) { 43 | $path = substr($requestUri, strlen($baseuri)); 44 | } else { 45 | $path = $requestUri; 46 | } 47 | $module = null; 48 | $controller = null; 49 | $action = null; 50 | $rest = null; 51 | $path = trim($path, Yaf_Router::URI_DELIMITER); 52 | if ($path != '') { 53 | $path = explode(Yaf_Router::URI_DELIMITER, $path); 54 | $path = array_filter($path, 'strlen'); 55 | if (Yaf_Application::isModuleName($path[0])) { 56 | $module = $path[0]; 57 | array_shift($path); 58 | } 59 | if (count($path) && !empty($path[0])) { 60 | $controller = $path[0]; 61 | array_shift($path); 62 | } 63 | 64 | if (count($path) && !empty($path[0])) { 65 | $action = $path[0]; 66 | array_shift($path); 67 | } 68 | $rest = implode(Yaf_Router::URI_DELIMITER, $path); 69 | $actionPrefer = Yaf_G::iniGet('yaf.action_prefer'); 70 | 71 | if ($module == null && $controller == null && $action == null) { 72 | if ($actionPrefer == true) { 73 | $action = $rest; 74 | } else { 75 | $controller = $rest; 76 | } 77 | $rest = null; 78 | } elseif ($module == null && $action == null && $rest == null) { 79 | if ($actionPrefer == true) { 80 | $action = $controller; 81 | $controller = null; 82 | } 83 | } elseif ($controller == null && $action == null && $rest != null) { 84 | $controller = $module; 85 | $action = $rest; 86 | $module = null; 87 | $rest = null; 88 | } elseif ($action == null && $rest == null) { 89 | $action = $controller; 90 | $controller = $module; 91 | $module = null; 92 | } elseif ($controller == null && $action == null) { 93 | $controller = $module; 94 | $action = $rest; 95 | $module = null; 96 | $rest = null; 97 | } elseif ($action == null) { 98 | $action = $rest; 99 | $rest = null; 100 | } 101 | 102 | if ($module != null) { 103 | $request->setModuleName($module); 104 | } 105 | if ($controller != null) { 106 | $request->setControllerName($controller); 107 | } 108 | if ($action != null) { 109 | $request->setActionName($action); 110 | } 111 | $params = array(); 112 | if ($rest!=null && trim($rest)!='') { 113 | $path = explode(Yaf_Router::URI_DELIMITER, $rest); 114 | if (($numSegs = count($path))!=0) { 115 | for ($i = 0; $i < $numSegs; $i = $i + 2) { 116 | $key = urldecode($path[$i]); 117 | $val = isset($path[$i + 1]) ? 118 | urldecode($path[$i + 1]) : null; 119 | $params[$key] = (isset($params[$key]) 120 | ? (array_merge((array) $params[$key], array($val))) 121 | : $val); 122 | } 123 | } 124 | $request->setParam($params); 125 | } 126 | 127 | } 128 | return true; 129 | } 130 | 131 | /** 132 | * used to create routes on the fly from config 133 | * 134 | * @param array $config 135 | */ 136 | public function getInstance(array $config) 137 | { 138 | return new self(); 139 | } 140 | 141 | } 142 | -------------------------------------------------------------------------------- /framework/Yaf/Route/Supervar.php: -------------------------------------------------------------------------------- 1 | _varName = $varName; 23 | } 24 | } 25 | 26 | 27 | /** 28 | * Processes a request and sets its controller and action based on a 29 | * supervar value. 30 | * 31 | * @param Yaf_Request_Abstract 32 | * @return Yaf_Request_Abstract|boolean 33 | */ 34 | public function route(Yaf_Request_Abstract $request) 35 | { 36 | $requestUri = $request->getQuery($this->_varName); 37 | if ($requestUri==null || $requestUri=='') { 38 | return false; 39 | } 40 | $module = null; 41 | $controller = null; 42 | $action = null; 43 | $rest = null; 44 | $path = trim($requestUri, Yaf_Router::URI_DELIMITER); 45 | if ($path != '' && $path!='/') { 46 | $path = explode(Yaf_Router::URI_DELIMITER, $path); 47 | if (Yaf_Application::isModuleName($path[0])) { 48 | $module = $path[0]; 49 | array_shift($path); 50 | } 51 | 52 | if (count($path) && !empty($path[0])) { 53 | $controller = $path[0]; 54 | array_shift($path); 55 | } 56 | 57 | if (count($path) && !empty($path[0])) { 58 | $action = $path[0]; 59 | array_shift($path); 60 | } 61 | $rest = implode(Yaf_Router::URI_DELIMITER, $path); 62 | $actionPrefer = Yaf_G::iniGet('yaf.action_prefer'); 63 | 64 | if ($module == null && $controller == null && $action == null) { 65 | if ($actionPrefer == true) { 66 | $action = $rest; 67 | } else { 68 | $controller = $rest; 69 | } 70 | $rest = null; 71 | } elseif ($module == null && $action == null && $rest == null) { 72 | if ($actionPrefer == true) { 73 | $action = $controller; 74 | $controller = null; 75 | } 76 | } elseif ($controller == null && $action == null && $rest != null) { 77 | $controller = $module; 78 | $action = $rest; 79 | $module = null; 80 | $rest = null; 81 | } elseif ($action == null && $rest == null) { 82 | $action = $controller; 83 | $controller = $module; 84 | $module = null; 85 | } elseif ($controller == null && $action == null) { 86 | $controller = $module; 87 | $action = $rest; 88 | $module = null; 89 | $rest = null; 90 | } elseif ($action == null) { 91 | $action = $rest; 92 | $rest = null; 93 | } 94 | 95 | if ($module != null) { 96 | $request->setModuleName($module); 97 | } 98 | if ($controller != null) { 99 | $request->setControllerName($controller); 100 | } 101 | if ($action != null) { 102 | $request->setActionName($action); 103 | } 104 | $params = array(); 105 | if ($rest!=null && trim($rest)!='') { 106 | $path = explode(Yaf_Router::URI_DELIMITER, $rest); 107 | if (($numSegs = count($path))!=0) { 108 | for ($i = 0; $i < $numSegs; $i = $i + 2) { 109 | $key = urldecode($path[$i]); 110 | $val = isset($path[$i + 1]) ? 111 | urldecode($path[$i + 1]) : null; 112 | $params[$key] = (isset($params[$key]) 113 | ? (array_merge((array) $params[$key], array($val))) 114 | : $val); 115 | } 116 | } 117 | $request->setParam($params); 118 | } 119 | 120 | } 121 | return true; 122 | } 123 | 124 | /** 125 | * used to create routes on the fly from config 126 | * 127 | * @param array $config 128 | */ 129 | public static function getInstance(array $config) 130 | { 131 | if (!is_string($config['varname']) || $config['varname']=='') { 132 | return null; 133 | } 134 | return new self($config['varname']); 135 | } 136 | 137 | } 138 | -------------------------------------------------------------------------------- /framework/Yaf/Router.php: -------------------------------------------------------------------------------- 1 | addRoute( 35 | '_default', 36 | $this->_getRouteFromArray($defaultRoute) 37 | ); 38 | } else { 39 | $this->addRoute('_default', new Yaf_Route_Static()); 40 | } 41 | } 42 | 43 | /** 44 | * Add route to the route chain 45 | * 46 | * @param string $name Name of the route 47 | * @param Yaf_Route_Interface $route Instance of the route 48 | * @return Yaf_Router 49 | */ 50 | public function addRoute($name, Yaf_Route_Interface $route) 51 | { 52 | $this->_routes[$name] = $route; 53 | return $this; 54 | } 55 | 56 | /** 57 | * 58 | * Example INI: 59 | * routes.archive.type = "simple" 60 | * routes.archive.module = Index 61 | * routes.archive.controller = archive 62 | * routes.archive.action = show 63 | * 64 | * routes.news.type = "static" 65 | * routes.news.route = "news" 66 | * 67 | * And finally after you have created a Yaf_Config with above ini: 68 | * $router = new Yaf_Router(); 69 | * $router->addConfig($config); 70 | * 71 | * @param array|Yaf_Config $config Configuration object 72 | * @throws Yaf_Router_Exception 73 | * @return Yaf_Router 74 | */ 75 | public function addConfig($config) 76 | { 77 | if (is_array($config)) { 78 | //$config = new Yaf_Config_Simple($config); 79 | } else if ($config instanceof Yaf_Config_Abstract) { 80 | $config = $config->toArray(); 81 | } else { 82 | throw new Yaf_Exception_RouterFailed( 83 | 'Expecting Array or Yaf_Config_Abstract instance' 84 | ); 85 | } 86 | $name = key($config); 87 | foreach ($config as $entry) { 88 | $route = $this->_getRouteFromArray($entry); 89 | if ($route!=null) { 90 | if ($route instanceof Yaf_Route_Interface) { 91 | $this->addRoute($name, $route); 92 | } else { 93 | $this->addRoute($name, $route); 94 | } 95 | } else { 96 | if (is_string($name)) { 97 | throw new Yaf_Exception_RouterFailed( 98 | 'Unable to initialize route named '.$name 99 | ); 100 | } else { 101 | throw new Yaf_Exception_RouterFailed( 102 | 'Unable to initialize route at index '.$name 103 | ); 104 | } 105 | } 106 | next($config); 107 | $name = key($config); 108 | } 109 | 110 | /*//exit(); 111 | foreach ($config as $name => $info) { 112 | $route = $this->_getRouteFromConfig($info); 113 | 114 | if ($route!=null) { 115 | if ($route instanceof Yaf_Route_Interface) { 116 | $this->addRoute($name, $route); 117 | } else { 118 | $this->addRoute($name, $route); 119 | } 120 | } else { 121 | throw new Yaf_Exception_RouterFailed( 122 | 'Unable to initialize route named '.$name 123 | ); 124 | } 125 | }*/ 126 | 127 | return $this; 128 | } 129 | 130 | /** 131 | * Get a route from a config instance 132 | * 133 | * @param Yaf_Config_Abstract $info 134 | * @return Yaf_Route_Interface 135 | */ 136 | protected function _getRouteFromConfig(Yaf_Config_Abstract $info) 137 | { 138 | $useNamespace = Yaf_G::iniGet('yaf.use_namespace'); 139 | if ($useNamespace) { 140 | $class = (isset($info['type'])) 141 | ? '\\Yaf\\Route\\'.ucfirst($info['type']) 142 | : '\\Yaf\\Route\\Static'; 143 | } else { 144 | $class = (isset($info['type'])) 145 | ? 'Yaf_Route_'.ucfirst($info['type']) 146 | : 'Yaf_Route_Static'; 147 | } 148 | try { 149 | $route = call_user_func(array($class, 'getInstance'), $info); 150 | } catch (Exception $e) { 151 | return null; 152 | } 153 | return $route; 154 | } 155 | 156 | /** 157 | * Get a route from an array 158 | * 159 | * @param array $info 160 | * @return Yaf_Route_Interface 161 | */ 162 | protected function _getRouteFromArray(array $info) 163 | { 164 | $useNamespace = Yaf_G::iniGet('yaf.use_namespace'); 165 | if ($useNamespace) { 166 | $class = (isset($info['type'])) 167 | ? '\\Yaf\\Route\\'.ucfirst($info['type']) 168 | : '\\Yaf\\Route\\Static'; 169 | } else { 170 | $class = (isset($info['type'])) 171 | ? 'Yaf_Route_'.ucfirst($info['type']) 172 | : 'Yaf_Route_Static'; 173 | } 174 | try { 175 | $route = call_user_func(array($class, 'getInstance'), $info); 176 | } catch (Exception $e) { 177 | return null; 178 | } 179 | return $route; 180 | } 181 | 182 | /** 183 | * Retrieve a currently matched route 184 | * 185 | * @throws Yaf_Exception_RouterFailed 186 | * @return Yaf_Route_Interface Route object 187 | */ 188 | public function getCurrentRoute() 189 | { 190 | return $this->_current; 191 | } 192 | 193 | /** 194 | * Retrieve a named route 195 | * 196 | * @param string $name Name of the route 197 | * @throws Yaf_Exception_RouterFailed 198 | * @return Yaf_Route_Interface Route object 199 | */ 200 | public function getRoute($name) 201 | { 202 | if (!isset($this->_routes[$name])) { 203 | return null; 204 | /* throw new Yaf_Exception_RouterFailed( 205 | "Route $name is not defined" 206 | ); */ 207 | } 208 | return $this->_routes[$name]; 209 | } 210 | 211 | /** 212 | * Retrieve an array of routes added to the route chain 213 | * 214 | * @return array All of the defined routes 215 | */ 216 | public function getRoutes() 217 | { 218 | return $this->_routes; 219 | } 220 | 221 | /** 222 | * Find a matching route to the current Request and inject 223 | * returning values to the Request object. 224 | * 225 | * @return bool if there is a valid route 226 | */ 227 | public function route(Yaf_Request_Abstract $request) 228 | { 229 | // Find the matching route 230 | $routeMatched = false; 231 | 232 | foreach (array_reverse($this->_routes, true) as $name => $route) { 233 | if (($ret = $route->route($request))!=false) { 234 | $this->_current = $name; 235 | $routeMatched = true; 236 | break; 237 | } 238 | } 239 | 240 | if (!$routeMatched) { 241 | return false; 242 | } else { 243 | $request->setRouted(true); 244 | return true; 245 | } 246 | return false; 247 | } 248 | } 249 | -------------------------------------------------------------------------------- /framework/Yaf/Session.php: -------------------------------------------------------------------------------- 1 | session); 38 | } 39 | 40 | /** 41 | * Defined by Iterator interface 42 | * 43 | * @return mixed 44 | */ 45 | public function current () 46 | { 47 | return current($this->session); 48 | } 49 | 50 | public function del($name) 51 | { 52 | return $this->offsetUnset($name); 53 | } 54 | 55 | public function __destruct() 56 | { 57 | 58 | } 59 | 60 | /** 61 | * Magic function so that $obj->value will work. 62 | * 63 | * @param string $name 64 | * @return mixed 65 | */ 66 | public function __get ($name) 67 | { 68 | $result = null; 69 | if ($name == null) { 70 | return null; 71 | } 72 | if (array_key_exists($name, $this->session)) { 73 | $result = $this->session[$name]; 74 | } else if (array_key_exists($name, $_SESSION)) { 75 | $result = $_SESSION[$name]; 76 | } 77 | return $result; 78 | } 79 | 80 | /** 81 | * Retrieve singleton instance 82 | * 83 | * @return Yaf_Session 84 | */ 85 | public static function getInstance() 86 | { 87 | if (null === self::$_instance) { 88 | self::$_instance = new self(); 89 | self::start(); 90 | } 91 | return self::$_instance; 92 | } 93 | 94 | public function has($name) 95 | { 96 | return $this->offsetExists($name); 97 | } 98 | 99 | /** 100 | * Support isset() overloading on PHP 5.1 101 | * 102 | * @param string $name 103 | * @return boolean 104 | */ 105 | public function __isset ($name) 106 | { 107 | return (isset($this->session[$name])?true:isset($_SESSION[$name])); 108 | } 109 | 110 | /** 111 | * Defined by Iterator interface 112 | * 113 | * @return mixed 114 | */ 115 | public function key () 116 | { 117 | return key($this->session); 118 | } 119 | /** 120 | * Defined by Iterator interface 121 | * 122 | */ 123 | public function next () 124 | { 125 | next($this->session); 126 | } 127 | 128 | /** 129 | * Support isset() overloading on PHP 5.1 130 | * 131 | * @param string $name 132 | * @return boolean 133 | */ 134 | public function offsetExists ($name) 135 | { 136 | return $this->__isset($name); 137 | } 138 | /** 139 | * Return a session value specified by name 140 | * @param string $name 141 | * @return mixed 142 | */ 143 | public function offsetGet ($name) 144 | { 145 | return $this->__get($name); 146 | } 147 | /** 148 | * Set a key of the session with value 149 | * @param string $name 150 | * @param string $value 151 | * @return void 152 | */ 153 | public function offsetSet ($name, $value) 154 | { 155 | return $this->__set($name, $value); 156 | } 157 | /** 158 | * Support unset() overloading on PHP 5.1 159 | * 160 | * @param string $name 161 | * @return void 162 | */ 163 | public function offsetUnset ($name) 164 | { 165 | unset($this->session[$name]); 166 | unset($_SESSION[$name]); 167 | } 168 | 169 | /** 170 | * Defined by Iterator interface 171 | * 172 | */ 173 | public function rewind () 174 | { 175 | reset($this->session); 176 | } 177 | /** 178 | * Allow setting of a session variable. 179 | * Throw an exception if the name is not string. 180 | * 181 | * @param string $name 182 | * @param mixed $value 183 | * @throws Yaf_Exception 184 | * @return void 185 | */ 186 | public function __set ($name, $value) 187 | { 188 | if (is_string($name)) { 189 | $this->session[$name] = $value; 190 | $_SESSION[$name] = $value; 191 | } else { 192 | throw new Yaf_Exception('Expect a string key name'); 193 | } 194 | } 195 | 196 | protected function __sleep() 197 | { 198 | 199 | } 200 | 201 | /** 202 | * Starts the session 203 | */ 204 | public static function start() 205 | { 206 | $session = self::getInstance(); 207 | if ($session->started == true) { 208 | return true; 209 | } else { 210 | session_start(); 211 | $session->started = true; 212 | $session->session = $_SESSION; 213 | } 214 | } 215 | /** 216 | * Support unset() overloading on PHP 5.1 217 | * 218 | * @param string $name 219 | * @return void 220 | */ 221 | public function __unset($name) 222 | { 223 | unset($this->session[$name]); 224 | } 225 | /** 226 | * Defined by Iterator interface 227 | * 228 | * @return boolean 229 | */ 230 | public function valid () 231 | { 232 | $key = key($this->session); 233 | return ($key == null || $key == false) ? false: true; 234 | } 235 | 236 | protected function __wakeup() 237 | { 238 | 239 | } 240 | } -------------------------------------------------------------------------------- /framework/Yaf/View/Interface.php: -------------------------------------------------------------------------------- 1 | value pairs to set en 29 | * masse. 30 | * 31 | * @param string|array $name The assignment strategy to use 32 | * (key or array of key => value pairs) 33 | * @param mixed $value (Optional) If assigning a named variable, use this 34 | * as the value. 35 | * @return void 36 | */ 37 | public function assign($name, $value = null); 38 | 39 | 40 | /** 41 | * Processes a view script and returns the output. 42 | * 43 | * @param string $tpl The script name to process. 44 | * @param array $tplVars The script variables. 45 | * @return string The script output. 46 | */ 47 | public function render($tpl, $tplVars=array()); 48 | /** 49 | * Processes a view script and displays the output. 50 | * 51 | * @param string $tpl The script name to process. 52 | * @param array $tplVars The script variables. 53 | * @return void 54 | */ 55 | public function display($tpl, $tplVars=array()); 56 | } 57 | -------------------------------------------------------------------------------- /framework/Yaf_Namespace/Action/Abstract.php: -------------------------------------------------------------------------------- 1 | _controller; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /framework/Yaf_Namespace/Bootstrap/Abstract.php: -------------------------------------------------------------------------------- 1 | _readonly; 31 | } 32 | abstract public function toArray(); 33 | } -------------------------------------------------------------------------------- /framework/Yaf_Namespace/Config/Exception.php: -------------------------------------------------------------------------------- 1 | setErrorNo($errtype); 18 | $app->setErrorMsg($errmsg); 19 | } 20 | trigger_error($errmsg, $errtype); 21 | } 22 | } -------------------------------------------------------------------------------- /framework/Yaf_Namespace/Exception/DispatchFailed.php: -------------------------------------------------------------------------------- 1 | true, 17 | 'catchException' => false, 18 | 'autoload_started' => 0, 19 | 'configs' => null, 20 | 'directory' => null, 21 | 'local_library' => null, 22 | 'ext' => Router::YAF_DEFAULT_EXT, 23 | 'view_ext' => Loader::YAF_DEFAULT_VIEW_EXT, 24 | 'default_module' => Router::YAF_ROUTER_DEFAULT_MODULE, 25 | 'default_controller' => Router::YAF_ROUTER_DEFAULT_CONTROLLER, 26 | 'default_action' => Router::YAF_ROUTER_DEFAULT_ACTION, 27 | 'bootstrap' => Bootstrap_Abstract::YAF_DEFAULT_BOOTSTRAP, 28 | 'modules' => null, 29 | 'default_route' => null 30 | ); 31 | //missing globals to check 32 | //local_namespace 33 | protected static $_ini = array( 34 | 'yaf.library' => '', 35 | 'yaf.action_prefer' => false, 36 | 'yaf.lowcase_path' => false, 37 | 'yaf.use_spl_autoload' => false, 38 | 'yaf.forward_limit' => '5', 39 | 'yaf.name_suffix' => true, 40 | 'yaf.name_separator' => '', 41 | 'yaf.cache_config' => false, 42 | 'yaf.st_compatible' => false, 43 | 'yaf.environ' => 'product', 44 | 'yaf.use_namespace' => false 45 | ); 46 | 47 | public static function iniSet($key, $value) 48 | { 49 | self::$_ini[$key] = $value; 50 | } 51 | 52 | public static function iniGet($key) 53 | { 54 | if (($iniValue = ini_get($key))!==false) { 55 | //we have ini set from php 56 | if ($iniValue == '0') { 57 | $value = false; 58 | } elseif ($iniValue == '1') { 59 | $value = true; 60 | } else { 61 | $value = $iniValue; 62 | } 63 | self::iniSet($key, $value); 64 | return $value; 65 | } else { 66 | if (isset(self::$_ini[$key])) { 67 | return self::$_ini[$key]; 68 | } 69 | } 70 | return null; 71 | } 72 | 73 | public static function set($key, $value) 74 | { 75 | self::$_globals[$key] = $value; 76 | } 77 | 78 | public static function get($key) 79 | { 80 | if (isset(self::$_globals[$key])) { 81 | return self::$_globals[$key]; 82 | } 83 | return null; 84 | } 85 | 86 | 87 | public static function isAbsolutePath($path) 88 | { 89 | if ( 90 | substr($path, 0, 1) == "/" 91 | || 92 | ( 93 | (strpos($path, ":") !== false) 94 | && 95 | (strpos(PHP_OS, "WIN") !== FALSE) 96 | ) 97 | ) { 98 | return true; 99 | } else { 100 | return false; 101 | } 102 | } 103 | } -------------------------------------------------------------------------------- /framework/Yaf_Namespace/Plugin/Abstract.php: -------------------------------------------------------------------------------- 1 | method = $method; 42 | if ($module!=null || $action!=null || $controller!=null) { 43 | $this->setActionName($action); 44 | $this->setControllerName($controller); 45 | $this->setModuleName($module); 46 | $this->setRouted(true); 47 | } else { 48 | if ($module == null) { 49 | $this->setModuleName(\Yaf\G::get('default_module')); 50 | } 51 | if ($controller == null) { 52 | $this->setControllerName(\Yaf\G::get('default_controller')); 53 | } 54 | if ($action == null) { 55 | $this->setActionName(\Yaf\G::get('default_action')); 56 | } 57 | } 58 | 59 | if ($params) { 60 | $this->setParam($params); 61 | } 62 | } 63 | 64 | private function __clone() 65 | { 66 | //close is not possible to do 67 | } 68 | 69 | } -------------------------------------------------------------------------------- /framework/Yaf_Namespace/Response/Abstract.php: -------------------------------------------------------------------------------- 1 | _body .= (string) $body; 43 | return $this; 44 | } 45 | 46 | /** 47 | * Clear the entire body 48 | * 49 | * @return boolean 50 | */ 51 | public function clearBody() 52 | { 53 | $this->_body = ''; 54 | return true; 55 | } 56 | 57 | /** 58 | * Clear headers 59 | * 60 | * @return Yaf_Response_Abstract 61 | */ 62 | public function clearHeaders() 63 | { 64 | $this->_headers = array(); 65 | return $this; 66 | } 67 | 68 | private function __clone() 69 | { 70 | //close is not possible 71 | } 72 | 73 | public function __construct() 74 | { 75 | } 76 | 77 | public function __destruct() 78 | { 79 | } 80 | /** 81 | * Return the body content 82 | * 83 | * @return string 84 | */ 85 | public function getBody() 86 | { 87 | return $this->_body; 88 | } 89 | /** 90 | * Return array of headers; see {@link $_headers} for format 91 | * 92 | * @return array 93 | */ 94 | public function getHeader() 95 | { 96 | return $this->_headers; 97 | } 98 | /** 99 | * Prepend content the body 100 | * 101 | * @param string $body 102 | * @return Yaf_Response_Abstract 103 | */ 104 | public function prependBody($body) 105 | { 106 | $this->_body = $body . $this->_body; 107 | return $this; 108 | } 109 | /** 110 | * Send the response, including all headers 111 | * 112 | * @return void 113 | */ 114 | public function response() 115 | { 116 | if ($this->_sendheader == true) { 117 | $this->sendHeaders(); 118 | } 119 | echo $this->_body; 120 | } 121 | 122 | private function setAllHeaders() 123 | { 124 | //did not found what should this do 125 | } 126 | /** 127 | * Set body content 128 | * 129 | * @param string $body 130 | * @return Yaf_Response_Abstract 131 | */ 132 | public function setBody($body) 133 | { 134 | $this->_body = (string) $body; 135 | return $this; 136 | } 137 | 138 | /** 139 | * Set a header 140 | * 141 | * If $replace is true, replaces any headers already defined with that 142 | * $name. 143 | * 144 | * @param string $name 145 | * @param string $value 146 | * @param boolean $replace 147 | * @return Yaf_Response_Abstract 148 | */ 149 | public function setHeader($name, $value, $replace = false) 150 | { 151 | $name = $this->_normalizeHeader($name); 152 | $value = (string) $value; 153 | 154 | if ($replace) { 155 | foreach ($this->_headers as $key => $header) { 156 | if ($name == $header['name']) { 157 | unset($this->_headers[$key]); 158 | } 159 | } 160 | } 161 | 162 | $this->_headers[] = array( 163 | 'name' => $name, 164 | 'value' => $value, 165 | 'replace' => $replace 166 | ); 167 | 168 | return $this; 169 | } 170 | 171 | /** 172 | * Set redirect URL 173 | * 174 | * Sets Location header. Forces replacement of any prior redirects. 175 | * 176 | * @param string $url 177 | * @return Yaf_Response_Abstract 178 | */ 179 | public function setRedirect($url) 180 | { 181 | $this->setHeader('Location', $url, true); 182 | return $this; 183 | } 184 | 185 | /** 186 | * Magic __toString functionality 187 | * 188 | * Returns response value as string 189 | * using output buffering. 190 | * 191 | * @return string 192 | */ 193 | public function __toString() 194 | { 195 | ob_start(); 196 | $this->response(); 197 | return ob_get_clean(); 198 | } 199 | 200 | 201 | 202 | //method added to be possible 203 | /** 204 | * Normalize a header name 205 | * 206 | * Normalizes a header name to X-Capitalized-Names 207 | * 208 | * @param string $name 209 | * @return string 210 | */ 211 | protected function _normalizeHeader($name) 212 | { 213 | $filtered = str_replace(array('-', '_'), ' ', (string) $name); 214 | $filtered = ucwords(strtolower($filtered)); 215 | $filtered = str_replace(' ', '-', $filtered); 216 | return $filtered; 217 | } 218 | 219 | /** 220 | * Send all headers 221 | * 222 | * Sends any headers specified. 223 | * If an {@link setHttpResponseCode() HTTP response code} 224 | * has been specified, it is sent with the first header. 225 | * 226 | * @return Yaf_Response_Abstract 227 | */ 228 | protected function sendHeaders() 229 | { 230 | foreach ($this->_headers as $header) { 231 | header( 232 | $header['name'] . ': ' . $header['value'], 233 | $header['replace'] 234 | ); 235 | } 236 | return $this; 237 | } 238 | 239 | } 240 | -------------------------------------------------------------------------------- /framework/Yaf_Namespace/Response/Cli.php: -------------------------------------------------------------------------------- 1 | _body; 25 | } 26 | } -------------------------------------------------------------------------------- /framework/Yaf_Namespace/Response/Exception.php: -------------------------------------------------------------------------------- 1 | $code) || (599 < $code)) { 28 | throw new Exception('Invalid HTTP response code'); 29 | } 30 | 31 | $this->_responseCode = $code; 32 | return $this; 33 | } 34 | 35 | /** 36 | * Retrieve HTTP response code 37 | * 38 | * @return int 39 | */ 40 | public function getResponseCode() 41 | { 42 | return $this->_responseCode; 43 | } 44 | 45 | /** 46 | * Send all headers 47 | * 48 | * Sends any headers specified. 49 | * If an {@link setResponseCode() HTTP response code} 50 | * has been specified, it is sent with the first header. 51 | * 52 | * @return Yaf_Response_Http 53 | */ 54 | protected function sendHeaders() 55 | { 56 | $httpCodeSent = false; 57 | 58 | foreach ($this->_headers as $header) { 59 | if (!$httpCodeSent && $this->_responseCode) { 60 | header( 61 | $header['name'] . ': ' . $header['value'], 62 | $header['replace'], $this->_responseCode 63 | ); 64 | $httpCodeSent = true; 65 | } else { 66 | header( 67 | $header['name'] . ': ' . $header['value'], 68 | $header['replace'] 69 | ); 70 | } 71 | } 72 | 73 | /*if (!$httpCodeSent) { 74 | header('HTTP/1.1 ' . $this->_responseCode); 75 | $httpCodeSent = true; 76 | }*/ 77 | 78 | return $this; 79 | } 80 | 81 | /** 82 | * Set redirect URL 83 | * 84 | * Sets Location header. Forces replacement of any prior redirects. 85 | * 86 | * @param string $url 87 | * @return Yaf_Response_Abstract 88 | */ 89 | public function setRedirect($url) 90 | { 91 | $this->setHeader('Location', $url, true) 92 | ->setResponseCode(302); 93 | return $this; 94 | } 95 | } -------------------------------------------------------------------------------- /framework/Yaf_Namespace/Route/Exception.php: -------------------------------------------------------------------------------- 1 | _ctlPrefer = $controller_prefer; 25 | } 26 | if (is_string($delimiter) && $delimiter!='') { 27 | $this->_delimiter = $delimiter; 28 | } 29 | 30 | } 31 | /** 32 | * Processes a request and sets its controller and action. If 33 | * no route was possible, default route is set. 34 | * 35 | * @param Yaf_Request_Abstract 36 | * @return Yaf_Request_Abstract|boolean 37 | */ 38 | 39 | public function route(\Yaf\Request_Abstract $request) 40 | { 41 | $requestUri = $request->getRequestUri(); 42 | $baseuri = $request->getBaseUri(); 43 | if ( 44 | $requestUri!='' 45 | && $baseuri!='' 46 | && stripos($requestUri, $baseuri)===0 47 | ) { 48 | $path = substr($requestUri, strlen($baseuri)); 49 | } else { 50 | $path = $requestUri; 51 | } 52 | $path = trim(urldecode($path), \Yaf\Router::URI_DELIMITER); 53 | $rest = ''; 54 | if (is_string($this->_delimiter) && $this->_delimiter!='') { 55 | if (($queryStringPos = strpos($path, $this->_delimiter))!==false) { 56 | $rest = substr( 57 | $path, 58 | $queryStringPos+strlen($this->_delimiter), 59 | strlen($path)-1 60 | ); 61 | $path = substr( 62 | $path, 63 | 0, 64 | $queryStringPos 65 | ); 66 | } 67 | } 68 | $route = ''; 69 | if ($path != '' && $path!='/') { 70 | $route = str_replace( 71 | \Yaf\Router::URI_DELIMITER, 72 | '_', 73 | trim($path, \Yaf\Router::URI_DELIMITER) 74 | ); 75 | } 76 | if ($route!='') { 77 | if ($this->_ctlPrefer == true) { 78 | $request->setControllerName($route); 79 | } else { 80 | $request->setActionName($route); 81 | } 82 | } 83 | $params = array(); 84 | if ($rest!=null && trim($rest)!='') { 85 | $path = explode( 86 | \Yaf\Router::URI_DELIMITER, 87 | trim($rest, \Yaf\Router::URI_DELIMITER) 88 | ); 89 | if (($numSegs = count($path))!=0) { 90 | for ($i = 0; $i < $numSegs; $i = $i + 2) { 91 | $key = urldecode($path[$i]); 92 | $val = isset($path[$i + 1]) ? 93 | urldecode($path[$i + 1]) : null; 94 | $params[$key] = (isset($params[$key]) 95 | ? (array_merge((array) $params[$key], array($val))) 96 | : $val); 97 | } 98 | } 99 | $request->setParam($params); 100 | } 101 | 102 | return true; 103 | } 104 | /** 105 | * used to create routes on the fly from config 106 | * 107 | * @param array $config 108 | */ 109 | public static function getInstance(array $config) 110 | { 111 | $controllerPrefer = false; 112 | if ( 113 | isset($config['controllerPrefer']) 114 | && 115 | is_bool($config['controllerPrefer']) 116 | ) { 117 | $controllerPrefer = $config['controllerPrefer']; 118 | } 119 | $delimiter = '#!'; 120 | if (isset($config['delimiter'])) { 121 | $delimiter = $config['delimiter']; 122 | } 123 | return new self( 124 | $controllerPrefer, $delimiter 125 | ); 126 | } 127 | } -------------------------------------------------------------------------------- /framework/Yaf_Namespace/Route/Regex.php: -------------------------------------------------------------------------------- 1 | _route = $match; 65 | $this->_default = (array) $route; 66 | $this->_maps = (array) $map; 67 | $this->_verify = $verify; 68 | } 69 | 70 | /** 71 | * Matches a user submitted path with a previously defined route. 72 | * Assigns and returns an array of defaults on a successful match. 73 | * 74 | * @param string $path Path used to match against this routing map 75 | * @return array|false An array of assigned values or a false on a mismatch 76 | */ 77 | public function route(\Yaf\Request_Abstract $request) 78 | { 79 | $requestUri = $request->getRequestUri(); 80 | $baseuri = $request->getBaseUri(); 81 | if ( 82 | $requestUri!='' 83 | && $baseuri!='' 84 | && stripos($requestUri, $baseuri)!==false 85 | ) { 86 | $path = substr($requestUri, strlen($baseuri)); 87 | } else { 88 | $path = $requestUri; 89 | } 90 | $path = urldecode($path); 91 | $res = preg_match($this->_route, $path, $values); 92 | 93 | if ($res === 0) { 94 | return false; 95 | } 96 | 97 | $values = $this->_getMappedValues($values); 98 | 99 | if (isset($this->_default['module'])) { 100 | $request->setModuleName($this->_default['module']); 101 | } 102 | if (isset($this->_default['controller'])) { 103 | $request->setControllerName($this->_default['controller']); 104 | } 105 | if (isset($this->_default['action'])) { 106 | $request->setActionName($this->_default['action']); 107 | } 108 | $request->setParam($values); 109 | 110 | return true; 111 | } 112 | 113 | /** 114 | * Uses user provided map array which consists 115 | * of index => name parameter mapping. If map is not found, 116 | * it returns nothing. 117 | * 118 | * @param array $values Indexed or associative array of values to map 119 | * @return array An array of mapped values 120 | */ 121 | protected function _getMappedValues($values) 122 | { 123 | $return = array(); 124 | foreach ($values as $key => $value) { 125 | if (is_int($key)) { 126 | if (array_key_exists($key, $this->_maps)) { 127 | $index = $this->_maps[$key]; 128 | $return[$index] = $values[$key]; 129 | } 130 | } else { 131 | $return[$key] = $values[$key]; 132 | } 133 | } 134 | return $return; 135 | } 136 | } 137 | -------------------------------------------------------------------------------- /framework/Yaf_Namespace/Route/Rewrite.php: -------------------------------------------------------------------------------- 1 | _route = $match; 54 | $this->_default = (array) $route; 55 | $this->_verify = $verify; 56 | } 57 | 58 | /** 59 | * Matches a user submitted path with a previously defined route. 60 | * Assigns and returns an array of defaults on a successful match. 61 | * 62 | * @param string $path Path used to match against this routing map 63 | * @return array|false An array of assigned values or a false on a mismatch 64 | */ 65 | public function route(\Yaf\Request_Abstract $request) 66 | { 67 | $requestUri = $request->getRequestUri(); 68 | $baseuri = $request->getBaseUri(); 69 | if ( 70 | $requestUri!='' 71 | && $baseuri!='' 72 | && stripos($requestUri, $baseuri)!==false 73 | ) { 74 | $path = substr($requestUri, strlen($baseuri)); 75 | } else { 76 | $path = $requestUri; 77 | } 78 | $path = trim(urldecode($path), \Yaf\Router::URI_DELIMITER); 79 | 80 | $values = $this->_match($path); 81 | if ($values == null) { 82 | return false; 83 | } 84 | 85 | if (isset($this->_default['module'])) { 86 | $request->setModuleName($this->_default['module']); 87 | } 88 | if (isset($this->_default['controller'])) { 89 | $request->setControllerName($this->_default['controller']); 90 | } 91 | if (isset($this->_default['action'])) { 92 | $request->setActionName($this->_default['action']); 93 | } 94 | $request->setParam($values); 95 | 96 | return true; 97 | } 98 | 99 | /** 100 | * @todo this method can be write differently with (P< style match 101 | * Matches a user submitted path with parts defined by a map. Assigns and 102 | * returns an array of variables on a successful match. 103 | * 104 | * @param string $path Path used to match against this routing map 105 | * @return array|false An array of assigned values or a false on a mismatch 106 | */ 107 | protected function _match($path) 108 | { 109 | $staticCount = 0; 110 | $pathStaticCount = 0; 111 | $values = array(); 112 | $matchedPath = ''; 113 | $parts = array(); 114 | $variables = array(); 115 | $wildcardData = array(); 116 | 117 | if ($this->_route !== '') { 118 | foreach ( 119 | explode( 120 | \Yaf\Router::URI_DELIMITER, trim( 121 | $this->_route, \Yaf\Router::URI_DELIMITER 122 | ) 123 | ) as $pos => $part 124 | ) { 125 | if ( 126 | substr($part, 0, 1) == \Yaf\Router::URI_VARIABLE 127 | && substr($part, 1, 1) != \Yaf\Router::URI_VARIABLE 128 | ) { 129 | $name = substr($part, 1); 130 | $parts[$pos] = null; 131 | $variables[$pos] = $name; 132 | } else { 133 | if (substr($part, 0, 1) == \Yaf\Router::URI_VARIABLE) { 134 | $part = substr($part, 1); 135 | } 136 | 137 | $parts[$pos] = $part; 138 | 139 | if ($part !== '*') { 140 | $staticCount++; 141 | } 142 | } 143 | } 144 | } 145 | if ($path !== '') { 146 | $pathMatch = explode(\Yaf\Router::URI_DELIMITER, $path); 147 | foreach ($pathMatch as $pos => $pathPart) { 148 | // Path is longer than a route, it's not a match 149 | if (!array_key_exists($pos, $parts)) { 150 | return false; 151 | } 152 | 153 | $matchedPath .= $pathPart . \Yaf\Router::URI_DELIMITER; 154 | 155 | // If it's a wildcard, get the rest of URL as 156 | // wildcard data and stop matching 157 | if ($parts[$pos] == '*') { 158 | $count = count($pathMatch); 159 | for ($i = $pos; $i < $count; $i+=2) { 160 | $var = urldecode($pathMatch[$i]); 161 | if ( 162 | !isset($wildcardData[$var]) 163 | && !isset($this->_default[$var]) 164 | && !isset($values[$var]) 165 | ) { 166 | $wildcardData[$var] = 167 | (isset($pathMatch[$i+1])) ? 168 | urldecode($pathMatch[$i+1]) : 169 | null; 170 | } 171 | } 172 | 173 | $matchedPath = implode( 174 | \Yaf\Router::URI_DELIMITER, $pathMatch 175 | ); 176 | break; 177 | } 178 | 179 | $name = isset($variables[$pos]) ? $variables[$pos] : null; 180 | $pathPart = urldecode($pathPart); 181 | 182 | $part = $parts[$pos]; 183 | 184 | if (substr($part, 0, 2) === '@@') { 185 | $part = substr($part, 1); 186 | } 187 | 188 | // If it's a static part, match directly 189 | if ($name === null && $part != $pathPart) { 190 | return false; 191 | } 192 | 193 | // If it's a variable with requirement, 194 | // match a regex. If not - everything matches 195 | if ( 196 | $part !== null 197 | && !preg_match('#^' . $part . '$#' . 'iu', $pathPart) 198 | ) { 199 | return false; 200 | } 201 | 202 | // If it's a variable store it's value for later 203 | if ($name !== null) { 204 | $values[$name] = $pathPart; 205 | } else { 206 | $pathStaticCount++; 207 | } 208 | } 209 | } 210 | 211 | // Check if all static mappings have been matched 212 | if ($staticCount != $pathStaticCount) { 213 | return false; 214 | } 215 | $return = $values + $wildcardData; 216 | 217 | 218 | // Check if all map variables have been initialized 219 | foreach ($variables as $var) { 220 | if (!array_key_exists($var, $return)) { 221 | return false; 222 | } elseif ($return[$var] == '' || $return[$var] === null) { 223 | // Empty variable? Replace with the default value. 224 | $return[$var] = $this->_default[$var]; 225 | } 226 | } 227 | if ($values == null && $wildcardData == null && $staticCount!=0) { 228 | $return = $return + $this->_default; 229 | } 230 | return $return; 231 | 232 | } 233 | } 234 | -------------------------------------------------------------------------------- /framework/Yaf_Namespace/Route/Simple.php: -------------------------------------------------------------------------------- 1 | _module = $module; 32 | $this->_controller = $controller; 33 | $this->_action = $action; 34 | } 35 | } 36 | /** 37 | * Processes a request and sets its controller and action. If 38 | * no route was possible, default route is set. 39 | * 40 | * @param Yaf_Request_Abstract 41 | * @return Yaf_Request_Abstract|boolean 42 | */ 43 | 44 | public function route(\Yaf\Request_Abstract $request) 45 | { 46 | $module = isset($_GET[$this->_module]) 47 | ?$_GET[$this->_module]:null; 48 | $controller = isset($_GET[$this->_controller]) 49 | ?$_GET[$this->_controller]:null; 50 | $action = isset($_GET[$this->_action]) 51 | ?$_GET[$this->_action]:null; 52 | if ($module == null && $controller == null && $action == null) { 53 | return false; 54 | } else { 55 | if ($module!=null) { 56 | $request->setModuleName($module); 57 | } 58 | if ($controller!=null) { 59 | $request->setControllerName($controller); 60 | } 61 | if ($action!=null) { 62 | $request->setActionName($action); 63 | } 64 | } 65 | return true; 66 | } 67 | /** 68 | * used to create routes on the fly from config 69 | * 70 | * @param array $config 71 | */ 72 | public static function getInstance(array $config) 73 | { 74 | if (!isset($config['module']) || !is_string($config['module'])) { 75 | return null; 76 | } elseif ( 77 | !isset($config['controller']) 78 | || !is_string($config['controller']) 79 | ) { 80 | return null; 81 | } elseif (!isset($config['action']) || !is_string($config['action'])) { 82 | return null; 83 | } else { 84 | return new self( 85 | $config['module'], $config['controller'], $config['action'] 86 | ); 87 | } 88 | } 89 | } -------------------------------------------------------------------------------- /framework/Yaf_Namespace/Route/Static.php: -------------------------------------------------------------------------------- 1 | getRequestUri(); 43 | $baseuri = $request->getBaseUri(); 44 | if ( 45 | $requestUri!='' 46 | && $baseuri!='' 47 | && stripos($requestUri, $baseuri)===0 48 | ) { 49 | $path = substr($requestUri, strlen($baseuri)); 50 | } else { 51 | $path = $requestUri; 52 | } 53 | $module = null; 54 | $controller = null; 55 | $action = null; 56 | $rest = null; 57 | $path = trim($path, Router::URI_DELIMITER); 58 | if ($path != '') { 59 | $path = explode(Router::URI_DELIMITER, $path); 60 | $path = array_filter($path, 'strlen'); 61 | if (Application::isModuleName($path[0])) { 62 | $module = $path[0]; 63 | array_shift($path); 64 | } 65 | if (count($path) && !empty($path[0])) { 66 | $controller = $path[0]; 67 | array_shift($path); 68 | } 69 | 70 | if (count($path) && !empty($path[0])) { 71 | $action = $path[0]; 72 | array_shift($path); 73 | } 74 | $rest = implode(Router::URI_DELIMITER, $path); 75 | $actionPrefer = G::iniGet('yaf.action_prefer'); 76 | 77 | if ($module == null && $controller == null && $action == null) { 78 | if ($actionPrefer == true) { 79 | $action = $rest; 80 | } else { 81 | $controller = $rest; 82 | } 83 | $rest = null; 84 | } elseif ($module == null && $action == null && $rest == null) { 85 | if ($actionPrefer == true) { 86 | $action = $controller; 87 | $controller = null; 88 | } 89 | } elseif ($controller == null && $action == null && $rest != null) { 90 | $controller = $module; 91 | $action = $rest; 92 | $module = null; 93 | $rest = null; 94 | } elseif ($action == null && $rest == null) { 95 | $action = $controller; 96 | $controller = $module; 97 | $module = null; 98 | } elseif ($controller == null && $action == null) { 99 | $controller = $module; 100 | $action = $rest; 101 | $module = null; 102 | $rest = null; 103 | } elseif ($action == null) { 104 | $action = $rest; 105 | $rest = null; 106 | } 107 | 108 | if ($module != null) { 109 | $request->setModuleName($module); 110 | } 111 | if ($controller != null) { 112 | $request->setControllerName($controller); 113 | } 114 | if ($action != null) { 115 | $request->setActionName($action); 116 | } 117 | $params = array(); 118 | if ($rest!=null && trim($rest)!='') { 119 | $path = explode(Router::URI_DELIMITER, $rest); 120 | if (($numSegs = count($path))!=0) { 121 | for ($i = 0; $i < $numSegs; $i = $i + 2) { 122 | $key = urldecode($path[$i]); 123 | $val = isset($path[$i + 1]) ? 124 | urldecode($path[$i + 1]) : null; 125 | $params[$key] = (isset($params[$key]) 126 | ? (array_merge((array) $params[$key], array($val))) 127 | : $val); 128 | } 129 | } 130 | $request->setParam($params); 131 | } 132 | 133 | } 134 | return true; 135 | } 136 | 137 | /** 138 | * used to create routes on the fly from config 139 | * 140 | * @param array $config 141 | */ 142 | public function getInstance(array $config) 143 | { 144 | return new self(); 145 | } 146 | 147 | } 148 | -------------------------------------------------------------------------------- /framework/Yaf_Namespace/Route/Supervar.php: -------------------------------------------------------------------------------- 1 | _varName = $varName; 29 | } 30 | } 31 | 32 | 33 | /** 34 | * Processes a request and sets its controller and action based on a 35 | * supervar value. 36 | * 37 | * @param Yaf_Request_Abstract 38 | * @return Yaf_Request_Abstract|boolean 39 | */ 40 | public function route(\Yaf\Request_Abstract $request) 41 | { 42 | $requestUri = $request->getQuery($this->_varName); 43 | if ($requestUri==null || $requestUri=='') { 44 | return false; 45 | } 46 | $module = null; 47 | $controller = null; 48 | $action = null; 49 | $rest = null; 50 | $path = trim($requestUri, \Yaf\Router::URI_DELIMITER); 51 | if ($path != '' && $path!='/') { 52 | $path = explode(\Yaf\Router::URI_DELIMITER, $path); 53 | if (\Yaf\Application::isModuleName($path[0])) { 54 | $module = $path[0]; 55 | array_shift($path); 56 | } 57 | 58 | if (count($path) && !empty($path[0])) { 59 | $controller = $path[0]; 60 | array_shift($path); 61 | } 62 | 63 | if (count($path) && !empty($path[0])) { 64 | $action = $path[0]; 65 | array_shift($path); 66 | } 67 | $rest = implode(\Yaf\Router::URI_DELIMITER, $path); 68 | $actionPrefer = \Yaf\G::iniGet('yaf.action_prefer'); 69 | 70 | if ($module == null && $controller == null && $action == null) { 71 | if ($actionPrefer == true) { 72 | $action = $rest; 73 | } else { 74 | $controller = $rest; 75 | } 76 | $rest = null; 77 | } elseif ($module == null && $action == null && $rest == null) { 78 | if ($actionPrefer == true) { 79 | $action = $controller; 80 | $controller = null; 81 | } 82 | } elseif ($controller == null && $action == null && $rest != null) { 83 | $controller = $module; 84 | $action = $rest; 85 | $module = null; 86 | $rest = null; 87 | } elseif ($action == null && $rest == null) { 88 | $action = $controller; 89 | $controller = $module; 90 | $module = null; 91 | } elseif ($controller == null && $action == null) { 92 | $controller = $module; 93 | $action = $rest; 94 | $module = null; 95 | $rest = null; 96 | } elseif ($action == null) { 97 | $action = $rest; 98 | $rest = null; 99 | } 100 | 101 | if ($module != null) { 102 | $request->setModuleName($module); 103 | } 104 | if ($controller != null) { 105 | $request->setControllerName($controller); 106 | } 107 | if ($action != null) { 108 | $request->setActionName($action); 109 | } 110 | $params = array(); 111 | if ($rest!=null && trim($rest)!='') { 112 | $path = explode(\Yaf\Router::URI_DELIMITER, $rest); 113 | if (($numSegs = count($path))!=0) { 114 | for ($i = 0; $i < $numSegs; $i = $i + 2) { 115 | $key = urldecode($path[$i]); 116 | $val = isset($path[$i + 1]) ? 117 | urldecode($path[$i + 1]) : null; 118 | $params[$key] = (isset($params[$key]) 119 | ? (array_merge((array) $params[$key], array($val))) 120 | : $val); 121 | } 122 | } 123 | $request->setParam($params); 124 | } 125 | 126 | } 127 | return true; 128 | } 129 | 130 | /** 131 | * used to create routes on the fly from config 132 | * 133 | * @param array $config 134 | */ 135 | public static function getInstance(array $config) 136 | { 137 | if (!is_string($config['varname']) || $config['varname']=='') { 138 | return null; 139 | } 140 | return new self($config['varname']); 141 | } 142 | 143 | } 144 | -------------------------------------------------------------------------------- /framework/Yaf_Namespace/Router.php: -------------------------------------------------------------------------------- 1 | addRoute( 41 | '_default', 42 | $this->_getRouteFromArray($defaultRoute) 43 | ); 44 | } else { 45 | $this->addRoute('_default', new Route_Static()); 46 | } 47 | } 48 | 49 | /** 50 | * Add route to the route chain 51 | * 52 | * @param string $name Name of the route 53 | * @param Yaf_Route_Interface $route Instance of the route 54 | * @return Yaf_Router 55 | */ 56 | public function addRoute($name, Route_Interface $route) 57 | { 58 | $this->_routes[$name] = $route; 59 | return $this; 60 | } 61 | 62 | /** 63 | * 64 | * Example INI: 65 | * routes.archive.type = "simple" 66 | * routes.archive.module = Index 67 | * routes.archive.controller = archive 68 | * routes.archive.action = show 69 | * 70 | * routes.news.type = "static" 71 | * routes.news.route = "news" 72 | * 73 | * And finally after you have created a Yaf_Config with above ini: 74 | * $router = new Yaf_Router(); 75 | * $router->addConfig($config); 76 | * 77 | * @param array|Yaf_Config $config Configuration object 78 | * @throws Yaf_Router_Exception 79 | * @return Yaf_Router 80 | */ 81 | public function addConfig($config) 82 | { 83 | if (is_array($config)) { 84 | //$config = new Yaf_Config_Simple($config); 85 | } else if ($config instanceof Config_Abstract) { 86 | $config = $config->toArray(); 87 | } else { 88 | throw new Exception\RouterFailed( 89 | 'Expecting Array or Yaf_Config_Abstract instance' 90 | ); 91 | } 92 | $name = key($config); 93 | foreach ($config as $entry) { 94 | $route = $this->_getRouteFromArray($entry); 95 | if ($route!=null) { 96 | if ($route instanceof Route_Interface) { 97 | $this->addRoute($name, $route); 98 | } else { 99 | $this->addRoute($name, $route); 100 | } 101 | } else { 102 | if (is_string($name)) { 103 | throw new Exception\RouterFailed( 104 | 'Unable to initialize route named '.$name 105 | ); 106 | } else { 107 | throw new Exception\RouterFailed( 108 | 'Unable to initialize route at index '.$name 109 | ); 110 | } 111 | } 112 | next($config); 113 | $name = key($config); 114 | } 115 | 116 | /*//exit(); 117 | foreach ($config as $name => $info) { 118 | $route = $this->_getRouteFromConfig($info); 119 | 120 | if ($route!=null) { 121 | if ($route instanceof Yaf_Route_Interface) { 122 | $this->addRoute($name, $route); 123 | } else { 124 | $this->addRoute($name, $route); 125 | } 126 | } else { 127 | throw new Yaf_Exception_RouterFailed( 128 | 'Unable to initialize route named '.$name 129 | ); 130 | } 131 | }*/ 132 | 133 | return $this; 134 | } 135 | 136 | /** 137 | * Get a route from a config instance 138 | * 139 | * @param Yaf_Config_Abstract $info 140 | * @return Yaf_Route_Interface 141 | */ 142 | protected function _getRouteFromConfig(Config_Abstract $info) 143 | { 144 | $useNamespace = G::iniGet('yaf.use_namespace'); 145 | if ($useNamespace) { 146 | $class = (isset($info['type'])) 147 | ? '\\Yaf\\Route\\'.ucfirst($info['type']) 148 | : '\\Yaf\\Route\\Static'; 149 | } else { 150 | $class = (isset($info['type'])) 151 | ? 'Yaf_Route_'.ucfirst($info['type']) 152 | : 'Yaf_Route_Static'; 153 | } 154 | try { 155 | $route = call_user_func(array($class, 'getInstance'), $info); 156 | } catch (\Exception $e) { 157 | return null; 158 | } 159 | return $route; 160 | } 161 | 162 | /** 163 | * Get a route from an array 164 | * 165 | * @param array $info 166 | * @return Yaf_Route_Interface 167 | */ 168 | protected function _getRouteFromArray(array $info) 169 | { 170 | $useNamespace = G::iniGet('yaf.use_namespace'); 171 | if ($useNamespace) { 172 | $class = (isset($info['type'])) 173 | ? '\\Yaf\\Route\\'.ucfirst($info['type']) 174 | : '\\Yaf\\Route\\Static'; 175 | } else { 176 | $class = (isset($info['type'])) 177 | ? 'Yaf_Route_'.ucfirst($info['type']) 178 | : 'Yaf_Route_Static'; 179 | } 180 | try { 181 | $route = call_user_func(array($class, 'getInstance'), $info); 182 | } catch (\Exception $e) { 183 | return null; 184 | } 185 | return $route; 186 | } 187 | 188 | /** 189 | * Retrieve a currently matched route 190 | * 191 | * @throws Yaf_Exception_RouterFailed 192 | * @return Yaf_Route_Interface Route object 193 | */ 194 | public function getCurrentRoute() 195 | { 196 | return $this->_current; 197 | } 198 | 199 | /** 200 | * Retrieve a named route 201 | * 202 | * @param string $name Name of the route 203 | * @throws Yaf_Exception_RouterFailed 204 | * @return Yaf_Route_Interface Route object 205 | */ 206 | public function getRoute($name) 207 | { 208 | if (!isset($this->_routes[$name])) { 209 | return null; 210 | /* throw new Yaf_Exception_RouterFailed( 211 | "Route $name is not defined" 212 | ); */ 213 | } 214 | return $this->_routes[$name]; 215 | } 216 | 217 | /** 218 | * Retrieve an array of routes added to the route chain 219 | * 220 | * @return array All of the defined routes 221 | */ 222 | public function getRoutes() 223 | { 224 | return $this->_routes; 225 | } 226 | 227 | /** 228 | * Find a matching route to the current Request and inject 229 | * returning values to the Request object. 230 | * 231 | * @return bool if there is a valid route 232 | */ 233 | public function route(Request_Abstract $request) 234 | { 235 | // Find the matching route 236 | $routeMatched = false; 237 | 238 | foreach (array_reverse($this->_routes, true) as $name => $route) { 239 | if (($ret = $route->route($request))!=false) { 240 | $this->_current = $name; 241 | $routeMatched = true; 242 | break; 243 | } 244 | } 245 | 246 | if (!$routeMatched) { 247 | return false; 248 | } else { 249 | $request->setRouted(true); 250 | return true; 251 | } 252 | return false; 253 | } 254 | } 255 | -------------------------------------------------------------------------------- /framework/Yaf_Namespace/Session.php: -------------------------------------------------------------------------------- 1 | session); 44 | } 45 | 46 | /** 47 | * Defined by Iterator interface 48 | * 49 | * @return mixed 50 | */ 51 | public function current () 52 | { 53 | return current($this->session); 54 | } 55 | 56 | public function del($name) 57 | { 58 | return $this->offsetUnset($name); 59 | } 60 | 61 | public function __destruct() 62 | { 63 | 64 | } 65 | 66 | /** 67 | * Magic function so that $obj->value will work. 68 | * 69 | * @param string $name 70 | * @return mixed 71 | */ 72 | public function __get ($name) 73 | { 74 | $result = null; 75 | if ($name == null) { 76 | return null; 77 | } 78 | if (array_key_exists($name, $this->session)) { 79 | $result = $this->session[$name]; 80 | } else if (array_key_exists($name, $_SESSION)) { 81 | $result = $_SESSION[$name]; 82 | } 83 | return $result; 84 | } 85 | 86 | /** 87 | * Retrieve singleton instance 88 | * 89 | * @return Yaf_Session 90 | */ 91 | public static function getInstance() 92 | { 93 | if (null === self::$_instance) { 94 | self::$_instance = new self(); 95 | self::start(); 96 | } 97 | return self::$_instance; 98 | } 99 | 100 | public function has($name) 101 | { 102 | return $this->offsetExists($name); 103 | } 104 | 105 | /** 106 | * Support isset() overloading on PHP 5.1 107 | * 108 | * @param string $name 109 | * @return boolean 110 | */ 111 | public function __isset ($name) 112 | { 113 | return (isset($this->session[$name])?true:isset($_SESSION[$name])); 114 | } 115 | 116 | /** 117 | * Defined by Iterator interface 118 | * 119 | * @return mixed 120 | */ 121 | public function key () 122 | { 123 | return key($this->session); 124 | } 125 | /** 126 | * Defined by Iterator interface 127 | * 128 | */ 129 | public function next () 130 | { 131 | next($this->session); 132 | } 133 | 134 | /** 135 | * Support isset() overloading on PHP 5.1 136 | * 137 | * @param string $name 138 | * @return boolean 139 | */ 140 | public function offsetExists ($name) 141 | { 142 | return $this->__isset($name); 143 | } 144 | /** 145 | * Return a session value specified by name 146 | * @param string $name 147 | * @return mixed 148 | */ 149 | public function offsetGet ($name) 150 | { 151 | return $this->__get($name); 152 | } 153 | /** 154 | * Set a key of the session with value 155 | * @param string $name 156 | * @param string $value 157 | * @return void 158 | */ 159 | public function offsetSet ($name, $value) 160 | { 161 | return $this->__set($name, $value); 162 | } 163 | /** 164 | * Support unset() overloading on PHP 5.1 165 | * 166 | * @param string $name 167 | * @return void 168 | */ 169 | public function offsetUnset ($name) 170 | { 171 | unset($this->session[$name]); 172 | unset($_SESSION[$name]); 173 | } 174 | 175 | /** 176 | * Defined by Iterator interface 177 | * 178 | */ 179 | public function rewind () 180 | { 181 | reset($this->session); 182 | } 183 | /** 184 | * Allow setting of a session variable. 185 | * Throw an exception if the name is not string. 186 | * 187 | * @param string $name 188 | * @param mixed $value 189 | * @throws Yaf_Exception 190 | * @return void 191 | */ 192 | public function __set ($name, $value) 193 | { 194 | if (is_string($name)) { 195 | $this->session[$name] = $value; 196 | $_SESSION[$name] = $value; 197 | } else { 198 | throw new Exception('Expect a string key name'); 199 | } 200 | } 201 | 202 | protected function __sleep() 203 | { 204 | 205 | } 206 | 207 | /** 208 | * Starts the session 209 | */ 210 | public static function start() 211 | { 212 | $session = self::getInstance(); 213 | if ($session->started == true) { 214 | return true; 215 | } else { 216 | session_start(); 217 | $session->started = true; 218 | $session->session = $_SESSION; 219 | } 220 | } 221 | /** 222 | * Support unset() overloading on PHP 5.1 223 | * 224 | * @param string $name 225 | * @return void 226 | */ 227 | public function __unset($name) 228 | { 229 | unset($this->session[$name]); 230 | } 231 | /** 232 | * Defined by Iterator interface 233 | * 234 | * @return boolean 235 | */ 236 | public function valid () 237 | { 238 | $key = key($this->session); 239 | return ($key == null || $key == false) ? false: true; 240 | } 241 | 242 | protected function __wakeup() 243 | { 244 | 245 | } 246 | } -------------------------------------------------------------------------------- /framework/Yaf_Namespace/View/Interface.php: -------------------------------------------------------------------------------- 1 | value pairs to set en 35 | * masse. 36 | * 37 | * @param string|array $name The assignment strategy to use 38 | * (key or array of key => value pairs) 39 | * @param mixed $value (Optional) If assigning a named variable, use this 40 | * as the value. 41 | * @return void 42 | */ 43 | public function assign($name, $value = null); 44 | 45 | 46 | /** 47 | * Processes a view script and returns the output. 48 | * 49 | * @param string $tpl The script name to process. 50 | * @param array $tplVars The script variables. 51 | * @return string The script output. 52 | */ 53 | public function render($tpl, $tplVars=array()); 54 | /** 55 | * Processes a view script and displays the output. 56 | * 57 | * @param string $tpl The script name to process. 58 | * @param array $tplVars The script variables. 59 | * @return void 60 | */ 61 | public function display($tpl, $tplVars=array()); 62 | } 63 | -------------------------------------------------------------------------------- /framework/loader.php: -------------------------------------------------------------------------------- 1 | getConfig(); 17 | 18 | Yaf_Registry::set("config", $config); 19 | } 20 | 21 | /** 22 | * 注册一个插件 23 | */ 24 | function _initPlugin($dispatcher) { 25 | $user = new UserPlugin(); 26 | $dispatcher->registerPlugin($user); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /sample/application/controllers/Error.php: -------------------------------------------------------------------------------- 1 | getView()->assign("exception", $exception); 5 | } 6 | 7 | } 8 | -------------------------------------------------------------------------------- /sample/application/controllers/Index.php: -------------------------------------------------------------------------------- 1 | _view->assign(Yaf_Registry::get("config")->common->toArray()); 6 | } 7 | 8 | public function indexAction() { 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /sample/application/library/A.php: -------------------------------------------------------------------------------- 1 | 9 | -------------------------------------------------------------------------------- /sample/application/library/A/B.php: -------------------------------------------------------------------------------- 1 | 6 | -------------------------------------------------------------------------------- /sample/application/library/Yaf/TEST.php: -------------------------------------------------------------------------------- 1 | 8 | -------------------------------------------------------------------------------- /sample/application/modules/Index/controllers/Action.php: -------------------------------------------------------------------------------- 1 | disableView(); 12 | echo "Hello"; 13 | $this->forward('index'); 14 | */ 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /sample/application/modules/Index/controllers/Index.php: -------------------------------------------------------------------------------- 1 | _render = 0; 6 | echo "Laruence"; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /sample/application/modules/Index/models/User.php: -------------------------------------------------------------------------------- 1 | 5 | -------------------------------------------------------------------------------- /sample/application/modules/Index/views/Index/Index.: -------------------------------------------------------------------------------- 1 | lkajdkfljdsalkjflkjdsalkflksajflkjdsalkfjlkdsajlkfjdlksa 2 | -------------------------------------------------------------------------------- /sample/application/modules/Test/controllers/Action.php: -------------------------------------------------------------------------------- 1 | disableView(); 12 | echo "Hello"; 13 | $this->forward('index'); 14 | */ 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /sample/application/modules/Test/controllers/Index.php: -------------------------------------------------------------------------------- 1 | _render = 0; 6 | echo "Laruence"; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /sample/application/modules/Test/models/User.php: -------------------------------------------------------------------------------- 1 | 5 | -------------------------------------------------------------------------------- /sample/application/modules/Test/views/Index/Index.: -------------------------------------------------------------------------------- 1 | lkajdkfljdsalkjflkjdsalkflksajflkjdsalkfjlkdsajlkfjdlksa 2 | -------------------------------------------------------------------------------- /sample/application/plugins/User.php: -------------------------------------------------------------------------------- 1 | getMessage(); 3 | -------------------------------------------------------------------------------- /sample/application/views/index/index.phtml: -------------------------------------------------------------------------------- 1 | 2 |
3 |";print_r($app); print ""; 72 | } 73 | 74 | public function testGetREquest() 75 | { 76 | 77 | } 78 | 79 | public function testGetRouter() 80 | { 81 | 82 | } 83 | 84 | public function testInitView() 85 | { 86 | 87 | } 88 | 89 | public function testRegisterPlugin() 90 | { 91 | 92 | } 93 | 94 | public function testReturnResponse() 95 | { 96 | 97 | } 98 | 99 | public function testSetDefaultAction() 100 | { 101 | $this->dispatcher = Yaf_Dispatcher::getInstance(); 102 | $this->assertEquals( 103 | 'index', 104 | $this->readAttribute($this->dispatcher, '_default_action') 105 | ); 106 | $this->dispatcher->setDefaultAction('test'); 107 | $this->assertEquals( 108 | 'test', 109 | $this->readAttribute($this->dispatcher, '_default_action') 110 | ); 111 | //set back to index 112 | $this->dispatcher->setDefaultAction('index'); 113 | } 114 | 115 | public function testSetDefaultController() 116 | { 117 | $this->dispatcher = Yaf_Dispatcher::getInstance(); 118 | $this->assertEquals( 119 | 'Index', 120 | $this->readAttribute($this->dispatcher, '_default_controller') 121 | ); 122 | $this->dispatcher->setDefaultController('test'); 123 | $this->assertEquals( 124 | 'Test', 125 | $this->readAttribute($this->dispatcher, '_default_controller') 126 | ); 127 | //set back to index 128 | $this->dispatcher->setDefaultController('index'); 129 | } 130 | 131 | public function testSetDefaultModule() 132 | { 133 | $app = new Yaf_Application( 134 | TEST_APPLICATION_PATH.'conf/application.ini', 135 | 'production' 136 | ); 137 | $this->dispatcher = Yaf_Dispatcher::getInstance(); 138 | $this->assertEquals( 139 | 'Index', 140 | $this->readAttribute($this->dispatcher, '_default_module') 141 | ); 142 | $this->dispatcher->setDefaultModule('foo'); 143 | $this->assertEquals( 144 | 'Foo', 145 | $this->readAttribute($this->dispatcher, '_default_module') 146 | ); 147 | //set back to index 148 | $this->dispatcher->setDefaultModule('index'); 149 | } 150 | /** 151 | * @runInSeparateProcess 152 | */ 153 | public function testCase031() 154 | { 155 | $config = array( 156 | "application" => array( 157 | "directory" => TEST_APPLICATION_PATH, 158 | "dispatcher" => array( 159 | "defaultRoute" => array( 160 | "type" => "map", 161 | "delimiter" => '##', 162 | "controllerPrefer" => 1, 163 | ), 164 | ), 165 | ), 166 | ); 167 | 168 | $app = new Yaf_Application($config); 169 | $routes = $app->getDispatcher()->getRouter()->getRoutes(); 170 | $this->assertTrue(isset($routes['_default'])); 171 | $this->assertInstanceOf('Yaf_Route_Map', $routes['_default']); 172 | } 173 | } -------------------------------------------------------------------------------- /tests/framework/Yaf/ExceptionTest.php: -------------------------------------------------------------------------------- 1 | assertSame($previous, $exception->getPrevious()); 15 | $this->assertEquals('Exception', $exception->getMessage()); 16 | $this->assertEquals( 17 | 100, $exception->getPrevious()->getCode() 18 | ); 19 | } 20 | } -------------------------------------------------------------------------------- /tests/framework/Yaf/Loader/testCase027.php: -------------------------------------------------------------------------------- 1 | array( 23 | "directory" => TEST_APPLICATION_PATH.'application/', 24 | "dispatcher" => array( 25 | "catchException" => 0, 26 | "throwException" => 0 27 | ) 28 | ) 29 | ); 30 | $app = new Yaf_Application($config); 31 | include(dirname(__FILE__).'/Loader/testCase027.php'); 32 | try { 33 | $app->execute('testCase027'); 34 | } catch (PHPUnit_Framework_Error_Warning $e) { 35 | $this->assertContains( 36 | 'Could not find script '.TEST_APPLICATION_PATH. 37 | 'application/controllers/NoExists.php', 38 | $e->getMessage() 39 | ); 40 | } 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /tests/framework/Yaf/RegistryTest.php: -------------------------------------------------------------------------------- 1 | assertEquals( 14 | 'Ageli Platform', Yaf_Registry::get("name") 15 | ); 16 | $this->assertTrue(Yaf_Registry::has("name")); 17 | $name = "name"; 18 | Yaf_Registry::del($name); 19 | $this->assertNull(Yaf_Registry::get("name")); 20 | $this->assertFalse(Yaf_Registry::has("name")); 21 | } 22 | } -------------------------------------------------------------------------------- /tests/framework/Yaf/Request/SimpleTest.php: -------------------------------------------------------------------------------- 1 | request = new Yaf_Request_Simple( 17 | 'CLI', 'index', 'dummy', 'index' 18 | ); 19 | } 20 | 21 | /** 22 | * @runInSeparateProcess 23 | */ 24 | public function testCase02() 25 | { 26 | if (!defined('YAF_MODE')) { 27 | //@todo for some reason this need to b true to pass the test 28 | Yaf_G::iniSet('yaf.use_spl_autoload', true); 29 | Yaf_G::iniSet('yaf.lowcase_path', false); 30 | } else { 31 | ini_set('yaf.use_spl_autoload', false); 32 | ini_set('yaf.lowcase_path', false); 33 | } 34 | $this->assertEquals('CLI', $this->request->getMethod()); 35 | $this->assertEquals('index', $this->request->getModuleName()); 36 | $this->assertEquals('dummy', $this->request->getControllerName()); 37 | $this->assertEquals('index', $this->request->getActionName()); 38 | $this->assertFalse($this->request->isDispatched()); 39 | $this->assertTrue($this->request->isRouted()); 40 | $this->request->setParam('name', 'Laruence'); 41 | $this->assertEquals('Laruence', $this->request->getParam('name')); 42 | $this->assertNull($this->request->getParam('non-exists')); 43 | $this->assertTrue($this->request->isCli()); 44 | $app = new Yaf_Application( 45 | array( 46 | "application" => array( 47 | "directory" => dirname(__FILE__) 48 | ) 49 | ) 50 | ); 51 | 52 | try { 53 | $app->getDispatcher()->dispatch($this->request); 54 | $this->fail( 55 | 'An Yaf_Exception_LoadFailed_Controller '. 56 | 'exception was not throwed' 57 | ); 58 | } catch (Exception $e) { 59 | $this->assertEquals( 60 | 'Could not find controller script '.dirname(__FILE__). 61 | '/controllers/Dummy.php', 62 | $e->getMessage() 63 | ); 64 | } 65 | } 66 | 67 | } -------------------------------------------------------------------------------- /tests/framework/Yaf/Response/CliTest.php: -------------------------------------------------------------------------------- 1 | appendBody($body); 16 | $response->prependBody($string); 17 | $response->appendBody("kfjdaksljfklajdsfkljasdkljfkjasdf"); 18 | 19 | $this->assertEquals( 20 | 'laruenceifjakdsljfklasdjfkljasdkljfkljadsf'. 21 | 'kfjdaksljfklajdsfkljasdkljfkjasdf', 22 | $response->getBody() 23 | ); 24 | unset($string); 25 | $this->assertEquals( 26 | 'laruenceifjakdsljfklasdjfkljasdkljfkljadsf'. 27 | 'kfjdaksljfklajdsfkljasdkljfkjasdf', 28 | $response->getBody() 29 | ); 30 | unset($body); 31 | $this->assertEquals( 32 | 'laruenceifjakdsljfklasdjfkljasdkljfkljadsf'. 33 | 'kfjdaksljfklajdsfkljasdkljfkjasdf', 34 | $response->getBody() 35 | ); 36 | ob_start(); 37 | $response->response(); 38 | $content = ob_get_clean(); 39 | $this->assertEquals( 40 | 'laruenceifjakdsljfklasdjfkljasdkljfkljadsf'. 41 | 'kfjdaksljfklajdsfkljasdkljfkjasdf', 42 | $content 43 | ); 44 | } 45 | } -------------------------------------------------------------------------------- /tests/framework/Yaf/Response/HttpTest.php: -------------------------------------------------------------------------------- 1 | appendBody($body); 16 | $response->prependBody($string); 17 | $response->appendBody("kfjdaksljfklajdsfkljasdkljfkjasdf"); 18 | 19 | $this->assertEquals( 20 | 'laruenceifjakdsljfklasdjfkljasdkljfkljadsf'. 21 | 'kfjdaksljfklajdsfkljasdkljfkjasdf', 22 | $response->getBody() 23 | ); 24 | unset($string); 25 | $this->assertEquals( 26 | 'laruenceifjakdsljfklasdjfkljasdkljfkljadsf'. 27 | 'kfjdaksljfklajdsfkljasdkljfkjasdf', 28 | $response->getBody() 29 | ); 30 | unset($body); 31 | $this->assertEquals( 32 | 'laruenceifjakdsljfklasdjfkljasdkljfkljadsf'. 33 | 'kfjdaksljfklajdsfkljasdkljfkjasdf', 34 | $response->getBody() 35 | ); 36 | } 37 | 38 | public function testCase026() 39 | { 40 | $response = new Yaf_Response_Http(); 41 | $response->setBody("ell")->appendBody("o")->prependBody("H"); 42 | $this->assertEquals( 43 | 'Hello', 44 | $response->getBody() 45 | ); 46 | } 47 | } -------------------------------------------------------------------------------- /tests/framework/Yaf/Route/MapTest.php: -------------------------------------------------------------------------------- 1 | request = new Yaf_Request_Http(); 28 | $this->router = new Yaf_Router(); 29 | } 30 | 31 | 32 | public function testMapNoDelimiterInRequestControllerPrefer() 33 | { 34 | $route = new Yaf_Route_Map(true); 35 | $this->request->setRequestUri('/product/foo/bar/'); 36 | $this->request->setBaseUri('/'); 37 | $return = $route->route($this->request); 38 | $this->assertTrue($return); 39 | 40 | $this->assertEquals(null, $this->request->getModuleName()); 41 | $this->assertEquals( 42 | 'product_foo_bar', $this->request->getControllerName() 43 | ); 44 | $this->assertEquals(null, $this->request->getActionName()); 45 | $params = $this->request->getParams(); 46 | $this->assertEquals(array(), $params); 47 | } 48 | 49 | public function testMapNoDelimiterInRequestActionPrefer() 50 | { 51 | $route = new Yaf_Route_Map(); 52 | $this->request->setRequestUri('/product/foo/bar/'); 53 | $this->request->setBaseUri('/'); 54 | $return = $route->route($this->request); 55 | $this->assertTrue($return); 56 | 57 | $this->assertEquals(null, $this->request->getModuleName()); 58 | $this->assertEquals( 59 | 'product_foo_bar', $this->request->getActionName() 60 | ); 61 | $this->assertEquals(null, $this->request->getControllerName()); 62 | $params = $this->request->getParams(); 63 | $this->assertEquals(array(), $params); 64 | } 65 | 66 | public function testMapDelimiterInRequest() 67 | { 68 | $route = new Yaf_Route_Map(true, '_'); 69 | $this->request->setRequestUri('/user/list/_/foo/22'); 70 | $this->request->setBaseUri('/'); 71 | $return = $route->route($this->request); 72 | $this->assertTrue($return); 73 | 74 | $this->assertEquals(null, $this->request->getModuleName()); 75 | $this->assertEquals( 76 | 'user_list', $this->request->getControllerName() 77 | ); 78 | $this->assertEquals(null, $this->request->getActionName()); 79 | $params = $this->request->getParams(); 80 | $this->assertEquals(array('foo'=>'22'), $params); 81 | } 82 | 83 | public function tearDown() 84 | { 85 | $this->request=null; 86 | $this->router=null; 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /tests/framework/Yaf/Route/RewriteTest.php: -------------------------------------------------------------------------------- 1 | request = new Yaf_Request_Http(); 28 | $this->router = new Yaf_Router(); 29 | $app = Yaf_Application::app(); 30 | if ($app == null) { 31 | //Lets create the Application 32 | $app = new Yaf_Application("framework/Yaf/_files/application.ini"); 33 | } 34 | } 35 | 36 | 37 | public function testRewriteSuccess() 38 | { 39 | $route = new Yaf_Route_Rewrite( 40 | "/page/:id", 41 | array( 42 | "controller" => "page", 43 | "action" => "edit" 44 | ) 45 | ); 46 | //print "
";print_r($route); print ""; 47 | $this->request->setRequestUri('/page/12/'); 48 | //$this->request->setBaseUri('/'); 49 | $return = $route->route($this->request); 50 | //print "
";print_r($this->request); print ""; 51 | $this->assertTrue($return); 52 | 53 | $this->assertEquals(null, $this->request->getModuleName()); 54 | $this->assertEquals('page', $this->request->getControllerName()); 55 | $this->assertEquals('edit', $this->request->getActionName()); 56 | $params = $this->request->getParams(); 57 | $this->assertEquals(1, count($params)); 58 | $this->assertEquals( 59 | array( 60 | "id"=>"12", 61 | ), $params 62 | ); 63 | } 64 | 65 | 66 | public function testNotMatchedWithVariablesAndDefaults() 67 | { 68 | $route = new Yaf_Route_Rewrite( 69 | ':controller/:action', 70 | array( 71 | 'controller' => 'index', 72 | 'action' => 'index' 73 | ) 74 | ); 75 | $this->request->setRequestUri('archive/action/bogus'); 76 | $return = $route->route($this->request); 77 | $this->assertFalse($return); 78 | } 79 | 80 | public function testNotMatchedWithVariablesAndStatic() 81 | { 82 | $route = new Yaf_Route_Rewrite('archive/:year/:month', array()); 83 | $this->request->setRequestUri('ctrl/act/2000'); 84 | $return = $route->route($this->request); 85 | $this->assertFalse($return); 86 | } 87 | 88 | public function testStaticMatchWithWildcard() 89 | { 90 | $route = new Yaf_Route_Rewrite( 91 | 'news/view/*', 92 | array('controller' => 'news', 'action' => 'view') 93 | ); 94 | $this->request->setRequestUri('/news/view/show/all/year/2000/empty/'); 95 | $return = $route->route($this->request); 96 | $this->assertTrue($return); 97 | $this->assertEquals('news', $this->request->getControllerName()); 98 | $this->assertEquals('view', $this->request->getActionName()); 99 | $params = $this->request->getParams(); 100 | $this->assertEquals(3, count($params)); 101 | $this->assertEquals( 102 | array( 103 | "show"=>"all", 104 | "year"=>"2000", 105 | "empty"=>null, 106 | ), $params 107 | ); 108 | } 109 | 110 | public function testVariableValues() 111 | { 112 | $route = new Yaf_Route_Rewrite(':controller/:action/:year', array()); 113 | $this->request->setRequestUri('/ctrl/act/2000'); 114 | $return = $route->route($this->request); 115 | $this->assertTrue($return); 116 | $this->assertEquals(null, $this->request->getControllerName()); 117 | $this->assertEquals(null, $this->request->getActionName()); 118 | $params = $this->request->getParams(); 119 | $this->assertEquals(3, count($params)); 120 | $this->assertEquals( 121 | array( 122 | "controller"=>"ctrl", 123 | "action"=>"act", 124 | "year"=>"2000", 125 | ), $params 126 | ); 127 | 128 | } 129 | 130 | public function testRewriteInstanceArray() 131 | { 132 | $this->request->setRequestUri('/product/test/14'); 133 | $this->router->addConfig( 134 | array( 135 | 'route_name1'=>array( 136 | 'type' => 'rewrite', 137 | 'match' => '/product/:name/:value', 138 | 'route' => array( 139 | 'controller' => 'product', 140 | 'action' => 'info', 141 | ), 142 | ) 143 | ) 144 | ); 145 | $return = $this->router->route($this->request); 146 | $currentRouteName = $this->router->getCurrentRoute(); 147 | $this->assertEquals('route_name1', $currentRouteName); 148 | $currentRoute = $this->router->getRoute($currentRouteName); 149 | $this->assertInstanceOf('Yaf_Route_Rewrite', $currentRoute); 150 | $this->assertEquals(null, $this->request->getModuleName()); 151 | $this->assertEquals('product', $this->request->getControllerName()); 152 | $this->assertEquals('info', $this->request->getActionName()); 153 | $params = $this->request->getParams(); 154 | 155 | $this->assertTrue(is_array($params)); 156 | $this->assertEquals( 157 | array( 158 | "name"=>"test", 159 | "value"=>"14", 160 | ), $params 161 | ); 162 | } 163 | public function testRewriteInstanceConfig() 164 | { 165 | $config = new Yaf_Config_Ini("framework/Yaf/_files/route_rewrite.ini"); 166 | $this->router->addConfig($config->production->routes); 167 | $this->request->setRequestUri('/product/test/14'); 168 | $return = $this->router->route($this->request); 169 | $currentRouteName = $this->router->getCurrentRoute(); 170 | $this->assertEquals('route_name1', $currentRouteName); 171 | $currentRoute = $this->router->getRoute($currentRouteName); 172 | $this->assertInstanceOf('Yaf_Route_Rewrite', $currentRoute); 173 | $this->assertEquals(null, $this->request->getModuleName()); 174 | $this->assertEquals('product', $this->request->getControllerName()); 175 | $this->assertEquals('info', $this->request->getActionName()); 176 | $params = $this->request->getParams(); 177 | 178 | $this->assertTrue(is_array($params)); 179 | $this->assertEquals( 180 | array( 181 | "name"=>"test", 182 | "value"=>"14", 183 | ), $params 184 | ); 185 | } 186 | 187 | public function testCase011() 188 | { 189 | $this->request->setRequestUri('/subdir/ap/1.2/name/value'); 190 | $this->request->setBaseUri('/subdir'); 191 | $route = new Yaf_Route_Rewrite( 192 | "/subdir/:name/:version", 193 | array( 194 | "action" => "version" 195 | ) 196 | ); 197 | $this->router->addRoute("subdir", $route) 198 | ->addRoute( 199 | "ap", 200 | new Yaf_Route_Rewrite( 201 | "/ap/:version/*", 202 | array( 203 | "action" => 'ap' 204 | ) 205 | ) 206 | )->route($this->request); 207 | 208 | $this->assertEquals('ap', $this->router->getCurrentRoute()); 209 | $this->assertEquals('1.2', $this->request->getParam('version')); 210 | $this->assertEquals('ap', $this->request->getActionName()); 211 | $this->assertEquals(null, $this->request->getControllerName()); 212 | $this->assertEquals('value', $this->request->getParam('name')); 213 | 214 | } 215 | 216 | public function tearDown() 217 | { 218 | $this->request=null; 219 | $this->router=null; 220 | } 221 | } 222 | -------------------------------------------------------------------------------- /tests/framework/Yaf/SessionTest.php: -------------------------------------------------------------------------------- 1 | session = Yaf_Session::getInstance(); 15 | } 16 | 17 | /** 18 | * @runInSeparateProcess 19 | */ 20 | public function testCase016() 21 | { 22 | $_SESSION["name"] = "Laruence"; 23 | $age = 28; 24 | $this->session->age = $age; 25 | $this->assertEquals($age, $this->session->age); 26 | $this->assertEquals($_SESSION['age'], $this->session->age); 27 | $session2 = Yaf_Session::getInstance(); 28 | $session2['company'] = 'Baidu'; 29 | $this->assertTrue(isset($session2->age)); 30 | $this->assertTrue($session2->has('age')); 31 | $this->assertTrue($session2->has('name')); 32 | $this->assertEquals(2, count($session2)); 33 | $currentInSession = $_SESSION; 34 | foreach ($session2 as $key => $value) { 35 | $this->assertEquals($currentInSession[$key], $value); 36 | } 37 | unset($session2); 38 | $session3 = Yaf_Session::getInstance(); 39 | $session3->del("name"); 40 | $this->assertFalse($session3->has('name')); 41 | $this->assertFalse(isset($session3->name)); 42 | unset($session3["company"]); 43 | unset($session3->age); 44 | $this->assertEquals(0, count($session3)); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /tests/framework/Yaf/View/errorinview.php: -------------------------------------------------------------------------------- 1 | render('test/testCase038.phtml'); 14 | ?> -------------------------------------------------------------------------------- /tests/framework/Yaf/View/recursiveRender.php: -------------------------------------------------------------------------------- 1 | render('test/testCase039.phtml', array('tpl'=>'test/testCase038.phtml')); 14 | ?> -------------------------------------------------------------------------------- /tests/framework/Yaf/View/testCase033.php: -------------------------------------------------------------------------------- 1 | disableView(); 8 | $this->forward("dummy"); 9 | } 10 | 11 | public function dummyAction() { 12 | Yaf_Dispatcher::getInstance()->enableView(); 13 | } 14 | } 15 | ?> -------------------------------------------------------------------------------- /tests/framework/Yaf/View/testCase041.php: -------------------------------------------------------------------------------- 1 | forward("controller", "dummy"); 8 | return false; /* don't auto-render */ 9 | } 10 | 11 | public function dummyAction() { 12 | Yaf_Dispatcher::getInstance()->enableView(); 13 | } 14 | } 15 | ?> -------------------------------------------------------------------------------- /tests/framework/Yaf/_files/application.ini: -------------------------------------------------------------------------------- 1 | ;在Yaf_Config_Ini中, 可以支持继承 2 | ;可以直接使用PHP中定义的常量 3 | [product] 4 | application.directory=APPLICATION_PATH "/application" 5 | application.dispatcher.throwException=false 6 | application.dispatcher.catchException=true 7 | application.modules="Foo,Bar,Teste" 8 | routes.route_name2.type="simple" 9 | routes.route_name2.controller=c 10 | routes.route_name2.module=m 11 | routes.route_name2.action=a 12 | 13 | routes.route_name1.type="simple" 14 | routes.route_name1.controller=c1 15 | routes.route_name1.module=m1 16 | routes.route_name1.action=a1 17 | 18 | routes.route_name4.type="regex" 19 | routes.route_name4.match="#^list/([^/]*)/([^/]*)#" 20 | routes.route_name4.route.controller=Index 21 | routes.route_name4.route.action=action 22 | routes.route_name4.map.1=name 23 | routes.route_name4.map.2=value 24 | 25 | 26 | common.webroot="/work/yaf/" 27 | common.title="Yaf" 28 | [testing : product] 29 | [development : product] 30 | -------------------------------------------------------------------------------- /tests/framework/Yaf/_files/application_rewrite.ini: -------------------------------------------------------------------------------- 1 | ;在Yaf_Config_Ini中, 可以支持继承 2 | ;可以直接使用PHP中定义的常量 3 | [production] 4 | application.directory=APPLICATION_PATH "/application" 5 | application.dispatcher.throwException=false 6 | application.dispatcher.catchException=true 7 | 8 | common.webroot="/work/yaf/" 9 | common.title="Yaf" 10 | [testing : production] 11 | [development : production] 12 | -------------------------------------------------------------------------------- /tests/framework/Yaf/_files/route_rewrite.ini: -------------------------------------------------------------------------------- 1 | ;在Yaf_Config_Ini中, 可以支持继承 2 | ;可以直接使用PHP中定义的常量 3 | [production] 4 | application.directory=APPLICATION_PATH "/application" 5 | application.dispatcher.throwException=false 6 | application.dispatcher.catchException=true 7 | application.modules="Foo,Bar,Teste" 8 | 9 | ;a rewrite route match request /product/*/* 10 | routes.route_name1.type="rewrite" 11 | routes.route_name1.match="/product/:name/:value" 12 | routes.route_name1.route.controller=product 13 | routes.route_name1.route.action=info 14 | 15 | common.webroot="/work/yaf/" 16 | common.title="Yaf" 17 | [testing : production] 18 | [development : production] 19 | -------------------------------------------------------------------------------- /tests/framework/Yaf/_files/route_simple.ini: -------------------------------------------------------------------------------- 1 | ;在Yaf_Config_Ini中, 可以支持继承 2 | ;可以直接使用PHP中定义的常量 3 | [production] 4 | application.directory=APPLICATION_PATH "/application" 5 | application.dispatcher.throwException=false 6 | application.dispatcher.catchException=true 7 | application.modules="Foo,Bar,Teste" 8 | 9 | routes.route_name1.type="simple" 10 | routes.route_name1.controller=controller 11 | routes.route_name1.module=module 12 | routes.route_name1.action=action 13 | 14 | common.webroot="/work/yaf/" 15 | common.title="Yaf" 16 | [testing : production] 17 | [development : production] 18 | -------------------------------------------------------------------------------- /tests/framework/Yaf/_files/simple.ini: -------------------------------------------------------------------------------- 1 | [base] 2 | application.directory=APPLICATION_PATH "/application" 3 | name = "base" 4 | array.1 = 1 5 | 5=5 6 | array.name="name" 7 | routes.regex.type="regex" 8 | routes.regex.match="^/ap/(.*)" 9 | routes.regex.route.controller="Index" 10 | routes.regex.route.action="action" 11 | routes.regex.map.0="name" 12 | routes.regex.map.1="name" 13 | routes.regex.map.2="value" 14 | routes.simple.type="simple" 15 | routes.simple.controller="c" 16 | routes.simple.module="m" 17 | routes.simple.action="a" 18 | routes.supervar.type="supervar" 19 | routes.supervar.varname="c" 20 | routes.rewrite.type="rewrite" 21 | routes.rewrite.match="/yaf/:name/:value" 22 | routes.rewrite.route.controller="Index" 23 | routes.rewrite.route.action="action" 24 | 25 | [extra : base ] 26 | value = "2" 27 | name = "extra" 28 | array.name = "new_name" 29 | array.2 = "test" 30 | 31 | [product : extra] 32 | 33 | [nocatch : extra] 34 | application.dispatcher.throwException=Off 35 | application.dispatcher.catchException=yes 36 | routes.rewrite.match="/yaf/:name/:age" 37 | 38 | [envtest] 39 | env=${FOO} 40 | ini=${yaf.directory} 41 | const=FOO 42 | 43 | -------------------------------------------------------------------------------- /tests/framework/Yaf/_files/testCase013.ini: -------------------------------------------------------------------------------- 1 | [base] 2 | application.directory=APPLICATION_PATH "/applcation" 3 | name = "base" 4 | array.1 = 1 5 | 5=5 6 | array.name="name" 7 | routes.regex.type="regex" 8 | routes.regex.match="^/ap/(.*)" 9 | routes.regex.route.controller="Index" 10 | routes.regex.route.action="action" 11 | routes.regex.map.0="name" 12 | routes.regex.map.1="name" 13 | routes.regex.map.2="value" 14 | routes.simple.type="simple" 15 | routes.simple.controller="c" 16 | routes.simple.module="m" 17 | routes.simple.action="a" 18 | routes.supervar.type="supervar" 19 | routes.supervar.varname="c" 20 | routes.rewrite.type="rewrite" 21 | routes.rewrite.match="/yaf/:name/:value" 22 | routes.rewrite.route.controller="Index" 23 | routes.rewrite.route.action="action" 24 | 25 | [extra : base ] 26 | value = "2" 27 | name = "extra" 28 | array.name = "new_name" 29 | array.2 = "test" 30 | 31 | [product : extra] 32 | 33 | [nocatch : extra] 34 | application.dispatcher.throwException=Off 35 | application.dispatcher.catchException=yes 36 | routes.rewrite.match="/yaf/:name/:age" 37 | 38 | [envtest] 39 | env=${FOO} 40 | ini=${yaf.directory} 41 | const=FOO 42 | 43 | -------------------------------------------------------------------------------- /tests/framework/Yaf/_files/testCase020.php: -------------------------------------------------------------------------------- 1 | getLastErrorNo(); 5 | $GLOBALS['errMessageTestCase020BeforeClear'] = 6 | Yaf_Application::app()->getLastErrorMsg(); 7 | Yaf_Application::app()->clearLastError(); 8 | $GLOBALS['errNoTestCase020AfterClear'] = 9 | Yaf_Application::app()->getLastErrorNo(); 10 | $GLOBALS['errMessageTestCase020AfterClear'] = 11 | Yaf_Application::app()->getLastErrorMsg(); 12 | } -------------------------------------------------------------------------------- /tests/framework/Yaf/_files/testCase021.php: -------------------------------------------------------------------------------- 1 | 5 |