W porządku Pyton

Jutro zerknę, bo dzisiaj już nie mam siły :/ Wrzucam dwie klasy, żeby widać było jak to mniej więcej wygląda(jakby mógł ktoś też powiedzieć czy idę w dobrą stronę, czy też złą byłbym wdzięczny):
<?php
namespace Router;
use Router\Components\Request;
use Router\IAbstract\AbstractRouter;
use Router\Components\Url;
class Router extends AbstractRouter
{
protected $routes = [];
protected $module;
protected $controller;
protected $action;
protected $params = [];
protected $regex = [
':module' => '#(^[\a-zA-Z]*)$#',
':controller' => '#(^[a-zA-Z]*)$#',
':action' => '#(^[-a-zA-Z]*)$#',
':name' => '#(^[-a-zA-Z]*)$#',
':param' => '#(^[0-9]*)$#'
];
protected $regex_keys = [];
private $default_module;
private $default_controller;
private $default_action;
protected $request;
public function __construct()
{
$this->module = '';
$this->default_module = '';
$this->default_controller = '';
$this->default_action = '';
$this->setRequest(new Request());
$this->setRegexKeys();
}
public function add
($path, Array $route) {
$combine[] = $path;
$combine[] = $route;
$this->routes[] = $combine;
return $this;
}
public function remove
(Array $route) {
foreach ($this->routes as $i => $stored) {
if ($stored == $route) {
unset($this->routes[$i]); }
}
}
public function resolve()
{
$path_info = $this->routeArray(new Url());
// i tutaj właśnie to prawdopodobne łączenia z getem, albo osobna funkcja
//var_dump($_GET);
//$path_info = array();
//var_dump($path_info);
/*if (empty($path_info)) {
echo 'cos2';
$path = key($_GET);
$path_info = explode('/', trim($path, '/'));
//$path_info = array_values($_GET);
//unset($_GET);
//var_dump($_GET);
var_dump($path_info);
}*/
foreach ($this->routes as $element) {
if (true === $this->searchAddress($address, $path_info)) {
$this->setElementIfExist('module', $address, $element[1], $path_info);
$check_controller = $this->setElementIfExist('controller', $address, $element[1], $path_info);
$check_action = $this->setElementIfExist('action', $address, $element[1], $path_info);
if ($check_controller && $check_action) {
$this->setParams($path_info, $values, $address);
$action_array['module'] = $this->module;
$action_array['controller'] = $this->controller;
$action_array['action'] = $this->action;
$action_array['params'] = $this->params;
return true;
} else {
empty($this->module) ?
$action_array['module'] = $this->default_module : $action_array['module'] = $this->module;
$action_array['controller'] = $this->default_controller;
$action_array['action'] = $this->default_action;
}
}
}
return false;
}
private function setParams($path_info, $values, $address)
{
$index = 1;
for ($i=0; $i<count($path_info); $i++) {
if (preg_match("#(^[:{1}][a-zA-Z]+)#", $address[$i]) && $path_info[$i] != $this->controller && $path_info[$i] != $this->action && $path_info[$i] != $this->module) { $this->params[$index] = $path_info[$i];
$index++;
} else {
if ($address[$i] == $path_info[$i] && $address[$i] != $this->controller && $address[$i] != $this->action && $path_info[$i] != $this->module) {
foreach ($values as $value) {
if ($value == $path_info[$i]) {
$this->params[$index] = $path_info[$i];
$index++;
}
}
}
}
}
}
public function setDefaultModule($namespace)
{
$this->default_module = $this->stringFilter($namespace);
}
public function setDefaultController($controller)
{
$this->default_controller = $this->stringFilter($controller);
}
public function setDefaultAction($action)
{
$this->default_action = $this->stringFilter($action);
}
protected function setRequest(Request $request)
{
$this->request = $request;
}
public function request($type, $action=null)
{
$this->request->parse($type, $action);
}
}
i druga klasa Abstract:
<?php
namespace Router\IAbstract;
use Router\Components\Url;
abstract class AbstractRouter implements IRouter
{
protected $routes = [];
protected $module;
protected $controller;
protected $action;
protected $params = [];
protected $regex = [];
protected $regex_keys = [];
protected $index;
protected function setRegexKeys()
{
}
protected
function searchAddress
(Array $routes, Array $path_info) {
// parse to GET
for ($i = 0; $i < count($path_info); $i++) {
return false;
}
if (preg_match("#(^[:]{1}[a-zA-Z])#", $routes[$i])) {
$is_exist = false;
foreach ($this->regex_keys as $key) {
if ($key == $routes[$i]) {
if (preg_match($this->regex[$key], $path_info[$i])) { // klucze nienumeryczne!! $is_exist = true;
break;
}
}
}
if (false === $is_exist) {
return false;
}
} else {
if (isset($path_info[$i])) { if ($path_info[$i] == $routes[$i]) {
if ($i == count($path_info)) { return false;
}
}
} else {
return false;
}
}
}
}
return true;
}
protected
function setElementIfExist
($name, Array $address, Array $element, Array $path_info) {
foreach ($element as $key => $value) {
for ($i=0; $i < count($path_info); $i++) {
if ($address[$i] == $value) {
$this->$name = $address[$i];
return true;
} else {
for ($j=0; $j < count($address); $j++) { if (preg_match('#(^[:]{1}[a-zA-Z])#', $address[$j])) {
if ($name == $addr) {
++$this->index;
if ($this->index == $value) {
$this->$name = $path_info[$j];
return true;
}
}
}
}
}
}
}
}
}
return false;
}
protected function stringFilter($string)
{
$string = filter_var($string, FILTER_SANITIZE_STRING);
$string = filter_var($string, FILTER_SANITIZE_FULL_SPECIAL_CHARS);
return $string;
}
public function routeArray(Url $url)
{
$url->divideAddress($url->getAddress());
return $url->getActions();
}
}
Zaawansowane to myśle to to nie jest, ale na początek pisania myślę tragedii chyba nie ma

Pozdrawiam,
szubi
Nie napisałem wcześniej: Nie wzoruję się na niczym w zasadzie. Zerknąłem do Cake'a i szczerze powiedziawszy zainteresował mnie ten fragmencik:
Router::connect(
"/:controller/:id",
array("action" => "edit", "[method]" => "PUT"), );
ale wolałbym chyba zrobić osobną klasę Request i w takiej mniej więcej formie to definiować:
$router->add(
'/admin/users/show/:param',
'controller' => 'users',
'action' => 'show',
'param' => 1
)
)->request('get');
A wracając do mojego pytania:
Połączyłem path_info z getem i w tej chwili to wygląda tak:
http://localhost/index/admin/users/show/?param=2 -> wysłane getem z formularza
http://localhost/index/admin/users/show/2 -> sam path_info
Jeśli get istnieje to zostaje dołączony do tablicy path_info razem ze swoim indeksem. Działa pod jednym warunkiem. Kiedy jego klucz jest taki sam jak klucz zdefiniowany w drugiej tablicy(akcji):
?
param=2
'controller' => 'users',
'action' => 'show',
'PARAM' => 1
)
Trochę ograniczenie, ale z drugiej strony normalnie też to tak raczej wygląda, bo przecież klucz nie powinien być bez znaczenia.
Teraz oba adresy zwracają dokładnie to samo, ale nie jestem do końca pewien tego rozwiązania. Czy mógłbym prosić o jakieś wskazówki?
Pozdrawiam,
szubi