| 1 |
<?php |
| 2 | |
| 3 | //Soma::load('somaSingleton'); |
| 4 | |
| 5 | |
| 6 | class somaView extends somaSingleton |
| 7 | { |
| 8 | |
| 9 | protected $_meta = array('meta' => array(), 'css' => array(), 'js' => array()); |
| 10 | |
| 11 | protected $_layout; |
| 12 | protected $_partial; |
| 13 | protected $_template; |
| 14 | |
| 15 | protected $_variables = array(); |
| 16 | |
| 17 | public function addMeta($name, $value) |
| 18 | { |
| 19 | $this->_meta['meta'][$name] = $value; |
| 20 | } |
| 21 | |
| 22 | public function appendMeta($name, $value) |
| 23 | { |
| 24 | $this->_meta['meta'][$name] .= $value; |
| 25 | } |
| 26 | |
| 27 | public function prependMeta($name, $value) |
| 28 | { |
| 29 | $this->_meta['meta'][$name] = $value . $this->_meta['meta'][$name]; |
| 30 | } |
| 31 | |
| 32 | public function removeMeta($name) |
| 33 | { |
| 34 | unset($this->_meta['meta'][$name]); |
| 35 | } |
| 36 | |
| 37 | public function getMeta($name) |
| 38 | { |
| 39 | return (isset($this->_meta['meta'][$name])) ? $this->_meta['meta'][$name] : null; |
| 40 | } |
| 41 | |
| 42 | public function printMeta() |
| 43 | { |
| 44 | $return = ''; |
| 45 | if (is_array($this->_meta['meta'])) |
| 46 | { |
| 47 | foreach ($this->_meta['meta'] as $metaName => $value) |
| 48 | { |
| 49 | |
| 50 | if($metaName == 'title') |
| 51 | { |
| 52 | $return .= '<title>' . $value . '</title>' . "\n"; |
| 53 | } |
| 54 | else if(in_array($metaName, array('refresh', 'expires', 'content-type'))) |
| 55 | { |
| 56 | $return .= '<meta name="' . $metaName . '" content="' . $value .'" />' . "\n"; |
| 57 | } |
| 58 | else |
| 59 | { |
| 60 | $return .= '<meta http-equiv="' . $metaName . '" content="' . $value .'" />' . "\n"; |
| 61 | } |
| 62 | |
| 63 | } |
| 64 | } |
| 65 | return $return; |
| 66 | } |
| 67 | |
| 68 | public function addJsScript($name, $src) |
| 69 | { |
| 70 | $this->_meta['js'][$name] = $src; |
| 71 | } |
| 72 | |
| 73 | public function removeJsScript($name) |
| 74 | { |
| 75 | unset($this->_meta['js'][$name]); |
| 76 | } |
| 77 | |
| 78 | public function printJsScript() |
| 79 | { |
| 80 | $return = ''; |
| 81 | if (is_array($this->_meta['js'])) |
| 82 | { |
| 83 | foreach ($this->_meta['js'] as $name => $jsPath) |
| 84 | { |
| 85 | $return .= '<script src="' . somaConfig::get('/config/layout/base_path', null) . $jsPath . '" type="text/javascript"></script>' . "\n"; |
| 86 | } |
| 87 | } |
| 88 | return $return; |
| 89 | } |
| 90 | |
| 91 | public function addCss($name, $href, $media = 'screen') |
| 92 | { |
| 93 | $this->_meta['css'][$name]['href'] = $href; |
| 94 | $this->_meta['css'][$name]['media'] = $media; |
| 95 | } |
| 96 | |
| 97 | public function removeCss($name) |
| 98 | { |
| 99 | unset($this->_meta['css'][$name]); |
| 100 | } |
| 101 | |
| 102 | public function printCss() |
| 103 | { |
| 104 | $return = ''; |
| 105 | if (is_array($this->_meta['css'])) |
| 106 | { |
| 107 | foreach ($this->_meta['css'] as $name => $value) |
| 108 | { |
| 109 | $return .= '<link rel="stylesheet" type="text/css" media="' . $value['media'] . '" href="' . somaConfig::get('/config/layout/base_path', null) . $value['href'] . '" />' . "\n"; |
| 110 | } |
| 111 | } |
| 112 | return $return; |
| 113 | } |
| 114 | |
| 115 | protected static $_instances = array(); |
| 116 | |
| 117 | protected function __construct() |
| 118 | { |
| 119 | } |
| 120 | |
| 121 | public static function getInstance($name = 'default') |
| 122 | { |
| 123 | if (!isset(self::$_instances[$name])) |
| 124 | { |
| 125 | self::$_instances[$name] = new somaView(); |
| 126 | } |
| 127 | return self::$_instances[$name]; |
| 128 | } |
| 129 | |
| 130 | public function getVariables() |
| 131 | { |
| 132 | return $this->_variables; |
| 133 | } |
| 134 | |
| 135 | public function addVariables($variables) |
| 136 | { |
| 137 | $this->_variables = array_merge($this->_variables, $variables); |
| 138 | } |
| 139 | |
| 140 | public function render() |
| 141 | { |
| 142 | if($this->_layout === null) |
| 143 | { |
| 144 | return; |
| 145 | } |
| 146 | |
| 147 | foreach ($this->getVariables() as $name => $value) |
| 148 | { |
| 149 | ${$name} = $value; |
| 150 | } |
| 151 | unset($name); |
| 152 | unset($value); |
| 153 | |
| 154 | ob_start(); |
| 155 | |
| 156 | if (file_exists(SOMA_PROJECT_PATH . '/app/' . SOMA_APP_NAME . '/views/'. somaConfig::get('/config/templates_skin') . '/' . somaConfig::get('/config/layouts_dir') . '/' .$this->getLayout().'.php')) |
| 157 | { |
| 158 | require(SOMA_PROJECT_PATH . '/app/' . SOMA_APP_NAME . '/views/'. somaConfig::get('/config/templates_skin') . '/' . somaConfig::get('/config/layouts_dir') . '/' .$this->getLayout().'.php'); |
| 159 | } |
| 160 | else if(file_exists(SOMA_PROJECT_PATH . '/app/' . SOMA_APP_NAME . '/views/'. somaConfig::get('/config/templates_skin') . '/' . somaConfig::get('/config/layouts_dir') . '/_' .$this->getLayout().'.php')) |
| 161 | { |
| 162 | require(SOMA_PROJECT_PATH . '/app/' . SOMA_APP_NAME . '/views/'. somaConfig::get('/config/templates_skin') . '/' . somaConfig::get('/config/layouts_dir') . '/_' .$this->getLayout().'.php'); |
| 163 | } |
| 164 | else |
| 165 | { |
| 166 | throw new somaException('Nie znaleziono layoutu'); |
| 167 | } |
| 168 | |
| 169 | return ob_get_clean(); |
| 170 | } |
| 171 | |
| 172 | public function setLayout($name) |
| 173 | { |
| 174 | $this->_layout = $name; |
| 175 | } |
| 176 | |
| 177 | public function getLayout() |
| 178 | { |
| 179 | return $this->_layout; |
| 180 | } |
| 181 | |
| 182 | public function setTemplate($name) |
| 183 | { |
| 184 | $arr = explode('/', $name); |
| 185 | $controller = $arr[0]; |
| 186 | $action = $arr[1]; |
| 187 | $partial = (isset($arr[2])) ? $arr[2] : $action; |
| 188 | |
| 189 | $this->_template = $controller . '/' . $action . '/' . $partial; |
| 190 | } |
| 191 | |
| 192 | public function getTemplate() |
| 193 | { |
| 194 | return $this->_template; |
| 195 | } |
| 196 | |
| 197 | public function getAlternateTemplate() |
| 198 | { |
| 199 | list($controller, $action, $action) = explode('/', $this->getTemplate()); |
| 200 | return $controller . '/' . $action . '/_' . $action; |
| 201 | } |
| 202 | |
| 203 | |
| 204 | public function setPartial($name) |
| 205 | { |
| 206 | $arr = explode('/', $name); |
| 207 | $controller = $arr[0]; |
| 208 | $action = $arr[1]; |
| 209 | $partial = (isset($arr[2])) ? $arr[2] : $action; |
| 210 | |
| 211 | |
| 212 | $this->_partial = $controller . '/' . $action . '/' . $partial; |
| 213 | } |
| 214 | |
| 215 | public function getPartial() |
| 216 | { |
| 217 | return $this->_partial; |
| 218 | } |
| 219 | |
| 220 | public function getAlternatePartial() |
| 221 | { |
| 222 | list($controller, $action, $partial) = explode('/', $this->getPartial()); |
| 223 | return $controller . '/' . $action . '/_' . $partial; |
| 224 | } |
| 225 | |
| 226 | public function partial($name, $vars = array()) |
| 227 | { |
| 228 | |
| 229 | //TODO zrobienie partiali |
| 230 | $this->setPartial($name); |
| 231 | if(is_string($vars)) |
| 232 | { |
| 233 | if ($vars === 'all') |
| 234 | { |
| 235 | $vars = $this->getVariables(); |
| 236 | } |
| 237 | else |
| 238 | { |
| 239 | throw new somaException('nieprawidłowy parametr 2'); |
| 240 | } |
| 241 | } |
| 242 | |
| 243 | foreach ($vars as $nameVal => $value) |
| 244 | { |
| 245 | ${$nameVal} = $value; |
| 246 | } |
| 247 | |
| 248 | unset($nameVal); |
| 249 | unset($value); |
| 250 | unset($vars); |
| 251 | unset($name); |
| 252 | |
| 253 | |
| 254 | |
| 255 | |
| 256 | |
| 257 | ob_start(); |
| 258 | |
| 259 | |
| 260 | if (file_exists(SOMA_PROJECT_PATH . '/app/' . SOMA_APP_NAME . '/views/'. somaConfig::get('/config/templates_skin') . '/' . somaConfig::get('/config/templates_dir') . '/' .$this->getPartial().'.php')) |
| 261 | { |
| 262 | require(SOMA_PROJECT_PATH . '/app/' . SOMA_APP_NAME . '/views/'. somaConfig::get('/config/templates_skin') . '/' . somaConfig::get('/config/templates_dir') . '/' .$this->getPartial().'.php'); |
| 263 | } |
| 264 | else if(file_exists(SOMA_PROJECT_PATH . '/app/' . SOMA_APP_NAME . '/views/'. somaConfig::get('/config/templates_skin') . '/' . somaConfig::get('/config/templates_dir') . '/'. $this->getAlternatePartial() . '.php')) |
| 265 | { |
| 266 | require(SOMA_PROJECT_PATH . '/app/' . SOMA_APP_NAME . '/views/'. somaConfig::get('/config/templates_skin') . '/' . somaConfig::get('/config/templates_dir') . '/' . $this->getAlternatePartial() . '.php'); |
| 267 | } |
| 268 | else |
| 269 | { |
| 270 | throw new somaException('Nie znaleziono szablonu'); |
| 271 | } |
| 272 | |
| 273 | |
| 274 | return ob_get_clean(); |
| 275 | } |
| 276 | |
| 277 | public function getContent() |
| 278 | { |
| 279 | |
| 280 | foreach ($this->getVariables() as $name => $value) |
| 281 | { |
| 282 | ${$name} = $value; |
| 283 | } |
| 284 | unset($name); |
| 285 | unset($value); |
| 286 | |
| 287 | ob_start(); |
| 288 | |
| 289 | if (file_exists(SOMA_PROJECT_PATH . '/app/' . SOMA_APP_NAME . '/views/'. somaConfig::get('/config/templates_skin') . '/' . somaConfig::get('/config/templates_dir') . '/' .$this->getTemplate().'.php')) |
| 290 | { |
| 291 | require(SOMA_PROJECT_PATH . '/app/' . SOMA_APP_NAME . '/views/'. somaConfig::get('/config/templates_skin') . '/' . somaConfig::get('/config/templates_dir') . '/' .$this->getTemplate().'.php'); |
| 292 | } |
| 293 | else if(file_exists(SOMA_PROJECT_PATH . '/app/' . SOMA_APP_NAME . '/views/'. somaConfig::get('/config/templates_skin') . '/' . somaConfig::get('/config/templates_dir') . '/'. $this->getAlternateTemplate() . '.php')) |
| 294 | { |
| 295 | require(SOMA_PROJECT_PATH . '/app/' . SOMA_APP_NAME . '/views/'. somaConfig::get('/config/templates_skin') . '/' . somaConfig::get('/config/templates_dir') . '/' . $this->getAlternateTemplate() . '.php'); |
| 296 | } |
| 297 | else |
| 298 | { |
| 299 | throw new somaException('Nie znaleziono szablonu'); |
| 300 | } |
| 301 | |
| 302 | return ob_get_clean(); |
| 303 | } |
| 304 | |
| 305 | } |
| 1 |
<?php |
| 2 | |
| 3 | abstract class somaApplicationAbstract |
| 4 | { |
| 5 | |
| 6 | protected $uri; |
| 7 | |
| 8 | protected $controller; |
| 9 | |
| 10 | protected $controllerClassName; |
| 11 | |
| 12 | protected $_controllerInstance = null; |
| 13 | |
| 14 | protected $action; |
| 15 | |
| 16 | public static $controllers = array(); |
| 17 | |
| 18 | protected $actionMethod; |
| 19 | |
| 20 | protected $params; |
| 21 | |
| 22 | protected $_applicationExtensionClass = null; |
| 23 | |
| 24 | |
| 25 | /** |
| 26 | * Check if controller exists |
| 27 | * |
| 28 | */ |
| 29 | public static function controllerExists($controllerName) |
| 30 | { |
| 31 | $controllerClassPath = somaPath::getControllerClassPath($controllerName); |
| 32 | |
| 33 | if (!somaSystem::classInFile($controllerClassPath, $controllerName.'Controller')) |
| 34 | { |
| 35 | return false; |
| 36 | } |
| 37 | return true; |
| 38 | } |
| 39 | |
| 40 | |
| 41 | public function actionExists($controllerName, $actionName) |
| 42 | { |
| 43 | return method_exists($controllerName.'Controller', $actionName.'Action'); |
| 44 | } |
| 45 | |
| 46 | public function loadHelpers() |
| 47 | { |
| 48 | if (somaConfig::get('/config/i18n')) |
| 49 | { |
| 50 | require_once(SOMA_SOMAPHP_PATH.'/lib/helpers/somaI18n.helper.php'); |
| 51 | } |
| 52 | require_once(SOMA_SOMAPHP_PATH.'/lib/helpers/somaHTML.helper.php'); |
| 53 | require_once(SOMA_SOMAPHP_PATH.'/lib/helpers/somaString.helper.php'); |
| 54 | require_once(SOMA_SOMAPHP_PATH.'/lib/helpers/somaForm.helper.php'); |
| 55 | |
| 56 | } |
| 57 | |
| 58 | |
| 59 | |
| 60 | public function loadController() |
| 61 | { |
| 62 | |
| 63 | if(!$this->controllerExists($this->controller) && !$this->actionExists($this->controller, $this->action)) |
| 64 | { |
| 65 | if (($controller = somaConfig::get('/config/default_controller', false)) && ($action = somaConfig::get('/config/default_action', false))) |
| 66 | { |
| 67 | |
| 68 | $this->controller = $controller; |
| 69 | $this->action = $action; |
| 70 | |
| 71 | |
| 72 | |
| 73 | if (somaRequest::getRequestUri() == '/' && $this->controllerExists($controller) && $this->actionExists($controller, $action)) |
| 74 | { |
| 75 | $this->controllerClassName = $controller . 'Controller'; |
| 76 | $this->actionMethod = $action . 'Action'; |
| 77 | } |
| 78 | else if ((somaConfig::get('/config/default_controller') == 'index') && (somaConfig::get('/config/default_action') == 'index') && (somaRequest::getRequestUri() =='/')) |
| 79 | { |
| 80 | include(SOMA_SOMAPHP_PATH . '/data/templates/start.php'); |
| 81 | exit(0); |
| 82 | } |
| 83 | else if (somaConfig::get('/config/error404/URL', 0)) |
| 84 | { |
| 85 | somaController::redirect(somaConfig::get('/config/error404/URL', 0)); |
| 86 | exit(0); |
| 87 | } |
| 88 | else if (somaRequest::getRequestUri()) |
| 89 | { |
| 90 | include(SOMA_SOMAPHP_PATH . '/data/templates/error404.php'); |
| 91 | exit(0); |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | |
| 96 | |
| 97 | |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | |
| 102 | public function getControllerInstance() |
| 103 | { |
| 104 | if(!isset(self::$controllers[$this->controller])) |
| 105 | { |
| 106 | self::$controllers[$this->controller] = new $this->controllerClassName; |
| 107 | } |
| 108 | return self::$controllers[$this->controller]; |
| 109 | } |
| 110 | |
| 111 | |
| 112 | public function executeAction() |
| 113 | { |
| 114 | //ładowanie konfiguracji z kontrolera |
| 115 | $configHandler = new somaConfigHandler(); |
| 116 | $configHandler->loadController($this->controller, $this->action); |
| 117 | |
| 118 | $this->getControllerInstance()->setName($this->controller); |
| 119 | $this->getControllerInstance()->setAction($this->action); |
| 120 | |
| 121 | if(!$this->getControllerInstance()->getLayout()) |
| 122 | { |
| 123 | $this->getControllerInstance()->setLayout($this->controller . '/' . $this->action); |
| 124 | } |
| 125 | |
| 126 | |
| 127 | |
| 128 | if (somaConfig::get('/config/settings_from_database/enable') == 'on') |
| 129 | { |
| 130 | $configHandler->loadDatabase(); |
| 131 | } |
| 132 | |
| 133 | |
| 134 | |
| 135 | if ((somaConfig::get('/config/cli', 'off') !== 'on') && (somaConfig::get('/config/auth/enable') == 'on' )) |
| 136 | { |
| 137 | somaSession::initialize(); |
| 138 | |
| 139 | somaAuth::getInstance()->initialize(); |
| 140 | if (!(somaConfig::get('/config/auth/allowall', null)) && !somaAuth::getInstance()->isAuthenticateTo($this->controller . '/' . $this->action) ) |
| 141 | { |
| 142 | $c = new somaController(); |
| 143 | $c->redirect(somaConfig::get('/config/auth/forbidden/name'), somaConfig::get('/config/auth/forbidden/params')); |
| 144 | exit(); |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | |
| 149 | somaRequest::validate($this->controller . '/' . $this->action); |
| 150 | |
| 151 | if(method_exists($this->getControllerInstance(), 'validate' . ucfirst($this->action))) |
| 152 | { |
| 153 | call_user_func(array($this->getControllerInstance(), 'validate' . ucfirst($this->action))); |
| 154 | } |
| 155 | |
| 156 | $css = somaConfig::get('/config/layout/css', array()); |
| 157 | $js = somaConfig::get('/config/layout/js', array()); |
| 158 | $meta = somaConfig::get('/config/layout/meta', array()); |
| 159 | |
| 160 | foreach ($css as $name => $file) |
| 161 | { |
| 162 | $media = (isset($file['media'])) ? $file['media'] : 'screen'; |
| 163 | somaView::getInstance()->addCss($name, $file['href'], $media); |
| 164 | } |
| 165 | |
| 166 | foreach ($js as $name => $file) |
| 167 | { |
| 168 | somaView::getInstance()->addJsScript($name, $file); |
| 169 | } |
| 170 | |
| 171 | foreach ($meta as $name => $content) |
| 172 | { |
| 173 | somaView::getInstance()->addMeta($name, $content); |
| 174 | } |
| 175 | |
| 176 | |
| 177 | somaController::execute($this->controller . '/' . $this->action); |
| 178 | |
| 179 | |
| 180 | |
| 181 | |
| 182 | //call_user_func(array($this->getControllerInstance(), $this->actionMethod)); |
| 183 | |
| 184 | |
| 185 | } |
| 186 | |
| 187 | public function resolveAction() |
| 188 | { |
| 189 | |
| 190 | somaRequest::initialize(); |
| 191 | |
| 192 | if (somaConfig::get('/config/cli', 'off') !== 'on') |
| 193 | { |
| 194 | $router = new somaRouter(); |
| 195 | |
| 196 | $requestInfo = $router->dispatch(new somaUri(somaRequest::getRequestUri())); |
| 197 | |
| 198 | if(isset($requestInfo['params']) && is_array($requestInfo['params'])) |
| 199 | { |
| 200 | somaRequest::setParams($requestInfo['params']); |
| 201 | } |
| 202 | |
| 203 | $this->controller = $requestInfo['controller']; |
| 204 | $this->action = $requestInfo['action']; |
| 205 | } |
| 206 | else |
| 207 | { |
| 208 | $this->controller = somaConfig::get('/config/default_controller', false); |
| 209 | $this->action = somaConfig::get('/config/default_action', false); |
| 210 | $this->controllerExists($this->controller); |
| 211 | $this->controllerClassName = $this->controller.'Controller'; |
| 212 | require_once(SOMA_SOMAPHP_PATH . '/data/soma/app/generator/controllers/create/create.php'); |
| 213 | self::$controllers[$this->controller] = new $this->controllerClassName; |
| 214 | } |
| 215 | |
| 216 | |
| 217 | |
| 218 | |
| 219 | $this->controllerClassName = $this->controller.'Controller'; |
| 220 | $this->actionMethod = $this->action.'Action'; |
| 221 | |
| 222 | $this->loadController(); |
| 223 | |
| 224 | } |
| 225 | |
| 226 | |
| 227 | |
| 228 | public function getApplicationExtensionClass() |
| 229 | { |
| 230 | if ($this->_applicationExtensionClass === null) |
| 231 | { |
| 232 | $returnedClass = 'somaApplicationExtension'; |
| 233 | |
| 234 | $className = 'somaApplicationProject'; |
| 235 | $classPath = SOMA_PROJECT_PATH . '/lib/' . $className . '.class.php'; |
| 236 | if (somaSystem::classInFile($classPath, $className)) |
| 237 | { |
| 238 | $returnedClass = $className; |
| 239 | } |
| 240 | |
| 241 | $className = 'somaApplicationApp'; |
| 242 | $classPath = SOMA_PROJECT_PATH . '/app/' . SOMA_APP_NAME . '/lib/' . $className . '.class.php'; |
| 243 | if (somaSystem::classInFile($classPath, $className)) |
| 244 | { |
| 245 | $returnedClass = $className; |
| 246 | } |
| 247 | |
| 248 | $className = 'somaApplicationController'; |
| 249 | $classPath = SOMA_PROJECT_PATH . '/app/' . SOMA_APP_NAME . '/controllers/' . $this->controller . '/lib/' . $className . '.class.php'; |
| 250 | if (somaSystem::classInFile($classPath, $className)) |
| 251 | { |
| 252 | $returnedClass = $className; |
| 253 | } |
| 254 | |
| 255 | $this->_applicationExtensionClass = new $returnedClass(); |
| 256 | } |
| 257 | |
| 258 | return $this->_applicationExtensionClass; |
| 259 | } |
| 260 | |
| 261 | |
| 262 | public function executePreAction() |
| 263 | { |
| 264 | $this->getApplicationExtensionClass()->preAction(); |
| 265 | } |
| 266 | |
| 267 | public function executePostAction() |
| 268 | { |
| 269 | $this->getApplicationExtensionClass()->postAction(); |
| 270 | } |
| 271 | |
| 272 | public function dispatch() |
| 273 | { |
| 274 | |
| 275 | |
| 276 | |
| 277 | $this->loadHelpers(); |
| 278 | somaDB::initDoctrine(); |
| 279 | |
| 280 | |
| 281 | |
| 282 | |
| 283 | $this->resolveAction(); |
| 284 | |
| 285 | if(strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 6.0') !== false) |
| 286 | { |
| 287 | $this->controller = somaConfig::get('/config/ie6/controller'); |
| 288 | $this->action = somaConfig::get('/config/ie6/action'); |
| 289 | } |
| 290 | |
| 291 | |
| 292 | try |
| 293 | { |
| 294 | |
| 295 | $this->executePreAction(); |
| 296 | $this->executeAction(); |
| 297 | $this->executePostAction(); |
| 298 | |
| 299 | } |
| 300 | catch(somaException $e) |
| 301 | { |
| 302 | somaController::redirect(somaConfig::get('/config/error404/URL', 0)); |
| 303 | } |
| 304 | |
| 305 | $view = somaView::getInstance(); |
| 306 | $view->addVariables($this->getControllerInstance()->exportVariables()); |
| 307 | $view->setLayout($this->getControllerInstance()->getLayout()); |
| 308 | $view->setTemplate($this->getControllerInstance()->getTemplate()); |
| 309 | |
| 310 | |
| 311 | if(!$view->getMeta('content-type')) |
| 312 | { |
| 313 | $type = somaConfig::get('/config/layout/type'); |
| 314 | $charset = somaConfig::get('/config/layout/charset'); |
| 315 | $meta = $type . '; charset=' . $charset; |
| 316 | $view->addMeta('Content-Type', $meta); |
| 317 | } |
| 318 | |
| 319 | $response = $view->render(); |
| 320 | echo $response; |
| 321 | |
| 322 | |
| 323 | |
| 324 | } |
| 325 | } |
| 326 |
| 1 |
<?php |
| 2 | /** |
| 3 | * SomaPHP |
| 4 | * |
| 5 | * Copyright (C) 2007 Krzysztof Kowalik <krzysztof.kowalik@somaphp.net> |
| 6 | * |
| 7 | * This library is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU Lesser General Public |
| 9 | * License Version 3 as published by the Free Software Foundation. |
| 10 | * |
| 11 | * You should have received a copy of the GNU Lesser General Public |
| 12 | * License along with this library in the file LICENSE.txt. |
| 13 | * If not, it is available at URL http://www.somaphp.net/license |
| 14 | * |
| 15 | * @license http://www.somaphp.net/license GNU Lesser General Public |
| 16 | * @author Krzysztof Kowalik |
| 17 | * @copyright Copyright (C) 2007 Krzysztof Kowalik |
| 18 | * @package SomaPHP |
| 19 | * @version SVN: $Id: Soma.php 87 2008-05-12 05:19:56Z kowalikus $ |
| 20 | */ |
| 21 | |
| 22 | /** |
| 23 | * Główna klasa frameworka. Inicjuje wykonanie frameworka |
| 24 | * |
| 25 | * @package SomaPHP |
| 26 | * @final |
| 27 | */ |
| 28 | final class Soma |
| 29 | { |
| 30 | /** |
| 31 | * numer wersji frameworka |
| 32 | */ |
| 33 | const VERSION = '0.1.0'; |
| 34 | |
| 35 | /** |
| 36 | * Ładuje plik z klasą |
| 37 | * |
| 38 | * @param string nazwa klasy |
| 39 | * @return void |
| 40 | * @static |
| 41 | */ |
| 42 | static public function load($className) |
| 43 | { |
| 44 | |
| 45 | $autoload = somaConfig::get('/autoload'); |
| 46 | |
| 47 | if(isset($autoload[$className])) |
| 48 | { |
| 49 | //Próba załadowania z tablicy autoload |
| 50 | if(file_exists($autoload[$className])) |
| 51 | { |
| 52 | require_once($autoload[$className]); |
| 53 | } |
| 54 | } |
| 55 | else |
| 56 | { |
| 57 | |
| 58 | $pathToAppLib = SOMA_PROJECT_PATH . '/app/' . SOMA_APP_NAME . '/lib/'; |
| 59 | |
| 60 | $fileName = $pathToAppLib . $className . '.class.php'; |
| 61 | if(file_exists($fileName)) |
| 62 | { |
| 63 | require_once($fileName); |
| 64 | } |
| 65 | |
| 66 | |
| 67 | |
| 68 | |
| 69 | //Próba załadowania z katalogu models |
| 70 | |
| 71 | $pathToModels = SOMA_PROJECT_PATH . '/models/'; |
| 72 | $fileName = $pathToModels . $className . '.php'; |
| 73 | if(file_exists($fileName)) |
| 74 | { |
| 75 | require_once($fileName); |
| 76 | } |
| 77 | else |
| 78 | { |
| 79 | //Próba załadowania z katalogu models/generated |
| 80 | $pathToModels = SOMA_PROJECT_PATH . '/models/generated/'; |
| 81 | $fileName = $pathToModels . $className . '.php'; |
| 82 | if(file_exists($fileName)) |
| 83 | { |
| 84 | require_once($fileName); |
| 85 | } |
| 86 | |
| 87 | } |
| 88 | |
| 89 | |
| 90 | |
| 91 | |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * Ładuje plik z helperem |
| 97 | * |
| 98 | * @param string nazwa helpera |
| 99 | * @static |
| 100 | * @return void |
| 101 | */ |
| 102 | static public function loadHelper($name) |
| 103 | { |
| 104 | somaSystem::loadFile(SOMA_SOMAPHP_PATH . '/lib/helpers/' . $name . '.helper.php'); |
| 105 | } |
| 106 | |
| 107 | /** |
| 108 | * Automatyczne ładowanie plików z klasami |
| 109 | * |
| 110 | * @param string nazwa klasy |
| 111 | * @static |
| 112 | * @return void |
| 113 | */ |
| 114 | static public function autoload($className) |
| 115 | { |
| 116 | self::load($className); |
| 117 | } |
| 118 | |
| 119 | |
| 120 | /** |
| 121 | * Ustawia poziom raportowania błędów. |
| 122 | * Inicjuje obiekt odpowiedzialny za konfigurację |
| 123 | * Ustawia ścieżkę przeszukiwania |
| 124 | * |
| 125 | * @static |
| 126 | * @return void |
| 127 | */ |
| 128 | static public function init() |
| 129 | { |
| 130 | error_reporting(SOMA_ERROR_LEVEL); |
| 131 | |
| 132 | ini_set('display_errors', 1); |
| 133 | |
| 134 | set_include_path(get_include_path() . PATH_SEPARATOR . SOMA_PROJECT_PATH . '/models/'); |
| 135 | |
| 136 | require_once(SOMA_SOMAPHP_PATH . '/lib/utility/somaException.class.php'); |
| 137 | require_once(SOMA_SOMAPHP_PATH . '/lib/utility/somaArray.class.php'); |
| 138 | require_once(SOMA_SOMAPHP_PATH . '/lib/base/somaCollection.class.php'); |
| 139 | |
| 140 | require_once(SOMA_SOMAPHP_PATH . '/lib/config/somaConfig.class.php'); |
| 141 | |
| 142 | |
| 143 | |
| 144 | |
| 145 | somaConfig::initialize(); |
| 146 | |
| 147 | spl_autoload_register(array('Soma', 'autoload')); |
| 148 | |
| 149 | self::register3rdparty(); |
| 150 | |
| 151 | } |
| 152 | |
| 153 | /** |
| 154 | * Uruchamia frameworka |
| 155 | * |
| 156 | * @static |
| 157 | * @return void |
| 158 | */ |
| 159 | static public function run() |
| 160 | { |
| 161 | try |
| 162 | { |
| 163 | self::init(); |
| 164 | |
| 165 | |
| 166 | $application = new somaApplication(); |
| 167 | $application->dispatch(); |
| 168 | } |
| 169 | catch (somaException $e) |
| 170 | { |
| 171 | $e->printTrace(); |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | /** |
| 176 | * Rejestruje plugin w systemie |
| 177 | * |
| 178 | * @package string nazwa pluginu |
| 179 | * @return void |
| 180 | */ |
| 181 | public function register3rdparty() |
| 182 | { |
| 183 | $components = somaConfig::get('/config/3rdparty/enable', array()); |
| 184 | |
| 185 | $bridge = new somaBridge(); |
| 186 | |
| 187 | foreach ($components as $component) |
| 188 | { |
| 189 | call_user_func(array('somaBridge', 'enable' . ucfirst($component))); |
| 190 | } |
| 191 | } |
| 192 | |
| 193 | } |
| 194 | |
| 195 | /** |
| 196 | * Automatyczne ładowanie plików z klasami |
| 197 | * |
| 198 | * @see Soma::autoload |
| 199 | */ |
| 200 | |
| 201 | /* |
| 202 | function __autoload($className) |
| 203 | { |
| 204 | Soma::autoload($className); |
| 205 | Doctrine::autoload($className); |
| 206 | } |
| 207 | */ |
| 208 | |
| 209 | //spl_autoload_register(array('Doctrine', 'autoload')); |
| 210 | |
| 211 | |
| 212 |
| 1 |
<?php |
| 2 | |
| 3 | define('SOMA_PROJECT_PATH', realpath(dirname(__FILE__) . '/../../project')); |
| 4 | define('SOMA_SOMAPHP_PATH', "./../../somaPHP"); |
| 5 | define('SOMA_WWW_PATH', realpath(dirname(__FILE__))); |
| 6 | define('SOMA_APP_NAME', 'main'); |
| 7 | define('SOMA_ENV', 'prod'); |
| 8 | define('SOMA_ERROR_LEVEL', E_ALL); |
| 9 | define('SOMA_LOG_LEVEL', 1); |
| 10 | define('SOMA_CACHE_LEVEL', 5); |
| 11 | |
| 12 | require_once(SOMA_SOMAPHP_PATH.'/lib/Soma.php'); |
| 13 | |
| 14 | Soma::run(); |