From e09bda6d57252c5d8f9d64a3cfa5942893988994 Mon Sep 17 00:00:00 2001 From: Thor Brink Date: Thu, 1 Feb 2024 13:42:38 +0000 Subject: [PATCH 01/11] feat!: require php 8.3 --- .github/workflows/release.yml | 4 ++-- .github/workflows/test.yml | 6 +++--- composer.json | 5 +++-- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ab10f1b0..be54018b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -18,7 +18,7 @@ jobs: - name: Create Release and bump version files uses: helsingborg-stad/release-wp-plugin-action@1.0.2 with: - php-version: 8.2 + php-version: 8.3 node-version: 20.6.0 build-assets: needs: ['release'] @@ -75,7 +75,7 @@ jobs: if: ${{ hashFiles('composer.json') != '' }} with: tools: composer - php-version: '7.4' + php-version: '7.3' - name: Build PHP if: ${{ hashFiles('composer.json') != '' }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d5377075..0bbb6716 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -2,9 +2,9 @@ name: Run Tests on: push: - branches: [ "master" ] + branches: [ "main" ] pull_request: - branches: [ "master" ] + branches: [ "main" ] permissions: contents: read @@ -16,7 +16,7 @@ jobs: strategy: matrix: - php-versions: ['7.4'] + php-versions: ['8.3'] name: Test running PHP ${{ matrix.php-versions }} steps: diff --git a/composer.json b/composer.json index 26f25b17..f2fd69b7 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,8 @@ "test:coverage": "XDEBUG_MODE=coverage vendor/bin/phpunit --coverage-html .coverage/html --coverage-clover .coverage/clover.xml" }, "require": { - "helsingborg-stad/blade-engine-wrapper": "^1.0.0" + "helsingborg-stad/blade-engine-wrapper": "^2.0.1", + "php": "^8.3" }, "require-dev": { "phpunit/phpunit": "^9.6", @@ -26,4 +27,4 @@ } }, "version": "3.13.5" -} \ No newline at end of file +} From b45d0a7144a09676cd9274328fe8be7912c4be3e Mon Sep 17 00:00:00 2001 From: Thor Brink Date: Wed, 14 Feb 2024 11:15:44 +0000 Subject: [PATCH 02/11] feat!: require php ^8.3 --- composer.json | 7 ++--- source/php/Component/BaseController.php | 2 ++ source/php/Init.php | 26 +++++++-------- source/php/Register.php | 42 +++++++------------------ 4 files changed, 29 insertions(+), 48 deletions(-) diff --git a/composer.json b/composer.json index f2fd69b7..5f4dc37e 100644 --- a/composer.json +++ b/composer.json @@ -14,12 +14,11 @@ "test:coverage": "XDEBUG_MODE=coverage vendor/bin/phpunit --coverage-html .coverage/html --coverage-clover .coverage/clover.xml" }, "require": { - "helsingborg-stad/blade-engine-wrapper": "^2.0.1", - "php": "^8.3" + "php": "^8.3", + "helsingborg-stad/blade": "^3.0" }, "require-dev": { - "phpunit/phpunit": "^9.6", - "helsingborg-stad/render-blade-view": "^0.0.2" + "phpunit/phpunit": "^9.6" }, "autoload": { "psr-4": { diff --git a/source/php/Component/BaseController.php b/source/php/Component/BaseController.php index 9804572a..2034abed 100644 --- a/source/php/Component/BaseController.php +++ b/source/php/Component/BaseController.php @@ -24,6 +24,8 @@ class BaseController */ private $uid = null; + protected array $compParams; + /** * Run init */ diff --git a/source/php/Init.php b/source/php/Init.php index bb43acb6..3a006acc 100644 --- a/source/php/Init.php +++ b/source/php/Init.php @@ -3,14 +3,13 @@ namespace ComponentLibrary; use ComponentLibrary\Register; -use HelsingborgStad\BladeEngineWrapper as Blade; +use HelsingborgStad\GlobalBladeService\GlobalBladeService; class Init { private $register = null; public function __construct($externalViewPaths) { - $blade = new Blade(); $paths = array( 'viewPaths' => array(), 'controllerPaths' => array(), @@ -36,19 +35,20 @@ public function __construct($externalViewPaths) { $viewPaths ); } - - if(is_array($viewPaths) && !empty($viewPaths)) { - foreach ($viewPaths as $path) { - $directory = rtrim($path, DIRECTORY_SEPARATOR); - if(is_dir($directory)) { - $blade->addViewPath(rtrim($path, DIRECTORY_SEPARATOR)); - } - } - } else { + + if(!is_array($viewPaths) || empty($viewPaths)) { throw new \Exception("View paths not defined."); + } + + $sanitizeViewPaths = array(); + foreach ($viewPaths as $path) { + $directory = rtrim($path, DIRECTORY_SEPARATOR); + if(is_dir($directory)) { + $sanitizeViewPaths[] = $directory; + } } - $bladeInstance = $blade->instance(); + $bladeInstance = GlobalBladeService::getInstance($sanitizeViewPaths); $this->register = new Register($bladeInstance); @@ -88,6 +88,6 @@ public function __construct($externalViewPaths) { public function getEngine() { - return $this->register->getEngine(); + return GlobalBladeService::getInstance(); } } diff --git a/source/php/Register.php b/source/php/Register.php index b7c9550d..5298d520 100644 --- a/source/php/Register.php +++ b/source/php/Register.php @@ -2,6 +2,10 @@ namespace ComponentLibrary; +use HelsingborgStad\BladeService\BladeServiceInterface; +use Illuminate\Support\Facades\Blade; +use Throwable; + class Register { private static $cache = [ @@ -17,11 +21,11 @@ class Register public $controllerPaths = []; private $reservedNames = ["data", "class", "list", "lang"]; private $controllers = []; - private $blade = null; + private BladeServiceInterface $blade; - public function __construct($engine) + public function __construct(BladeServiceInterface $bladeService) { - $this->blade = $engine; + $this->blade = $bladeService; } /** @@ -56,7 +60,9 @@ public function add($slug, $defaultArgs, $view = null) ); //Add include alias - $this->registerComponentAlias($slug); + $this->blade->registerComponentDirective( + ucfirst($slug) . '.' . $slug, + $slug); // Register view composer $this->registerViewComposer($this->data->{$slug}); @@ -145,36 +151,10 @@ private function getViewName($slug, $view = null): string return $view; } - /** - * Santize string - * @return string The string to be sanitized - */ - private function sanitizeSlug($string): string - { - return preg_replace( - "/[^a-z-]/i", - "", - str_replace(".blade.php", "", $string) - ); - } - - /** - * Registers all components as include aliases - * - * @return bool - */ - private function registerComponentAlias($componentSlug) - { - $this->blade->component( - ucfirst($componentSlug) . '.' . $componentSlug, - $componentSlug - ); - } - public function registerViewComposer($component) { try { - $this->blade->composer( + $this->blade->registerComponent( ucfirst($component->slug) . '.' . $component->slug, function ($view) use ($component) { From 1ddbf28a36f3f8ce1a9e6c98bee85b85bc42e8d6 Mon Sep 17 00:00:00 2001 From: Thor Brink Date: Wed, 14 Feb 2024 13:35:15 +0000 Subject: [PATCH 03/11] fix: updgrade blade package --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 5f4dc37e..9a376ccc 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ }, "require": { "php": "^8.3", - "helsingborg-stad/blade": "^3.0" + "helsingborg-stad/blade": "^3.1" }, "require-dev": { "phpunit/phpunit": "^9.6" From 4205dc4088855330238372ee6fcc86fa42057ac6 Mon Sep 17 00:00:00 2001 From: Thor Brink Date: Thu, 15 Feb 2024 07:32:39 +0000 Subject: [PATCH 04/11] fix: update blade package --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 9a376ccc..51cfd988 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ }, "require": { "php": "^8.3", - "helsingborg-stad/blade": "^3.1" + "helsingborg-stad/blade": "^3.2" }, "require-dev": { "phpunit/phpunit": "^9.6" From 12d45019455a7c4495f832a3685fd55279eb6cb4 Mon Sep 17 00:00:00 2001 From: Thor Brink Date: Thu, 15 Feb 2024 13:55:47 +0000 Subject: [PATCH 05/11] fix: initialize if in wp --- component-library.php | 8 ++++++++ source/php/Component/Hero/Hero.php | 2 +- source/php/Init.php | 16 ++++++++++------ source/php/Register.php | 9 ++------- 4 files changed, 21 insertions(+), 14 deletions(-) diff --git a/component-library.php b/component-library.php index f4744a15..6345a775 100644 --- a/component-library.php +++ b/component-library.php @@ -13,6 +13,8 @@ * Domain Path: /languages */ +use ComponentLibrary\Init as ComponentLibraryInit; + // Protect agains direct file access if (! defined('WPINC')) { //die; @@ -31,4 +33,10 @@ load_plugin_textdomain('component-library', false, plugin_basename(dirname(__FILE__)) . '/languages'); } +if( function_exists('add_action') ) { + add_action('plugins_loaded', function() { + new ComponentLibraryInit([]); + }); +} + require_once COMPONENTLIBRARY_PATH . 'Public.php'; \ No newline at end of file diff --git a/source/php/Component/Hero/Hero.php b/source/php/Component/Hero/Hero.php index d759f8f7..e2c984a4 100644 --- a/source/php/Component/Hero/Hero.php +++ b/source/php/Component/Hero/Hero.php @@ -179,7 +179,7 @@ private function twoColumn($customHeroData) { private function hasContent(): bool { - $stringEmpty = fn ($value): bool => empty(trim($value)); + $stringEmpty = fn ($value): bool => empty(trim($value ?? "")); if (!$stringEmpty($this->data['meta'])) return true; if (!$stringEmpty($this->data['title'])) return true; diff --git a/source/php/Init.php b/source/php/Init.php index 3a006acc..44315d09 100644 --- a/source/php/Init.php +++ b/source/php/Init.php @@ -8,6 +8,7 @@ class Init { private $register = null; + private static bool $internalViewPathsAdded = false; public function __construct($externalViewPaths) { $paths = array( @@ -18,9 +19,12 @@ public function __construct($externalViewPaths) { // Add view path to renderer // In this case all components, their controller and view path are located under the same folder structure. // This may differ in a Wordpress child implementation. - $internalPaths = array( - __DIR__ . DIRECTORY_SEPARATOR . 'Component' . DIRECTORY_SEPARATOR, - ); + $internalPaths = array(); + + if( !self::$internalViewPathsAdded ) { + $internalPaths = array( __DIR__ . DIRECTORY_SEPARATOR . 'Component' . DIRECTORY_SEPARATOR ); + self::$internalViewPathsAdded = true; + } // Initialize all view paths so that this library is last $viewPaths = array_unique( @@ -40,15 +44,15 @@ public function __construct($externalViewPaths) { throw new \Exception("View paths not defined."); } - $sanitizeViewPaths = array(); + $sanitizedViewPaths = array(); foreach ($viewPaths as $path) { $directory = rtrim($path, DIRECTORY_SEPARATOR); if(is_dir($directory)) { - $sanitizeViewPaths[] = $directory; + $sanitizedViewPaths[] = $directory; } } - $bladeInstance = GlobalBladeService::getInstance($sanitizeViewPaths); + $bladeInstance = GlobalBladeService::getInstance($sanitizedViewPaths); $this->register = new Register($bladeInstance); diff --git a/source/php/Register.php b/source/php/Register.php index 5298d520..2a2e346b 100644 --- a/source/php/Register.php +++ b/source/php/Register.php @@ -59,12 +59,7 @@ public function add($slug, $defaultArgs, $view = null) 'controller' => (string) $slug ); - //Add include alias - $this->blade->registerComponentDirective( - ucfirst($slug) . '.' . $slug, - $slug); - - // Register view composer + $this->blade->registerComponentDirective( ucfirst($slug) . '.' . $slug, $slug); $this->registerViewComposer($this->data->{$slug}); } @@ -151,7 +146,7 @@ private function getViewName($slug, $view = null): string return $view; } - public function registerViewComposer($component) + public function registerViewComposer(object $component) { try { $this->blade->registerComponent( From cb90356fe8d76dec4293aef5ba614b625f96e017 Mon Sep 17 00:00:00 2001 From: Thor Brink Date: Fri, 16 Feb 2024 10:17:19 +0000 Subject: [PATCH 06/11] fix: allow php version ^7.4|^8.0 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 51cfd988..9873a835 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ "test:coverage": "XDEBUG_MODE=coverage vendor/bin/phpunit --coverage-html .coverage/html --coverage-clover .coverage/clover.xml" }, "require": { - "php": "^8.3", + "php": "^7.4|^8.0", "helsingborg-stad/blade": "^3.2" }, "require-dev": { From 58cd5c6165d42b2495a42a77012ff964d68a9e3b Mon Sep 17 00:00:00 2001 From: Thor Brink Date: Mon, 19 Feb 2024 07:38:48 +0000 Subject: [PATCH 07/11] require php ^8.0 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 9873a835..1a5a7888 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ "test:coverage": "XDEBUG_MODE=coverage vendor/bin/phpunit --coverage-html .coverage/html --coverage-clover .coverage/clover.xml" }, "require": { - "php": "^7.4|^8.0", + "php": "^8.0", "helsingborg-stad/blade": "^3.2" }, "require-dev": { From 36f1c2c4f099a251902b302f2a9d87849ad07d31 Mon Sep 17 00:00:00 2001 From: Thor Brink Date: Mon, 19 Feb 2024 11:58:52 +0000 Subject: [PATCH 08/11] fix: broken composer file --- composer.json | 5 ----- 1 file changed, 5 deletions(-) diff --git a/composer.json b/composer.json index 141072ab..d566db0d 100644 --- a/composer.json +++ b/composer.json @@ -25,10 +25,5 @@ "ComponentLibrary\\": "source/php/" } }, -<<<<<<< HEAD - "version": "3.13.5" -} -======= "version": "3.17.5" } ->>>>>>> main From 9d50cec70470149862bc1baea42cccaa441df67e Mon Sep 17 00:00:00 2001 From: Thor Brink Date: Tue, 20 Feb 2024 06:42:14 +0000 Subject: [PATCH 09/11] test: more php versions --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0bbb6716..c10f2d01 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -16,7 +16,7 @@ jobs: strategy: matrix: - php-versions: ['8.3'] + php-versions: ['8.0', '8.1', '8.2', '8.3', '8.4'] name: Test running PHP ${{ matrix.php-versions }} steps: From 09beb9b027ef48940058bd29c7266cdac022c55f Mon Sep 17 00:00:00 2001 From: Thor Brink Date: Tue, 20 Feb 2024 06:43:24 +0000 Subject: [PATCH 10/11] fix: remove strict from composer check --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c10f2d01..eb6f6c27 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -28,7 +28,7 @@ jobs: php-version: ${{ matrix.php-versions }} - name: Validate composer.json and composer.lock - run: composer validate --strict + run: composer validate - name: Cache Composer packages id: composer-cache From cea1e20d91fb0562106d8cfce41a34faaa105d77 Mon Sep 17 00:00:00 2001 From: Thor Brink Date: Tue, 20 Feb 2024 06:53:22 +0000 Subject: [PATCH 11/11] ci: allow strict check --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index eb6f6c27..c10f2d01 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -28,7 +28,7 @@ jobs: php-version: ${{ matrix.php-versions }} - name: Validate composer.json and composer.lock - run: composer validate + run: composer validate --strict - name: Cache Composer packages id: composer-cache