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"
|
||||
]
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"Tests\\": "tests"
|
||||
}
|
||||
},
|
||||
"require": {
|
||||
"twig/twig": "^2.7",
|
||||
"psr/simple-cache": "^1.0",
|
||||
|
@ -21,7 +21,7 @@ if (!$ap->isCacheEnabled()) {
|
||||
$cache->clear();
|
||||
}
|
||||
|
||||
$caches = $cache->getMultiple(array(
|
||||
$caches = (array) $cache->getMultiple(array(
|
||||
'routes',
|
||||
'templates',
|
||||
'forms'
|
||||
@ -32,12 +32,20 @@ $cachesBool = $caches["routes"] === null || $caches['templates'] === null || $ca
|
||||
if (!$ap->isCacheEnabled() || $cachesBool) {
|
||||
$cache->clear();
|
||||
$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 */
|
||||
foreach ($modules as $module) {
|
||||
$moduleDIR = $modulesDIR . "/" . $module;
|
||||
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)) {
|
||||
$cache->set(
|
||||
'templates',
|
||||
@ -69,7 +77,7 @@ if (!$ap->isCacheEnabled() || $cachesBool) {
|
||||
}
|
||||
}
|
||||
}
|
||||
$caches = $cache->getMultiple(array(
|
||||
$caches = (array) $cache->getMultiple(array(
|
||||
'routes',
|
||||
'templates',
|
||||
'forms'
|
||||
@ -94,12 +102,10 @@ foreach ($caches['routes'] as $key => $value) {
|
||||
$loader->loadClass($value->controller);
|
||||
$function = $value->function;
|
||||
// dump($function);
|
||||
/** @var DeltaCMS\Classes\Controller $controller */
|
||||
/** @var \DeltaCMS\Controller $controller */
|
||||
$controller = new $value->controller();
|
||||
// dd(new $routeArgs->controller());
|
||||
if ($composants) {
|
||||
$controller->setUrlArguments($composants);
|
||||
}
|
||||
// if(isset($json->templateFolder)) $controller->loadTwig($json->templateFolder);
|
||||
echo $controller->$function();
|
||||
die;
|
||||
|
@ -2,6 +2,8 @@
|
||||
|
||||
namespace DeltaCMS\Cache;
|
||||
|
||||
use Exception;
|
||||
|
||||
class FileCache extends AbstractCache
|
||||
{
|
||||
private $folder;
|
||||
@ -29,12 +31,17 @@ class FileCache extends AbstractCache
|
||||
}
|
||||
$file = $this->folder . DIRECTORY_SEPARATOR . $key;
|
||||
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) {
|
||||
return $res["value"];
|
||||
} else {
|
||||
$this->delete($key);
|
||||
}
|
||||
} else {
|
||||
throw new Exception("Cache file couldn't be read", 1);
|
||||
}
|
||||
}
|
||||
return $default;
|
||||
}
|
||||
@ -62,7 +69,11 @@ class FileCache extends AbstractCache
|
||||
|
||||
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) {
|
||||
$this->delete($key);
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ class Controller
|
||||
protected $urlArguments = array();
|
||||
protected $moduleRoot = null;
|
||||
|
||||
/** @var \DeltaCMS\Cache\FileCache */
|
||||
/** @var \Psr\SimpleCache\CacheInterface */
|
||||
|
||||
protected $cache;
|
||||
|
||||
|
@ -27,8 +27,6 @@ class DeltaCMS
|
||||
/**
|
||||
* Get actual DeltaCMS instance
|
||||
*
|
||||
* @param array $settings
|
||||
* Settings to set to the software
|
||||
*
|
||||
* @return DeltaCMS
|
||||
*/
|
||||
@ -53,12 +51,8 @@ class DeltaCMS
|
||||
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 function setLoader(FilesystemLoader $loader)
|
||||
// {
|
||||
// $this->loader = $loader;
|
||||
// }
|
||||
|
||||
public function addLoaderFolder(string $path, string $prefix = "DeltaCMS")
|
||||
{
|
||||
|
@ -2,6 +2,8 @@
|
||||
|
||||
namespace DeltaCMS;
|
||||
|
||||
use ReflectionClass;
|
||||
|
||||
abstract class Enum
|
||||
{
|
||||
/** @var null|array $constCacheArray */
|
||||
|
@ -39,7 +39,7 @@ class Form
|
||||
$adder = "add" . ucfirst($name);
|
||||
$value = filter_input(INPUT_POST, $name);
|
||||
$field = $this->getField($settings->type);
|
||||
$value = $field->processValue($value, $settings);
|
||||
$value = $field->getValue();
|
||||
if (is_callable(array($entity, $setter))) {
|
||||
$entity->$setter($value);
|
||||
} elseif (is_callable(array($entity, $adder))) {
|
||||
@ -86,7 +86,7 @@ class Form
|
||||
$form = $forms[$formname];
|
||||
$this->fields = $form->fields;
|
||||
// dd($this->fields);
|
||||
if ($this->isSubmitting($this->fields)) {
|
||||
if ($this->isSubmitting()) {
|
||||
if ($entity !== null) {
|
||||
$this->putFieldsInEntity(
|
||||
$entity,
|
||||
|
@ -7,6 +7,7 @@ class ArrayInput extends AbstractInput
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->options = array(
|
||||
'elements' => array()
|
||||
);
|
||||
|
@ -8,6 +8,7 @@ class EntityInput extends AbstractInput
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->setOption("type", "text");
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,7 @@ interface Input
|
||||
/**
|
||||
* get options that will be passed into the final object
|
||||
*
|
||||
* @return void
|
||||
* @return array
|
||||
*/
|
||||
public function getAttributes(): array;
|
||||
|
||||
@ -29,7 +29,7 @@ interface Input
|
||||
/**
|
||||
* get options that will be passed into the final object
|
||||
*
|
||||
* @return void
|
||||
* @return array
|
||||
*/
|
||||
public function getOptions(): array;
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
use PHPUnit\Runner\Exception;
|
||||
|
||||
function startsWith($haystack, $needle)
|
||||
{
|
||||
@ -11,7 +12,7 @@ function startsWith($haystack, $needle)
|
||||
* @param string $slug
|
||||
* @param object $options options->regex &| options->setting
|
||||
*
|
||||
* @return bool|array
|
||||
* @return bool|stdClass
|
||||
*/
|
||||
function slugEqualToURI($slug, $uri, $options)
|
||||
{
|
||||
@ -49,14 +50,17 @@ function slugEqualToURI($slug, $uri, $options)
|
||||
|
||||
function jsonc_decode($filename, $assoc = false, $depth = 512, $options = 0)
|
||||
{
|
||||
return json_decode(
|
||||
preg_replace(
|
||||
$fileContent = file_get_contents($filename);
|
||||
if ($fileContent === false) {
|
||||
throw new Exception("File" . $filename . " is not readable or not existing", 1);
|
||||
}
|
||||
$fileContent = preg_replace(
|
||||
'![ \t]*//.*[ \t]*[\r\n]!',
|
||||
'',
|
||||
file_get_contents($filename)
|
||||
),
|
||||
$assoc,
|
||||
$depth,
|
||||
$options
|
||||
$fileContent
|
||||
);
|
||||
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\InvalidArgumentException;
|
||||
|
||||
use Exception;
|
||||
|
||||
class Logger extends AbstractLogger
|
||||
{
|
||||
|
||||
@ -26,7 +28,11 @@ class Logger extends AbstractLogger
|
||||
public function __construct($file = "./logs.log")
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
@ -1,9 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace Tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use DeltaCMS\Cache\FileCache;
|
||||
use DeltaCMS\Logger;
|
||||
use Psr\Log\InvalidArgumentException;
|
||||
use Exception;
|
||||
|
||||
final class LoggerTest extends TestCase
|
||||
{
|
||||
|
@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace Tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use DeltaCMS\Cache\SessionCache;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user