mirror of
https://github.com/Aviortheking/DeltaCMS.git
synced 2025-04-23 03:12:14 +00:00
Reworked most file to respect PSR-2
This commit is contained in:
parent
fb3249fa74
commit
5d522a2064
6
.phpcs.xml
Normal file
6
.phpcs.xml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="PSR2" xsi:noNamespaceSchemaLocation="../../../phpcs.xsd">
|
||||||
|
<description>The PSR-2 coding standard.</description>
|
||||||
|
<arg name="tab-width" value="4"/>
|
||||||
|
<rule ref="PSR1"/>
|
||||||
|
<rule ref="PSR2"/>
|
||||||
|
</ruleset>
|
@ -13,6 +13,19 @@
|
|||||||
"psr-4": {
|
"psr-4": {
|
||||||
"AdminPanel\\": "src/AdminPanel",
|
"AdminPanel\\": "src/AdminPanel",
|
||||||
"": "src/Modules"
|
"": "src/Modules"
|
||||||
}
|
},
|
||||||
|
"exclude-from-classmap": [
|
||||||
|
"src/Modules"
|
||||||
|
],
|
||||||
|
"files": [
|
||||||
|
"src/AdminPanel/Functions.php"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"twig/twig": "^2.7"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"squizlabs/php_codesniffer": "^3.4",
|
||||||
|
"symfony/var-dumper": "^4.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
43
src/AdminPanel/Classes/AdminPanel.php
Normal file
43
src/AdminPanel/Classes/AdminPanel.php
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace AdminPanel\Classes;
|
||||||
|
|
||||||
|
use Twig\Loader\FilesystemLoader;
|
||||||
|
use Twig\Environment;
|
||||||
|
|
||||||
|
class AdminPanel
|
||||||
|
{
|
||||||
|
/** @var AdminPanel $instance */
|
||||||
|
private static $instance = null;
|
||||||
|
public static function getInstance()
|
||||||
|
{
|
||||||
|
if (!isset(AdminPanel::$instance)) {
|
||||||
|
AdminPanel::$instance = new self();
|
||||||
|
Cache::getInstance()->addTemplateFolder("/AdminPanel/Twig");
|
||||||
|
AdminPanel::$instance->addLoaderFolder(ROOT . "/AdminPanel/Twig");
|
||||||
|
}
|
||||||
|
return AdminPanel::$instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
private $loader;
|
||||||
|
public function getLoader()
|
||||||
|
{
|
||||||
|
return $this->loader;
|
||||||
|
}
|
||||||
|
public function addLoaderFolder(String $path, String $prefix = "AdminPanel")
|
||||||
|
{
|
||||||
|
$this->loader->addPath($path, $prefix);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @var \Twig\Environment $twig */
|
||||||
|
private $twig;
|
||||||
|
public function getTwig()
|
||||||
|
{
|
||||||
|
return isset($this->twig) ? $this->twig : $this->twig = new Environment($this->loader);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->loader = new FilesystemLoader();
|
||||||
|
}
|
||||||
|
}
|
23
src/AdminPanel/Classes/Authentificator.php
Normal file
23
src/AdminPanel/Classes/Authentificator.php
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace AdminPanel\Classes;
|
||||||
|
|
||||||
|
class Authentificator
|
||||||
|
{
|
||||||
|
|
||||||
|
/** @var Authentificator $instance */
|
||||||
|
private static $instance = null;
|
||||||
|
private $isLoggedIn = false;
|
||||||
|
public static function getInstance()
|
||||||
|
{
|
||||||
|
if (!isset(Authentificator::$instance)) {
|
||||||
|
Authentificator::$instance = new self();
|
||||||
|
}
|
||||||
|
return Authentificator::$instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isLoggedIn()
|
||||||
|
{
|
||||||
|
return $this->isLoggedIn;
|
||||||
|
}
|
||||||
|
}
|
48
src/AdminPanel/Classes/Cache.php
Normal file
48
src/AdminPanel/Classes/Cache.php
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace AdminPanel\Classes;
|
||||||
|
|
||||||
|
class Cache
|
||||||
|
{
|
||||||
|
/** @var Cache $instance */
|
||||||
|
private static $instance = null;
|
||||||
|
private static $folder = "../cache/";
|
||||||
|
private static $tpFileName = "templates.json";
|
||||||
|
private static $templates;
|
||||||
|
|
||||||
|
public static function getInstance()
|
||||||
|
{
|
||||||
|
if (!isset(Cache::$instance)) {
|
||||||
|
Cache::$instance = new self();
|
||||||
|
}
|
||||||
|
return Cache::$instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
if (!is_dir(Cache::$folder)) {
|
||||||
|
mkdir(Cache::$folder);
|
||||||
|
}
|
||||||
|
Cache::$templates = Cache::$folder . Cache::$tpFileName;
|
||||||
|
if (!is_file(Cache::$templates)) {
|
||||||
|
$fp = fopen(Cache::$templates, "wb");
|
||||||
|
fwrite($fp, "{}");
|
||||||
|
fclose($fp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addTemplateFolder(string $folder, string $namespace = "AdminPanel")
|
||||||
|
{
|
||||||
|
$fp = fopen(Cache::$templates, "wb");
|
||||||
|
$json = file_get_contents(Cache::$templates);
|
||||||
|
// $json = json_decode(fread($fp, filesize(Cache::$templates)));
|
||||||
|
$json[$folder] = $namespace;
|
||||||
|
fwrite($fp, json_encode($json));
|
||||||
|
fclose($fp);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addRoute(string $name, string $path, string $controller, string $function, $options = array())
|
||||||
|
{
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
|
}
|
@ -2,18 +2,36 @@
|
|||||||
|
|
||||||
namespace AdminPanel\Classes;
|
namespace AdminPanel\Classes;
|
||||||
|
|
||||||
class Controller {
|
use Twig\Loader\FilesystemLoader;
|
||||||
|
use Twig\Environment;
|
||||||
|
|
||||||
protected $urlArguments = array();
|
class Controller
|
||||||
|
{
|
||||||
|
|
||||||
public function setUrlArguments($args) {
|
protected $urlArguments = array();
|
||||||
$this->urlArguments = $args;
|
protected $moduleRoot = null;
|
||||||
}
|
|
||||||
|
|
||||||
protected function getUrlArguments() {
|
public function setUrlArguments($args)
|
||||||
return $this->urlArguments;
|
{
|
||||||
}
|
$this->urlArguments = $args;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getUrlArguments()
|
||||||
|
{
|
||||||
|
return $this->urlArguments;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setModuleRoot($root)
|
||||||
|
{
|
||||||
|
$this->moduleRoot = $root;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getModuleRoot()
|
||||||
|
{
|
||||||
|
return $this->moduleRoot;
|
||||||
|
}
|
||||||
|
|
||||||
//TODO implements functions and variables to add functionnalities to controllers
|
//TODO implements functions and variables to add functionnalities to controllers
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,45 +2,51 @@
|
|||||||
|
|
||||||
namespace AdminPanel\Classes\Enum;
|
namespace AdminPanel\Classes\Enum;
|
||||||
|
|
||||||
abstract class Enum {
|
abstract class Enum
|
||||||
/** @var null|array $constCacheArray */
|
{
|
||||||
private static $constCacheArray = NULL;
|
/** @var null|array $constCacheArray */
|
||||||
|
private static $constCacheArray = null;
|
||||||
|
|
||||||
private static function getConstants() {
|
private static function getConstants()
|
||||||
if (self::$constCacheArray == NULL) {
|
{
|
||||||
self::$constCacheArray = [];
|
if (self::$constCacheArray == null) {
|
||||||
}
|
self::$constCacheArray = [];
|
||||||
$calledClass = get_called_class();
|
}
|
||||||
if (!array_key_exists($calledClass, self::$constCacheArray)) {
|
$calledClass = get_called_class();
|
||||||
$reflect = new ReflectionClass($calledClass);
|
if (!array_key_exists($calledClass, self::$constCacheArray)) {
|
||||||
self::$constCacheArray[$calledClass] = $reflect->getConstants();
|
$reflect = new ReflectionClass($calledClass);
|
||||||
}
|
self::$constCacheArray[$calledClass] = $reflect->getConstants();
|
||||||
return self::$constCacheArray[$calledClass];
|
}
|
||||||
}
|
return self::$constCacheArray[$calledClass];
|
||||||
|
}
|
||||||
|
|
||||||
public static function isValidName($name, $strict = false) {
|
public static function isValidName($name, $strict = false)
|
||||||
$constants = self::getConstants();
|
{
|
||||||
|
$constants = self::getConstants();
|
||||||
|
|
||||||
if ($strict) {
|
if ($strict) {
|
||||||
return array_key_exists($name, $constants);
|
return array_key_exists($name, $constants);
|
||||||
}
|
}
|
||||||
|
|
||||||
$keys = array_map('strtolower', array_keys($constants));
|
$keys = array_map('strtolower', array_keys($constants));
|
||||||
return in_array(strtolower($name), $keys);
|
return in_array(strtolower($name), $keys);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function isValidValue($value, $strict = true) {
|
public static function isValidValue($value, $strict = true)
|
||||||
$values = array_values(self::getConstants());
|
{
|
||||||
return in_array($value, $values, $strict);
|
$values = array_values(self::getConstants());
|
||||||
}
|
return in_array($value, $values, $strict);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// abstract class DaysOfWeek extends BasicEnum {
|
/*
|
||||||
// const Sunday = 0;
|
abstract class DaysOfWeek extends Enum {
|
||||||
// const Monday = 1;
|
const Sunday = 0;
|
||||||
// const Tuesday = 2;
|
const Monday = 1;
|
||||||
// const Wednesday = 3;
|
const Tuesday = 2;
|
||||||
// const Thursday = 4;
|
const Wednesday = 3;
|
||||||
// const Friday = 5;
|
const Thursday = 4;
|
||||||
// const Saturday = 6;
|
const Friday = 5;
|
||||||
// }
|
const Saturday = 6;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
99
src/AdminPanel/Functions.php
Normal file
99
src/AdminPanel/Functions.php
Normal file
@ -0,0 +1,99 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use AdminPanel\Classes\Cache;
|
||||||
|
|
||||||
|
function ping()
|
||||||
|
{
|
||||||
|
return "pong";
|
||||||
|
}
|
||||||
|
|
||||||
|
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|array
|
||||||
|
*/
|
||||||
|
function slugEqualToURI($slug, $uri, $options)
|
||||||
|
{
|
||||||
|
$uri = explode("/", trim($uri, "\/"));
|
||||||
|
$slug = explode("/", trim($slug, '\/'));
|
||||||
|
$return = array();
|
||||||
|
|
||||||
|
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])) {
|
||||||
|
$return[$elemnt] = $uri[$key];
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
//TODO correspond with module settings
|
||||||
|
} else {
|
||||||
|
if ($value == $uri[$key]) {
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function getModulesJSON()
|
||||||
|
{
|
||||||
|
$t = array();
|
||||||
|
$modulesDIR = "./Modules";
|
||||||
|
$modules = array_diff(scandir($modulesDIR), array('..', '.'));
|
||||||
|
foreach ($modules as $module) {
|
||||||
|
$moduleDIR = $modulesDIR . "/" . $module;
|
||||||
|
$file = $moduleDIR . "/" . strtolower($module) . ".json";
|
||||||
|
if (is_dir($moduleDIR) && is_file($file)) {
|
||||||
|
$json = json_decode(file_get_contents($file), true);
|
||||||
|
if ($json) {
|
||||||
|
$t[$module] = $json;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $t;
|
||||||
|
}
|
||||||
|
|
||||||
|
function initCache()
|
||||||
|
{
|
||||||
|
$json = getModulesJSON();
|
||||||
|
foreach ($json as $moduleName => $moduleValues) {
|
||||||
|
if (isset($moduleValues["routes"])) {
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
|
if (isset($moduleValues["templateFolder"])) {
|
||||||
|
Cache::getInstance()->addTemplateFolder(ROOT . "/Modules/" . $moduleName . $moduleValues["templateFolder"], $moduleName);
|
||||||
|
}
|
||||||
|
// return $moduleValues;
|
||||||
|
}
|
||||||
|
return $json;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Define constant.
|
||||||
|
* (well really it's just an hack for my linter I really don't why we can't define constant in the main process)
|
||||||
|
*
|
||||||
|
* @param string $name constant name
|
||||||
|
* @param mixed $value contant value
|
||||||
|
*/
|
||||||
|
function dconst(string $name, $value)
|
||||||
|
{
|
||||||
|
define($name, $value);
|
||||||
|
}
|
@ -4,7 +4,7 @@ namespace AdminLib\Classes;
|
|||||||
|
|
||||||
use AdminPanel\Classes\Controller;
|
use AdminPanel\Classes\Controller;
|
||||||
|
|
||||||
|
class AdminController extends Controller
|
||||||
class AdminController extends Controller {
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -4,10 +4,10 @@ namespace AdminLib\Controller;
|
|||||||
|
|
||||||
use AdminLib\Classes\AdminController;
|
use AdminLib\Classes\AdminController;
|
||||||
|
|
||||||
class IndexController extends AdminController {
|
class IndexController extends AdminController
|
||||||
|
{
|
||||||
public function index() {
|
public function index()
|
||||||
return "Hello Administrator!";
|
{
|
||||||
}
|
return "Hello Administrator!";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,15 +3,21 @@
|
|||||||
namespace Index\Controller;
|
namespace Index\Controller;
|
||||||
|
|
||||||
use AdminPanel\Classes\Controller;
|
use AdminPanel\Classes\Controller;
|
||||||
|
use AdminPanel\Classes\AdminPanel;
|
||||||
|
|
||||||
class IndexController extends Controller {
|
class IndexController extends Controller
|
||||||
|
{
|
||||||
|
|
||||||
public function index() {
|
public function index()
|
||||||
return "hello world!";
|
{
|
||||||
}
|
return AdminPanel::getInstance()->getTwig()->render("@Index/index.twig", [
|
||||||
|
"title" => "Coming Soon"
|
||||||
|
]);
|
||||||
|
// return file_get_contents($this->getModuleRoot() . "/index.html");
|
||||||
|
}
|
||||||
|
|
||||||
public function test() {
|
public function test()
|
||||||
var_dump($this->getUrlArguments());
|
{
|
||||||
return "test working!";
|
return "hello " . $this->getUrlArguments()["slug"];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,11 +3,27 @@
|
|||||||
namespace ModuleName\Controller;
|
namespace ModuleName\Controller;
|
||||||
|
|
||||||
use AdminPanel\Classes\Controller;
|
use AdminPanel\Classes\Controller;
|
||||||
|
use AdminPanel\Classes\Authentificator;
|
||||||
|
|
||||||
|
class ExampleController extends Controller
|
||||||
|
{
|
||||||
|
|
||||||
class ExampleController extends Controller {
|
public function example()
|
||||||
|
{
|
||||||
|
return "hello " . $this->getUrlArguments()["arg"] . "!";
|
||||||
|
}
|
||||||
|
|
||||||
public function example() {
|
public function index()
|
||||||
return "hello Controller!";
|
{
|
||||||
}
|
return "Hellow Example Controller!";
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isLoggedIn()
|
||||||
|
{
|
||||||
|
if (Authentificator::getInstance()->isLoggedIn()) {
|
||||||
|
return "test is false!";
|
||||||
|
} else {
|
||||||
|
return "test is true";
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
118
src/index.php
118
src/index.php
@ -1,81 +1,65 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use AdminPanel\Classes\AdminPanel;
|
||||||
|
use AdminPanel\Classes\Cache;
|
||||||
|
|
||||||
|
session_start();
|
||||||
ini_set('display_errors', 'On');
|
ini_set('display_errors', 'On');
|
||||||
|
|
||||||
define("ROOT", __DIR__);
|
|
||||||
|
|
||||||
use AdminPanel\Classes\Controller;
|
|
||||||
|
|
||||||
/** @var Composer\Autoload\ClassLoader $loader */
|
/** @var Composer\Autoload\ClassLoader $loader */
|
||||||
$loader = require_once ROOT . "/../vendor/autoload.php";
|
$loader = require_once __DIR__ . "/../vendor/autoload.php";
|
||||||
// var_dump($_SERVER["REQUEST_URI"] . "/");
|
// var_dump($_SERVER["REQUEST_URI"] . "/");
|
||||||
// $_SERVER["REQUEST_URI"] = "/test/";
|
// $_SERVER["REQUEST_URI"] = "/test/";
|
||||||
//get all dirs
|
//get all dirs
|
||||||
$modulesDIR = ROOT . "/Modules";
|
$modulesDIR = __DIR__ . "/Modules";
|
||||||
$modules = array_diff(scandir($modulesDIR), array('..', '.'));
|
$modules = array_diff(scandir($modulesDIR), array('..', '.'));
|
||||||
|
|
||||||
|
dconst("ROOT", __DIR__);
|
||||||
|
|
||||||
|
initCache();
|
||||||
|
/*
|
||||||
|
1: get all the template folders
|
||||||
|
2: match routes directly with modules
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/** @var string $module */
|
/** @var string $module */
|
||||||
foreach ($modules as $module) {
|
foreach ($modules as $module) {
|
||||||
$moduleDIR = $modulesDIR . "/" . $module;
|
$moduleDIR = $modulesDIR . "/" . $module;
|
||||||
if (is_dir($moduleDIR)) {
|
if (is_dir($moduleDIR)) {
|
||||||
$json = json_decode(file_get_contents($moduleDIR . "/" . strtolower($module) . ".json"));
|
$json = json_decode(file_get_contents($moduleDIR . "/" . strtolower($module) . ".json"));
|
||||||
foreach ($json->routes as $routeName => $routeArgs) {
|
foreach ($json->routes as $routeName => $routeArgs) {
|
||||||
$args = isset($routeArgs->args) ? $routeArgs->args : new stdClass();
|
$args = isset($routeArgs->args) ? $routeArgs->args : new stdClass();
|
||||||
$composants = slugEqualToURI($routeArgs->path, $_SERVER["REQUEST_URI"], $args);
|
$composants = slugEqualToURI($routeArgs->path, $_SERVER["REQUEST_URI"], $args);
|
||||||
if($composants !== false) {
|
// dump($composants !== false);
|
||||||
$loader->loadClass($routeArgs->controller);
|
if ($composants !== false) {
|
||||||
$function = $routeArgs->function;
|
if (isset($json->templateFolder)) {
|
||||||
/** @var AdminPanel\Classes\Controller $controller */
|
AdminPanel::getInstance()->addLoaderFolder($moduleDIR . $json->templateFolder, $module);
|
||||||
$controller = new $routeArgs->controller;
|
}
|
||||||
$controller->setUrlArguments($composants);
|
if (isset($routeArgs->file)) {
|
||||||
echo $controller->$function();
|
if (isset($routeArgs->type)) {
|
||||||
die;
|
header("Content-Type: " . $routeArgs->type . "; charset=UTF-8");
|
||||||
}
|
}
|
||||||
}
|
echo file_get_contents($moduleDIR . $routeArgs->file);
|
||||||
}
|
die;
|
||||||
|
}
|
||||||
|
$loader->loadClass($routeArgs->controller);
|
||||||
|
$function = $routeArgs->function;
|
||||||
|
// dump($function);
|
||||||
|
/** @var AdminPanel\Classes\Controller $controller */
|
||||||
|
$controller = new $routeArgs->controller;
|
||||||
|
$controller->setUrlArguments($composants);
|
||||||
|
$controller->setModuleRoot($moduleDIR);
|
||||||
|
// if(isset($json->templateFolder)) $controller->loadTwig($json->templateFolder);
|
||||||
|
echo $controller->$function();
|
||||||
|
die;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
http_response_code(404);
|
||||||
// echo Controller::example();
|
// dd();
|
||||||
|
echo "404";
|
||||||
// require_once ROOT . "/system/router.php";
|
die;
|
||||||
|
|
||||||
// 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|array
|
|
||||||
*/
|
|
||||||
function slugEqualToURI($slug, $uri, $options) {
|
|
||||||
$uri = explode("/", trim($uri, "\/"));
|
|
||||||
$slug = explode("/", trim($slug, '\/'));
|
|
||||||
$return = array();
|
|
||||||
|
|
||||||
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])) {
|
|
||||||
$return[$elemnt] = $uri[$key];
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
else return false;
|
|
||||||
//TODO correspond with module settings
|
|
||||||
} else {
|
|
||||||
if($value == $uri[$key]) continue;
|
|
||||||
else return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $return;
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user