From 13e082fb127edb6d6821f25093b5507359f72b10 Mon Sep 17 00:00:00 2001
From: Dennis Eichhorn
Date: Sun, 21 Aug 2016 17:42:54 +0200
Subject: [PATCH 1/7] Start own markdown implementation
---
Utils/Parser/Markdown/Markdown.php | 123 +++++++++++++++++++++++++++++
1 file changed, 123 insertions(+)
create mode 100644 Utils/Parser/Markdown/Markdown.php
diff --git a/Utils/Parser/Markdown/Markdown.php b/Utils/Parser/Markdown/Markdown.php
new file mode 100644
index 000000000..2b79709c2
--- /dev/null
+++ b/Utils/Parser/Markdown/Markdown.php
@@ -0,0 +1,123 @@
+
+ * @author Dennis Eichhorn
+ * @copyright 2013 Dennis Eichhorn
+ * @license OMS License 1.0
+ * @version 1.0.0
+ * @link http://orange-management.com
+ */
+namespace phpOMS\Utils\Parser\Markdown;
+
+/**
+ * Array utils.
+ *
+ * @category Framework
+ * @package phpOMS\Utils
+ * @author OMS Development Team
+ * @author Dennis Eichhorn
+ * @license OMS License 1.0
+ * @link http://orange-management.com
+ * @since 1.0.0
+ */
+class Markdown
+{
+ private static $blockTypes = [
+ '#' => ['Header'],
+ '*' => ['Rule', 'List'],
+ '+' => ['List'],
+ '-' => ['SetextHeader', 'Table', 'Rule', 'List'],
+ '0' => ['List'],
+ '1' => ['List'],
+ '2' => ['List'],
+ '3' => ['List'],
+ '4' => ['List'],
+ '5' => ['List'],
+ '6' => ['List'],
+ '7' => ['List'],
+ '8' => ['List'],
+ '9' => ['List'],
+ ':' => ['Table'],
+ '<' => ['Comment', 'Markup'],
+ '=' => ['SetextHeader'],
+ '>' => ['Quote'],
+ '[' => ['Reference'],
+ '_' => ['Rule'],
+ '`' => ['FencedCode'],
+ '|' => ['Table'],
+ '~' => ['FencedCode'],
+ ];
+
+ private static $inlineTypes = [
+ '"' => ['SpecialCharacter'],
+ '!' => ['Image'],
+ '&' => ['SpecialCharacter'],
+ '*' => ['Emphasis'],
+ ':' => ['Url'],
+ '<' => ['UrlTag', 'EmailTag', 'Markup', 'SpecialCharacter'],
+ '>' => ['SpecialCharacter'],
+ '[' => ['Link'],
+ '_' => ['Emphasis'],
+ '`' => ['Code'],
+ '~' => ['Strikethrough'],
+ '\\' => ['EscapeSequence'],
+ ];
+
+ private static $tags = [
+ 'calendar' => [
+ 'match' => 'regex here',
+ 'parsed' => 'output here',
+ ],
+ ];
+
+ public function __construct()
+ {
+ }
+
+ public function parse(string $raw) : string
+ {
+ $raw = $this->cleanup($raw);
+ $lines = explode("\n", $raw);
+
+ return trim($this->parseLines($lines), " \n");
+ }
+
+ private function cleanup(string $raw) : string
+ {
+ $raw = str_replace(["\r\n", "\r", "\t"], ["\n", "\n", ' '], $raw);
+ $raw = trim($raw);
+ $raw = trim($raw, "\n");
+
+ return $raw;
+ }
+
+ private function parseLines(array $lines) : string
+ {
+ $block = array_keys(self::$blockTypes);
+ $inline = array_keys(self::$inlineTypes);
+
+ foreach($lines as $line) {
+ foreach($line as $character) {
+
+ }
+ }
+
+ return '';
+ }
+
+ private function countIndention(string $line) : int
+ {
+ $indent = 0;
+ while (isset($line[$indent]) && $line[$indent] === ' ') {
+ $indent++;
+ }
+
+ return $indent;
+ }
+}
\ No newline at end of file
From 9811a2928b0ac8f33cc0bb72f1aa999f44f88100 Mon Sep 17 00:00:00 2001
From: Dennis Eichhorn
Date: Sun, 21 Aug 2016 17:43:10 +0200
Subject: [PATCH 2/7] Don't rely on defined path
---
Module/ModuleManager.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Module/ModuleManager.php b/Module/ModuleManager.php
index 16e5ec8a2..640452127 100644
--- a/Module/ModuleManager.php
+++ b/Module/ModuleManager.php
@@ -43,7 +43,7 @@ class ModuleManager
* @var string
* @since 1.0.0
*/
- const MODULE_PATH = ROOT_PATH . DIRECTORY_SEPARATOR . 'Modules';
+ const MODULE_PATH = __DIR__ . '/../../Modules';
/**
* All modules that are running on this uri.
From 635ea38f7fdda5e52b1c7adb11b96bcaac6741d9 Mon Sep 17 00:00:00 2001
From: Dennis Eichhorn
Date: Sun, 21 Aug 2016 20:08:15 +0200
Subject: [PATCH 3/7] Adjusting file/dir location
---
DataStorage/Cache/FileCache.php | 2 +-
Log/FileLogger.php | 2 +-
Module/InstallerAbstract.php | 2 +-
System/File/ContainerInterface.php | 82 ++++
.../{NullFile.php => DirectoryInterface.php} | 5 +-
System/File/FileInterface.php | 51 +--
System/File/Ftp/FtpStorage.php | 0
System/File/{ => Local}/Directory.php | 5 +-
System/File/Local/File.php | 387 ++++++++++++++++++
System/File/{ => Local}/FileAbstract.php | 14 +-
System/File/Local/LocalStorage.php | 0
System/File/StorageInterface.php | 0
12 files changed, 480 insertions(+), 70 deletions(-)
create mode 100644 System/File/ContainerInterface.php
rename System/File/{NullFile.php => DirectoryInterface.php} (89%)
create mode 100644 System/File/Ftp/FtpStorage.php
rename System/File/{ => Local}/Directory.php (98%)
create mode 100644 System/File/Local/File.php
rename System/File/{ => Local}/FileAbstract.php (94%)
create mode 100644 System/File/Local/LocalStorage.php
create mode 100644 System/File/StorageInterface.php
diff --git a/DataStorage/Cache/FileCache.php b/DataStorage/Cache/FileCache.php
index 43c66af5d..5639d871d 100644
--- a/DataStorage/Cache/FileCache.php
+++ b/DataStorage/Cache/FileCache.php
@@ -15,7 +15,7 @@
*/
namespace phpOMS\DataStorage\Cache;
-use phpOMS\System\File\Directory;
+use phpOMS\System\File\Local\Directory;
/**
* MemCache class.
diff --git a/Log/FileLogger.php b/Log/FileLogger.php
index 2b706cbbb..ce79d414d 100644
--- a/Log/FileLogger.php
+++ b/Log/FileLogger.php
@@ -16,7 +16,7 @@
namespace phpOMS\Log;
use phpOMS\Datatypes\Exception\InvalidEnumValue;
-use phpOMS\System\File\File;
+use phpOMS\System\File\Local\File;
use phpOMS\System\File\PathException;
use phpOMS\Utils\StringUtils;
diff --git a/Module/InstallerAbstract.php b/Module/InstallerAbstract.php
index 0d790b188..426ee52f6 100644
--- a/Module/InstallerAbstract.php
+++ b/Module/InstallerAbstract.php
@@ -17,7 +17,7 @@ namespace phpOMS\Module;
use phpOMS\DataStorage\Database\DatabaseType;
use phpOMS\DataStorage\Database\Pool;
-use phpOMS\System\File\Directory;
+use phpOMS\System\File\Local\Directory;
use phpOMS\System\File\PathException;
use phpOMS\System\File\PermissionException;
use phpOMS\Utils\Parser\Php\ArrayParser;
diff --git a/System/File/ContainerInterface.php b/System/File/ContainerInterface.php
new file mode 100644
index 000000000..1ba1d1ca9
--- /dev/null
+++ b/System/File/ContainerInterface.php
@@ -0,0 +1,82 @@
+
+ * @author Dennis Eichhorn
+ * @copyright 2013 Dennis Eichhorn
+ * @license OMS License 1.0
+ * @version 1.0.0
+ * @link http://orange-management.com
+ */
+namespace phpOMS\System\File;
+
+/**
+ * Filesystem class.
+ *
+ * Performing operations on the file system
+ *
+ * @category Framework
+ * @package phpOMS\System\File
+ * @author OMS Development Team
+ * @author Dennis Eichhorn
+ * @license OMS License 1.0
+ * @link http://orange-management.com
+ * @since 1.0.0
+ */
+interface ContainerInterface
+{
+ public static function created(string $path) : \DateTime;
+
+ public static function changed(string $path) : \DateTime;
+
+ public static function owner(string $path) : int;
+
+ public static function permission(string $path) : int;
+
+ public static function parent(string $path) : string;
+
+ public static function create(string $path) : bool;
+
+ public static function delete(string $path) : bool;
+
+ public static function copy(string $from, string $to, bool $overwrite = false) : bool;
+
+ public static function move(string $from, string $to, bool $overwrite = false) : bool;
+
+ public static function size(string $path) : int;
+
+ public static function exists(string $path) : bool;
+
+ public function getCount() : int;
+
+ public function getSize() : int;
+
+ public function getName() : string;
+
+ public function getPath() : string;
+
+ public function getParent() : FileInterface;
+
+ public function createNode() : bool;
+
+ public function copyNode() : bool;
+
+ public function moveNode() : bool;
+
+ public function deleteNode() : bool;
+
+ public function getCreatedAt() : \DateTime;
+
+ public function getChangedAt() : \DateTime;
+
+ public function getOwner() : int;
+
+ public function getPermission() : string;
+
+ public function index();
+}
diff --git a/System/File/NullFile.php b/System/File/DirectoryInterface.php
similarity index 89%
rename from System/File/NullFile.php
rename to System/File/DirectoryInterface.php
index ed5c4f40c..ba4c9e7e7 100644
--- a/System/File/NullFile.php
+++ b/System/File/DirectoryInterface.php
@@ -28,7 +28,6 @@ namespace phpOMS\System\File;
* @link http://orange-management.com
* @since 1.0.0
*/
-class NullFile extends File
+interface DirectoryInterface extends ContainerInterface, \Iterator, \ArrayAccess
{
-
-}
\ No newline at end of file
+}
diff --git a/System/File/FileInterface.php b/System/File/FileInterface.php
index 76af1146c..fc47deb25 100644
--- a/System/File/FileInterface.php
+++ b/System/File/FileInterface.php
@@ -28,63 +28,14 @@ namespace phpOMS\System\File;
* @link http://orange-management.com
* @since 1.0.0
*/
-interface FileInterface
+interface FileInterface extends ContainerInterface
{
- public static function created(string $path) : \DateTime;
-
- public static function changed(string $path) : \DateTime;
-
- public static function owner(string $path) : int;
-
- public static function permission(string $path) : int;
-
- public static function parent(string $path) : string;
-
- public static function create(string $path) : bool;
-
- public static function delete(string $path) : bool;
-
- public static function copy(string $from, string $to, bool $overwrite = false) : bool;
-
- public static function move(string $from, string $to, bool $overwrite = false) : bool;
public static function put(string $path, string $content, bool $overwrite = true) : bool;
public static function get(string $path) : string;
- public static function size(string $path) : int;
-
- public static function exists(string $path) : bool;
-
- public function getCount() : int;
-
- public function getSize() : int;
-
- public function getName() : string;
-
- public function getPath() : string;
-
- public function getParent() : FileInterface;
-
- public function createNode() : bool;
-
- public function copyNode() : bool;
-
- public function moveNode() : bool;
-
- public function deleteNode() : bool;
-
public function putContent() : bool;
public function getContent() : string;
-
- public function getCreatedAt() : \DateTime;
-
- public function getChangedAt() : \DateTime;
-
- public function getOwner() : int;
-
- public function getPermission() : string;
-
- public function index();
}
diff --git a/System/File/Ftp/FtpStorage.php b/System/File/Ftp/FtpStorage.php
new file mode 100644
index 000000000..e69de29bb
diff --git a/System/File/Directory.php b/System/File/Local/Directory.php
similarity index 98%
rename from System/File/Directory.php
rename to System/File/Local/Directory.php
index 2e2b04ed4..784980c94 100644
--- a/System/File/Directory.php
+++ b/System/File/Local/Directory.php
@@ -13,8 +13,9 @@
* @version 1.0.0
* @link http://orange-management.com
*/
-namespace phpOMS\System\File;
+namespace phpOMS\System\File\Local;
+use phpOMS\System\File\DirectoryInterface;
use phpOMS\Utils\StringUtils;
/**
@@ -30,7 +31,7 @@ use phpOMS\Utils\StringUtils;
* @link http://orange-management.com
* @since 1.0.0
*/
-class Directory extends FileAbstract implements \Iterator, \ArrayAccess
+class Directory extends FileAbstract implements DirectoryInterface
{
/**
* Direcotry list filter.
diff --git a/System/File/Local/File.php b/System/File/Local/File.php
new file mode 100644
index 000000000..c7b59f92c
--- /dev/null
+++ b/System/File/Local/File.php
@@ -0,0 +1,387 @@
+
+ * @author Dennis Eichhorn
+ * @copyright 2013 Dennis Eichhorn
+ * @license OMS License 1.0
+ * @version 1.0.0
+ * @link http://orange-management.com
+ */
+namespace phpOMS\System\File\Local;
+use phpOMS\System\File\FileInterface;
+
+/**
+ * Filesystem class.
+ *
+ * Performing operations on the file system
+ *
+ * @category Framework
+ * @package phpOMS\System\File
+ * @author OMS Development Team
+ * @author Dennis Eichhorn
+ * @license OMS License 1.0
+ * @link http://orange-management.com
+ * @since 1.0.0
+ */
+class File extends FileAbstract implements FileInterface
+{
+
+ /**
+ * Constructor.
+ *
+ * @param string $path Path
+ *
+ * @since 1.0.0
+ * @author Dennis Eichhorn
+ */
+ public function __construct(string $path)
+ {
+ parent::__construct($path);
+ $this->count = 1;
+
+ if (file_exists($this->path)) {
+ $this->index();
+ }
+ }
+
+ /**
+ * Index file.
+ *
+ * @return void
+ *
+ * @since 1.0.0
+ * @author Dennis Eichhorn
+ */
+ public function index()
+ {
+ parent::index();
+
+ $this->size = filesize($this->path);
+ }
+
+ /**
+ * Save string to file.
+ *
+ * If the directory doesn't exist where the string should be saved it will be created
+ * as well as potential subdirectories. The directories will be created with '0644'
+ * permission.
+ *
+ * @param string $path Path to save the string to
+ * @param string $content Content to save to file
+ * @param bool $overwrite Should the file be overwritten if it already exists
+ *
+ * @example File::put('/var/www/html/test.txt', 'string'); // true
+ * @example File::put('/var/www/html/test.txt', 'string', false); // false
+ *
+ * @return bool Returns true on successfule file write and false on failure
+ *
+ * @since 1.0.0
+ * @author Dennis Eichhorn
+ */
+ public static function put(string $path, string $content, bool $overwrite = true) : bool
+ {
+ if ($overwrite || !file_exists($path)) {
+ if (!Directory::exists(dirname($path))) {
+ Directory::create(dirname($path), '0644', true);
+ }
+
+ file_put_contents($path, $content);
+
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * Get content of file.
+ *
+ * @param string $path Path to read from
+ *
+ * @example File::get('/var/www/html/test.txt');
+ *
+ * @return string The content of the file to read from.
+ *
+ * @throws PathException In case the file doesn't exist this exception gets thrown.
+ *
+ * @since 1.0.0
+ * @author Dennis Eichhorn
+ */
+ public static function get(string $path) : string
+ {
+ if (!file_exists($path)) {
+ throw new PathException($path);
+ }
+
+ return file_get_contents($path);
+ }
+
+ /**
+ * Checks if a file exists.
+ *
+ * @param string $path Path of the file to check the existance for.
+ *
+ * @example File::exists('/var/www/html/test.txt');
+ *
+ * @return bool Returns true if the file exists and false if it doesn't.
+ *
+ * @since 1.0.0
+ * @author Dennis Eichhorn
+ */
+ public static function exists(string $path) : bool
+ {
+ return file_exists($path);
+ }
+
+ /**
+ * Gets the parent directory path of the specified file.
+ *
+ * @param string $path Path of the file to get the parent directory for.
+ *
+ * @example File::parent('/var/www/html/test.txt'); // /var/www
+ *
+ * @return string Returns the parent full directory path.
+ *
+ * @since 1.0.0
+ * @author Dennis Eichhorn
+ */
+ public static function parent(string $path) : string
+ {
+ return Directory::parent(dirname($path));
+ }
+
+ /**
+ * Gets the date when the file got created.
+ *
+ * @param string $path Path of the file to get the date of creation for.
+ *
+ * @return \DateTime Returns the \DateTime of when the file was created.
+ *
+ * @throws PathException Throws this exception if the file to get the creation date for doesn't exist.
+ *
+ * @example File::created('/var/www/html/test.txt');
+ *
+ * @since 1.0.0
+ * @author Dennis Eichhorn
+ */
+ public static function created(string $path) : \DateTime
+ {
+ if (!file_exists($path)) {
+ throw new PathException($path);
+ }
+
+ $created = new \DateTime();
+ $created->setTimestamp(filemtime($path));
+
+ return $created;
+ }
+
+ /**
+ * Gets the date when the file got changed the last time.
+ *
+ * @param string $path Path of the file to get the last date of change for.
+ *
+ * @return \DateTime Returns the \DateTime of when the file was last changed.
+ *
+ * @throws PathException Throws this exception if the file to get the last change date for doesn't exist.
+ *
+ * @example File::changed('/var/www/html/test.txt');
+ *
+ * @since 1.0.0
+ * @author Dennis Eichhorn
+ */
+ public static function changed(string $path) : \DateTime
+ {
+ if (!file_exists($path)) {
+ throw new PathException($path);
+ }
+
+ $changed = new \DateTime();
+ $changed->setTimestamp(filectime($path));
+
+ return $changed;
+ }
+
+ public static function size(string $path) : int
+ {
+ if (!file_exists($path)) {
+ throw new PathException($path);
+ }
+
+ return filesize($path);
+ }
+
+ public static function owner(string $path) : int
+ {
+ if (!file_exists($path)) {
+ throw new PathException($path);
+ }
+
+ return fileowner($path);
+ }
+
+ public static function permission(string $path) : int
+ {
+ if (!file_exists($path)) {
+ throw new PathException($path);
+ }
+
+ return fileperms($path);
+ }
+
+ public static function dirname(string $path) : string
+ {
+ return dirname($path);
+ }
+
+ public static function copy(string $from, string $to, bool $overwrite = false) : bool
+ {
+ if (!file_exists($from)) {
+ throw new PathException($from);
+ }
+
+ if ($overwrite || !file_exists($to)) {
+ if (!Directory::exists(dirname($to))) {
+ Directory::create(dirname($to), '0644', true);
+ }
+
+ copy($from, $to);
+
+ return true;
+ }
+
+ return false;
+ }
+
+ public static function move(string $from, string $to, bool $overwrite = false) : bool
+ {
+ if (!file_exists($from)) {
+ throw new PathException($from);
+ }
+
+ if ($overwrite || !file_exists($to)) {
+ if (!Directory::exists(dirname($to))) {
+ Directory::create(dirname($to), '0644', true);
+ }
+
+ rename($from, $to);
+
+ return true;
+ }
+
+ return false;
+ }
+
+ public static function delete(string $path) : bool
+ {
+ if (!file_exists($path)) {
+ return false;
+ }
+
+ unlink($path);
+
+ return true;
+ }
+
+ public function getDirName() : string
+ {
+ return basename(dirname($this->path));
+ }
+
+ public function getDirPath() : string
+ {
+ return dirname($this->path);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function createNode() : bool
+ {
+ return self::create($this->path);
+ }
+
+ public static function create(string $path) : bool
+ {
+ if (!file_exists($path)) {
+ if (!Directory::exists(dirname($path))) {
+ Directory::create(dirname($path), '0644', true);
+ }
+
+ touch($path);
+
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * Get file content.
+ *
+ * @return string
+ *
+ * @since 1.0.0
+ * @author Dennis Eichhorn
+ */
+ public function getContent() : string
+ {
+ return file_get_contents($this->path);
+ }
+
+ /**
+ * Set file content.
+ *
+ * @param string $content Content to set
+ *
+ * @since 1.0.0
+ * @author Dennis Eichhorn
+ */
+ public function setContent(string $content)
+ {
+ file_put_contents($this->path, $content);
+ }
+
+ public function getFileName() : string
+ {
+ return explode('.', $this->name)[0];
+ }
+
+ public function getExtension() : string
+ {
+ $extension = explode('.', $this->name);
+
+ return $extension[1] ?? '';
+ }
+
+ public function getParent() : FileInterface
+ {
+ // TODO: Implement getParent() method.
+ }
+
+ public function copyNode() : bool
+ {
+ // TODO: Implement copyNode() method.
+ }
+
+ public function moveNode() : bool
+ {
+ // TODO: Implement moveNode() method.
+ }
+
+ public function deleteNode() : bool
+ {
+ // TODO: Implement deleteNode() method.
+ }
+
+ public function putContent() : bool
+ {
+ // TODO: Implement putContent() method.
+ }
+}
\ No newline at end of file
diff --git a/System/File/FileAbstract.php b/System/File/Local/FileAbstract.php
similarity index 94%
rename from System/File/FileAbstract.php
rename to System/File/Local/FileAbstract.php
index ba0bef6be..84ac380a9 100644
--- a/System/File/FileAbstract.php
+++ b/System/File/Local/FileAbstract.php
@@ -13,7 +13,7 @@
* @version 1.0.0
* @link http://orange-management.com
*/
-namespace phpOMS\System\File;
+namespace phpOMS\System\File\Local;
/**
* Filesystem class.
@@ -28,7 +28,7 @@ namespace phpOMS\System\File;
* @link http://orange-management.com
* @since 1.0.0
*/
-abstract class FileAbstract implements FileInterface
+abstract class FileAbstract implements ContainerInterface
{
/**
* Path.
@@ -176,16 +176,6 @@ abstract class FileAbstract implements FileInterface
return new Directory(Directory::parent($this->path));
}
- /**
- * Create file/directory.
- *
- * @return bool
- *
- * @since 1.0.0
- * @author Dennis Eichhorn
- */
- abstract public function createNode() : bool;
-
/**
* Get created at.
*
diff --git a/System/File/Local/LocalStorage.php b/System/File/Local/LocalStorage.php
new file mode 100644
index 000000000..e69de29bb
diff --git a/System/File/StorageInterface.php b/System/File/StorageInterface.php
new file mode 100644
index 000000000..e69de29bb
From a4938066f47243faeb7648e96e9e3bb81ec97245 Mon Sep 17 00:00:00 2001
From: Dennis Eichhorn
Date: Sun, 21 Aug 2016 20:12:39 +0200
Subject: [PATCH 4/7] Fixing includes and naming
---
System/File/Local/Directory.php | 10 +++-------
System/File/Local/File.php | 1 +
2 files changed, 4 insertions(+), 7 deletions(-)
diff --git a/System/File/Local/Directory.php b/System/File/Local/Directory.php
index 784980c94..f334edfee 100644
--- a/System/File/Local/Directory.php
+++ b/System/File/Local/Directory.php
@@ -16,6 +16,7 @@
namespace phpOMS\System\File\Local;
use phpOMS\System\File\DirectoryInterface;
+use phpOMS\System\File\PathException;
use phpOMS\Utils\StringUtils;
/**
@@ -190,7 +191,7 @@ class Directory extends FileAbstract implements DirectoryInterface
* @since 1.0.0
* @author Dennis Eichhorn
*/
- public static function deletePath($path) : bool
+ public static function delete(string $path) : bool
{
$path = realpath($oldPath = $path);
if ($path === false || !is_dir($path) || StringUtils::startsWith($path, ROOT_PATH)) {
@@ -205,7 +206,7 @@ class Directory extends FileAbstract implements DirectoryInterface
foreach ($files as $file) {
if (is_dir($file)) {
- self::deletePath($file);
+ self::delete($file);
} else {
unlink($file);
}
@@ -256,11 +257,6 @@ class Directory extends FileAbstract implements DirectoryInterface
/* Iterator */
- public static function delete(string $path) : bool
- {
- // TODO: Implement delete() method.
- }
-
public static function copy(string $from, string $to, bool $overwrite = false) : bool
{
// TODO: Implement copy() method.
diff --git a/System/File/Local/File.php b/System/File/Local/File.php
index c7b59f92c..e52f628bd 100644
--- a/System/File/Local/File.php
+++ b/System/File/Local/File.php
@@ -15,6 +15,7 @@
*/
namespace phpOMS\System\File\Local;
use phpOMS\System\File\FileInterface;
+use phpOMS\System\File\PathException;
/**
* Filesystem class.
From d34f50218ac8ea0211fff16d4c699e5e87d92c19 Mon Sep 17 00:00:00 2001
From: Dennis Eichhorn
Date: Sun, 21 Aug 2016 20:42:52 +0200
Subject: [PATCH 5/7] Preparing storage usage
---
System/File/File.php | 301 ----------------------------
System/File/Local/LocalStorage.php | 305 +++++++++++++++++++++++++++++
System/File/Storage.php | 40 ++++
System/File/StorageAbstract.php | 49 +++++
System/File/StorageInterface.php | 0
5 files changed, 394 insertions(+), 301 deletions(-)
delete mode 100644 System/File/File.php
create mode 100644 System/File/Storage.php
create mode 100644 System/File/StorageAbstract.php
delete mode 100644 System/File/StorageInterface.php
diff --git a/System/File/File.php b/System/File/File.php
deleted file mode 100644
index 47e6c60da..000000000
--- a/System/File/File.php
+++ /dev/null
@@ -1,301 +0,0 @@
-
- * @author Dennis Eichhorn
- * @copyright 2013 Dennis Eichhorn
- * @license OMS License 1.0
- * @version 1.0.0
- * @link http://orange-management.com
- */
-namespace phpOMS\System\File;
-
-/**
- * Filesystem class.
- *
- * Performing operations on the file system
- *
- * @category Framework
- * @package phpOMS\System\File
- * @author OMS Development Team
- * @author Dennis Eichhorn
- * @license OMS License 1.0
- * @link http://orange-management.com
- * @since 1.0.0
- */
-class File extends FileAbstract
-{
-
- /**
- * Constructor.
- *
- * @param string $path Path
- *
- * @since 1.0.0
- * @author Dennis Eichhorn
- */
- public function __construct(string $path)
- {
- parent::__construct($path);
- $this->count = 1;
-
- if (file_exists($this->path)) {
- $this->index();
- }
- }
-
- /**
- * Index file.
- *
- * @return void
- *
- * @since 1.0.0
- * @author Dennis Eichhorn
- */
- public function index()
- {
- parent::index();
-
- $this->size = filesize($this->path);
- }
-
- public static function put(string $path, string $content, bool $overwrite = true) : bool
- {
- if ($overwrite || !file_exists($path)) {
- if (!Directory::exists(dirname($path))) {
- Directory::create(dirname($path), '0644', true);
- }
-
- file_put_contents($path, $content);
-
- return true;
- }
-
- return false;
- }
-
- public static function get(string $path) : string
- {
- if (!file_exists($path)) {
- throw new PathException($path);
- }
-
- return file_get_contents($path);
- }
-
- public static function exists(string $path) : bool
- {
- return file_exists($path);
- }
-
- public static function parent(string $path) : string
- {
- return Directory::parent(dirname($path));
- }
-
- public static function created(string $path) : \DateTime
- {
- if (!file_exists($path)) {
- throw new PathException($path);
- }
-
- $created = new \DateTime();
- $created->setTimestamp(filemtime($path));
-
- return $created;
- }
-
- public static function changed(string $path) : \DateTime
- {
- if (!file_exists($path)) {
- throw new PathException($path);
- }
-
- $changed = new \DateTime();
- $changed->setTimestamp(filectime($path));
-
- return $changed;
- }
-
- public static function size(string $path) : int
- {
- if (!file_exists($path)) {
- throw new PathException($path);
- }
-
- return filesize($path);
- }
-
- public static function owner(string $path) : int
- {
- if (!file_exists($path)) {
- throw new PathException($path);
- }
-
- return fileowner($path);
- }
-
- public static function permission(string $path) : int
- {
- if (!file_exists($path)) {
- throw new PathException($path);
- }
-
- return fileperms($path);
- }
-
- public static function dirname(string $path) : string
- {
- return dirname($path);
- }
-
- public static function copy(string $from, string $to, bool $overwrite = false) : bool
- {
- if (!file_exists($from)) {
- throw new PathException($from);
- }
-
- if ($overwrite || !file_exists($to)) {
- if (!Directory::exists(dirname($to))) {
- Directory::create(dirname($to), '0644', true);
- }
-
- copy($from, $to);
-
- return true;
- }
-
- return false;
- }
-
- public static function move(string $from, string $to, bool $overwrite = false) : bool
- {
- if (!file_exists($from)) {
- throw new PathException($from);
- }
-
- if ($overwrite || !file_exists($to)) {
- if (!Directory::exists(dirname($to))) {
- Directory::create(dirname($to), '0644', true);
- }
-
- rename($from, $to);
-
- return true;
- }
-
- return false;
- }
-
- public static function delete(string $path) : bool
- {
- if (!file_exists($path)) {
- return false;
- }
-
- unlink($path);
-
- return true;
- }
-
- public function getDirName() : string
- {
- return basename(dirname($this->path));
- }
-
- public function getDirPath() : string
- {
- return dirname($this->path);
- }
-
- /**
- * {@inheritdoc}
- */
- public function createNode() : bool
- {
- return self::create($this->path);
- }
-
- public static function create(string $path) : bool
- {
- if (!file_exists($path)) {
- if (!Directory::exists(dirname($path))) {
- Directory::create(dirname($path), '0644', true);
- }
-
- touch($path);
-
- return true;
- }
-
- return false;
- }
-
- /**
- * Get file content.
- *
- * @return string
- *
- * @since 1.0.0
- * @author Dennis Eichhorn
- */
- public function getContent() : string
- {
- return file_get_contents($this->path);
- }
-
- /**
- * Set file content.
- *
- * @param string $content Content to set
- *
- * @since 1.0.0
- * @author Dennis Eichhorn
- */
- public function setContent(string $content)
- {
- file_put_contents($this->path, $content);
- }
-
- public function getFileName() : string
- {
- return explode('.', $this->name)[0];
- }
-
- public function getExtension() : string
- {
- $extension = explode('.', $this->name);
-
- return $extension[1] ?? '';
- }
-
- public function getParent() : FileInterface
- {
- // TODO: Implement getParent() method.
- }
-
- public function copyNode() : bool
- {
- // TODO: Implement copyNode() method.
- }
-
- public function moveNode() : bool
- {
- // TODO: Implement moveNode() method.
- }
-
- public function deleteNode() : bool
- {
- // TODO: Implement deleteNode() method.
- }
-
- public function putContent() : bool
- {
- // TODO: Implement putContent() method.
- }
-}
\ No newline at end of file
diff --git a/System/File/Local/LocalStorage.php b/System/File/Local/LocalStorage.php
index e69de29bb..cbc9a10cb 100644
--- a/System/File/Local/LocalStorage.php
+++ b/System/File/Local/LocalStorage.php
@@ -0,0 +1,305 @@
+
+ * @author Dennis Eichhorn
+ * @copyright 2013 Dennis Eichhorn
+ * @license OMS License 1.0
+ * @version 1.0.0
+ * @link http://orange-management.com
+ */
+namespace phpOMS\System\File\Local;
+use phpOMS\System\File\ContainerInterface;
+use phpOMS\System\File\FileInterface;
+use phpOMS\System\File\PathException;
+use phpOMS\System\File\StorageAbstract;
+
+/**
+ * Filesystem class.
+ *
+ * Performing operations on the file system
+ *
+ * @category Framework
+ * @package phpOMS\System\File
+ * @author OMS Development Team
+ * @author Dennis Eichhorn
+ * @license OMS License 1.0
+ * @link http://orange-management.com
+ * @since 1.0.0
+ */
+class LocalStorage extends StorageAbstract
+{
+
+ public static function created(string $path) : \DateTime
+ {
+ // TODO: Implement created() method.
+ }
+
+ public static function changed(string $path) : \DateTime
+ {
+ // TODO: Implement changed() method.
+ }
+
+ public static function owner(string $path) : int
+ {
+ // TODO: Implement owner() method.
+ }
+
+ public static function permission(string $path) : int
+ {
+ // TODO: Implement permission() method.
+ }
+
+ public static function parent(string $path) : string
+ {
+ // TODO: Implement parent() method.
+ }
+
+ public static function create(string $path) : bool
+ {
+ // TODO: Implement create() method.
+ }
+
+ public static function delete(string $path) : bool
+ {
+ // TODO: Implement delete() method.
+ }
+
+ public static function copy(string $from, string $to, bool $overwrite = false) : bool
+ {
+ // TODO: Implement copy() method.
+ }
+
+ public static function move(string $from, string $to, bool $overwrite = false) : bool
+ {
+ // TODO: Implement move() method.
+ }
+
+ public static function size(string $path) : int
+ {
+ // TODO: Implement size() method.
+ }
+
+ public static function exists(string $path) : bool
+ {
+ // TODO: Implement exists() method.
+ }
+
+ public function getCount() : int
+ {
+ // TODO: Implement getCount() method.
+ }
+
+ public function getSize() : int
+ {
+ // TODO: Implement getSize() method.
+ }
+
+ public function getName() : string
+ {
+ // TODO: Implement getName() method.
+ }
+
+ public function getPath() : string
+ {
+ // TODO: Implement getPath() method.
+ }
+
+ public function getParent() : FileInterface
+ {
+ // TODO: Implement getParent() method.
+ }
+
+ public function createNode() : bool
+ {
+ // TODO: Implement createNode() method.
+ }
+
+ public function copyNode() : bool
+ {
+ // TODO: Implement copyNode() method.
+ }
+
+ public function moveNode() : bool
+ {
+ // TODO: Implement moveNode() method.
+ }
+
+ public function deleteNode() : bool
+ {
+ // TODO: Implement deleteNode() method.
+ }
+
+ public function getCreatedAt() : \DateTime
+ {
+ // TODO: Implement getCreatedAt() method.
+ }
+
+ public function getChangedAt() : \DateTime
+ {
+ // TODO: Implement getChangedAt() method.
+ }
+
+ public function getOwner() : int
+ {
+ // TODO: Implement getOwner() method.
+ }
+
+ public function getPermission() : string
+ {
+ // TODO: Implement getPermission() method.
+ }
+
+ public function index()
+ {
+ // TODO: Implement index() method.
+ }
+
+ /**
+ * Return the current element
+ * @link http://php.net/manual/en/iterator.current.php
+ * @return mixed Can return any type.
+ * @since 5.0.0
+ */
+ public function current()
+ {
+ // TODO: Implement current() method.
+ }
+
+ /**
+ * Move forward to next element
+ * @link http://php.net/manual/en/iterator.next.php
+ * @return void Any returned value is ignored.
+ * @since 5.0.0
+ */
+ public function next()
+ {
+ // TODO: Implement next() method.
+ }
+
+ /**
+ * Return the key of the current element
+ * @link http://php.net/manual/en/iterator.key.php
+ * @return mixed scalar on success, or null on failure.
+ * @since 5.0.0
+ */
+ public function key()
+ {
+ // TODO: Implement key() method.
+ }
+
+ /**
+ * Checks if current position is valid
+ * @link http://php.net/manual/en/iterator.valid.php
+ * @return boolean The return value will be casted to boolean and then evaluated.
+ * Returns true on success or false on failure.
+ * @since 5.0.0
+ */
+ public function valid()
+ {
+ // TODO: Implement valid() method.
+ }
+
+ /**
+ * Rewind the Iterator to the first element
+ * @link http://php.net/manual/en/iterator.rewind.php
+ * @return void Any returned value is ignored.
+ * @since 5.0.0
+ */
+ public function rewind()
+ {
+ // TODO: Implement rewind() method.
+ }
+
+ /**
+ * Whether a offset exists
+ * @link http://php.net/manual/en/arrayaccess.offsetexists.php
+ * @param mixed $offset
+ * An offset to check for.
+ *
+ * @return boolean true on success or false on failure.
+ *
+ *
+ * The return value will be casted to boolean if non-boolean was returned.
+ * @since 5.0.0
+ */
+ public function offsetExists($offset)
+ {
+ // TODO: Implement offsetExists() method.
+ }
+
+ /**
+ * Offset to retrieve
+ * @link http://php.net/manual/en/arrayaccess.offsetget.php
+ * @param mixed $offset
+ * The offset to retrieve.
+ *
+ * @return mixed Can return all value types.
+ * @since 5.0.0
+ */
+ public function offsetGet($offset)
+ {
+ // TODO: Implement offsetGet() method.
+ }
+
+ /**
+ * Offset to set
+ * @link http://php.net/manual/en/arrayaccess.offsetset.php
+ * @param mixed $offset
+ * The offset to assign the value to.
+ *
+ * @param mixed $value
+ * The value to set.
+ *
+ * @return void
+ * @since 5.0.0
+ */
+ public function offsetSet($offset, $value)
+ {
+ // TODO: Implement offsetSet() method.
+ }
+
+ /**
+ * Offset to unset
+ * @link http://php.net/manual/en/arrayaccess.offsetunset.php
+ * @param mixed $offset
+ * The offset to unset.
+ *
+ * @return void
+ * @since 5.0.0
+ */
+ public function offsetUnset($offset)
+ {
+ // TODO: Implement offsetUnset() method.
+ }
+
+ public static function put(string $path, string $content, bool $overwrite = true) : bool
+ {
+ // TODO: Implement put() method.
+ }
+
+ public static function get(string $path) : string
+ {
+ // TODO: Implement get() method.
+ }
+
+ public function putContent() : bool
+ {
+ // TODO: Implement putContent() method.
+ }
+
+ public function getContent() : string
+ {
+ // TODO: Implement getContent() method.
+ }
+
+ protected function getType() : ContainerInterface
+ {
+ // TODO: Implement getType() method.
+ }
+}
\ No newline at end of file
diff --git a/System/File/Storage.php b/System/File/Storage.php
new file mode 100644
index 000000000..b8b03f026
--- /dev/null
+++ b/System/File/Storage.php
@@ -0,0 +1,40 @@
+
+ * @author Dennis Eichhorn
+ * @copyright 2013 Dennis Eichhorn
+ * @license OMS License 1.0
+ * @version 1.0.0
+ * @link http://orange-management.com
+ */
+namespace phpOMS\System\File;
+
+/**
+ * Filesystem class.
+ *
+ * Performing operations on the file system
+ *
+ * @category Framework
+ * @package phpOMS\System\File
+ * @author OMS Development Team
+ * @author Dennis Eichhorn
+ * @license OMS License 1.0
+ * @link http://orange-management.com
+ * @since 1.0.0
+ */
+final class Storage
+{
+ public static function env(string $env = 'local') : string
+ {
+ $env = ucfirst(strtolower($env));
+ $env = __NAMESPACE__ . '\\' . $env . '\\' . $env . 'Storage';
+
+ return $env::getInstance();
+ }
+}
diff --git a/System/File/StorageAbstract.php b/System/File/StorageAbstract.php
new file mode 100644
index 000000000..f3ce96770
--- /dev/null
+++ b/System/File/StorageAbstract.php
@@ -0,0 +1,49 @@
+
+ * @author Dennis Eichhorn
+ * @copyright 2013 Dennis Eichhorn
+ * @license OMS License 1.0
+ * @version 1.0.0
+ * @link http://orange-management.com
+ */
+namespace phpOMS\System\File;
+
+/**
+ * Filesystem class.
+ *
+ * Performing operations on the file system
+ *
+ * @category Framework
+ * @package phpOMS\System\File
+ * @author OMS Development Team
+ * @author Dennis Eichhorn
+ * @license OMS License 1.0
+ * @link http://orange-management.com
+ * @since 1.0.0
+ */
+abstract class StorageAbstract implements DirectoryInterface, FileInterface
+{
+ protected static $instance = null;
+
+ protected function __construct()
+ {
+ }
+
+ public static function getInstance()
+ {
+ if(!isset(static::$instance)) {
+ static::$instance = new static();
+ }
+
+ return static::$instance;
+ }
+
+ abstract protected function getType() : ContainerInterface;
+}
diff --git a/System/File/StorageInterface.php b/System/File/StorageInterface.php
deleted file mode 100644
index e69de29bb..000000000
From c98cd94edcd605ad189851a19e34d22b592d17ac Mon Sep 17 00:00:00 2001
From: Dennis Eichhorn
Date: Sun, 21 Aug 2016 20:47:35 +0200
Subject: [PATCH 6/7] Support storage registering
---
System/File/Storage.php | 23 ++++++++++++++++++++---
1 file changed, 20 insertions(+), 3 deletions(-)
diff --git a/System/File/Storage.php b/System/File/Storage.php
index b8b03f026..59176967f 100644
--- a/System/File/Storage.php
+++ b/System/File/Storage.php
@@ -30,11 +30,28 @@ namespace phpOMS\System\File;
*/
final class Storage
{
+ private static $registered = [];
+
public static function env(string $env = 'local') : string
{
- $env = ucfirst(strtolower($env));
- $env = __NAMESPACE__ . '\\' . $env . '\\' . $env . 'Storage';
-
+ if (isset(self::$registered[$env])) {
+ $env = self::$registered[$env];
+ } else {
+ $env = ucfirst(strtolower($env));
+ $env = __NAMESPACE__ . '\\' . $env . '\\' . $env . 'Storage';
+ }
+
return $env::getInstance();
}
+
+ public static function register(string $name, string $class) : bool
+ {
+ if (isset(self::$registered[$name])) {
+ return false;
+ }
+
+ self::$registered[$name] = $class;
+
+ return true;
+ }
}
From 87b62a3ed9508362541ab943aadf239b3c506838 Mon Sep 17 00:00:00 2001
From: Dennis Eichhorn
Date: Sun, 21 Aug 2016 21:39:12 +0200
Subject: [PATCH 7/7] Formatting and spell checks
---
DataStorage/Database/Query/Builder.php | 1 -
System/File/Local/Directory.php | 4 ++--
System/File/Storage.php | 2 +-
3 files changed, 3 insertions(+), 4 deletions(-)
diff --git a/DataStorage/Database/Query/Builder.php b/DataStorage/Database/Query/Builder.php
index dd60ceac2..89239de23 100644
--- a/DataStorage/Database/Query/Builder.php
+++ b/DataStorage/Database/Query/Builder.php
@@ -18,7 +18,6 @@ namespace phpOMS\DataStorage\Database\Query;
use phpOMS\DataStorage\Database\BuilderAbstract;
use phpOMS\DataStorage\Database\Connection\ConnectionAbstract;
-use phpOMS\DataStorage\Database\Query;
/**
* Database query builder.
diff --git a/System/File/Local/Directory.php b/System/File/Local/Directory.php
index f334edfee..8d0c2d6eb 100644
--- a/System/File/Local/Directory.php
+++ b/System/File/Local/Directory.php
@@ -35,7 +35,7 @@ use phpOMS\Utils\StringUtils;
class Directory extends FileAbstract implements DirectoryInterface
{
/**
- * Direcotry list filter.
+ * Directory list filter.
*
* @var string
* @since 1.0.0
@@ -43,7 +43,7 @@ class Directory extends FileAbstract implements DirectoryInterface
private $filter = '*';
/**
- * Direcotry nodes (files and directories).
+ * Directory nodes (files and directories).
*
* @var FileAbstract[]
* @since 1.0.0
diff --git a/System/File/Storage.php b/System/File/Storage.php
index 59176967f..f289bbdd9 100644
--- a/System/File/Storage.php
+++ b/System/File/Storage.php
@@ -40,7 +40,7 @@ final class Storage
$env = ucfirst(strtolower($env));
$env = __NAMESPACE__ . '\\' . $env . '\\' . $env . 'Storage';
}
-
+
return $env::getInstance();
}