Removed use of mix-manifest

This commit is contained in:
Chris Kankiewicz
2020-01-25 22:51:07 -07:00
parent d59799f0df
commit 7158d5f997
7 changed files with 7 additions and 47 deletions

View File

@@ -15,7 +15,7 @@ class FinderProvider
{
/** @const Application paths to be hidden */
protected const APP_FILES = [
'app', 'node_modules', 'vendor', 'mix-manifest.json', 'index.php'
'app', 'node_modules', 'vendor', 'index.php'
];
/** @const Array of sort options mapped to their respective methods */

View File

@@ -2,8 +2,6 @@
namespace App\ViewFunctions;
use Tightenco\Collect\Support\Collection;
class Asset extends ViewFunction
{
/** @const Constant description */
@@ -21,30 +19,8 @@ class Asset extends ViewFunction
*/
public function __invoke(string $path): string
{
$assetPath = self::ASSET_PATH . $path;
$assetPath = dirname($_SERVER['SCRIPT_NAME']) . self::ASSET_PATH . ltrim($path, '/');
if ($this->mixManifest()->has($assetPath)) {
return $this->mixManifest()->get($assetPath);
}
return $assetPath;
}
/**
* Return the mix manifest collection.
*
* @return \Tightenco\Collect\Support\Collection
*/
protected function mixManifest(): Collection
{
$mixManifest = $this->container->get('base_path') . '/mix-manifest.json';
if (! is_file($mixManifest)) {
return new Collection();
}
return Collection::make(
json_decode(file_get_contents($mixManifest), true) ?? []
);
return '/' . ltrim($assetPath, '/');
}
}

View File

@@ -4,6 +4,5 @@ vendor
.env.example
directory-lister.svg
LICENSE
mix-manifest.json
README.md
index.php

View File

@@ -5,6 +5,5 @@ vendor
.htaccess
directory-lister.svg
LICENSE
mix-manifest.json
README.md
index.php

View File

@@ -24,6 +24,8 @@ class TestCase extends PHPUnitTestCase
*/
public function setUp(): void
{
$_SERVER['SCRIPT_NAME'] = '/index.php';
$this->config = new Config([
'app' => [
'sort_order' => 'type',

View File

@@ -11,19 +11,7 @@ class AssetTest extends TestCase
{
$asset = new Asset($this->container, $this->config);
$this->assertEquals('/app/dist/test.css', $asset('test.css'));
$this->assertEquals(
'/app/dist/app.css?id=417c7a9bc03852aafb27',
$asset('app.css')
);
}
public function test_it_can_return_an_asset_path_without_a_mix_manifest(): void
{
$this->container->set('base_path', $this->filePath('subdir'));
$asset = new Asset($this->container, $this->config);
$this->assertEquals('/app/dist/test.css', $asset('test.css'));
$this->assertEquals('/app/dist/app.css', $asset('app.css'));
$this->assertEquals('/app/dist/css/app.css', $asset('css/app.css'));
$this->assertEquals('/app/dist/js/app.js', $asset('js/app.js'));
}
}

View File

@@ -1,4 +0,0 @@
{
"/app/dist/app.js": "/app/dist/app.js?id=6753a7269276c7b52692",
"/app/dist/app.css": "/app/dist/app.css?id=417c7a9bc03852aafb27"
}