diff --git a/app/config/container.php b/app/config/container.php index cba797e..2eeddfd 100644 --- a/app/config/container.php +++ b/app/config/container.php @@ -4,9 +4,13 @@ use App\Factories; return [ /** Path definitions */ - 'app_path' => dirname(__DIR__), 'base_path' => dirname(__DIR__, 2), + 'app_path' => dirname(__DIR__), + 'asset_path' => DI\string('{app_path}/assets'), + 'cache_path' => DI\string('{app_path}/cache'), 'config_path' => DI\string('{app_path}/config'), + 'translations_path' => DI\string('{app_path}/translations'), + 'views_path' => DI\string('{app_path}/views'), 'icons_config' => DI\string('{config_path}/icons.php'), /** Container definitions */ diff --git a/app/src/Controllers/ZipController.php b/app/src/Controllers/ZipController.php index 0e7f6c4..d4e48ed 100644 --- a/app/src/Controllers/ZipController.php +++ b/app/src/Controllers/ZipController.php @@ -77,7 +77,7 @@ class ZipController { $zip = new ZipArchive; $zip->open((string) $tempFile = new TemporaryFile( - $this->container->get('base_path') . '/app/cache' + $this->container->get('cache_path') ), ZipArchive::CREATE | ZipArchive::OVERWRITE); foreach ($this->finder->in($path)->files() as $file) { diff --git a/app/src/Factories/TranslationFactory.php b/app/src/Factories/TranslationFactory.php index 6dffbab..abe0d9d 100644 --- a/app/src/Factories/TranslationFactory.php +++ b/app/src/Factories/TranslationFactory.php @@ -47,7 +47,7 @@ class TranslationFactory Collection::make(self::LANGUAGES)->each( function (string $language) use ($translator): void { - $resource = sprintf($this->container->get('app_path') . '/translations/%s.yaml', $language); + $resource = sprintf($this->container->get('translations_path') . '/%s.yaml', $language); $translator->addResource('yaml', $resource, $language); } ); diff --git a/app/src/Factories/TwigFactory.php b/app/src/Factories/TwigFactory.php index 7a795ab..b95aa5e 100644 --- a/app/src/Factories/TwigFactory.php +++ b/app/src/Factories/TwigFactory.php @@ -54,7 +54,9 @@ class TwigFactory */ public function __invoke(): Twig { - $twig = new Twig(new FilesystemLoader('app/views')); + $twig = new Twig(new FilesystemLoader( + $this->container->get('views_path') + )); $twig->getEnvironment()->setCache( $this->container->get('view_cache') diff --git a/app/src/ViewFunctions/Asset.php b/app/src/ViewFunctions/Asset.php index 878a3bd..ffc31c9 100644 --- a/app/src/ViewFunctions/Asset.php +++ b/app/src/ViewFunctions/Asset.php @@ -7,9 +7,6 @@ use Tightenco\Collect\Support\Collection; class Asset extends ViewFunction { - /** @const Constant description */ - protected const ASSET_PATH = 'app/assets/'; - /** @var string The function name */ protected $name = 'asset'; @@ -41,7 +38,7 @@ class Asset extends ViewFunction $path = $this->mixManifest()->get($path); } - return self::ASSET_PATH . ltrim($path, '/'); + return 'app/assets/' . ltrim($path, '/'); } /** @@ -51,7 +48,7 @@ class Asset extends ViewFunction */ protected function mixManifest(): Collection { - $mixManifest = $this->container->get('base_path') . '/' . self::ASSET_PATH . 'mix-manifest.json'; + $mixManifest = $this->container->get('asset_path') . '/mix-manifest.json'; if (! is_file($mixManifest)) { return new Collection; diff --git a/tests/TestCase.php b/tests/TestCase.php index 01e97e5..ad41ef6 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -30,6 +30,8 @@ class TestCase extends PHPUnitTestCase )->build(); $this->container->set('base_path', $this->testFilesPath); + $this->container->set('asset_path', $this->filePath('app/assets')); + $this->container->set('cache_path', $this->filePath('app/cache')); } /** diff --git a/tests/ViewFunctions/AssetTest.php b/tests/ViewFunctions/AssetTest.php index 205f2e3..2a2889a 100644 --- a/tests/ViewFunctions/AssetTest.php +++ b/tests/ViewFunctions/AssetTest.php @@ -17,9 +17,9 @@ class AssetTest extends TestCase $this->assertEquals('app/assets/images/icon.png', $asset('images/icon.png')); } - public function test_it_can_return_an_asset_from_a_subdirectory(): void + public function test_it_can_return_an_asset_path_without_a_mix_manifest_file(): void { - $this->container->set('base_path', $this->filePath('subdir')); + $this->container->set('asset_path', $this->filePath('.')); $asset = new Asset($this->container);