Get things into a somewhat working state on the login form
This commit is contained in:
parent
7de2c8684c
commit
791cbaa5ce
15 changed files with 450 additions and 132 deletions
34
app/Http/ViewComposers/AssetComposer.php
Normal file
34
app/Http/ViewComposers/AssetComposer.php
Normal file
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
namespace Pterodactyl\Http\ViewComposers;
|
||||
|
||||
use Illuminate\View\View;
|
||||
use Pterodactyl\Services\Helpers\AssetHashService;
|
||||
|
||||
class AssetComposer
|
||||
{
|
||||
/**
|
||||
* @var \Pterodactyl\Services\Helpers\AssetHashService
|
||||
*/
|
||||
private $assetHashService;
|
||||
|
||||
/**
|
||||
* AssetComposer constructor.
|
||||
*
|
||||
* @param \Pterodactyl\Services\Helpers\AssetHashService $assetHashService
|
||||
*/
|
||||
public function __construct(AssetHashService $assetHashService)
|
||||
{
|
||||
$this->assetHashService = $assetHashService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide access to the asset service in the views.
|
||||
*
|
||||
* @param \Illuminate\View\View $view
|
||||
*/
|
||||
public function compose(View $view)
|
||||
{
|
||||
$view->with('asset', $this->assetHashService);
|
||||
}
|
||||
}
|
|
@ -3,6 +3,7 @@
|
|||
namespace Pterodactyl\Providers;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Pterodactyl\Http\ViewComposers\AssetComposer;
|
||||
use Pterodactyl\Http\ViewComposers\ServerListComposer;
|
||||
use Pterodactyl\Http\ViewComposers\Server\ServerDataComposer;
|
||||
|
||||
|
@ -13,6 +14,8 @@ class ViewComposerServiceProvider extends ServiceProvider
|
|||
*/
|
||||
public function boot()
|
||||
{
|
||||
$this->app->make('view')->composer('*', AssetComposer::class);
|
||||
|
||||
$this->app->make('view')->composer('server.*', ServerDataComposer::class);
|
||||
|
||||
// Add data to make the sidebar work when viewing a server.
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
namespace Pterodactyl\Services\Helpers;
|
||||
|
||||
use Illuminate\Container\Container;
|
||||
use Illuminate\Filesystem\FilesystemManager;
|
||||
use Illuminate\Contracts\Foundation\Application;
|
||||
use Illuminate\Contracts\Cache\Repository as CacheRepository;
|
||||
|
@ -56,20 +55,47 @@ class AssetHashService
|
|||
*
|
||||
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
|
||||
*/
|
||||
public function getUrl(string $resource): string
|
||||
public function url(string $resource): string
|
||||
{
|
||||
$file = last(explode('/', $resource));
|
||||
|
||||
return '/' . ltrim(str_replace($file, array_get($this->getManifest(), $file, $file), $resource), '/');
|
||||
return '/' . ltrim(str_replace($file, array_get($this->manifest(), $file, $file), $resource), '/');
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a built CSS import using the provided URL.
|
||||
*
|
||||
* @param string $resource
|
||||
* @return string
|
||||
*
|
||||
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
|
||||
*/
|
||||
public function css(string $resource): string
|
||||
{
|
||||
return '<link href="' . $this->url($resource) . '" rel="stylesheet preload" crossorigin="anonymous" referrerpolicy="no-referrer">';
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a built JS import using the provided URL.
|
||||
*
|
||||
* @param string $resource
|
||||
* @return string
|
||||
*
|
||||
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
|
||||
*/
|
||||
public function js(string $resource): string
|
||||
{
|
||||
return '<script src="' . $this->url($resource) . '" crossorigin="anonymous"></script>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the asset manifest and store it in the cache for quicker lookups.
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
|
||||
*/
|
||||
public function getManifest(): array
|
||||
protected function manifest(): array
|
||||
{
|
||||
if (! is_null(self::$manifest)) {
|
||||
return self::$manifest;
|
||||
|
@ -88,41 +114,4 @@ class AssetHashService
|
|||
|
||||
return self::$manifest = $contents;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the URL for a resource in a static context.
|
||||
*
|
||||
* @param string $resource
|
||||
* @return string
|
||||
*
|
||||
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
|
||||
*/
|
||||
public static function url(string $resource): string
|
||||
{
|
||||
return Container::getInstance()->make(self::class)->getUrl($resource);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $resource
|
||||
* @return string
|
||||
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
|
||||
*/
|
||||
public static function css(string $resource): string
|
||||
{
|
||||
$path = self::url($resource);
|
||||
|
||||
return '<link href="' . $path . '" rel="stylesheet preload" crossorigin="anonymous" referrerpolicy="no-referrer">';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $resource
|
||||
* @return string
|
||||
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
|
||||
*/
|
||||
public static function js(string $resource): string
|
||||
{
|
||||
$path = self::url($resource);
|
||||
|
||||
return '<script src="' . $path . '" crossorigin="anonymous">';
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue