Implemented application routes

This commit is contained in:
Dennis Eichhorn 2016-07-22 00:16:01 +02:00
parent 31b25cd07f
commit e63f175b2c
4 changed files with 19 additions and 14 deletions

View File

@ -17,6 +17,8 @@ namespace phpOMS\Module;
use phpOMS\DataStorage\Database\DatabaseType; use phpOMS\DataStorage\Database\DatabaseType;
use phpOMS\DataStorage\Database\Pool; use phpOMS\DataStorage\Database\Pool;
use phpOMS\System\File\Directory;
use phpOMS\System\File\PathException;
use phpOMS\System\File\PermissionException; use phpOMS\System\File\PermissionException;
use phpOMS\Utils\Parser\Php\ArrayParser; use phpOMS\Utils\Parser\Php\ArrayParser;
@ -153,9 +155,9 @@ class InstallerAbstract
$directories = new Directory(ROOT_PATH . '/Modules/' . $info->getDirectory() . '/Admin/Routes'); $directories = new Directory(ROOT_PATH . '/Modules/' . $info->getDirectory() . '/Admin/Routes');
foreach($directories as $key => $subdir) { foreach($directories as $key => $subdir) {
if($subdir instanceOf Directory) { if($subdir instanceof Directory) {
foreach($subdir as $key2 => $file) { foreach($subdir as $key2 => $file) {
self::installRoutes(ROOT_PATH . '/' . $subdir->getName() . '/' . $file->getName() . '/Routes.php', $file->getPath()); self::installRoutes(ROOT_PATH . '/' . $subdir->getName() . '/' . basename($file->getName(), '.php') . '/Routes.php', $file->getPath());
} }
} }
} }
@ -177,7 +179,7 @@ class InstallerAbstract
private static function installRoutes(string $destRoutePath, string $srcRoutePath) private static function installRoutes(string $destRoutePath, string $srcRoutePath)
{ {
if(!file_exists($destRoutePath)) { if(!file_exists($destRoutePath)) {
mkdir($destRoutePath); file_put_contents($destRoutePath, '<?php return [];');
} }
if (file_exists($destRoutePath) && file_exists($srcRoutePath)) { if (file_exists($destRoutePath) && file_exists($srcRoutePath)) {
@ -189,10 +191,18 @@ class InstallerAbstract
$appRoutes = array_merge_recursive($appRoutes, $moduleRoutes); $appRoutes = array_merge_recursive($appRoutes, $moduleRoutes);
if (is_writable($destRoutePath)) { if (is_writable($destRoutePath)) {
file_put_contents($destRoutePath, '<?php return ' . ArrayParser::serializeArray($appRoutes) . ';', LOCK_EX); file_put_contents($destRoutePath, '<?php return' . ArrayParser::serializeArray($appRoutes) . ';', LOCK_EX);
} else { } else {
throw new PermissionException($destRoutePath); throw new PermissionException($destRoutePath);
} }
} else {
if(!file_exists($srcRoutePath)) {
throw new PathException($srcRoutePath);
}
if(!file_exists($destRoutePath)) {
throw new PathException($destRoutePath);
}
} }
} }

View File

@ -360,12 +360,6 @@ class ModuleManager
*/ */
public function reInit(string $module) : bool public function reInit(string $module) : bool
{ {
if (file_exists($path = __DIR__ . '/../Web/Routes.php')) {
unlink($path);
}
file_put_contents($path, '<?php return [];');
$info = $this->loadInfo($module); $info = $this->loadInfo($module);
/** @var $class InstallerAbstract */ /** @var $class InstallerAbstract */
$class = '\\Modules\\' . $info->getDirectory() . '\\Admin\\Installer'; $class = '\\Modules\\' . $info->getDirectory() . '\\Admin\\Installer';

View File

@ -15,6 +15,7 @@
*/ */
namespace phpOMS\System\File; namespace phpOMS\System\File;
use phpOMS\Utils\StringUtils;
use phpOMS\Validation\Validator; use phpOMS\Validation\Validator;
/** /**
@ -43,7 +44,7 @@ class Directory extends FileAbstract implements \Iterator, \ArrayAccess
/** /**
* Direcotry nodes (files and directories). * Direcotry nodes (files and directories).
* *
* @var string * @var FileAbstract[]
* @since 1.0.0 * @since 1.0.0
*/ */
private $nodes = []; private $nodes = [];
@ -80,7 +81,7 @@ class Directory extends FileAbstract implements \Iterator, \ArrayAccess
parent::index(); parent::index();
foreach (glob($this->path . DIRECTORY_SEPARATOR . $this->filter) as $filename) { foreach (glob($this->path . DIRECTORY_SEPARATOR . $this->filter) as $filename) {
if(strpos($filename, '.') === false) { if(!StringUtils::endsWith(trim($filename), '.') ) {
$file = is_dir($filename) ? new self($filename) : new File($filename); $file = is_dir($filename) ? new self($filename) : new File($filename);
$this->add($file); $this->add($file);
@ -102,7 +103,7 @@ class Directory extends FileAbstract implements \Iterator, \ArrayAccess
{ {
$this->count += $file->getCount(); $this->count += $file->getCount();
$this->size += $file->getSize(); $this->size += $file->getSize();
$this->nodes[$this->getName()] = $file; $this->nodes[$file->getName()] = $file;
return $file->createNode(); return $file->createNode();
} }

View File

@ -104,7 +104,7 @@ abstract class FileAbstract
*/ */
public function __construct(string $path) public function __construct(string $path)
{ {
$this->path = $path; $this->path = rtrim($path, '/\\');
$this->name = basename($path); $this->name = basename($path);
$this->createdAt = new \DateTime('now'); $this->createdAt = new \DateTime('now');