A super easy PHP Framework for web development! https://github.com/exacti/phacil-framework
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

229 lines
5.4 KiB

6 years ago
<?php
/*
* Copyright © 2021 ExacTI Technology Solutions. All rights reserved.
* GPLv3 General License.
* https://exacti.com.br
* Phacil PHP Framework - https://github.com/exacti/phacil-framework
*/
namespace Phacil\Framework;
use \Phacil\Framework\Interfaces\Action as ActionInterface;
use \Phacil\Framework\Traits\Action as ActionTrait;
use \Phacil\Framework\Config;
3 years ago
/**
* Action class to route all user controllers
*
* @since 1.0.0
*
* @package Phacil\Framework
**/
3 years ago
final class Action implements ActionInterface {
use ActionTrait;
/**
* @inheritdoc
*/
6 years ago
public function __construct($route, $args = array()) {
$path = '';
$pathC = "";
6 years ago
$parts = explode('/', str_replace('../', '', (string)$route));
$this->route = $route;
6 years ago
foreach ($parts as $part) {
$pathNew = $path;
6 years ago
$path .= $part;
if (is_dir(Config::DIR_APP_MODULAR() . $path)) {
$path = $path.'/';
array_shift($parts);
continue;
}elseif (is_dir(Config::DIR_APP_MODULAR() . ucfirst($path))) {
$path = ucfirst($path).'/';
array_shift($parts);
continue;
}elseif (is_dir(Config::DIR_APPLICATION() . 'controller/' . $path)) {
6 years ago
$path .= '/';
array_shift($parts);
continue;
}
$strReplaceOnPathNew = str_replace('../', '', $pathNew);
$strReplaceOnPath = str_replace('../', '', $path);
$strReplaceOnPart = str_replace('../', '', $part);
$pregReplaceOnPath = preg_replace('/[^a-zA-Z0-9]/', '', $path);
$pregReplaceOnPart = preg_replace('/[^a-zA-Z0-9]/', '', $part);
6 years ago
if (is_file(Config::DIR_APP_MODULAR() . $strReplaceOnPathNew . 'Controller/' . $strReplaceOnPart . '.php')) {
$this->file = Config::DIR_APP_MODULAR() . $strReplaceOnPathNew . 'Controller/' . $strReplaceOnPart . '.php';
$this->class = 'Controller' . $pregReplaceOnPath;
$this->classAlt = [
'class' => $this->mountClass($strReplaceOnPathNew, $pregReplaceOnPart),
'legacy' => $this->class,
'ucfirst' => ucfirst($pregReplaceOnPart),
'direct' => $pregReplaceOnPart
];
array_shift($parts);
break;
} elseif (is_file(Config::DIR_APP_MODULAR() . $strReplaceOnPathNew . 'Controller/' . ucfirst($strReplaceOnPart) . '.php')) {
$this->file = Config::DIR_APP_MODULAR() . $strReplaceOnPathNew . 'Controller/' . ucfirst($strReplaceOnPart) . '.php';
$this->class = 'Controller' . $pregReplaceOnPath;
$this->classAlt = [
'class' => $this->mountClass($strReplaceOnPathNew, $pregReplaceOnPart),
'legacy' => $this->class,
'ucfirst' => ucfirst($pregReplaceOnPart),
'direct' => $pregReplaceOnPart
];
array_shift($parts);
break;
} elseif (is_file(Config::DIR_APPLICATION() . 'controller/' . $strReplaceOnPath . '.php')) {
$this->file = Config::DIR_APPLICATION() . 'controller/' . $strReplaceOnPath . '.php';
6 years ago
$this->class = 'Controller' . $pregReplaceOnPath;
6 years ago
$this->classAlt = [
'class' => $this->mountClass($strReplaceOnPathNew, $pregReplaceOnPart),
10 months ago
'legacy' => $this->class,
'ucfirst' => ucfirst($pregReplaceOnPart),
'direct' => $pregReplaceOnPart
];
array_shift($parts);
break;
}elseif (is_file(Config::DIR_APPLICATION() . 'controller/' . strtolower($strReplaceOnPath) . '.php')) {
$this->file = Config::DIR_APPLICATION() . 'controller/' . strtolower($strReplaceOnPath) . '.php';
$this->class = 'Controller' . $pregReplaceOnPath;
$this->classAlt = [
'class' => $this->mountClass($strReplaceOnPathNew, $pregReplaceOnPart),
'legacy' => $this->class,
'ucfirst' => ucfirst($pregReplaceOnPart),
'direct' => $pregReplaceOnPart
];
6 years ago
array_shift($parts);
break;
}
}
if ($args) {
$this->args = $args;
}
$method = array_shift($parts);
if ($method) {
$this->method = $method;
} else {
$this->method = 'index';
}
if (!$this->classAlt) {
$lastTry = explode('/', $this->route, 2);
$class1 = $this->mountClass($lastTry[0] . "\\", str_replace("/", "\\", end($lastTry)));
$class2 = implode("\\", explode("\\", $class1, -1));
if(class_exists($class1)){
$this->classAlt = [
'class' => $class1
];
$this->method = 'index';
} elseif(class_exists($class2)){
$this->classAlt = [
'class' => $class2
];
$this->method = $method;
}
}
6 years ago
}
}
/**
* Action class to route all framework system controllers
*
* @since 1.0.1
*
* @package Phacil\Framework
*/
3 years ago
final class ActionSystem implements ActionInterface {
use ActionTrait;
/**
* @inheritdoc
*/
6 years ago
public function __construct($route, $args = array()) {
$path = '';
$parts = explode('/', str_replace('../', '', (string)$route));
foreach ($parts as $part) {
$path .= $part;
if (is_dir(Config::DIR_SYSTEM() . '' . $path)) {
6 years ago
$path .= '/';
array_shift($parts);
continue;
}
if (is_file(Config::DIR_SYSTEM() . '' . str_replace('../', '', $path) . '.php')) {
$this->file = Config::DIR_SYSTEM() . '' . str_replace('../', '', $path) . '.php';
6 years ago
$this->class = 'System' . preg_replace('/[^a-zA-Z0-9]/', '', $path);
$this->classAlt = [
'legacy' => $this->class,
'direct' => preg_replace('/[^a-zA-Z0-9]/', '', $part)
];
6 years ago
array_shift($parts);
break;
}
}
if ($args) {
$this->args = $args;
}
$method = array_shift($parts);
if ($method) {
$this->method = $method;
} else {
$this->method = 'index';
}
}
}