mirror of
https://github.com/DirectoryLister/DirectoryLister.git
synced 2025-08-24 22:46:08 +02:00
Internal improvements to file and directory path handling
This commit is contained in:
@@ -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 */
|
||||
|
@@ -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) {
|
||||
|
@@ -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);
|
||||
}
|
||||
);
|
||||
|
@@ -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')
|
||||
|
@@ -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;
|
||||
|
@@ -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'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -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);
|
||||
|
||||
|
Reference in New Issue
Block a user