Internal improvements to file and directory path handling

This commit is contained in:
Chris Kankiewicz
2020-04-07 15:48:24 -07:00
parent 56cc465501
commit e8ada93fe2
7 changed files with 16 additions and 11 deletions

View File

@@ -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 */

View File

@@ -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) {

View 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);
}
);

View File

@@ -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')

View File

@@ -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;

View File

@@ -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'));
}
/**

View File

@@ -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);