/** * Parse application options * * @param array $options * @throws Yaf_Exception When no bootstrap path is provided * @throws Yaf_Exception When invalid bootstrap information are provided * @return Yaf_Application */ protected function parseOptions(array $options) { if (!is_array($options)) { throw new Yaf_Exception_TypeError('Expected an array of application configure'); } $options = array_change_key_case($options, CASE_LOWER); if (!isset($options['application'])) { throw new Yaf_Exception_TypeError('Expected an array of application configure'); } $options = $options['application']; if (!empty($options['directory'])) { Yaf_G::set('directory', preg_replace("/" . preg_quote(DIRECTORY_SEPARATOR, "/") . "\$/", "", $options['directory'])); } else { throw new Yaf_Exception_StartupError('Expected a directory entry in application configures'); } if (!empty($options['ext'])) { Yaf_G::set('ext', $options['ext']); } if (!empty($options['bootstrap']) && is_string($options['bootstrap'])) { $this->_options['bootstrap'] = $options['bootstrap']; } if (!empty($options['library'])) { if (is_string($options['library'])) { $this->_options['local_library'] = $options['library']; } elseif (is_array($options['library'])) { if (!empty($options['library']['directory']) && is_string($options['library']['directory'])) { $this->_options['local_library'] = $options['library']['directory']; } if (!empty($options['library']['namespace']) && is_string($options['library']['namespace'])) { $this->_options['local_namespace'] = $options['library']['namespace']; } } } else { $this->_options['local_library'] = Yaf_G::get('directory') . DIRECTORY_SEPARATOR . Yaf_Loader::YAF_LIBRARY_DIRECTORY_NAME; } if (!empty($options['view']) && is_array($options['view']) && !empty($options['view']['ext']) && is_string($options['view']['ext'])) { Yaf_G::set('view_ext', $options['view']['ext']); } if (!empty($options['baseUri']) && is_string($options['baseUri'])) { $this->_options['baseUri'] = $options['baseUri']; } else { $this->_options['baseUri'] = $_SERVER['PHP_SELF']; } if (!empty($options['dispatcher']) && is_array($options['dispatcher'])) { if (!empty($options['dispatcher']['defaultModule']) && is_string($options['dispatcher']['defaultModule'])) { Yaf_G::set('default_module', $options['dispatcher']['defaultModule']); } else { Yaf_G::set('default_module', Yaf_Router::YAF_ROUTER_DEFAULT_MODULE); } if (!empty($options['dispatcher']['defaultController']) && is_string($options['dispatcher']['defaultController'])) { Yaf_G::set('default_controller', $options['dispatcher']['defaultController']); } else { Yaf_G::set('default_controller', Yaf_Router::YAF_ROUTER_DEFAULT_CONTROLLER); } if (!empty($options['dispatcher']['defaultAction']) && is_string($options['dispatcher']['defaultAction'])) { Yaf_G::set('default_action', $options['dispatcher']['defaultAction']); } else { Yaf_G::set('default_action', Yaf_Router::YAF_ROUTER_DEFAULT_ACTION); } if (isset($options['dispatcher']['throwException'])) { Yaf_G::set('throwException', (bool) $options['dispatcher']['throwException']); } if (isset($options['dispatcher']['catchException'])) { Yaf_G::set('catchException', (bool) $options['dispatcher']['catchException']); } if (isset($options['dispatcher']['defaultRoute']) && is_array($options['dispatcher']['defaultRoute'])) { Yaf_G::set('default_route', $options['dispatcher']['defaultRoute']); } } else { Yaf_G::set('default_module', Yaf_Router::YAF_ROUTER_DEFAULT_MODULE); Yaf_G::set('default_controller', Yaf_Router::YAF_ROUTER_DEFAULT_CONTROLLER); Yaf_G::set('default_action', Yaf_Router::YAF_ROUTER_DEFAULT_ACTION); $this->_options['throwException'] = true; $this->_options['catchException'] = true; } if (!empty($options['modules']) && is_string($options['modules'])) { $modules = preg_split("/,/", $options['modules']); foreach ($modules as $module) { $this->_modules[] = trim($module); } } if (empty($this->_modules)) { $this->_modules[] = Yaf_G::get('default_module'); } return true; }
/** * Set the throwExceptions flag and retrieve current status * * Set whether exceptions encounted in the dispatch loop should be thrown * or caught and trapped in the response object. * * Default behaviour is to trap them in the response object; call this * method to have them thrown. * * Passing no value will return the current value of the flag; passing a * boolean true or false value will set the flag and return the current * object instance. * * @param boolean $flag Defaults to null (return flag state) * @return boolean|Yaf_Dispatcher Used as a setter, * returns object; as a getter, returns boolean */ public function throwException($flag = null) { if ($flag !== null) { Yaf_G::set('throwException', (bool) $flag); return $this; } return Yaf_G::get('throwException'); }