diff --git a/src/Action/Install.php b/src/Action/Install.php index 62bbd6f..837d8a9 100644 --- a/src/Action/Install.php +++ b/src/Action/Install.php @@ -2,25 +2,30 @@ namespace Picea\Asset\Action; -use Picea\Asset\Extension; -use Picea\Compiler; -use Picea\Compiler\Context; -use Picea\Event\Extension\UrlBuildAssetEvent; +use Picea\Asset\FileFetcher; use Picea\EventTrait; class Install { use EventTrait; + public array $actions; + public function __construct( - public InstallActionInterface $action, - ) { } + InstallActionInterface $action, ... $actions + ) { + $this->actions = array_filter(array_merge([ $action ], $actions)); + } - public function launch() : bool + public function launch(FileFetcher $fileFetcher) : array { - $this->action->run(); + $output = []; - return true; + foreach($this->actions as $action) { + $output[$action::class] = $action->run($fileFetcher); + } + + return $output; } } diff --git a/src/Action/Symlink.php b/src/Action/Symlink.php index 55555e8..1be30ca 100644 --- a/src/Action/Symlink.php +++ b/src/Action/Symlink.php @@ -2,10 +2,18 @@ namespace Picea\Asset\Action; +use Picea\Asset\FileFetcher; + class Symlink implements InstallActionInterface { + public function __construct( + protected FileFetcher $fileFetcher + ) { } + public function run() : mixed { + dump($this->fileFetcher->getFileList()); + return null; } } \ No newline at end of file diff --git a/src/Asset.php b/src/Asset.php index f483e29..8b2efbe 100644 --- a/src/Asset.php +++ b/src/Asset.php @@ -3,8 +3,6 @@ namespace Picea\Asset; use Picea\Compiler; -use Picea\Compiler\Context; -use Picea\Event\Extension\UrlBuildAssetEvent; use Picea\EventTrait; class Asset { @@ -12,21 +10,22 @@ class Asset { use EventTrait; public function __construct( - null|Action\Install $install = null, - ) {} + public Action\Install $install, + public FileFetcher $fileFetcher, + ) { } public function registerExtension(Compiler $compiler) : self { $compiler->registerExtension(new Extension\ImportmapExtension()); -/* $compiler->getExtensionFromToken('asset')->eventRegister(new class() implements UrlBuildAssetEvent { - public function execute(string $uri, array $parameters = [], bool $appendVersion) : void - { - dump($uri); - } - }); */ - return $this; } + public function launchInstall() : void + { + $result = $this->install->launch($this->fileFetcher); + + #dump($result); + } + } diff --git a/src/FileFetcher.php b/src/FileFetcher.php new file mode 100644 index 0000000..fa094e8 --- /dev/null +++ b/src/FileFetcher.php @@ -0,0 +1,41 @@ +folderList : $this->folderList = $set; + } + + public function getFileList() : array + { + usort($this->folderList, fn($a, $b) => $a['order'] <=> $b['order']); + + $list = []; + + foreach($this->folderList() as $folder) { + $path = $folder['path'] . "/"; + $list[$path] = []; + + if ( \file_exists($path) ) { + $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::SELF_FIRST, RecursiveIteratorIterator::CATCH_GET_CHILD); + + foreach ($iterator as $file) { + if ( $file->isFile() ) { + $list[$path][] = $file; + } + } + } + } + + return $list; + } +}