From ff58d0787d6139b334578accd35a8d0ccb35a2b3 Mon Sep 17 00:00:00 2001 From: KyleKatarn Date: Mon, 28 Aug 2017 18:59:03 +0200 Subject: [PATCH 1/7] Implement pug-assets --- composer.json | 2 +- src/ServiceProvider.php | 20 ++++++++--- tests/ServiceProviderTest.php | 67 ++++++++++++++++++++++++++++++++++- tests/assets.pug | 4 +++ tests/assets/bar.js | 1 + tests/assets/foo.js | 1 + 6 files changed, 88 insertions(+), 7 deletions(-) create mode 100644 tests/assets.pug create mode 100644 tests/assets/bar.js create mode 100644 tests/assets/foo.js diff --git a/composer.json b/composer.json index 8048c9e..21bc183 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,7 @@ "php": ">=5.4.0", "illuminate/support": "4 - 5", "illuminate/view": "4 - 5", - "pug-php/pug": "1 - 2", + "pug-php/pug-assets": "^1.0.1", "pug/installer": "^0.1.3" }, "require-dev": { diff --git a/src/ServiceProvider.php b/src/ServiceProvider.php index 5dcf544..63d2cdf 100644 --- a/src/ServiceProvider.php +++ b/src/ServiceProvider.php @@ -4,6 +4,7 @@ // Dependencies use Illuminate\View\Engines\CompilerEngine; +use Pug\Assets; use Pug\Pug; class ServiceProvider extends \Illuminate\Support\ServiceProvider @@ -36,11 +37,20 @@ public function register() $this->app->singleton('laravel-pug.pug', function () { $config = $this->getConfig(); $pug = new Pug($config); - // Determine the cache dir if not configured - $pug->setCustomOption( - 'defaultCache', - storage_path($this->version() >= 5 ? '/framework/views' : '/views') - ); + $assets = new Assets($pug); + $this->app->singleton('laravel-pug.pug-assets', function () use ($assets) { + return $assets; + }); + + try { + $pug->getOption('defaultCache'); + } catch (\InvalidArgumentException $exception) { + // Determine the cache dir if not configured + $pug->setCustomOption( + 'defaultCache', + storage_path($this->version() >= 5 ? '/framework/views' : '/views') + ); + } return $pug; }); diff --git a/tests/ServiceProviderTest.php b/tests/ServiceProviderTest.php index 709cbef..9f41527 100644 --- a/tests/ServiceProviderTest.php +++ b/tests/ServiceProviderTest.php @@ -13,6 +13,8 @@ class Config implements ArrayAccess { + protected $useSysTempDir = false; + protected $data = array(); public function __construct($source = null) @@ -20,8 +22,21 @@ public function __construct($source = null) $this->data['source'] = $source; } + public function setUseSysTempDir($useSysTempDir) + { + $this->useSysTempDir = $useSysTempDir; + } + public function get($input) { + if ($this->useSysTempDir && in_array($input, ['laravel-pug', 'laravel-pug::config'])) { + return [ + 'assetDirectory' => __DIR__ . '/assets', + 'outputDirectory' => sys_get_temp_dir(), + 'defaultCache' => sys_get_temp_dir(), + ]; + } + return isset($this->data[$input]) ? $this->data[$input] :array( 'input' => $input, ); @@ -55,6 +70,8 @@ public function __toString() class LaravelTestApp implements Application, ArrayAccess { + protected $useSysTempDir = false; + protected $singletons = array(); const VERSION = '4.0.0'; @@ -64,6 +81,11 @@ public function version() return static::VERSION; } + public function setUseSysTempDir($useSysTempDir) + { + $this->useSysTempDir = $useSysTempDir; + } + public function basePath() { return __DIR__; @@ -180,7 +202,10 @@ public function factory($abstract) public function make($abstract, array $parameters = []) { - return new Config($abstract); + $config = new Config($abstract); + $config->setUseSysTempDir($this->useSysTempDir); + + return $config; } public function call($callback, array $parameters = [], $defaultMethod = null) @@ -513,4 +538,44 @@ public function testBootUnsupportedLaravel() $provider = new ServiceProvider($app); $provider->boot(); } + + /** + * @group i + */ + public function testView() + { + $this->app->setUseSysTempDir(true); + $view = new View(); + $resolver = new Resolver(); + $this->app['view.engine.resolver'] = $resolver; + $this->app['view'] = $view; + $this->provider->register(); + $this->provider->boot(); + + self::assertSame( + '', + preg_replace( + '/\s{2,}/', + '', + $this->app['view.engine.resolver']->get('pug')->get(__DIR__ . '/assets.pug') + ) + ); + + $contents = file_get_contents(sys_get_temp_dir() . '/js/app.min.js'); + + self::assertSame('a();b();', trim($contents)); + + unlink(sys_get_temp_dir() . '/js/app.min.js'); + +// $this->app->getSingleton('laravel-pug.pug-assets')->unsetMinify(); +// +// self::assertSame( +// 'app', +// preg_replace( +// '/\s{2,}/', +// '', +// $this->app['view.engine.resolver']->get('pug')->get(__DIR__ . '/assets.pug') +// ) +// ); + } } diff --git a/tests/assets.pug b/tests/assets.pug new file mode 100644 index 0000000..413c28e --- /dev/null +++ b/tests/assets.pug @@ -0,0 +1,4 @@ +head + minify app + script(src="foo.js") + script(src="bar.js") diff --git a/tests/assets/bar.js b/tests/assets/bar.js new file mode 100644 index 0000000..1f6cc89 --- /dev/null +++ b/tests/assets/bar.js @@ -0,0 +1 @@ +b(); \ No newline at end of file diff --git a/tests/assets/foo.js b/tests/assets/foo.js new file mode 100644 index 0000000..cd06e8a --- /dev/null +++ b/tests/assets/foo.js @@ -0,0 +1 @@ +a(); \ No newline at end of file From 2c603dbe7ab7334cb8a0027f5c187d31f7affd7d Mon Sep 17 00:00:00 2001 From: KyleKatarn Date: Tue, 29 Aug 2017 11:27:46 +0200 Subject: [PATCH 2/7] Pre-fill assets input/output directories option and handle environment --- .styleci.yml | 1 + src/ServiceProvider.php | 52 ++++++++++++++++++++++++------- tests/ServiceProviderTest.php | 58 +++++++++++++++++++++++++++-------- 3 files changed, 88 insertions(+), 23 deletions(-) diff --git a/.styleci.yml b/.styleci.yml index ad865e9..43d6073 100644 --- a/.styleci.yml +++ b/.styleci.yml @@ -5,6 +5,7 @@ finder: - "src/config" enabled: + - long_array_syntax - concat_with_spaces disabled: diff --git a/src/ServiceProvider.php b/src/ServiceProvider.php index 63d2cdf..0987873 100644 --- a/src/ServiceProvider.php +++ b/src/ServiceProvider.php @@ -9,6 +9,15 @@ class ServiceProvider extends \Illuminate\Support\ServiceProvider { + protected function setDefaultOption(Pug $pug, $name, $value) + { + try { + $pug->getOption($name); + } catch (\InvalidArgumentException $exception) { + $pug->setCustomOption($name, call_user_func($value)); + } + } + /** * Get the major Laravel version number. * @@ -38,19 +47,40 @@ public function register() $config = $this->getConfig(); $pug = new Pug($config); $assets = new Assets($pug); + $assets->setEnvironment(method_exists('App', 'environment') + ? App::environment() // @codeCoverageIgnore + : 'production' + ); + $this->app->singleton('laravel-pug.pug-assets', function () use ($assets) { return $assets; }); - try { - $pug->getOption('defaultCache'); - } catch (\InvalidArgumentException $exception) { - // Determine the cache dir if not configured - $pug->setCustomOption( - 'defaultCache', - storage_path($this->version() >= 5 ? '/framework/views' : '/views') - ); - } + // Determine the cache dir if not configured + $this->setDefaultOption($pug, 'defaultCache', function () { + return storage_path($this->version() >= 5 ? '/framework/views' : '/views'); + }); + + // Determine assets input directory + $this->setDefaultOption($pug, 'assetDirectory', function () { + return array_map(function ($params) { + list($function, $arg) = $params; + + return function_exists($function) ? call_user_func($function, $arg) : null; + }, array( + array('resource_path', 'assets'), + array('app_path', 'views/assets'), + array('app_path', 'assets'), + array('app_path', 'views'), + array('app_path', ''), + array('base_path', ''), + )); + }); + + // Determine assets output directory + $this->setDefaultOption($pug, 'outputDirectory', function () { + return function_exists('public_path') ? public_path() : null; + }); return $pug; }); @@ -114,9 +144,9 @@ public function bootLaravel4() */ public function bootLaravel5() { - $this->publishes([ + $this->publishes(array( __DIR__ . '/../config/config.php' => config_path('laravel-pug.php'), - ], 'laravel-pug'); + ), 'laravel-pug'); } /** diff --git a/tests/ServiceProviderTest.php b/tests/ServiceProviderTest.php index 9f41527..b4d5475 100644 --- a/tests/ServiceProviderTest.php +++ b/tests/ServiceProviderTest.php @@ -8,6 +8,8 @@ use Illuminate\Contracts\Foundation\Application; use Illuminate\Filesystem\Filesystem; use Illuminate\Support\Facades\Facade; +use Illuminate\View\Engines\CompilerEngine; +use Pug\Assets; include_once __DIR__ . '/helpers.php'; @@ -378,6 +380,7 @@ public function testVersion() /** * @covers ::register + * @covers ::setDefaultOption */ public function testRegister() { @@ -540,7 +543,8 @@ public function testBootUnsupportedLaravel() } /** - * @group i + * @covers ::register + * @covers ::setDefaultOption */ public function testView() { @@ -551,13 +555,17 @@ public function testView() $this->app['view'] = $view; $this->provider->register(); $this->provider->boot(); + $path = __DIR__ . '/assets.pug'; + + /** @var CompilerEngine $pug */ + $pug = $resolver->get('pug'); self::assertSame( '', preg_replace( '/\s{2,}/', '', - $this->app['view.engine.resolver']->get('pug')->get(__DIR__ . '/assets.pug') + $this->app['view.engine.resolver']->get('pug')->get($path) ) ); @@ -566,16 +574,42 @@ public function testView() self::assertSame('a();b();', trim($contents)); unlink(sys_get_temp_dir() . '/js/app.min.js'); + unlink($pug->getCompiler()->getCompiledPath($path)); + + /** @var Assets $assets */ + $assets = $this->app->getSingleton('laravel-pug.pug-assets'); + $assets->setEnvironment('dev'); + + self::assertSame( + 'app', + preg_replace('/\s{2,}/', '', $pug->get($path)) + ); + + unlink($pug->getCompiler()->getCompiledPath($path)); + + $assets->setEnvironment('production'); + + self::assertSame( + '', + preg_replace( + '/\s{2,}/', + '', + $this->app['view.engine.resolver']->get('pug')->get($path) + ) + ); + + self::assertSame('a();b();', trim($contents)); + + unlink(sys_get_temp_dir() . '/js/app.min.js'); + unlink($pug->getCompiler()->getCompiledPath($path)); + + $assets->unsetMinify(); + + self::assertSame( + 'app', + preg_replace('/\s{2,}/', '', $pug->get($path)) + ); -// $this->app->getSingleton('laravel-pug.pug-assets')->unsetMinify(); -// -// self::assertSame( -// 'app', -// preg_replace( -// '/\s{2,}/', -// '', -// $this->app['view.engine.resolver']->get('pug')->get(__DIR__ . '/assets.pug') -// ) -// ); + unlink($pug->getCompiler()->getCompiledPath($path)); } } From 6ebbb49e90cc7fb4fcec0611c2a4334fd3df30b0 Mon Sep 17 00:00:00 2001 From: KyleKatarn Date: Tue, 29 Aug 2017 11:43:15 +0200 Subject: [PATCH 3/7] Fix app environment call --- src/ServiceProvider.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ServiceProvider.php b/src/ServiceProvider.php index 0987873..a3ac872 100644 --- a/src/ServiceProvider.php +++ b/src/ServiceProvider.php @@ -47,8 +47,8 @@ public function register() $config = $this->getConfig(); $pug = new Pug($config); $assets = new Assets($pug); - $assets->setEnvironment(method_exists('App', 'environment') - ? App::environment() // @codeCoverageIgnore + $assets->setEnvironment(is_callable(array('App', 'environment')) + ? call_user_func(array('App', 'environment')) // @codeCoverageIgnore : 'production' ); From dae9254a50605aea5239cfcba0a67e1f371cfa6e Mon Sep 17 00:00:00 2001 From: KyleKatarn Date: Mon, 28 Aug 2017 18:59:03 +0200 Subject: [PATCH 4/7] Implement pug-assets --- composer.json | 2 +- src/ServiceProvider.php | 20 ++++++++--- tests/ServiceProviderTest.php | 67 ++++++++++++++++++++++++++++++++++- tests/assets.pug | 4 +++ tests/assets/bar.js | 1 + tests/assets/foo.js | 1 + 6 files changed, 88 insertions(+), 7 deletions(-) create mode 100644 tests/assets.pug create mode 100644 tests/assets/bar.js create mode 100644 tests/assets/foo.js diff --git a/composer.json b/composer.json index 8048c9e..21bc183 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,7 @@ "php": ">=5.4.0", "illuminate/support": "4 - 5", "illuminate/view": "4 - 5", - "pug-php/pug": "1 - 2", + "pug-php/pug-assets": "^1.0.1", "pug/installer": "^0.1.3" }, "require-dev": { diff --git a/src/ServiceProvider.php b/src/ServiceProvider.php index 5dcf544..63d2cdf 100644 --- a/src/ServiceProvider.php +++ b/src/ServiceProvider.php @@ -4,6 +4,7 @@ // Dependencies use Illuminate\View\Engines\CompilerEngine; +use Pug\Assets; use Pug\Pug; class ServiceProvider extends \Illuminate\Support\ServiceProvider @@ -36,11 +37,20 @@ public function register() $this->app->singleton('laravel-pug.pug', function () { $config = $this->getConfig(); $pug = new Pug($config); - // Determine the cache dir if not configured - $pug->setCustomOption( - 'defaultCache', - storage_path($this->version() >= 5 ? '/framework/views' : '/views') - ); + $assets = new Assets($pug); + $this->app->singleton('laravel-pug.pug-assets', function () use ($assets) { + return $assets; + }); + + try { + $pug->getOption('defaultCache'); + } catch (\InvalidArgumentException $exception) { + // Determine the cache dir if not configured + $pug->setCustomOption( + 'defaultCache', + storage_path($this->version() >= 5 ? '/framework/views' : '/views') + ); + } return $pug; }); diff --git a/tests/ServiceProviderTest.php b/tests/ServiceProviderTest.php index 709cbef..9f41527 100644 --- a/tests/ServiceProviderTest.php +++ b/tests/ServiceProviderTest.php @@ -13,6 +13,8 @@ class Config implements ArrayAccess { + protected $useSysTempDir = false; + protected $data = array(); public function __construct($source = null) @@ -20,8 +22,21 @@ public function __construct($source = null) $this->data['source'] = $source; } + public function setUseSysTempDir($useSysTempDir) + { + $this->useSysTempDir = $useSysTempDir; + } + public function get($input) { + if ($this->useSysTempDir && in_array($input, ['laravel-pug', 'laravel-pug::config'])) { + return [ + 'assetDirectory' => __DIR__ . '/assets', + 'outputDirectory' => sys_get_temp_dir(), + 'defaultCache' => sys_get_temp_dir(), + ]; + } + return isset($this->data[$input]) ? $this->data[$input] :array( 'input' => $input, ); @@ -55,6 +70,8 @@ public function __toString() class LaravelTestApp implements Application, ArrayAccess { + protected $useSysTempDir = false; + protected $singletons = array(); const VERSION = '4.0.0'; @@ -64,6 +81,11 @@ public function version() return static::VERSION; } + public function setUseSysTempDir($useSysTempDir) + { + $this->useSysTempDir = $useSysTempDir; + } + public function basePath() { return __DIR__; @@ -180,7 +202,10 @@ public function factory($abstract) public function make($abstract, array $parameters = []) { - return new Config($abstract); + $config = new Config($abstract); + $config->setUseSysTempDir($this->useSysTempDir); + + return $config; } public function call($callback, array $parameters = [], $defaultMethod = null) @@ -513,4 +538,44 @@ public function testBootUnsupportedLaravel() $provider = new ServiceProvider($app); $provider->boot(); } + + /** + * @group i + */ + public function testView() + { + $this->app->setUseSysTempDir(true); + $view = new View(); + $resolver = new Resolver(); + $this->app['view.engine.resolver'] = $resolver; + $this->app['view'] = $view; + $this->provider->register(); + $this->provider->boot(); + + self::assertSame( + '', + preg_replace( + '/\s{2,}/', + '', + $this->app['view.engine.resolver']->get('pug')->get(__DIR__ . '/assets.pug') + ) + ); + + $contents = file_get_contents(sys_get_temp_dir() . '/js/app.min.js'); + + self::assertSame('a();b();', trim($contents)); + + unlink(sys_get_temp_dir() . '/js/app.min.js'); + +// $this->app->getSingleton('laravel-pug.pug-assets')->unsetMinify(); +// +// self::assertSame( +// 'app', +// preg_replace( +// '/\s{2,}/', +// '', +// $this->app['view.engine.resolver']->get('pug')->get(__DIR__ . '/assets.pug') +// ) +// ); + } } diff --git a/tests/assets.pug b/tests/assets.pug new file mode 100644 index 0000000..413c28e --- /dev/null +++ b/tests/assets.pug @@ -0,0 +1,4 @@ +head + minify app + script(src="foo.js") + script(src="bar.js") diff --git a/tests/assets/bar.js b/tests/assets/bar.js new file mode 100644 index 0000000..1f6cc89 --- /dev/null +++ b/tests/assets/bar.js @@ -0,0 +1 @@ +b(); \ No newline at end of file diff --git a/tests/assets/foo.js b/tests/assets/foo.js new file mode 100644 index 0000000..cd06e8a --- /dev/null +++ b/tests/assets/foo.js @@ -0,0 +1 @@ +a(); \ No newline at end of file From 04f6a5d2e7a45db05322aaccf773f7ab385cbf6b Mon Sep 17 00:00:00 2001 From: KyleKatarn Date: Tue, 29 Aug 2017 11:27:46 +0200 Subject: [PATCH 5/7] Pre-fill assets input/output directories option and handle environment --- .styleci.yml | 1 + src/ServiceProvider.php | 52 ++++++++++++++++++++++++------- tests/ServiceProviderTest.php | 58 +++++++++++++++++++++++++++-------- 3 files changed, 88 insertions(+), 23 deletions(-) diff --git a/.styleci.yml b/.styleci.yml index ad865e9..43d6073 100644 --- a/.styleci.yml +++ b/.styleci.yml @@ -5,6 +5,7 @@ finder: - "src/config" enabled: + - long_array_syntax - concat_with_spaces disabled: diff --git a/src/ServiceProvider.php b/src/ServiceProvider.php index 63d2cdf..0987873 100644 --- a/src/ServiceProvider.php +++ b/src/ServiceProvider.php @@ -9,6 +9,15 @@ class ServiceProvider extends \Illuminate\Support\ServiceProvider { + protected function setDefaultOption(Pug $pug, $name, $value) + { + try { + $pug->getOption($name); + } catch (\InvalidArgumentException $exception) { + $pug->setCustomOption($name, call_user_func($value)); + } + } + /** * Get the major Laravel version number. * @@ -38,19 +47,40 @@ public function register() $config = $this->getConfig(); $pug = new Pug($config); $assets = new Assets($pug); + $assets->setEnvironment(method_exists('App', 'environment') + ? App::environment() // @codeCoverageIgnore + : 'production' + ); + $this->app->singleton('laravel-pug.pug-assets', function () use ($assets) { return $assets; }); - try { - $pug->getOption('defaultCache'); - } catch (\InvalidArgumentException $exception) { - // Determine the cache dir if not configured - $pug->setCustomOption( - 'defaultCache', - storage_path($this->version() >= 5 ? '/framework/views' : '/views') - ); - } + // Determine the cache dir if not configured + $this->setDefaultOption($pug, 'defaultCache', function () { + return storage_path($this->version() >= 5 ? '/framework/views' : '/views'); + }); + + // Determine assets input directory + $this->setDefaultOption($pug, 'assetDirectory', function () { + return array_map(function ($params) { + list($function, $arg) = $params; + + return function_exists($function) ? call_user_func($function, $arg) : null; + }, array( + array('resource_path', 'assets'), + array('app_path', 'views/assets'), + array('app_path', 'assets'), + array('app_path', 'views'), + array('app_path', ''), + array('base_path', ''), + )); + }); + + // Determine assets output directory + $this->setDefaultOption($pug, 'outputDirectory', function () { + return function_exists('public_path') ? public_path() : null; + }); return $pug; }); @@ -114,9 +144,9 @@ public function bootLaravel4() */ public function bootLaravel5() { - $this->publishes([ + $this->publishes(array( __DIR__ . '/../config/config.php' => config_path('laravel-pug.php'), - ], 'laravel-pug'); + ), 'laravel-pug'); } /** diff --git a/tests/ServiceProviderTest.php b/tests/ServiceProviderTest.php index 9f41527..b4d5475 100644 --- a/tests/ServiceProviderTest.php +++ b/tests/ServiceProviderTest.php @@ -8,6 +8,8 @@ use Illuminate\Contracts\Foundation\Application; use Illuminate\Filesystem\Filesystem; use Illuminate\Support\Facades\Facade; +use Illuminate\View\Engines\CompilerEngine; +use Pug\Assets; include_once __DIR__ . '/helpers.php'; @@ -378,6 +380,7 @@ public function testVersion() /** * @covers ::register + * @covers ::setDefaultOption */ public function testRegister() { @@ -540,7 +543,8 @@ public function testBootUnsupportedLaravel() } /** - * @group i + * @covers ::register + * @covers ::setDefaultOption */ public function testView() { @@ -551,13 +555,17 @@ public function testView() $this->app['view'] = $view; $this->provider->register(); $this->provider->boot(); + $path = __DIR__ . '/assets.pug'; + + /** @var CompilerEngine $pug */ + $pug = $resolver->get('pug'); self::assertSame( '', preg_replace( '/\s{2,}/', '', - $this->app['view.engine.resolver']->get('pug')->get(__DIR__ . '/assets.pug') + $this->app['view.engine.resolver']->get('pug')->get($path) ) ); @@ -566,16 +574,42 @@ public function testView() self::assertSame('a();b();', trim($contents)); unlink(sys_get_temp_dir() . '/js/app.min.js'); + unlink($pug->getCompiler()->getCompiledPath($path)); + + /** @var Assets $assets */ + $assets = $this->app->getSingleton('laravel-pug.pug-assets'); + $assets->setEnvironment('dev'); + + self::assertSame( + 'app', + preg_replace('/\s{2,}/', '', $pug->get($path)) + ); + + unlink($pug->getCompiler()->getCompiledPath($path)); + + $assets->setEnvironment('production'); + + self::assertSame( + '', + preg_replace( + '/\s{2,}/', + '', + $this->app['view.engine.resolver']->get('pug')->get($path) + ) + ); + + self::assertSame('a();b();', trim($contents)); + + unlink(sys_get_temp_dir() . '/js/app.min.js'); + unlink($pug->getCompiler()->getCompiledPath($path)); + + $assets->unsetMinify(); + + self::assertSame( + 'app', + preg_replace('/\s{2,}/', '', $pug->get($path)) + ); -// $this->app->getSingleton('laravel-pug.pug-assets')->unsetMinify(); -// -// self::assertSame( -// 'app', -// preg_replace( -// '/\s{2,}/', -// '', -// $this->app['view.engine.resolver']->get('pug')->get(__DIR__ . '/assets.pug') -// ) -// ); + unlink($pug->getCompiler()->getCompiledPath($path)); } } From eb0c48081d29b783dad9db4b19320ce668b6feb6 Mon Sep 17 00:00:00 2001 From: KyleKatarn Date: Tue, 29 Aug 2017 11:43:15 +0200 Subject: [PATCH 6/7] Fix app environment call --- src/ServiceProvider.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ServiceProvider.php b/src/ServiceProvider.php index 0987873..a3ac872 100644 --- a/src/ServiceProvider.php +++ b/src/ServiceProvider.php @@ -47,8 +47,8 @@ public function register() $config = $this->getConfig(); $pug = new Pug($config); $assets = new Assets($pug); - $assets->setEnvironment(method_exists('App', 'environment') - ? App::environment() // @codeCoverageIgnore + $assets->setEnvironment(is_callable(array('App', 'environment')) + ? call_user_func(array('App', 'environment')) // @codeCoverageIgnore : 'production' ); From ce6204e7064b18e4361ac9bc1b96e117104b44da Mon Sep 17 00:00:00 2001 From: KyleKatarn Date: Wed, 30 Aug 2017 10:04:29 +0200 Subject: [PATCH 7/7] Simplify app environment call --- src/ServiceProvider.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/ServiceProvider.php b/src/ServiceProvider.php index a3ac872..1daffdc 100644 --- a/src/ServiceProvider.php +++ b/src/ServiceProvider.php @@ -47,10 +47,8 @@ public function register() $config = $this->getConfig(); $pug = new Pug($config); $assets = new Assets($pug); - $assets->setEnvironment(is_callable(array('App', 'environment')) - ? call_user_func(array('App', 'environment')) // @codeCoverageIgnore - : 'production' - ); + $getEnv = array('App', 'environment'); + $assets->setEnvironment(is_callable($getEnv) ? call_user_func($getEnv) : 'production'); $this->app->singleton('laravel-pug.pug-assets', function () use ($assets) { return $assets;