diff --git a/.phpunit.result.cache b/.phpunit.result.cache deleted file mode 100644 index 0778e9c..0000000 --- a/.phpunit.result.cache +++ /dev/null @@ -1 +0,0 @@ -C:30:"PHPUnit\Runner\TestResultCache":204:{a:2:{s:7:"defects";a:1:{s:29:"TestEnum::testInstantiateEnum";i:3;}s:5:"times";a:3:{s:25:"TestEnum::testValidOption";d:0;s:25:"TestEnum::testIsValidName";d:0;s:29:"TestEnum::testInstantiateEnum";d:0.003;}}} \ No newline at end of file diff --git a/composer.json b/composer.json index 49cc7a4..bb0750e 100644 --- a/composer.json +++ b/composer.json @@ -2,6 +2,7 @@ "name": "avior/admin-panel", "type": "project", "license": "MIT License", + "description": "WIP Project", "authors": [ { "name": "Avior", @@ -9,12 +10,8 @@ } ], "autoload": { - "classmap": [ - "src/admin/system/" - ] - }, - "require": {}, - "require-dev": { - "phpunit/phpunit": "^8" + "psr-4": { + "AdminPanel\\": "src/" + } } } diff --git a/src/.htaccess b/src/.htaccess index 2c5ea01..7d55645 100644 --- a/src/.htaccess +++ b/src/.htaccess @@ -1,4 +1,4 @@ RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f -RewriteRule ^(.*)$ ./admin/init.php [L,QSA] +RewriteRule ^(.*)$ ./index.php [L,QSA] diff --git a/src/Classes/Controller.php b/src/Classes/Controller.php new file mode 100644 index 0000000..e620480 --- /dev/null +++ b/src/Classes/Controller.php @@ -0,0 +1,10 @@ +routeList[$regex] = $function; - } - - public function search(String $route) { - foreach ($this->routeList as $key => $value) { - if(preg_match($key, $route)) { - return $value; - } - } - return null; - } - - -} diff --git a/src/admin/system/functions.php b/src/admin/system/functions.php deleted file mode 100644 index ed85c5e..0000000 --- a/src/admin/system/functions.php +++ /dev/null @@ -1,55 +0,0 @@ - diff --git a/src/admin/system/modules.php b/src/admin/system/modules.php deleted file mode 100644 index 54906e0..0000000 --- a/src/admin/system/modules.php +++ /dev/null @@ -1,75 +0,0 @@ -items, $menu); - } - - public function addItem(Item $item) { - array_push($this->items, $item); - } -} - -class Item { - - private $name; - private $url; - private $function; - - - - public function toLoad($function) { - $this->function = $function; - } - -} - -class OptionItem extends Item { - /* - - */ -} - - -abstract class Module { - -} diff --git a/src/admin/system/router.php b/src/admin/system/router.php deleted file mode 100644 index 173437e..0000000 --- a/src/admin/system/router.php +++ /dev/null @@ -1,55 +0,0 @@ -routeList[$route] = $page; - } - - //fonction de recherche d'une route par rapport a un texte - //return function - public function search($path) { - foreach ($this->routeList as $reg => $page) { - if(preg_match($reg, $path)) { - return $page; - } - } - return function () { - return "404"; - }; - } - - public function redirecter($source, $redirectPage) { - $this->addRoute($source, function() { - header("Location: " . $redirectPage); - }); - } -} diff --git a/src/admin/system/website.php b/src/admin/system/website.php deleted file mode 100644 index a35c1ba..0000000 --- a/src/admin/system/website.php +++ /dev/null @@ -1,40 +0,0 @@ -root = $root; - } - - private function getTemplateFileURI() { - return $this->root . "/admin/settings/" . self::TEMPLATEJSON; - } - - public function addTemplate(String $name, String $path, String $func, $bool) { - var_dump($_SERVER); - - $val = array( - $name => array( - "URI" => $path, - "function" => $func, - "static" => $bool - ) - ); - if(! file_exists($this->getTemplateFileURI())) { - file_put_contents($this->getTemplateFileURI(), json_encode($val)); - } else { - $json = json_decode(file_get_contents($this->getTemplateFileURI()), true); - $json = array_merge($json, $val); - file_put_contents($this->getTemplateFileURI(), json_encode($json)); - } - } - - public function addJS() { - - } -} diff --git a/src/index.php b/src/index.php new file mode 100644 index 0000000..957bce0 --- /dev/null +++ b/src/index.php @@ -0,0 +1,73 @@ +routes as $routeName => $routeArgs) { + $args = isset($routeArgs->args) ? $routeArgs->args : new stdClass(); + + if(slugEqualToURI($routeArgs->path, $_SERVER["REQUEST_URI"], $args)) { + $loader->loadClass($routeArgs->controller); + $function = $routeArgs->function; + echo (new $routeArgs->controller)->$function(); + die; + } + } + } +} + + +// echo Controller::example(); + +// require_once ROOT . "/system/router.php"; + +// define("ROUTER", Router::getRouter()); +function startsWith($haystack, $needle) +{ + $length = strlen($needle); + return (substr($haystack, 0, $length) === $needle); +} + +/** + * @param string $uri + * @param string $slug + * @param object $options options->regex &| options->setting + * + * @return bool + */ +function slugEqualToURI($slug, $uri, $options) { + $uri = explode("/", trim($uri, "\/")); + $slug = explode("/", trim($slug, '\/')); + + if(count($uri) != count($slug)) return false; + + foreach ($slug as $key => $value) { + + if(preg_match("/{.+}/", $value)) { + $elemnt = preg_replace("/{|}/", "", $value); + $elOptions = $options->$elemnt; + if($elOptions->regex != null && preg_match($elOptions->regex, $uri[$key])) continue; + else return false; + //TODO correspond with module settings + } else { + if($value == $uri[$key]) continue; + else return false; + } + } + return true; +} diff --git a/src/test.php b/src/test.php deleted file mode 100644 index 8c4f0d8..0000000 --- a/src/test.php +++ /dev/null @@ -1,37 +0,0 @@ -
pouet