From 6231447f476ce9e5d3da97d3881d97dfaa6df930 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Sun, 17 Feb 2019 13:29:45 +0800 Subject: [PATCH 1/3] Improve performance by prefixing all global functions calls with \ to skip the look up and resolve process and go straight to the global function Signed-off-by: Mior Muhammad Zaki --- src/Asset.php | 8 ++++---- src/DependencyResolver.php | 6 +++--- src/Dispatcher.php | 8 ++++---- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Asset.php b/src/Asset.php index bf4c034..ef103b1 100644 --- a/src/Asset.php +++ b/src/Asset.php @@ -117,7 +117,7 @@ public function add( $attributes = [], $replaces = [] ) { - $type = (pathinfo($source, PATHINFO_EXTENSION) == 'css') ? 'style' : 'script'; + $type = (\pathinfo($source, PATHINFO_EXTENSION) == 'css') ? 'style' : 'script'; return $this->$type($name, $source, $dependencies, $attributes, $replaces); } @@ -140,7 +140,7 @@ public function style( $attributes = [], $replaces = [] ) { - if (! array_key_exists('media', $attributes)) { + if (! \array_key_exists('media', $attributes)) { $attributes['media'] = 'all'; } @@ -196,8 +196,8 @@ protected function register( $attributes = (array) $attributes; $replaces = (array) $replaces; - if (is_array($name)) { - $replaces = array_merge($name, $replaces); + if (\is_array($name)) { + $replaces = \array_merge($name, $replaces); $name = '*'; } diff --git a/src/DependencyResolver.php b/src/DependencyResolver.php index 191d809..4ce3b70 100644 --- a/src/DependencyResolver.php +++ b/src/DependencyResolver.php @@ -50,7 +50,7 @@ protected function evaluateAsset( // list and remove it from the array of assets. Otherwise, we will // not verify the asset's dependencies and determine if they've been // sorted. - if (count($assets[$asset]['dependencies']) == 0) { + if (\count($assets[$asset]['dependencies']) == 0) { $sorted[$asset] = $value; unset($assets[$asset]); @@ -117,7 +117,7 @@ protected function dependencyIsValid( ): bool { // Determine if asset and dependency is circular. $isCircular = function ($asset, $dependency, $assets) { - return isset($assets[$dependency]) && in_array($asset, $assets[$dependency]['dependencies']); + return isset($assets[$dependency]) && \in_array($asset, $assets[$dependency]['dependencies']); }; if (! isset($original[$dependency])) { @@ -171,7 +171,7 @@ protected function resolveDependenciesForAsset( $changed = false; foreach ($value['dependencies'] as $key => $dependency) { - if (in_array($dependency, $replaces)) { + if (\in_array($dependency, $replaces)) { $changed = true; unset($value['dependencies'][$key]); } diff --git a/src/Dispatcher.php b/src/Dispatcher.php index ca8cddb..096bb2e 100644 --- a/src/Dispatcher.php +++ b/src/Dispatcher.php @@ -96,11 +96,11 @@ public function run(string $group, array $assets = [], ?string $prefix = null): { $html = ''; - if (! isset($assets[$group]) || count($assets[$group]) == 0) { + if (! isset($assets[$group]) || \count($assets[$group]) == 0) { return $html; } - is_null($prefix) || $this->path = rtrim($prefix, '/'); + \is_null($prefix) || $this->path = \rtrim($prefix, '/'); foreach ($this->resolver->arrange($assets[$group]) as $data) { $html .= $this->asset($group, $data); @@ -143,7 +143,7 @@ protected function isLocalPath(string $path): bool return false; } - return filter_var($path, FILTER_VALIDATE_URL) === false; + return \filter_var($path, FILTER_VALIDATE_URL) === false; } /** @@ -158,7 +158,7 @@ protected function getAssetSourceUrl(string $source): string // If the source is not a complete URL, we will go ahead and prepend // the asset's path to the source provided with the asset. This will // ensure that we attach the correct path to the asset. - if (! $this->isLocalPath($file = $this->path.'/'.ltrim($source, '/'))) { + if (! $this->isLocalPath($file = $this->path.'/'.\ltrim($source, '/'))) { return $file; } From c5e2506ac1806d87b78f90c79d2c1ec4d88bbd1a Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Sun, 24 Feb 2019 12:11:41 +0800 Subject: [PATCH 2/3] Add RegistrableProvider. Signed-off-by: Mior Muhammad Zaki --- src/AssetServiceProvider.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/AssetServiceProvider.php b/src/AssetServiceProvider.php index 5dd431f..9a8fc27 100644 --- a/src/AssetServiceProvider.php +++ b/src/AssetServiceProvider.php @@ -5,8 +5,9 @@ use Illuminate\Support\ServiceProvider; use Illuminate\Contracts\Foundation\Application; use Illuminate\Contracts\Support\DeferrableProvider; +use Illuminate\Contracts\Support\RegistrableProvider; -class AssetServiceProvider extends ServiceProvider implements DeferrableProvider +class AssetServiceProvider extends ServiceProvider implements DeferrableProvider, RegistrableProvider { /** * Register the service provider. @@ -27,7 +28,7 @@ public function register() * * @return void */ - protected function registerAsset() + protected function registerAsset(): void { $this->app->singleton('orchestra.asset', function (Application $app) { return new Factory($app->make('orchestra.asset.dispatcher')); @@ -39,7 +40,7 @@ protected function registerAsset() * * @return void */ - protected function registerDispatcher() + protected function registerDispatcher(): void { $this->app->singleton('orchestra.asset.dispatcher', function (Application $app) { return new Dispatcher( @@ -56,7 +57,7 @@ protected function registerDispatcher() * * @return void */ - protected function registerResolver() + protected function registerResolver(): void { $this->app->singleton('orchestra.asset.resolver', function () { return new DependencyResolver(); From d7fa11f8cc6c8455d18076eee97f7e76738eeb5b Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Sun, 24 Feb 2019 13:29:31 +0800 Subject: [PATCH 3/3] Revert RegistrableProvider. Signed-off-by: Mior Muhammad Zaki --- src/AssetServiceProvider.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/AssetServiceProvider.php b/src/AssetServiceProvider.php index 9a8fc27..837abe3 100644 --- a/src/AssetServiceProvider.php +++ b/src/AssetServiceProvider.php @@ -5,9 +5,8 @@ use Illuminate\Support\ServiceProvider; use Illuminate\Contracts\Foundation\Application; use Illuminate\Contracts\Support\DeferrableProvider; -use Illuminate\Contracts\Support\RegistrableProvider; -class AssetServiceProvider extends ServiceProvider implements DeferrableProvider, RegistrableProvider +class AssetServiceProvider extends ServiceProvider implements DeferrableProvider { /** * Register the service provider.