- WIP on Picea's Asset.
This commit is contained in:
parent
35b28c311e
commit
cce9d9865b
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Picea\Asset;
|
||||
|
||||
use RecursiveIteratorIterator, RecursiveDirectoryIterator;
|
||||
|
||||
class FileFetcher extends \Picea\FileFetcher
|
||||
{
|
||||
protected array $folderList = [];
|
||||
|
||||
public array $supportedExtensionList = [];
|
||||
|
||||
public function folderList(?array $set = null) : ?array
|
||||
{
|
||||
return $set === null ? $this->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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue