diff --git a/composer.json b/composer.json index 0ed7af2..737f49b 100644 --- a/composer.json +++ b/composer.json @@ -13,8 +13,5 @@ "name": "OMAHM", "email": "hello@onemanandhismouse.com" } - ], - "require": { - "symfony/filesystem": "^4.2" - } + ] } diff --git a/composer.lock b/composer.lock deleted file mode 100644 index 16ab92a..0000000 --- a/composer.lock +++ /dev/null @@ -1,247 +0,0 @@ -{ - "_readme": [ - "This file locks the dependencies of your project to a known state", - "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", - "This file is @generated automatically" - ], - "content-hash": "0316e685594289f5afae571709f7e10d", - "packages": [ - { - "name": "symfony/filesystem", - "version": "v4.4.42", - "source": { - "type": "git", - "url": "https://github.com/symfony/filesystem.git", - "reference": "815412ee8971209bd4c1eecd5f4f481eacd44bf5" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/filesystem/zipball/815412ee8971209bd4c1eecd5f4f481eacd44bf5", - "reference": "815412ee8971209bd4c1eecd5f4f481eacd44bf5", - "shasum": "" - }, - "require": { - "php": ">=7.1.3", - "symfony/polyfill-ctype": "~1.8", - "symfony/polyfill-php80": "^1.16" - }, - "type": "library", - "autoload": { - "psr-4": { - "Symfony\\Component\\Filesystem\\": "" - }, - "exclude-from-classmap": [ - "/Tests/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Provides basic utilities for the filesystem", - "homepage": "https://symfony.com", - "support": { - "source": "https://github.com/symfony/filesystem/tree/v4.4.42" - }, - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], - "time": "2022-05-20T08:49:14+00:00" - }, - { - "name": "symfony/polyfill-ctype", - "version": "v1.26.0", - "source": { - "type": "git", - "url": "https://github.com/symfony/polyfill-ctype.git", - "reference": "6fd1b9a79f6e3cf65f9e679b23af304cd9e010d4" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/6fd1b9a79f6e3cf65f9e679b23af304cd9e010d4", - "reference": "6fd1b9a79f6e3cf65f9e679b23af304cd9e010d4", - "shasum": "" - }, - "require": { - "php": ">=7.1" - }, - "provide": { - "ext-ctype": "*" - }, - "suggest": { - "ext-ctype": "For best performance" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-main": "1.26-dev" - }, - "thanks": { - "name": "symfony/polyfill", - "url": "https://github.com/symfony/polyfill" - } - }, - "autoload": { - "files": [ - "bootstrap.php" - ], - "psr-4": { - "Symfony\\Polyfill\\Ctype\\": "" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Gert de Pagter", - "email": "BackEndTea@gmail.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony polyfill for ctype functions", - "homepage": "https://symfony.com", - "keywords": [ - "compatibility", - "ctype", - "polyfill", - "portable" - ], - "support": { - "source": "https://github.com/symfony/polyfill-ctype/tree/v1.26.0" - }, - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], - "time": "2022-05-24T11:49:31+00:00" - }, - { - "name": "symfony/polyfill-php80", - "version": "v1.26.0", - "source": { - "type": "git", - "url": "https://github.com/symfony/polyfill-php80.git", - "reference": "cfa0ae98841b9e461207c13ab093d76b0fa7bace" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/cfa0ae98841b9e461207c13ab093d76b0fa7bace", - "reference": "cfa0ae98841b9e461207c13ab093d76b0fa7bace", - "shasum": "" - }, - "require": { - "php": ">=7.1" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-main": "1.26-dev" - }, - "thanks": { - "name": "symfony/polyfill", - "url": "https://github.com/symfony/polyfill" - } - }, - "autoload": { - "files": [ - "bootstrap.php" - ], - "psr-4": { - "Symfony\\Polyfill\\Php80\\": "" - }, - "classmap": [ - "Resources/stubs" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Ion Bazan", - "email": "ion.bazan@gmail.com" - }, - { - "name": "Nicolas Grekas", - "email": "p@tchwork.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony polyfill backporting some PHP 8.0+ features to lower PHP versions", - "homepage": "https://symfony.com", - "keywords": [ - "compatibility", - "polyfill", - "portable", - "shim" - ], - "support": { - "source": "https://github.com/symfony/polyfill-php80/tree/v1.26.0" - }, - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], - "time": "2022-05-10T07:21:04+00:00" - } - ], - "packages-dev": [], - "aliases": [], - "minimum-stability": "stable", - "stability-flags": [], - "prefer-stable": false, - "prefer-lowest": false, - "platform": [], - "platform-dev": [], - "plugin-api-version": "2.3.0" -} diff --git a/src/Filesystem/Filesystem.php b/src/Filesystem/Filesystem.php deleted file mode 100644 index f5ab182..0000000 --- a/src/Filesystem/Filesystem.php +++ /dev/null @@ -1,212 +0,0 @@ -rootPath = $path; - $this->fs = new \Symfony\Component\Filesystem\Filesystem(); - } - - /** - * Check if the file or directory exists. - * - * @param string $path - * The path to the file or directory. - * - * @return boolean - */ - public function exists($path) { - return $this->fs->exists($this->fullPath($path)); - } - - /** - * Read content of a file. - * - * @param string $path - * The path to the file. - * - * @return mixed - * The file contents. - */ - public function read($path) { - $path = $this->fullPath($path); - - if (!$this->fs->exists($path)) { - return NULL; - } - - switch (pathinfo($path, PATHINFO_EXTENSION)) { - case 'yaml': - case 'yml': - return Yaml::parseFile($path); - - case 'env': - return parse_ini_file($path); - - default: - return file_get_contents($path); - - } - } - - /** - * Write content to a file. - * - * @param string $path - * The path to the file. - * @param mixed $content - * The contents to write to the file. - */ - public function write($path, $content) { - $path = $this->fullPath($path); - - if (str_ends_with($path, '.env')) { - $content = self::arrayToIni($content); - } - - if (str_ends_with($path, '.yml') || str_ends_with($path, '.yaml')) { - $content = Yaml::dump($content, 6); - } - - $this->fs->dumpFile($path, $content); - } - - /** - * Delete a file or directory. - * - * @param string $path - * The path to the file or directory. - */ - public function delete($path) { - $this->fs->remove($this->fullPath($path)); - } - - /** - * Copy a file or directory - * - * @param string $path - * The path of the file or directory to copy. - * @param string $destination - * The path of the destination. - */ - public function copy($path, $destination) { - $path = $this->fullPath($path); - $destination = $this->fullPath($destination); - - if ($this->isDir($path)) { - $this->fs->mirror($path, $destination); - } else { - $this->fs->copy($path, $destination); - } - } - - /** - * Create a directory. - * - * @param string $path - * The path of the directory. - */ - public function createDirectory($path) { - $this->fs->mkdir($this->fullPath($path)); - } - - /** - * Create a symlink. - * - * @param string $source - * The path of the file or directory to link to. - * @param string $link - * The name of the symlink. - */ - public function link($source, $link) { - $this->fs->symlink($this->fullPath($source), $this->fullPath($link)); - } - - /** - * Check if the path is a directory - * - * @param string $path The path to check. - * - * @return boolean - */ - public function isDir($path){ - return is_dir($this->fullPath($path)); - } - - /** - * Set the root path from which all file operation are based. - * - * @param string $path The path to set as the root. - */ - public function setRootPath($path) { - $this->rootPath = $path; - } - - /** - * Returns the full filesystem path. - * - * @param $path - * The path to append to the root path. - * @return string - * The full root and path. - */ - protected function fullPath($path) { - // If the path starts with a double slash do not prepend the rootPath. - if (str_starts_with($path, '//')) { - return substr($path, 1, strlen($path)); - } - - return $this->rootPath . $path; - } - - /** - * Convert arrays to ini file format. - * - * @param array $data - * Array of data to be written. - * @param int $i - * Ini file index. - * - * @return string - * string of ini format data. - */ - protected static function arrayToIni(array $data, $i = 0) { - $str = ""; - foreach ($data as $key => $val) { - if (is_array($val)) { - $str .= str_repeat(" ", $i * 2) . "[$key]" . PHP_EOL; - $str .= self::arrayToIni($val, $i + 1); - } - else { - $str .= str_repeat(" ", $i * 2) . "$key = $val" . PHP_EOL; - } - } - return $str; - } - -} \ No newline at end of file diff --git a/src/FilesystemInterface.php b/src/FilesystemInterface.php new file mode 100644 index 0000000..3cc862f --- /dev/null +++ b/src/FilesystemInterface.php @@ -0,0 +1,87 @@ +