From a6ff71bf4d5ad07b033468af2f22e49f9f17a85d Mon Sep 17 00:00:00 2001 From: Johannes Pichler Date: Fri, 1 Dec 2023 07:37:48 +0100 Subject: [PATCH 1/4] Make compatible with Laravel 10 --- .gitignore | 2 ++ composer.json | 13 ++++++++----- phpunit.xml | 31 ++++++++++++------------------- src/Blade.php | 27 ++++++++++----------------- src/Container.php | 25 +++++++++++++++++++++++++ tests/BladeTest.php | 2 +- 6 files changed, 58 insertions(+), 42 deletions(-) create mode 100644 src/Container.php diff --git a/.gitignore b/.gitignore index fc7ea17..790abfd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ /vendor composer.lock .DS_Store +.phpunit.cache/ +.phpunit.result.cache \ No newline at end of file diff --git a/composer.json b/composer.json index 2e5175c..6afacf9 100644 --- a/composer.json +++ b/composer.json @@ -10,12 +10,12 @@ } ], "require": { - "php": ">=7.0", - "illuminate/view": "^5.5|^6.0|^7.0|^8.0" + "php": ">=8.1", + "illuminate/view": "^10.0", + "illuminate/config": "^10.0" }, "require-dev": { - "phpunit/phpunit": "^6.0|^7.0", - "satooshi/php-coveralls": "^1.0" + "phpunit/phpunit": "^10.0" }, "autoload": { "psr-4": { @@ -23,5 +23,8 @@ } }, "minimum-stability": "dev", - "prefer-stable": true + "prefer-stable": true, + "scripts": { + "test": "vendor/bin/phpunit" + } } diff --git a/phpunit.xml b/phpunit.xml index f062023..fcc2c8b 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,21 +1,14 @@ - - - - ./tests/ - - - - - src/ - - + + + + + ./tests/ + + + + + src/ + + diff --git a/src/Blade.php b/src/Blade.php index 00f87e9..7ba3fab 100644 --- a/src/Blade.php +++ b/src/Blade.php @@ -2,7 +2,7 @@ namespace Jenssegers\Blade; -use Illuminate\Container\Container; +use Illuminate\Config\Repository; use Illuminate\Contracts\Container\Container as ContainerInterface; use Illuminate\Contracts\Foundation\Application; use Illuminate\Contracts\View\Factory as FactoryContract; @@ -13,6 +13,7 @@ use Illuminate\View\Compilers\BladeCompiler; use Illuminate\View\Factory; use Illuminate\View\ViewServiceProvider; +use Jenssegers\Blade\Container; class Blade implements FactoryContract { @@ -61,7 +62,7 @@ public function directive(string $name, callable $handler) { $this->compiler->directive($name, $handler); } - + public function if($name, callable $callback) { $this->compiler->if($name, $callback); @@ -113,21 +114,13 @@ public function __call(string $method, array $params) protected function setupContainer(array $viewPaths, string $cachePath) { - $this->container->bindIf('files', function () { - return new Filesystem; - }, true); - - $this->container->bindIf('events', function () { - return new Dispatcher; - }, true); - - $this->container->bindIf('config', function () use ($viewPaths, $cachePath) { - return [ - 'view.paths' => $viewPaths, - 'view.compiled' => $cachePath, - ]; - }, true); - + $this->container->singleton('files', fn () => new Filesystem); + $this->container->singleton('events', fn () => new Dispatcher); + $this->container->singleton('config', fn () => new Repository([ + 'view.paths' => $viewPaths, + 'view.compiled' => $cachePath, + ])); + Facade::setFacadeApplication($this->container); } } diff --git a/src/Container.php b/src/Container.php new file mode 100644 index 0000000..c0f16b4 --- /dev/null +++ b/src/Container.php @@ -0,0 +1,25 @@ +terminatingCallbacks[] = $callback; + + return $this; + } + + public function terminate() + { + foreach ($this->terminatingCallbacks as $callback) { + $callback(); + } + } +} \ No newline at end of file diff --git a/tests/BladeTest.php b/tests/BladeTest.php index a8f7e27..c7ba6b0 100644 --- a/tests/BladeTest.php +++ b/tests/BladeTest.php @@ -14,7 +14,7 @@ class BladeTest extends TestCase */ private $blade; - public function setUp() + protected function setUp(): void { $this->blade = new Blade('tests/views', 'tests/cache'); From a3278a7c830c69e229b2036e1654bea108739d56 Mon Sep 17 00:00:00 2001 From: Johannes Pichler Date: Sun, 3 Dec 2023 10:58:08 +0100 Subject: [PATCH 2/4] Add linter and github actions --- .github/workflows/tests.yml | 33 +++++++++++++++++++++++++++++++++ .travis.yml | 20 -------------------- composer.json | 7 +++++-- pint.json | 6 ++++++ src/Blade.php | 1 - src/Container.php | 6 +++--- tests/BladeTest.php | 8 ++++---- 7 files changed, 51 insertions(+), 30 deletions(-) create mode 100644 .github/workflows/tests.yml delete mode 100644 .travis.yml create mode 100644 pint.json diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..fdb3fcb --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,33 @@ +name: Tests + +on: ['push', 'pull_request'] + +jobs: + ci: + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest] + php: ['8.1', '8.2', '8.3'] + + name: PHP ${{ matrix.php }} - ${{ matrix.os }} - ${{ matrix.dependency-version }} + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + tools: composer:v2 + coverage: none + + - name: Install PHP dependencies + run: composer update --prefer-stable --no-interaction --no-progress + + - name: Unit Tests + run: composer test + + - name: Source Linter + run: composer lint \ No newline at end of file diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 799e576..0000000 --- a/.travis.yml +++ /dev/null @@ -1,20 +0,0 @@ -language: php - -php: - - 7.0 - - 7.1 - - 7.2 - - 7.3 - -sudo: false - -before_script: - - travis_retry composer self-update - - travis_retry composer install --dev --no-interaction - -script: - - mkdir -p build/logs - - ./vendor/bin/phpunit --coverage-clover build/logs/clover.xml - -after_success: - - php vendor/bin/coveralls -v diff --git a/composer.json b/composer.json index 6afacf9..591bced 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,8 @@ "illuminate/config": "^10.0" }, "require-dev": { - "phpunit/phpunit": "^10.0" + "phpunit/phpunit": "^10.0", + "laravel/pint": "^1.13" }, "autoload": { "psr-4": { @@ -25,6 +26,8 @@ "minimum-stability": "dev", "prefer-stable": true, "scripts": { - "test": "vendor/bin/phpunit" + "test": "vendor/bin/phpunit", + "lint": "vendor/bin/pint --test", + "fix": "vendor/bin/pint" } } diff --git a/pint.json b/pint.json new file mode 100644 index 0000000..362cf29 --- /dev/null +++ b/pint.json @@ -0,0 +1,6 @@ +{ + "preset": "laravel", + "exclude": [ + "tests/cache" + ] +} \ No newline at end of file diff --git a/src/Blade.php b/src/Blade.php index 7ba3fab..127bb93 100644 --- a/src/Blade.php +++ b/src/Blade.php @@ -13,7 +13,6 @@ use Illuminate\View\Compilers\BladeCompiler; use Illuminate\View\Factory; use Illuminate\View\ViewServiceProvider; -use Jenssegers\Blade\Container; class Blade implements FactoryContract { diff --git a/src/Container.php b/src/Container.php index c0f16b4..453a8f7 100644 --- a/src/Container.php +++ b/src/Container.php @@ -18,8 +18,8 @@ public function terminating(Closure $callback) public function terminate() { - foreach ($this->terminatingCallbacks as $callback) { - $callback(); + foreach ($this->terminatingCallbacks as $terminatingCallback) { + $terminatingCallback(); } } -} \ No newline at end of file +} diff --git a/tests/BladeTest.php b/tests/BladeTest.php index c7ba6b0..6748720 100644 --- a/tests/BladeTest.php +++ b/tests/BladeTest.php @@ -1,8 +1,8 @@ blade->composer('variables', function (View $view) { - $view->with('name', 'John Doe and ' . $view->offsetGet('name')); + $view->with('name', 'John Doe and '.$view->offsetGet('name')); }); $output = $this->blade->make('variables', ['name' => 'Jane Doe']); @@ -85,7 +85,7 @@ public function testCreator() $view->with('name', 'John Doe'); }); $this->blade->composer('variables', function (View $view) { - $view->with('name', 'Jane Doe and ' . $view->offsetGet('name')); + $view->with('name', 'Jane Doe and '.$view->offsetGet('name')); }); $output = $this->blade->make('variables'); @@ -166,7 +166,7 @@ public function testOther() private function expected(string $file): string { - $file_path = __DIR__ . '/expected/' . $file . '.html'; + $file_path = __DIR__.'/expected/'.$file.'.html'; return file_get_contents($file_path); } From e8ed27ac3ba0fa8cdc5c616f580714d28051b775 Mon Sep 17 00:00:00 2001 From: Johannes Pichler Date: Mon, 4 Dec 2023 14:16:23 +0100 Subject: [PATCH 3/4] Only bind instances if they do not exist --- src/Blade.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Blade.php b/src/Blade.php index 127bb93..be0c996 100644 --- a/src/Blade.php +++ b/src/Blade.php @@ -113,9 +113,9 @@ public function __call(string $method, array $params) protected function setupContainer(array $viewPaths, string $cachePath) { - $this->container->singleton('files', fn () => new Filesystem); - $this->container->singleton('events', fn () => new Dispatcher); - $this->container->singleton('config', fn () => new Repository([ + $this->container->bindIf('files', fn () => new Filesystem); + $this->container->bindIf('events', fn () => new Dispatcher); + $this->container->bindIf('config', fn () => new Repository([ 'view.paths' => $viewPaths, 'view.compiled' => $cachePath, ])); From fe24e8c77b588d6f4ed65662e158ffae4058683c Mon Sep 17 00:00:00 2001 From: Johannes Pichler Date: Mon, 4 Dec 2023 14:18:31 +0100 Subject: [PATCH 4/4] Add compatibility with Laravel v9 --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 591bced..dd6437c 100644 --- a/composer.json +++ b/composer.json @@ -11,8 +11,8 @@ ], "require": { "php": ">=8.1", - "illuminate/view": "^10.0", - "illuminate/config": "^10.0" + "illuminate/view": "^9.0|^10.0", + "illuminate/config": "^9.0|^10.0" }, "require-dev": { "phpunit/phpunit": "^10.0",