From ff2b3b0a5af7b375e4d552f453288e48f7728b4d Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sat, 14 Jan 2017 21:36:16 +0100 Subject: [PATCH] Preparing FTP handler --- System/File/Ftp/Directory.php | 38 ++++++ System/File/Ftp/File.php | 234 +++++++++++++++++++++++++++++++++ System/File/Ftp/FtpStorage.php | 28 ++++ 3 files changed, 300 insertions(+) create mode 100644 System/File/Ftp/Directory.php create mode 100644 System/File/Ftp/File.php diff --git a/System/File/Ftp/Directory.php b/System/File/Ftp/Directory.php new file mode 100644 index 000000000..7594f2b96 --- /dev/null +++ b/System/File/Ftp/Directory.php @@ -0,0 +1,38 @@ + + * @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\Ftp; + +use phpOMS\System\File\ContainerInterface; +use phpOMS\System\File\DirectoryInterface; +use phpOMS\System\File\PathException; +use phpOMS\Utils\StringUtils; + +/** + * 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 Directory extends FileAbstract implements DirectoryInterface +{ +} \ No newline at end of file diff --git a/System/File/Ftp/File.php b/System/File/Ftp/File.php new file mode 100644 index 000000000..f9565da50 --- /dev/null +++ b/System/File/Ftp/File.php @@ -0,0 +1,234 @@ + + * @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\Ftp; + +use phpOMS\System\File\ContainerInterface; +use phpOMS\System\File\ContentPutMode; +use phpOMS\System\File\FileInterface; +use phpOMS\System\File\PathException; + +/** + * 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 +{ + /** + * {@inheritdoc} + */ + public static function put(string $path, string $content, int $mode = ContentPutMode::REPLACE | ContentPutMode::CREATE) : bool + { + } + + /** + * {@inheritdoc} + */ + public static function get(string $path) : string + { + } + + /** + * {@inheritdoc} + */ + public static function set(string $path, string $content) : bool + { + return self::put($path, $content, ContentPutMode::REPLACE | ContentPutMode::CREATE); + } + + /** + * {@inheritdoc} + */ + public static function append(string $path, string $content) : bool + { + return self::put($path, $content, ContentPutMode::APPEND | ContentPutMode::CREATE); + } + + /** + * {@inheritdoc} + */ + public static function prepend(string $path, string $content) : bool + { + return self::put($path, $content, ContentPutMode::PREPEND | ContentPutMode::CREATE); + } + + /** + * {@inheritdoc} + */ + public static function exists(string $path) : bool + { + if(ftp_pwd($con) !== LocalFile::dirpath($path)) { + if(!ftp_chdir($con, $path)) { + return false; + } + } + + $list = ftp_nlist($con, $path); + + return in_array($path, $list); + } + + /** + * {@inheritdoc} + */ + public static function parent(string $path) : string + { + } + + /** + * {@inheritdoc} + */ + public static function sanitize(string $path, string $replace = '') : string + { + return preg_replace('/[^\w\s\d\.\-_~,;\/\[\]\(\]]/', $replace, $path); + } + + /** + * {@inheritdoc} + */ + public static function created(string $path) : \DateTime + { + + } + + /** + * {@inheritdoc} + */ + public static function changed(string $path) : \DateTime + { + + } + + /** + * {@inheritdoc} + */ + public static function size(string $path, bool $recursive = true) : int + { + + } + + /** + * {@inheritdoc} + */ + public static function owner(string $path) : int + { + + } + + /** + * {@inheritdoc} + */ + public static function permission(string $path) : string + { + + } + + /** + * Gets the directory name of a file. + * + * @param string $path Path of the file to get the directory name for. + * + * @return string Returns the directory name of the file. + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public static function dirname(string $path) : string + { + + } + + /** + * Gets the directory path of a file. + * + * @param string $path Path of the file to get the directory name for. + * + * @return string Returns the directory name of the file. + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public static function dirpath(string $path) : string + { + + } + + /** + * {@inheritdoc} + */ + public static function copy(string $from, string $to, bool $overwrite = false) : bool + { + + } + + /** + * {@inheritdoc} + */ + public static function move(string $from, string $to, bool $overwrite = false) : bool + { + + } + + /** + * {@inheritdoc} + */ + public static function delete(string $path) : bool + { + + } + + /** + * {@inheritdoc} + */ + public static function create(string $path) : bool + { + + } + + /** + * {@inheritdoc} + */ + public static function name(string $path) : string + { + return explode('.', basename($path))[0]; + } + + /** + * {@inheritdoc} + */ + public static function basename(string $path) : string + { + // TODO: Implement basename() method. + } + + /** + * {@inheritdoc} + */ + public static function extension(string $path) : string + { + $extension = explode('.', basename($path)); + + return $extension[1] ?? ''; + } +} \ No newline at end of file diff --git a/System/File/Ftp/FtpStorage.php b/System/File/Ftp/FtpStorage.php index 06093e705..e5897f874 100644 --- a/System/File/Ftp/FtpStorage.php +++ b/System/File/Ftp/FtpStorage.php @@ -32,6 +32,34 @@ use phpOMS\System\File\StorageAbstract; */ class FtpStorage extends StorageAbstract { + private $con = null; + + public function __construct(string $uri, int $port = 21, string $login = null, string $pass = null, bool $ssl = false) + { + $this->connect($uri, $port = 21, $login = null, $pass = null, $ssl = false); + } + + public function connect(string $uri, int $port = 21, string $login = null, string $pass = null, bool $ssl = false) : bool + { + if($ssl) { + $this->con = ftp_connect($uri, $port); + } else { + $this->con = ftp_ssl_connect($uri, $port); + } + + if(isset($login) && isset($pass)) { + ftp_login($this->con, $login, $pass); + } + } + + public function __destruct() + { + if(isset($this->con)) { + ftp_close($this->con); + $this->con = null; + } + } + /** * {@inheritdoc} */