-
Notifications
You must be signed in to change notification settings - Fork 239
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added assets hashing after build, added favicon
- Loading branch information
Showing
14 changed files
with
2,407 additions
and
2,249 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
namespace Engelsystem\Helpers; | ||
|
||
class Assets | ||
{ | ||
/** @var string */ | ||
protected string $assetsPath; | ||
|
||
/** @var string */ | ||
protected string $manifestFile = 'manifest.json'; | ||
|
||
/** | ||
* @param string $assetsPath Directory containing assets | ||
*/ | ||
public function __construct(string $assetsPath) | ||
{ | ||
$this->assetsPath = $assetsPath; | ||
} | ||
|
||
/** | ||
* @param string $asset | ||
* @return string | ||
*/ | ||
public function getAssetPath(string $asset): string | ||
{ | ||
$manifest = $this->assetsPath . DIRECTORY_SEPARATOR . $this->manifestFile; | ||
if (is_readable($manifest)) { | ||
$manifest = json_decode(file_get_contents($manifest), true); | ||
|
||
if (isset($manifest[$asset])) { | ||
$asset = $manifest[$asset]; | ||
} | ||
} | ||
|
||
return $asset; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
namespace Engelsystem\Helpers; | ||
|
||
use Engelsystem\Container\ServiceProvider; | ||
|
||
class AssetsServiceProvider extends ServiceProvider | ||
{ | ||
public function register() | ||
{ | ||
$this->app->when(Assets::class) | ||
->needs('$assetsPath') | ||
->give($this->app->get('path.assets.public')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace Engelsystem\Test\Unit\Helpers; | ||
|
||
use Engelsystem\Application; | ||
use Engelsystem\Helpers\Assets; | ||
use Engelsystem\Helpers\AssetsServiceProvider; | ||
use Engelsystem\Test\Unit\ServiceProviderTest; | ||
|
||
class AssetsServiceProviderTest extends ServiceProviderTest | ||
{ | ||
/** | ||
* @covers \Engelsystem\Helpers\AssetsServiceProvider::register | ||
*/ | ||
public function testRegister() | ||
{ | ||
$app = new Application(); | ||
$app->instance('path.assets.public', '/tmp'); | ||
|
||
$serviceProvider = new AssetsServiceProvider($app); | ||
$serviceProvider->register(); | ||
|
||
$this->assertArrayHasKey(Assets::class, $app->contextual); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace Engelsystem\Test\Unit\Helpers; | ||
|
||
use Engelsystem\Helpers\Assets; | ||
use Engelsystem\Test\Unit\TestCase; | ||
|
||
class AssetsTest extends TestCase | ||
{ | ||
/** | ||
* @covers \Engelsystem\Helpers\Assets::__construct | ||
* @covers \Engelsystem\Helpers\Assets::getAssetPath | ||
*/ | ||
public function testGetAssetPath() | ||
{ | ||
$assets = new Assets('/foo/bar'); | ||
$this->assertEquals('lorem.bar', $assets->getAssetPath('lorem.bar')); | ||
|
||
$assets = new Assets(__DIR__ . '/Stub/files'); | ||
$this->assertEquals('something.xyz', $assets->getAssetPath('something.xyz')); | ||
$this->assertEquals('lorem-hashed.ipsum', $assets->getAssetPath('foo.bar')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"foo.bar": "lorem-hashed.ipsum" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.