Chciałby prosić o ocenę oraz konstruktywną krytykę mojej klasy Route. Domyślam się że jest w niej dużo rzeczy do poprawny, udoskonalenia. Dopiero zaczynam na "poważnie" swoją przygode z OOP (w całości w php jestem samoukiem). Także prosze o wytknięci błędów.
Plik Route.php
/** * @autor: Rafał Kowalski * @version: 1.0 * @date release: 2.09.2013r */ class Route{ private $_url; private $_directory; private $_controller; private $_action; private $_param; public function __construct( $directory ) { $this->_url = $_SERVER['REQUEST_URI']; $this->_directory = $directory; $this->getParam(); } private function explodeURL( ) { } private function isAdmin( ) { { return true; } else { return false; } } private function getParam( ) { $array_MVC = $this->explodeURL(); if ( $this->isAdmin( ) ) { $this->_controller = $array_MVC[2]; $this->_action = $array_MVC[3]; $this->_param = (int)$array_MVC[4]; } else { $this->_controller = $array_MVC[1]; $this->_action = $array_MVC[2]; $this->_param = (int)$array_MVC[3]; } } public function isController( ) { { if( $this->isAdmin() ) { $this->_controller = 'Login'; } else { $this->_controller = 'Default'; } } else { foreach( $this->_directory as $path ) { { return true; } else { return false; } } } } public function defaultMethod( ) { { $this->_action = 'index()'; } } public function isParam( ) { { return false; } else { return true; } } public function run( ) { try { if( $this->isController( ) ) { $controller = new $this->_controller; $action = $this->_action; if( $this->isParam() ) { $controller->$action(); } else { $controller->$action( $this->_param); } } else { throw new RuntimeException("Błędne wywołanie skryptu"); } } catch( RuntimeException $e ) { Plik: '.$e->getFile().'<br /> Numer lini: '.$e->getLine().'<br /> Znak: '.$e->getTraceAsString(); exit; } } }
Oraz jego użycie index.php
include 'core/Route.php'; $route = new Route( $directory ); $route->run();