mirror of
https://github.com/Aviortheking/DeltaCMS.git
synced 2025-04-23 03:12:14 +00:00
Fixed files for PHPStan
This commit is contained in:
parent
9f56eec39a
commit
3d52fb48e2
@ -21,6 +21,11 @@
|
|||||||
"src/DeltaCMS/Functions.php"
|
"src/DeltaCMS/Functions.php"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
"autoload-dev": {
|
||||||
|
"psr-4": {
|
||||||
|
"Tests\\": "tests"
|
||||||
|
}
|
||||||
|
},
|
||||||
"require": {
|
"require": {
|
||||||
"twig/twig": "^2.7",
|
"twig/twig": "^2.7",
|
||||||
"psr/simple-cache": "^1.0",
|
"psr/simple-cache": "^1.0",
|
||||||
|
@ -21,7 +21,7 @@ if (!$ap->isCacheEnabled()) {
|
|||||||
$cache->clear();
|
$cache->clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
$caches = $cache->getMultiple(array(
|
$caches = (array) $cache->getMultiple(array(
|
||||||
'routes',
|
'routes',
|
||||||
'templates',
|
'templates',
|
||||||
'forms'
|
'forms'
|
||||||
@ -32,12 +32,20 @@ $cachesBool = $caches["routes"] === null || $caches['templates'] === null || $ca
|
|||||||
if (!$ap->isCacheEnabled() || $cachesBool) {
|
if (!$ap->isCacheEnabled() || $cachesBool) {
|
||||||
$cache->clear();
|
$cache->clear();
|
||||||
$modulesDIR = dirname(__DIR__) . "/src/Modules";
|
$modulesDIR = dirname(__DIR__) . "/src/Modules";
|
||||||
$modules = array_diff(scandir($modulesDIR), array('..', '.'));
|
$dirs = scandir($modulesDIR);
|
||||||
|
if ($dirs === false) {
|
||||||
|
throw new Exception("Modules folder seems is not readable, Exiting", 1);
|
||||||
|
}
|
||||||
|
$modules = array_diff($dirs, array('..', '.'));
|
||||||
/** @var string $module */
|
/** @var string $module */
|
||||||
foreach ($modules as $module) {
|
foreach ($modules as $module) {
|
||||||
$moduleDIR = $modulesDIR . "/" . $module;
|
$moduleDIR = $modulesDIR . "/" . $module;
|
||||||
if (is_dir($moduleDIR) && is_file($moduleDIR . "/" . strtolower($module) . ".json")) {
|
if (is_dir($moduleDIR) && is_file($moduleDIR . "/" . strtolower($module) . ".json")) {
|
||||||
$json = json_decode(file_get_contents($moduleDIR . "/" . strtolower($module) . ".json"));
|
$fileContent = file_get_contents($moduleDIR . "/" . strtolower($module) . ".json");
|
||||||
|
if ($fileContent === false) {
|
||||||
|
throw new Exception($module . " couldn't be read, please check that the JSON file is readable", 1);
|
||||||
|
}
|
||||||
|
$json = json_decode($fileContent);
|
||||||
if (isset($json->templateFolder)) {
|
if (isset($json->templateFolder)) {
|
||||||
$cache->set(
|
$cache->set(
|
||||||
'templates',
|
'templates',
|
||||||
@ -69,7 +77,7 @@ if (!$ap->isCacheEnabled() || $cachesBool) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$caches = $cache->getMultiple(array(
|
$caches = (array) $cache->getMultiple(array(
|
||||||
'routes',
|
'routes',
|
||||||
'templates',
|
'templates',
|
||||||
'forms'
|
'forms'
|
||||||
@ -94,12 +102,10 @@ foreach ($caches['routes'] as $key => $value) {
|
|||||||
$loader->loadClass($value->controller);
|
$loader->loadClass($value->controller);
|
||||||
$function = $value->function;
|
$function = $value->function;
|
||||||
// dump($function);
|
// dump($function);
|
||||||
/** @var DeltaCMS\Classes\Controller $controller */
|
/** @var \DeltaCMS\Controller $controller */
|
||||||
$controller = new $value->controller();
|
$controller = new $value->controller();
|
||||||
// dd(new $routeArgs->controller());
|
// dd(new $routeArgs->controller());
|
||||||
if ($composants) {
|
|
||||||
$controller->setUrlArguments($composants);
|
$controller->setUrlArguments($composants);
|
||||||
}
|
|
||||||
// if(isset($json->templateFolder)) $controller->loadTwig($json->templateFolder);
|
// if(isset($json->templateFolder)) $controller->loadTwig($json->templateFolder);
|
||||||
echo $controller->$function();
|
echo $controller->$function();
|
||||||
die;
|
die;
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
namespace DeltaCMS\Cache;
|
namespace DeltaCMS\Cache;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
|
||||||
class FileCache extends AbstractCache
|
class FileCache extends AbstractCache
|
||||||
{
|
{
|
||||||
private $folder;
|
private $folder;
|
||||||
@ -29,12 +31,17 @@ class FileCache extends AbstractCache
|
|||||||
}
|
}
|
||||||
$file = $this->folder . DIRECTORY_SEPARATOR . $key;
|
$file = $this->folder . DIRECTORY_SEPARATOR . $key;
|
||||||
if (is_file($file)) {
|
if (is_file($file)) {
|
||||||
$res = unserialize(file_get_contents($file));
|
$content = file_get_contents($file);
|
||||||
|
if ($content !== false) {
|
||||||
|
$res = unserialize($content);
|
||||||
if ($res["ttl"] > time() && $res['value'] !== null) {
|
if ($res["ttl"] > time() && $res['value'] !== null) {
|
||||||
return $res["value"];
|
return $res["value"];
|
||||||
} else {
|
} else {
|
||||||
$this->delete($key);
|
$this->delete($key);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
throw new Exception("Cache file couldn't be read", 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return $default;
|
return $default;
|
||||||
}
|
}
|
||||||
@ -62,7 +69,11 @@ class FileCache extends AbstractCache
|
|||||||
|
|
||||||
public function clear()
|
public function clear()
|
||||||
{
|
{
|
||||||
$keys = array_diff(scandir($this->folder), array("..", "."));
|
$files = scandir($this->folder);
|
||||||
|
if ($files === false) {
|
||||||
|
throw new Exception("couldn't clear cache, the folder seems unreadable", 1);
|
||||||
|
}
|
||||||
|
$keys = array_diff($files, array("..", "."));
|
||||||
foreach ($keys as $key) {
|
foreach ($keys as $key) {
|
||||||
$this->delete($key);
|
$this->delete($key);
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@ class Controller
|
|||||||
protected $urlArguments = array();
|
protected $urlArguments = array();
|
||||||
protected $moduleRoot = null;
|
protected $moduleRoot = null;
|
||||||
|
|
||||||
/** @var \DeltaCMS\Cache\FileCache */
|
/** @var \Psr\SimpleCache\CacheInterface */
|
||||||
|
|
||||||
protected $cache;
|
protected $cache;
|
||||||
|
|
||||||
|
@ -27,8 +27,6 @@ class DeltaCMS
|
|||||||
/**
|
/**
|
||||||
* Get actual DeltaCMS instance
|
* Get actual DeltaCMS instance
|
||||||
*
|
*
|
||||||
* @param array $settings
|
|
||||||
* Settings to set to the software
|
|
||||||
*
|
*
|
||||||
* @return DeltaCMS
|
* @return DeltaCMS
|
||||||
*/
|
*/
|
||||||
@ -53,12 +51,8 @@ class DeltaCMS
|
|||||||
return isset($this->logger) ? $this->logger : $this->logger = new Logger(dirname($this->root));
|
return isset($this->logger) ? $this->logger : $this->logger = new Logger(dirname($this->root));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @var \Twig\Loader\FileSystemLoader $loader */
|
/** @var \Twig\Loader\FilesystemLoader $loader */
|
||||||
private $loader;
|
private $loader;
|
||||||
// private function setLoader(FilesystemLoader $loader)
|
|
||||||
// {
|
|
||||||
// $this->loader = $loader;
|
|
||||||
// }
|
|
||||||
|
|
||||||
public function addLoaderFolder(string $path, string $prefix = "DeltaCMS")
|
public function addLoaderFolder(string $path, string $prefix = "DeltaCMS")
|
||||||
{
|
{
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
namespace DeltaCMS;
|
namespace DeltaCMS;
|
||||||
|
|
||||||
|
use ReflectionClass;
|
||||||
|
|
||||||
abstract class Enum
|
abstract class Enum
|
||||||
{
|
{
|
||||||
/** @var null|array $constCacheArray */
|
/** @var null|array $constCacheArray */
|
||||||
|
@ -39,7 +39,7 @@ class Form
|
|||||||
$adder = "add" . ucfirst($name);
|
$adder = "add" . ucfirst($name);
|
||||||
$value = filter_input(INPUT_POST, $name);
|
$value = filter_input(INPUT_POST, $name);
|
||||||
$field = $this->getField($settings->type);
|
$field = $this->getField($settings->type);
|
||||||
$value = $field->processValue($value, $settings);
|
$value = $field->getValue();
|
||||||
if (is_callable(array($entity, $setter))) {
|
if (is_callable(array($entity, $setter))) {
|
||||||
$entity->$setter($value);
|
$entity->$setter($value);
|
||||||
} elseif (is_callable(array($entity, $adder))) {
|
} elseif (is_callable(array($entity, $adder))) {
|
||||||
@ -86,7 +86,7 @@ class Form
|
|||||||
$form = $forms[$formname];
|
$form = $forms[$formname];
|
||||||
$this->fields = $form->fields;
|
$this->fields = $form->fields;
|
||||||
// dd($this->fields);
|
// dd($this->fields);
|
||||||
if ($this->isSubmitting($this->fields)) {
|
if ($this->isSubmitting()) {
|
||||||
if ($entity !== null) {
|
if ($entity !== null) {
|
||||||
$this->putFieldsInEntity(
|
$this->putFieldsInEntity(
|
||||||
$entity,
|
$entity,
|
||||||
|
@ -7,6 +7,7 @@ class ArrayInput extends AbstractInput
|
|||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
|
parent::__construct();
|
||||||
$this->options = array(
|
$this->options = array(
|
||||||
'elements' => array()
|
'elements' => array()
|
||||||
);
|
);
|
||||||
|
@ -8,6 +8,7 @@ class EntityInput extends AbstractInput
|
|||||||
{
|
{
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
|
parent::__construct();
|
||||||
$this->setOption("type", "text");
|
$this->setOption("type", "text");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ interface Input
|
|||||||
/**
|
/**
|
||||||
* get options that will be passed into the final object
|
* get options that will be passed into the final object
|
||||||
*
|
*
|
||||||
* @return void
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function getAttributes(): array;
|
public function getAttributes(): array;
|
||||||
|
|
||||||
@ -29,7 +29,7 @@ interface Input
|
|||||||
/**
|
/**
|
||||||
* get options that will be passed into the final object
|
* get options that will be passed into the final object
|
||||||
*
|
*
|
||||||
* @return void
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function getOptions(): array;
|
public function getOptions(): array;
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
use PHPUnit\Runner\Exception;
|
||||||
|
|
||||||
function startsWith($haystack, $needle)
|
function startsWith($haystack, $needle)
|
||||||
{
|
{
|
||||||
@ -11,7 +12,7 @@ function startsWith($haystack, $needle)
|
|||||||
* @param string $slug
|
* @param string $slug
|
||||||
* @param object $options options->regex &| options->setting
|
* @param object $options options->regex &| options->setting
|
||||||
*
|
*
|
||||||
* @return bool|array
|
* @return bool|stdClass
|
||||||
*/
|
*/
|
||||||
function slugEqualToURI($slug, $uri, $options)
|
function slugEqualToURI($slug, $uri, $options)
|
||||||
{
|
{
|
||||||
@ -49,14 +50,17 @@ function slugEqualToURI($slug, $uri, $options)
|
|||||||
|
|
||||||
function jsonc_decode($filename, $assoc = false, $depth = 512, $options = 0)
|
function jsonc_decode($filename, $assoc = false, $depth = 512, $options = 0)
|
||||||
{
|
{
|
||||||
return json_decode(
|
$fileContent = file_get_contents($filename);
|
||||||
preg_replace(
|
if ($fileContent === false) {
|
||||||
|
throw new Exception("File" . $filename . " is not readable or not existing", 1);
|
||||||
|
}
|
||||||
|
$fileContent = preg_replace(
|
||||||
'![ \t]*//.*[ \t]*[\r\n]!',
|
'![ \t]*//.*[ \t]*[\r\n]!',
|
||||||
'',
|
'',
|
||||||
file_get_contents($filename)
|
$fileContent
|
||||||
),
|
|
||||||
$assoc,
|
|
||||||
$depth,
|
|
||||||
$options
|
|
||||||
);
|
);
|
||||||
|
if ($fileContent === null) {
|
||||||
|
throw new Exception("An error occured", 1);
|
||||||
|
}
|
||||||
|
return json_decode($fileContent, $assoc, $depth, $options);
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,8 @@ namespace DeltaCMS;
|
|||||||
use Psr\Log\AbstractLogger;
|
use Psr\Log\AbstractLogger;
|
||||||
use Psr\Log\InvalidArgumentException;
|
use Psr\Log\InvalidArgumentException;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
|
||||||
class Logger extends AbstractLogger
|
class Logger extends AbstractLogger
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -26,7 +28,11 @@ class Logger extends AbstractLogger
|
|||||||
public function __construct($file = "./logs.log")
|
public function __construct($file = "./logs.log")
|
||||||
{
|
{
|
||||||
if (!file_exists($file)) {
|
if (!file_exists($file)) {
|
||||||
fclose(fopen($file, 'w'));
|
$ressource = fopen($file, 'w');
|
||||||
|
if ($ressource === false) {
|
||||||
|
throw new Exception("File at " . $file . " can't be created. exiting", 1);
|
||||||
|
}
|
||||||
|
fclose($ressource);
|
||||||
}
|
}
|
||||||
$this->file = $file;
|
$this->file = $file;
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
namespace Tests;
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use DeltaCMS\Cache\FileCache;
|
use DeltaCMS\Cache\FileCache;
|
||||||
use DeltaCMS\Logger;
|
use DeltaCMS\Logger;
|
||||||
use Psr\Log\InvalidArgumentException;
|
use Psr\Log\InvalidArgumentException;
|
||||||
|
use Exception;
|
||||||
|
|
||||||
final class LoggerTest extends TestCase
|
final class LoggerTest extends TestCase
|
||||||
{
|
{
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
namespace Tests;
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use DeltaCMS\Cache\SessionCache;
|
use DeltaCMS\Cache\SessionCache;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user