diff --git a/CHANGELOG.md b/CHANGELOG.md index c257fc4..19476b0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # CHANGELOG +## [1.1.0] +- change: added additional functional usage + ## [1.0.8] - fix: git - directory check for deletion diff --git a/bin/downloadSources.php b/bin/downloadSources.php deleted file mode 100644 index df6c645..0000000 --- a/bin/downloadSources.php +++ /dev/null @@ -1,18 +0,0 @@ -downloadSources(); \ No newline at end of file diff --git a/composer.json b/composer.json index 52f6350..373ce4c 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "flux-eco/source-downloader", "description": "Component for flux-capacitor apps developed by fluxlabs", - "version": "1.0.8", + "version": "1.1.0", "type": "flux-eco", "keywords": [ "flux-eco", @@ -23,15 +23,25 @@ }, "require": { "flux-eco/shell-executor": ">=0.0.1", + "flux-eco/dot-env": ">=0.0.1", "php": ">=7.4", "ext-curl": "*", "ext-json": "*", "ext-yaml": "*" }, "autoload": { + "files": [ + "fn/downloadSources.php", + "fn/getEnvSourceDownloaderGitFullClone.php", + "fn/getEnvSourceDownloaderSourceListFilePath.php", + "fn/getEnvSourceDownloaderVolumePath.php" + ], "psr-4": { "FluxEco\\SourceDownloader\\": [ "src/" + ], + "fluxy\\": [ + "fn/" ] } }, diff --git a/composer.lock b/composer.lock index 2f0e254..e709f7d 100644 --- a/composer.lock +++ b/composer.lock @@ -4,31 +4,85 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "544ed68328e2b30f1aa7914d4890be6b", + "content-hash": "89f03f561e1279b608ed79a2820af7b1", "packages": [ + { + "name": "flux-eco/dot-env", + "version": "1.1.0", + "source": { + "type": "git", + "url": "https://github.com/flux-eco/dot-env.git", + "reference": "018e9cc0f6ccadbbe764abc987d86e22d1058f6f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/flux-eco/dot-env/zipball/018e9cc0f6ccadbbe764abc987d86e22d1058f6f", + "reference": "018e9cc0f6ccadbbe764abc987d86e22d1058f6f", + "shasum": "" + }, + "require": { + "php": ">=7.4" + }, + "type": "flux-app", + "autoload": { + "files": [ + "fn/loadDotEnv.php" + ], + "psr-4": { + "fluxy\\": [ + "fn/" + ], + "FluxEco\\DotEnv\\": [ + "src/" + ] + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "GPL-3.0-only" + ], + "authors": [ + { + "name": "fluxlabs ag", + "email": "support@fluxlabs.ch", + "homepage": "https://fluxlabs.ch", + "role": "Developer" + } + ], + "description": "Loads .env-Files", + "homepage": "https://fluxlabs.ch", + "keywords": [ + "dot-env", + "flux-eco", + "fluxlabs" + ], + "support": { + "email": "support@fluxlabs.ch", + "source": "https://github.com/flux-eco/dot-env/tree/v1.1.0" + }, + "time": "2022-04-03T03:56:56+00:00" + }, { "name": "flux-eco/shell-executor", - "version": "0.0.1", + "version": "0.0.2", "source": { "type": "git", "url": "https://github.com/flux-eco/shell-executor.git", - "reference": "bf1dd67ecd242864449d42cb92a55a5c20357a98" + "reference": "bb67de623f80e14cee0cca902eca57eeaf9c9539" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/flux-eco/shell-executor/zipball/bf1dd67ecd242864449d42cb92a55a5c20357a98", - "reference": "bf1dd67ecd242864449d42cb92a55a5c20357a98", + "url": "https://api.github.com/repos/flux-eco/shell-executor/zipball/bb67de623f80e14cee0cca902eca57eeaf9c9539", + "reference": "bb67de623f80e14cee0cca902eca57eeaf9c9539", "shasum": "" }, "require": { - "composer-runtime-api": ">=2.1", "ext-curl": "*", "ext-json": "*", "ext-yaml": "*", - "php": ">=8.0" + "php": ">=7.4" }, "require-dev": { - "composer/composer": ">=2.0", "swoole/ide-helper": ">=4.6" }, "type": "flux-app", @@ -51,19 +105,19 @@ "role": "Developer" } ], - "description": "Component for flux-capacitor apps developed by fluxlabs", + "description": "Component for executing shell commands", "homepage": "https://fluxlabs.ch", "keywords": [ - "flux-capacitor", - "flux-ecosystem", - "fluxlabs ag" + "flux-eco", + "fluxlabs", + "shell-executor" ], "support": { "email": "support@fluxlabs.ch", "issues": "https://github.com/flux-eco/shell-executor/issues", - "source": "https://github.com/flux-eco/shell-executor/tree/v0.0.1" + "source": "https://github.com/flux-eco/shell-executor/tree/v0.0.2" }, - "time": "2022-03-28T03:02:50+00:00" + "time": "2022-04-01T02:41:15+00:00" } ], "packages-dev": [], diff --git a/examples/.env b/examples/.env new file mode 100644 index 0000000..3bfd379 --- /dev/null +++ b/examples/.env @@ -0,0 +1,3 @@ +SOURCE_DOWNLOADER_SOURCE_LIST_FILE_PATH=sourceList.yaml +SOURCE_DOWNLOADER_VOLUME_PATH=/tmp +SOURCE_DOWNLOADER_GIT_FULL_CLONE=0 \ No newline at end of file diff --git a/examples/downloadSources.php b/examples/downloadSources.php new file mode 100644 index 0000000..feb1a7a --- /dev/null +++ b/examples/downloadSources.php @@ -0,0 +1,15 @@ +load(__DIR__); + +$sourceListFile = getenv(SourceDownloader\Env::SOURCE_LIST_FILE_PATH); +$volumePath = getenv(SourceDownloader\Env::VOLUME_PATH); +$gitGetFullClone = getenv(SourceDownloader\Env::GIT_FULL_CLONE); + +$api = SourceDownloader\Api::new($gitGetFullClone); +$api->downloadSources($sourceListFile, $volumePath); \ No newline at end of file diff --git a/examples/downloadSourcesFunctional.php b/examples/downloadSourcesFunctional.php new file mode 100644 index 0000000..57072b4 --- /dev/null +++ b/examples/downloadSourcesFunctional.php @@ -0,0 +1,11 @@ +downloadSources($sourceListFile, $volumePath); +} \ No newline at end of file diff --git a/fn/getEnvSourceDownloaderGitFullClone.php b/fn/getEnvSourceDownloaderGitFullClone.php new file mode 100644 index 0000000..b81ab65 --- /dev/null +++ b/fn/getEnvSourceDownloaderGitFullClone.php @@ -0,0 +1,10 @@ +service = $service; - } - - public static function new(?string $sourceListFile = null, ?string $volumePath = null, ?bool $gitGetFullClone = null) : self - { - $apiGatewayService = Ports\Service::new(Adapters\Configs\Outbounds::new($sourceListFile, $volumePath, $gitGetFullClone)); - return new self($apiGatewayService); - } - - public function downloadSources() { - $this->service->downloadSources(); - } -} \ No newline at end of file diff --git a/src/Adapters/Configs/Outbounds.php b/src/Adapters/Configs/Outbounds.php index 34f88ab..7a7db42 100644 --- a/src/Adapters/Configs/Outbounds.php +++ b/src/Adapters/Configs/Outbounds.php @@ -6,33 +6,15 @@ class Outbounds implements Ports\Configs\Outbounds { - private string $sourceListFile; - private string $volumePath; private bool $gitGetFullClone; - private function __construct(string $sourceListFile, string $volumePath, bool $gitGetFullClone) + private function __construct(bool $gitGetFullClone) { - $this->sourceListFile = $sourceListFile; - $this->volumePath = $volumePath; $this->gitGetFullClone = $gitGetFullClone; } - public static function new( - ?string $sourceListFile = null, - ?string $volumePath = null, - ?bool $gitGetFullClone = null - ) : self { - if (is_null($sourceListFile) === true) { - $sourceListFile = getenv(Env::SOURCE_LIST_FILE); - } - if (is_null($volumePath) === true) { - $volumePath = getenv(Env::VOLUME_PATH); - } - if (is_null($gitGetFullClone) === true) { - $gitGetFullClone = getenv(Env::GIT_FULL_CLONE); - } - - return new self($sourceListFile, $volumePath, $gitGetFullClone); + public static function new(bool $gitGetFullClone) : self { + return new self($gitGetFullClone); } public function getShellExecutorClient() : Ports\ShellExecutor\ShellExecutorClient @@ -45,12 +27,12 @@ public function getGitFullClone() : bool return $this->gitGetFullClone; } - public function getSourceList() : array + public function getSourceList(string $sourceListFile, ?string $volumePath = null) : array { - $sources = yaml_parse(file_get_contents($this->sourceListFile)); + $sources = yaml_parse(file_get_contents($sourceListFile)); $transformedSources = []; foreach ($sources as $source) { - $source['directoryPath'] = $this->volumePath . $source['directoryPath']; + $source['directoryPath'] = $volumePath . $source['directoryPath']; $transformedSources[] = $source; } return $transformedSources; diff --git a/src/Api.php b/src/Api.php new file mode 100644 index 0000000..3775dbf --- /dev/null +++ b/src/Api.php @@ -0,0 +1,25 @@ +service = $service; + } + + public static function new(bool $gitGetFullClone = true) : self + { + $apiGatewayService = Ports\Service::new(Adapters\Configs\Outbounds::new($gitGetFullClone)); + return new self($apiGatewayService); + } + + public function downloadSources(string $sourceListFile = null, ?string $volumePath = null) { + $this->service->downloadSources($sourceListFile, $volumePath); + } +} \ No newline at end of file diff --git a/src/Core/Ports/Configs/Outbounds.php b/src/Core/Ports/Configs/Outbounds.php index bea963e..eb1767f 100644 --- a/src/Core/Ports/Configs/Outbounds.php +++ b/src/Core/Ports/Configs/Outbounds.php @@ -8,5 +8,5 @@ interface Outbounds { public function getShellExecutorClient() : Ports\ShellExecutor\ShellExecutorClient; public function getGitFullClone() : bool; - public function getSourceList() : array; + public function getSourceList(string $sourceListFile, ?string $volumePath = null) : array; } \ No newline at end of file diff --git a/src/Core/Ports/Service.php b/src/Core/Ports/Service.php index 3644977..4ed3458 100644 --- a/src/Core/Ports/Service.php +++ b/src/Core/Ports/Service.php @@ -18,9 +18,9 @@ public static function new(Configs\Outbounds $outbounds) : self return new self($outbounds); } - public function downloadSources() + public function downloadSources(string $sourceListFile = null, ?string $volumePath = null) { - $sourceList = $this->outbounds->getSourceList(); + $sourceList = $this->outbounds->getSourceList($sourceListFile, $volumePath); foreach ($sourceList as $source) { $process = Processes\DownloadProcess::new($this->outbounds); diff --git a/src/Adapters/Configs/Env.php b/src/Env.php similarity index 54% rename from src/Adapters/Configs/Env.php rename to src/Env.php index 585134a..6e3aad6 100644 --- a/src/Adapters/Configs/Env.php +++ b/src/Env.php @@ -1,10 +1,10 @@