From dc1599a1430b9cd20a8a5255093ea6bdac34aaba Mon Sep 17 00:00:00 2001 From: Sibin Grasic Date: Tue, 17 Sep 2024 14:38:48 +0200 Subject: [PATCH] feat: Migrated to XWP Asset Loader BREAKING CHANGE: Needs XWP Asset Loader --- .gitattributes | 12 +- .gitignore | 11 - composer.json | 20 +- composer.lock | 544 +++++++++++++++++++++++++++--- src/Bundle.php | 212 ------------ src/Legacy/Asset_Loader.php | 67 ++-- src/Legacy/Loader_Trait.php | 8 +- src/Loader.php | 111 +----- src/Resources/Asset.php | 191 ----------- src/Resources/File.php | 80 ----- src/Resources/Font.php | 15 - src/Resources/Image.php | 33 -- src/Resources/Script.php | 50 --- src/Resources/Style.php | 34 -- src/Retriever.php | 81 +---- src/Utils/Manifest.php | 117 ------- src/Utils/xwp-dep-loader-fns.php | 12 +- src/Utils/xwp-dep-loader-init.php | 11 - 18 files changed, 553 insertions(+), 1056 deletions(-) delete mode 100644 src/Bundle.php delete mode 100644 src/Resources/Asset.php delete mode 100644 src/Resources/File.php delete mode 100644 src/Resources/Font.php delete mode 100644 src/Resources/Image.php delete mode 100644 src/Resources/Script.php delete mode 100644 src/Resources/Style.php delete mode 100644 src/Utils/Manifest.php delete mode 100644 src/Utils/xwp-dep-loader-init.php diff --git a/.gitattributes b/.gitattributes index a547aa1..e9631df 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,18 +1,10 @@ /.github export-ignore -/docs export-ignore -/tests export-ignore -/.codeclimate.yml export-ignore /.editorconfig export-ignore /.gitattributes export-ignore /.gitignore export-ignore -/CHANGELOG.md export-ignore +/.phpcs.xml export-ignore +/.releaserc export-ignore /CODE_OF_CONDUCT.md export-ignore /composer.lock export-ignore /CONTRIBUTING.md export-ignore -/LICENSE export-ignore -/README.md export-ignore /SECURITY.md export-ignore -/package.json export-ignore -/.phpcs.xml export-ignore -/phpunit.xml export-ignore -/.releaserc export-ignore diff --git a/.gitignore b/.gitignore index 779260e..22d0d82 100644 --- a/.gitignore +++ b/.gitignore @@ -1,12 +1 @@ -node_modules vendor -test.php -php_errors.log - -.yarn/* -!.yarn/cache -!.yarn/patches -!.yarn/plugins -!.yarn/releases -!.yarn/sdks -!.yarn/versions diff --git a/composer.json b/composer.json index 83fbfe3..8e06ae6 100644 --- a/composer.json +++ b/composer.json @@ -3,12 +3,16 @@ "description": "Simple Asset Loader for WordPress", "license": "GPL-2.0-only", "require": { - "php": ">=8.0", - "x-wp/helper-classes": "^1", - "x-wp/helper-functions": "^1" + "x-wp/asset-loader": "^1" }, "require-dev": { - "oblak/wordpress-coding-standard": "^1" + "oblak/wordpress-coding-standard": "^1", + "php-stubs/wordpress-stubs": "^6.5", + "phpstan/extension-installer": "^1.3", + "phpstan/phpstan": "^1.10", + "phpstan/phpstan-deprecation-rules": "^1.1", + "swissspidy/phpstan-no-private": "^0.2.0", + "szepeviktor/phpstan-wordpress": "^1.3" }, "suggest": { "automattic/jetpack-autoloader": "Allow for better interoperability with other plugins that use this package." @@ -16,16 +20,16 @@ "autoload": { "psr-4": { "Oblak\\WP\\": "src/Legacy/", - "XWP\\Dependency\\": "src" + "XWP\\Dependency\\": "src/" }, "files": [ - "src/Utils/xwp-dep-loader-fns.php", - "src/Utils/xwp-dep-loader-init.php" + "src/Utils/xwp-dep-loader-fns.php" ] }, "config": { "allow-plugins": { - "dealerdirect/phpcodesniffer-composer-installer": true + "dealerdirect/phpcodesniffer-composer-installer": true, + "phpstan/extension-installer": true } } } diff --git a/composer.lock b/composer.lock index 0fd3ef0..becc3f6 100644 --- a/composer.lock +++ b/composer.lock @@ -4,34 +4,105 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "f3efb56dcc6feefca7cd1ac2d539d891", + "content-hash": "bc0396c9c5b158fb0427bccc8691d765", "packages": [ { - "name": "x-wp/helper-classes", - "version": "v1.3.0", + "name": "automattic/jetpack-constants", + "version": "v2.0.4", "source": { "type": "git", - "url": "https://github.com/x-wp/helper-classes.git", - "reference": "ef3c62875d20b89eaaf78a3b0f3d79d962dd2030" + "url": "https://github.com/Automattic/jetpack-constants.git", + "reference": "f6958c313a34c5e92171c45a57d9dc978e5975ed" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/x-wp/helper-classes/zipball/ef3c62875d20b89eaaf78a3b0f3d79d962dd2030", - "reference": "ef3c62875d20b89eaaf78a3b0f3d79d962dd2030", + "url": "https://api.github.com/repos/Automattic/jetpack-constants/zipball/f6958c313a34c5e92171c45a57d9dc978e5975ed", + "reference": "f6958c313a34c5e92171c45a57d9dc978e5975ed", "shasum": "" }, "require": { + "php": ">=7.0" + }, + "require-dev": { + "automattic/jetpack-changelogger": "^4.2.6", + "brain/monkey": "2.6.1", + "yoast/phpunit-polyfills": "^1.1.1" + }, + "suggest": { + "automattic/jetpack-autoloader": "Allow for better interoperability with other plugins that use this package." + }, + "type": "jetpack-library", + "extra": { + "autotagger": true, + "mirror-repo": "Automattic/jetpack-constants", + "changelogger": { + "link-template": "https://github.com/Automattic/jetpack-constants/compare/v${old}...v${new}" + }, + "branch-alias": { + "dev-trunk": "2.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "GPL-2.0-or-later" + ], + "description": "A wrapper for defining constants in a more testable way.", + "support": { + "source": "https://github.com/Automattic/jetpack-constants/tree/v2.0.4" + }, + "time": "2024-08-23T14:28:14+00:00" + }, + { + "name": "x-wp/asset-loader", + "version": "v1.0.0", + "source": { + "type": "git", + "url": "https://github.com/x-wp/asset-loader.git", + "reference": "8198e2337bee579fc96a6f09e2c74fd745c98b6f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/x-wp/asset-loader/zipball/8198e2337bee579fc96a6f09e2c74fd745c98b6f", + "reference": "8198e2337bee579fc96a6f09e2c74fd745c98b6f", + "shasum": "" + }, + "require": { + "automattic/jetpack-constants": "^2.0", "php": ">=8.0", - "x-wp/helper-traits": "^1" + "x-wp/helper-functions": "^1.9", + "x-wp/helper-traits": "^1.9" + }, + "provide": { + "x-wp/asset-loader-implementation": "1.0" + }, + "require-dev": { + "oblak/wordpress-coding-standard": "^1", + "php-stubs/wordpress-stubs": "^6.5", + "phpstan/extension-installer": "^1.3", + "phpstan/phpstan": "^1.10", + "phpstan/phpstan-deprecation-rules": "^1.1", + "swissspidy/phpstan-no-private": "^0.2.0", + "szepeviktor/phpstan-wordpress": "^1.3" }, "suggest": { "automattic/jetpack-autoloader": "Allow for better interoperability with other plugins that use this package." }, "type": "library", "autoload": { + "files": [ + "src/Functions/xwp-loader-init.php" + ], "psr-4": { - "XWP\\Helper\\Classes\\": "" - } + "XWP\\Dependency\\": "src/" + }, + "classmap": [ + "src/Core/" + ] }, "notification-url": "https://packagist.org/downloads/", "license": [ @@ -43,34 +114,25 @@ "email": "sibin.grasic@oblak.studio" } ], - "description": "Generic abstraction related to xWP packages", - "keywords": [ - "abstractions", - "contracts", - "decoupling", - "extended-wp", - "interfaces", - "interoperability", - "standards" - ], + "description": "Simple Asset Loader for WordPress", "support": { - "issues": "https://github.com/x-wp/helper-classes/issues", - "source": "https://github.com/x-wp/helper-classes/tree/v1.3.0" + "issues": "https://github.com/x-wp/asset-loader/issues", + "source": "https://github.com/x-wp/asset-loader/tree/v1.0.0" }, - "time": "2024-05-31T04:26:38+00:00" + "time": "2024-09-17T12:29:39+00:00" }, { "name": "x-wp/helper-functions", - "version": "v1.3.0", + "version": "v1.9.0", "source": { "type": "git", "url": "https://github.com/x-wp/helper-functions.git", - "reference": "92731d8a7e3db5c8f34c6b71b887f27e8f0a0a55" + "reference": "951890a5352d2c293c086e20affb7aa6d8cc2fd8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/x-wp/helper-functions/zipball/92731d8a7e3db5c8f34c6b71b887f27e8f0a0a55", - "reference": "92731d8a7e3db5c8f34c6b71b887f27e8f0a0a55", + "url": "https://api.github.com/repos/x-wp/helper-functions/zipball/951890a5352d2c293c086e20affb7aa6d8cc2fd8", + "reference": "951890a5352d2c293c086e20affb7aa6d8cc2fd8", "shasum": "" }, "require": { @@ -82,10 +144,11 @@ "type": "library", "autoload": { "files": [ - "xwp-helper-fns.php" + "xwp-helper-fns.php", + "xwp-helper-fns-req.php" ], "psr-4": { - "XWP\\Helper\\Functions\\": "" + "XWP\\Helper\\Functions\\": "." } }, "notification-url": "https://packagist.org/downloads/", @@ -110,22 +173,22 @@ ], "support": { "issues": "https://github.com/x-wp/helper-functions/issues", - "source": "https://github.com/x-wp/helper-functions/tree/v1.3.0" + "source": "https://github.com/x-wp/helper-functions/tree/v1.9.0" }, - "time": "2024-06-06T21:25:23+00:00" + "time": "2024-09-07T15:40:44+00:00" }, { "name": "x-wp/helper-traits", - "version": "v1.3.0", + "version": "v1.9.0", "source": { "type": "git", "url": "https://github.com/x-wp/helper-traits.git", - "reference": "b99bcb6f2fadeedba30fc63abe39aa8e88e0949f" + "reference": "485d1e932e133d2919756abd82d3d989b47e111a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/x-wp/helper-traits/zipball/b99bcb6f2fadeedba30fc63abe39aa8e88e0949f", - "reference": "b99bcb6f2fadeedba30fc63abe39aa8e88e0949f", + "url": "https://api.github.com/repos/x-wp/helper-traits/zipball/485d1e932e133d2919756abd82d3d989b47e111a", + "reference": "485d1e932e133d2919756abd82d3d989b47e111a", "shasum": "" }, "require": { @@ -162,9 +225,9 @@ ], "support": { "issues": "https://github.com/x-wp/helper-traits/issues", - "source": "https://github.com/x-wp/helper-traits/tree/v1.3.0" + "source": "https://github.com/x-wp/helper-traits/tree/v1.9.0" }, - "time": "2024-05-26T16:39:47+00:00" + "time": "2024-09-07T15:21:49+00:00" } ], "packages-dev": [ @@ -300,6 +363,54 @@ }, "time": "2024-01-24T23:43:48+00:00" }, + { + "name": "php-stubs/wordpress-stubs", + "version": "v6.6.0", + "source": { + "type": "git", + "url": "https://github.com/php-stubs/wordpress-stubs.git", + "reference": "86e8753e89d59849276dcdd91b9a7dd78bb4abe2" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-stubs/wordpress-stubs/zipball/86e8753e89d59849276dcdd91b9a7dd78bb4abe2", + "reference": "86e8753e89d59849276dcdd91b9a7dd78bb4abe2", + "shasum": "" + }, + "require-dev": { + "dealerdirect/phpcodesniffer-composer-installer": "^1.0", + "nikic/php-parser": "^4.13", + "php": "^7.4 || ^8.0", + "php-stubs/generator": "^0.8.3", + "phpdocumentor/reflection-docblock": "^5.4.1", + "phpstan/phpstan": "^1.10.49", + "phpunit/phpunit": "^9.5", + "szepeviktor/phpcs-psr-12-neutron-hybrid-ruleset": "^1.0", + "wp-coding-standards/wpcs": "3.1.0 as 2.3.0" + }, + "suggest": { + "paragonie/sodium_compat": "Pure PHP implementation of libsodium", + "symfony/polyfill-php80": "Symfony polyfill backporting some PHP 8.0+ features to lower PHP versions", + "szepeviktor/phpstan-wordpress": "WordPress extensions for PHPStan" + }, + "type": "library", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "WordPress function and class declaration stubs for static analysis.", + "homepage": "https://github.com/php-stubs/wordpress-stubs", + "keywords": [ + "PHPStan", + "static analysis", + "wordpress" + ], + "support": { + "issues": "https://github.com/php-stubs/wordpress-stubs/issues", + "source": "https://github.com/php-stubs/wordpress-stubs/tree/v6.6.0" + }, + "time": "2024-07-17T08:50:38+00:00" + }, { "name": "phpcompatibility/php-compatibility", "version": "9.3.5", @@ -625,18 +736,66 @@ }, "time": "2023-07-16T21:39:41+00:00" }, + { + "name": "phpstan/extension-installer", + "version": "1.4.3", + "source": { + "type": "git", + "url": "https://github.com/phpstan/extension-installer.git", + "reference": "85e90b3942d06b2326fba0403ec24fe912372936" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/extension-installer/zipball/85e90b3942d06b2326fba0403ec24fe912372936", + "reference": "85e90b3942d06b2326fba0403ec24fe912372936", + "shasum": "" + }, + "require": { + "composer-plugin-api": "^2.0", + "php": "^7.2 || ^8.0", + "phpstan/phpstan": "^1.9.0 || ^2.0" + }, + "require-dev": { + "composer/composer": "^2.0", + "php-parallel-lint/php-parallel-lint": "^1.2.0", + "phpstan/phpstan-strict-rules": "^0.11 || ^0.12 || ^1.0" + }, + "type": "composer-plugin", + "extra": { + "class": "PHPStan\\ExtensionInstaller\\Plugin" + }, + "autoload": { + "psr-4": { + "PHPStan\\ExtensionInstaller\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Composer plugin for automatic installation of PHPStan extensions", + "keywords": [ + "dev", + "static analysis" + ], + "support": { + "issues": "https://github.com/phpstan/extension-installer/issues", + "source": "https://github.com/phpstan/extension-installer/tree/1.4.3" + }, + "time": "2024-09-04T20:21:43+00:00" + }, { "name": "phpstan/phpdoc-parser", - "version": "1.29.1", + "version": "1.30.1", "source": { "type": "git", "url": "https://github.com/phpstan/phpdoc-parser.git", - "reference": "fcaefacf2d5c417e928405b71b400d4ce10daaf4" + "reference": "51b95ec8670af41009e2b2b56873bad96682413e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/fcaefacf2d5c417e928405b71b400d4ce10daaf4", - "reference": "fcaefacf2d5c417e928405b71b400d4ce10daaf4", + "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/51b95ec8670af41009e2b2b56873bad96682413e", + "reference": "51b95ec8670af41009e2b2b56873bad96682413e", "shasum": "" }, "require": { @@ -668,9 +827,114 @@ "description": "PHPDoc parser with support for nullable, intersection and generic types", "support": { "issues": "https://github.com/phpstan/phpdoc-parser/issues", - "source": "https://github.com/phpstan/phpdoc-parser/tree/1.29.1" + "source": "https://github.com/phpstan/phpdoc-parser/tree/1.30.1" + }, + "time": "2024-09-07T20:13:05+00:00" + }, + { + "name": "phpstan/phpstan", + "version": "1.12.3", + "source": { + "type": "git", + "url": "https://github.com/phpstan/phpstan.git", + "reference": "0fcbf194ab63d8159bb70d9aa3e1350051632009" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/0fcbf194ab63d8159bb70d9aa3e1350051632009", + "reference": "0fcbf194ab63d8159bb70d9aa3e1350051632009", + "shasum": "" + }, + "require": { + "php": "^7.2|^8.0" + }, + "conflict": { + "phpstan/phpstan-shim": "*" + }, + "bin": [ + "phpstan", + "phpstan.phar" + ], + "type": "library", + "autoload": { + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "PHPStan - PHP Static Analysis Tool", + "keywords": [ + "dev", + "static analysis" + ], + "support": { + "docs": "https://phpstan.org/user-guide/getting-started", + "forum": "https://github.com/phpstan/phpstan/discussions", + "issues": "https://github.com/phpstan/phpstan/issues", + "security": "https://github.com/phpstan/phpstan/security/policy", + "source": "https://github.com/phpstan/phpstan-src" }, - "time": "2024-05-31T08:52:43+00:00" + "funding": [ + { + "url": "https://github.com/ondrejmirtes", + "type": "github" + }, + { + "url": "https://github.com/phpstan", + "type": "github" + } + ], + "time": "2024-09-09T08:10:35+00:00" + }, + { + "name": "phpstan/phpstan-deprecation-rules", + "version": "1.2.1", + "source": { + "type": "git", + "url": "https://github.com/phpstan/phpstan-deprecation-rules.git", + "reference": "f94d246cc143ec5a23da868f8f7e1393b50eaa82" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/phpstan-deprecation-rules/zipball/f94d246cc143ec5a23da868f8f7e1393b50eaa82", + "reference": "f94d246cc143ec5a23da868f8f7e1393b50eaa82", + "shasum": "" + }, + "require": { + "php": "^7.2 || ^8.0", + "phpstan/phpstan": "^1.12" + }, + "require-dev": { + "php-parallel-lint/php-parallel-lint": "^1.2", + "phpstan/phpstan-phpunit": "^1.0", + "phpunit/phpunit": "^9.5" + }, + "type": "phpstan-extension", + "extra": { + "phpstan": { + "includes": [ + "rules.neon" + ] + } + }, + "autoload": { + "psr-4": { + "PHPStan\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "PHPStan rules for detecting usage of deprecated classes, methods, properties, constants and traits.", + "support": { + "issues": "https://github.com/phpstan/phpstan-deprecation-rules/issues", + "source": "https://github.com/phpstan/phpstan-deprecation-rules/tree/1.2.1" + }, + "time": "2024-09-11T15:52:35+00:00" }, { "name": "slevomat/coding-standard", @@ -817,6 +1081,196 @@ ], "time": "2024-01-11T20:47:48+00:00" }, + { + "name": "swissspidy/phpstan-no-private", + "version": "v0.2.1", + "source": { + "type": "git", + "url": "https://github.com/swissspidy/phpstan-no-private.git", + "reference": "f7a1890e350c8d8bf26370426a971d7490ae4245" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/swissspidy/phpstan-no-private/zipball/f7a1890e350c8d8bf26370426a971d7490ae4245", + "reference": "f7a1890e350c8d8bf26370426a971d7490ae4245", + "shasum": "" + }, + "require": { + "php": "^7.2 || ^8.0", + "phpstan/phpstan": "^1.10.3" + }, + "require-dev": { + "dealerdirect/phpcodesniffer-composer-installer": "^1.0.0", + "php-parallel-lint/php-parallel-lint": "^1.2", + "phpstan/phpstan-php-parser": "^1.1", + "phpstan/phpstan-phpunit": "^1.0", + "phpunit/phpunit": "^9.5", + "slevomat/coding-standard": "^8.8.0", + "squizlabs/php_codesniffer": "^3.5.3" + }, + "type": "phpstan-extension", + "extra": { + "phpstan": { + "includes": [ + "rules.neon" + ] + } + }, + "autoload": { + "psr-4": { + "Swissspidy\\PHPStan\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "PHPStan rules for detecting usage of pseudo-private functions, classes, and methods.", + "support": { + "issues": "https://github.com/swissspidy/phpstan-no-private/issues", + "source": "https://github.com/swissspidy/phpstan-no-private/tree/v0.2.1" + }, + "time": "2024-06-05T10:03:17+00:00" + }, + { + "name": "symfony/polyfill-php73", + "version": "v1.31.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-php73.git", + "reference": "0f68c03565dcaaf25a890667542e8bd75fe7e5bb" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-php73/zipball/0f68c03565dcaaf25a890667542e8bd75fe7e5bb", + "reference": "0f68c03565dcaaf25a890667542e8bd75fe7e5bb", + "shasum": "" + }, + "require": { + "php": ">=7.2" + }, + "type": "library", + "extra": { + "thanks": { + "name": "symfony/polyfill", + "url": "https://github.com/symfony/polyfill" + } + }, + "autoload": { + "files": [ + "bootstrap.php" + ], + "psr-4": { + "Symfony\\Polyfill\\Php73\\": "" + }, + "classmap": [ + "Resources/stubs" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill backporting some PHP 7.3+ features to lower PHP versions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "polyfill", + "portable", + "shim" + ], + "support": { + "source": "https://github.com/symfony/polyfill-php73/tree/v1.31.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2024-09-09T11:45:10+00:00" + }, + { + "name": "szepeviktor/phpstan-wordpress", + "version": "v1.3.5", + "source": { + "type": "git", + "url": "https://github.com/szepeviktor/phpstan-wordpress.git", + "reference": "7f8cfe992faa96b6a33bbd75c7bace98864161e7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/szepeviktor/phpstan-wordpress/zipball/7f8cfe992faa96b6a33bbd75c7bace98864161e7", + "reference": "7f8cfe992faa96b6a33bbd75c7bace98864161e7", + "shasum": "" + }, + "require": { + "php": "^7.2 || ^8.0", + "php-stubs/wordpress-stubs": "^4.7 || ^5.0 || ^6.0", + "phpstan/phpstan": "^1.10.31", + "symfony/polyfill-php73": "^1.12.0" + }, + "require-dev": { + "composer/composer": "^2.1.14", + "dealerdirect/phpcodesniffer-composer-installer": "^1.0", + "php-parallel-lint/php-parallel-lint": "^1.1", + "phpstan/phpstan-strict-rules": "^1.2", + "phpunit/phpunit": "^8.0 || ^9.0", + "szepeviktor/phpcs-psr-12-neutron-hybrid-ruleset": "^1.0", + "wp-coding-standards/wpcs": "3.1.0 as 2.3.0" + }, + "suggest": { + "swissspidy/phpstan-no-private": "Detect usage of internal core functions, classes and methods" + }, + "type": "phpstan-extension", + "extra": { + "phpstan": { + "includes": [ + "extension.neon" + ] + } + }, + "autoload": { + "psr-4": { + "SzepeViktor\\PHPStan\\WordPress\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "WordPress extensions for PHPStan", + "keywords": [ + "PHPStan", + "code analyse", + "code analysis", + "static analysis", + "wordpress" + ], + "support": { + "issues": "https://github.com/szepeviktor/phpstan-wordpress/issues", + "source": "https://github.com/szepeviktor/phpstan-wordpress/tree/v1.3.5" + }, + "time": "2024-06-28T22:27:19+00:00" + }, { "name": "wp-coding-standards/wpcs", "version": "3.0.1", @@ -889,9 +1343,7 @@ "stability-flags": [], "prefer-stable": false, "prefer-lowest": false, - "platform": { - "php": ">=8.0" - }, + "platform": [], "platform-dev": [], "plugin-api-version": "2.6.0" } diff --git a/src/Bundle.php b/src/Bundle.php deleted file mode 100644 index 016b9e1..0000000 --- a/src/Bundle.php +++ /dev/null @@ -1,212 +0,0 @@ - - * @implements \Iterator - * */ -class Bundle implements \ArrayAccess, \Iterator, \Countable, \JsonSerializable { - use Array_Access; - - /** - * Asset ids grouped by context - * - * @var array> - */ - protected array $grouped = array(); - - /** - * Class constructor - * - * @param string $id Bundle ID. - * @param ?string $version Bundle version. - * @param int $priority Bundle priority. - * @param string $base_dir Base directory for assets. - * @param string $base_uri Base URI for assets. - * @param array $assets Array of assets to load. - * @param string $manifest Manifest file. - */ - public function __construct( - protected string $id, - protected string $version, - protected int $priority, - protected string $base_dir, - protected string $base_uri, - array $assets, - string $manifest, - ) { - $this->load_assets( $assets, Manifest::load( $base_dir, $manifest, $id, $version ) ); - } - - /** - * Loads the assets - * - * @param array $assets Array of assets to load. - * @param array $manifest Asset manifest. - */ - protected function load_assets( array $assets, array $manifest ) { - $this->arr_data = \array_merge( - ...\array_map( - fn( $ast, $ctx ) => $this->load_asset_group( $ast, $ctx, $manifest ), - $assets, - \array_keys( $assets ), - ), - ); - $this->arr_data_keys = \array_keys( $this->arr_data ); - - $manifest = \array_diff_key( $manifest, $this->arr_data ); - - foreach ( $manifest as $id => $src ) { - $this->arr_data[ $id ] = $this->load_file( $src ); - $this->arr_data_keys[] = $id; - } - } - - /** - * Parses an asset file - * - * @param array $deps Asset group to parse. - * @param string $ctx Context for the asset. - * @param array $map Asset map. - * @return array - */ - protected function load_asset_group( array $deps, string $ctx, array $map ): array { - $parsed = array(); - foreach ( $deps as $dep ) { - if ( ! \is_array( $dep ) ) { - $dep = array( 'src' => $dep ); - } - $id = $dep['src']; - $src = $map[ $id ] ?? $id; - $ext = \pathinfo( $src, \PATHINFO_EXTENSION ); - - $dep = \wp_parse_args( - \array_merge( $dep, \compact( 'src' ) ), - array( - 'ctx' => $ctx, - 'deps' => array(), - 'mode' => 'auto', - ), - ); - - $parsed[ $id ] = $this->load_asset( $dep ); - - $this->grouped[ $ctx ][] = $id; - } - - return $parsed; - } - - /** - * Loads an asset - * - * @param array $asset Asset data. - * @return Asset - */ - protected function load_asset( array $asset ): Asset { - $ext = \pathinfo( $asset['src'], \PATHINFO_EXTENSION ); - - $cname = match ( $ext ) { - 'js' => Script::class, - 'css' => Style::class, - default => Script::class, - }; - - return new $cname( $this, ...$asset ); - } - - /** - * Loads a file - * - * @param string $src File source. - * @return File - */ - protected function load_file( string $src ): File { - $ext = \pathinfo( $src, \PATHINFO_EXTENSION ); - - $cname = match ( $ext ) { - 'jpg', 'png', 'gif', - 'ico', 'svg', 'jpeg', - 'webp', 'avif', 'apng' => Image::class, - 'ttf', 'woff', 'woff2' => Font::class, - default => Image::class, - }; - - return new $cname( $this, $src ); - } - - /** - * Get the bundle ID - * - * @return string - */ - public function id(): string { - return $this->id; - } - - /** - * Get the base directory - * - * @return string - */ - public function base_dir(): string { - return $this->base_dir; - } - - /** - * Get the base URI - * - * @return string - */ - public function base_uri(): string { - return $this->base_uri; - } - - /** - * Get the bundle version - * - * @return string - */ - public function version(): string { - return $this->version; - } - - /** - * Get the bundle priority - * - * @return int - */ - public function priority(): int { - return $this->priority; - } - - /** - * Get the context dependencies - * - * @param string $ctx Context to get dependencies for. - * @return array - */ - public function get_context_deps( string $ctx ): array { - return $this->grouped[ $ctx ] ?? array(); - } -} diff --git a/src/Legacy/Asset_Loader.php b/src/Legacy/Asset_Loader.php index 9b1267d..57d246c 100644 --- a/src/Legacy/Asset_Loader.php +++ b/src/Legacy/Asset_Loader.php @@ -11,51 +11,51 @@ /** * Handles the complete asset loading process. + * + * @mixin \XWP_Asset_Loader + * @deprecated 5.0.0 Use \XWP_Asset_Loader instead. */ final class Asset_Loader { use Singleton; /** - * Array of registered namespaces - * - * @var array - */ - private array $namespaces = array(); - - /** - * Class constructor + * Gets the singleton instance * - * Intializes the global loader hook and context, and registers the loader + * @return self */ - public function __construct() { - \add_filter( 'xwp_dependency_bundles', array( $this, 'load_legacy_bundles' ), 10, 1 ); + public static function get_instance(): self { + return self::instance(); } /** - * Gets the singleton instance + * Magic method to call methods on the asset loader * - * @return Asset_Loader + * @param string $name Method name. + * @param array $args Method arguments. + * @return mixed */ - public static function get_instance(): self { - return self::instance(); + public function __call( string $name, array $args = array() ): mixed { + return \XWP_Asset_Loader::instance()->$name( ...$args ); } /** * Registers a namespace to load assets for * * @param string $namespace Namespace to register. - * @param array $asset_data Asset data. + * @param array $args Asset data. * @return void */ - public function register_namespace( $namespace, $asset_data ) { - $this->namespaces[ $namespace ] = array( - 'assets' => $this->remap_assets( $asset_data['assets'] ), - 'base_dir' => $asset_data['dist_path'], - 'base_uri' => $asset_data['dist_uri'], - 'id' => $namespace, - 'manifest' => 'assets.php', - 'priority' => $asset_data['priority'] ?? 50, - 'version' => $asset_data['version'] ?? '0.0.0-dev', + public function register_namespace( $namespace, $args ) { + \XWP_Asset_Loader::load_bundle( + array( + 'assets' => $this->remap_assets( $args['assets'] ), + 'base_dir' => $args['base_dir'] ?? $args['dist_path'] ?? '', + 'base_uri' => $args['base_uri'] ?? $args['dist_uri'] ?? '', + 'id' => $namespace, + 'manifest' => 'assets.php', + 'priority' => $args['priority'] ?? 50, + 'version' => $args['version'] ?? '0.0.0-dev', + ), ); } @@ -68,21 +68,4 @@ public function register_namespace( $namespace, $asset_data ) { protected function remap_assets( array $assets ): array { return \array_map( static fn( $a ) => \array_merge( ...\array_values( $a ) ), $assets ); } - - /** - * Loads the legacy bundles - * - * @param array $bundles Bundles to load. - * @return array - */ - public function load_legacy_bundles( array $bundles ): array { - if ( ! \doing_filter( 'xwp_dependency_bundles' ) ) { - return $bundles; - } - - $legacy_bundles = $this->namespaces; - unset( $this->namespaces ); - - return \array_merge( $bundles, $legacy_bundles ); - } } diff --git a/src/Legacy/Loader_Trait.php b/src/Legacy/Loader_Trait.php index 46a0d5a..24a74e4 100644 --- a/src/Legacy/Loader_Trait.php +++ b/src/Legacy/Loader_Trait.php @@ -7,13 +7,13 @@ namespace Oblak\WP; -use XWP\Dependency\Retriever; - /** * Getters for asset path and URI. + * + * @deprecated 5.0.0 Use \XWP_Asset_Retriever instead. */ trait Loader_Trait { - use Retriever; + use \XWP_Asset_Retriever; /** * Initializes the asset loader @@ -22,7 +22,7 @@ trait Loader_Trait { * @param string|null $namespace Namespace for the assets. Defaults to null. Optional. */ protected function init_asset_loader( array $args, ?string $namespace = null ): void { - $this->bundle_id ??= $namespace ?? $args['namespace'] ?? \wp_generate_uuid4(); + $this->bundle_id ??= $namespace ?? $args['namespace'] ?? $args['id'] ?? \wp_generate_uuid4(); \add_action( 'init', fn() => Asset_Loader::instance()->register_namespace( $this->bundle_id, $args ) diff --git a/src/Loader.php b/src/Loader.php index f87fe13..ba26312 100644 --- a/src/Loader.php +++ b/src/Loader.php @@ -8,117 +8,18 @@ namespace XWP\Dependency; -use XWP\Helper\Traits\Singleton; - /** * Dependency loader class. + * + * @deprecated 5.0.0 Use \XWP_Asset_Loader instead. */ class Loader { - use Singleton; - - /** - * Current execution context - * - * @var string - */ - protected string $context; - - /** - * Hook we're using to load assets - * - * @var 'wp_enqueue_scripts'|'admin_enqueue_scripts' - */ - protected string $target; - - /** - * Array of registered bundles - * - * @var array - */ - protected array $bundles; - - /** - * Class constructor - */ - protected function __construct() { - $this->target = ! \is_admin() ? 'wp_enqueue_scripts' : 'admin_enqueue_scripts'; - $this->context = ! \is_admin() ? 'front' : 'admin'; - - \add_action( 'init', array( $this, 'load_bundles' ), 1000, 0 ); - \add_action( $this->target, array( $this, 'run' ), -1 ); - } - - /** - * Loads the bundles - */ - public function load_bundles() { - $bundles = \apply_filters( 'xwp_dependency_bundles', array(), $this->context ); - $bundles = \array_map( array( $this, 'load_bundle' ), $bundles ); - $bundles = \array_filter( $bundles ); - - $this->bundles = $bundles; - } - - /** - * Loads a bundle - * - * @param array|Bundle $config Bundle configuration. - * @return Bundle|null - */ - protected function load_bundle( array|Bundle $config ): ?Bundle { - if ( $config instanceof Bundle ) { - return $config; - } - - if ( ! $config['assets'] ) { - return null; - } - - $config = \wp_parse_args( - $config, - array( - 'manifest' => false, - 'priority' => 50, - 'version' => '0.0.0-dev', - ), - ); - - return new Bundle( ...$config ); - } - - /** - * Runs the loader on the target hook. - */ - public function run() { - foreach ( $this->bundles as $bundle ) { - $this->enqueue( $bundle, $bundle->get_context_deps( $this->context ) ); - } - } - - /** - * Enqueues a bundle assets. - * - * @param Bundle $bundle Bundle to enqueue. - * @param array $deps Dependencies to enqueue. - */ - public function enqueue( Bundle $bundle, array $deps ) { - foreach ( $deps as $dep ) { - \add_action( - $this->target, - static fn() => $bundle[ $dep ]->process( 'auto' ), - $bundle->priority(), - 0, - ); - } - } - /** - * Get a bundle by ID + * Returns the singleton instance of the loader. * - * @param string $id Bundle ID. - * @return Bundle|null + * @return \XWP_Asset_Loader */ - public function get_bundle( string $id ): ?Bundle { - return $this->bundles[ $id ] ?? null; + public static function instance(): \XWP_Asset_Loader { + return \XWP_Asset_Loader::instance(); } } diff --git a/src/Resources/Asset.php b/src/Resources/Asset.php deleted file mode 100644 index 56dd4aa..0000000 --- a/src/Resources/Asset.php +++ /dev/null @@ -1,191 +0,0 @@ -name; - } - - /** - * Get the context of the asset. - * - * @return string The context of the asset. - */ - public function ctx(): string { - return $this->ctx; - } - - /** - * Get the version of the asset. - * - * @return string The version of the asset. - */ - public function version(): string { - return $this->bundle->version(); - } - - /** - * Get the dependencies of the asset. - * - * @return array The dependencies of the asset. - */ - public function deps(): array { - return $this->deps; - } - - /** - * Get the handle of the asset. - * - * @return string The handle of the asset. - */ - public function handle(): string { - return $this->bundle->id() . '-' . $this->name(); - } - - /** - * Get the arguments of the asset. - * - * @return array The arguments of the asset. - */ - public function args(): array { - return $this->args ?? $this->default_args(); - } - - /** - * Process the asset. - * - * @param string $mode The mode of the asset. - * @return bool True if the asset is processed successfully, false otherwise. - */ - public function process( string $mode = 'auto' ): bool { - /** - * Should we register this asset type? - * - * @param bool $load_styles Whether to load styles. - * - * @since 2.0.0 - */ - if ( ! \apply_filters( "{$this->bundle->id()}_load_{$this->type()}s", true ) ) { - return false; - } - - return $this->register() && $this->enqueue( $mode ); - } - - /** - * Register the asset. - * - * @return bool True if the asset is registered successfully, false otherwise. - */ - public function register(): bool { - /** - * Short-cuts the loading of a specific style. - * - * @param bool $load_stype Whether to load the style. - * @param string $basename Style basename. - * - * @since 2.0.0 - */ - if ( ! \apply_filters( "{$this->bundle->id()}_load_{$this->type()}", true, $this->name() ) ) { - return false; - } - - return $this->callback( 'register', $this->cb_args() ); - } - - /** - * Enqueue the asset. - * - * @param string $mode The mode of the asset. - * @return bool True if the asset is enqueued successfully, false otherwise. - */ - public function enqueue( string $mode = 'auto' ): bool { - if ( $mode !== $this->mode ) { - return false; - } - - return $this->callback( 'enqueue', array( 'handle' => $this->handle() ) ); - } - - /** - * Call the callback function for the given action and arguments. - * - * @param string $action The action to perform. - * @param array $args The arguments for the callback function. - * @return bool True if the callback function is called successfully, false otherwise. - */ - protected function callback( string $action, array $args ): bool { - $callback = "wp_{$action}_{$this->type()}"; - - return $callback( ...$args ) ?? true; - } - - /** - * Get the callback arguments for registering or enqueuing the asset. - * - * @return array The callback arguments. - */ - protected function cb_args(): array { - return \array_merge( - array( - 'deps' => $this->deps(), - 'handle' => $this->handle(), - 'src' => $this->uri(), - 'ver' => $this->version(), - ), - $this->args(), - ); - } - - /** - * Get the type of asset. - * - * @return string The type of asset. Possible values are 'script' or 'style'. - */ - abstract protected function type(): string; - - /** - * Get the default enqueue/register arguments for the asset. - * - * @return array The default arguments for enqueue/register. - */ - abstract protected function default_args(): array; -} diff --git a/src/Resources/File.php b/src/Resources/File.php deleted file mode 100644 index 0fbe880..0000000 --- a/src/Resources/File.php +++ /dev/null @@ -1,80 +0,0 @@ -ext = \pathinfo( $this->src, \PATHINFO_EXTENSION ); - $this->name ??= \pathinfo( $this->src, \PATHINFO_FILENAME ); - } - - /** - * Get the file extension - * - * @return string - */ - public function ext(): string { - return $this->ext; - } - - /** - * Get the file path - * - * @return string - */ - public function path(): string { - return $this->bundle->base_dir() . '/' . $this->src; - } - - /** - * Get the file URI - * - * @return string - */ - public function uri(): string { - return $this->bundle->base_uri() . '/' . $this->src; - } - - /** - * Get the file contents - * - * @return string - */ - public function data(): string { - return \wp_load_filesystem()->get_contents( $this->path() ); - } -} diff --git a/src/Resources/Font.php b/src/Resources/Font.php deleted file mode 100644 index 3ecc927..0000000 --- a/src/Resources/Font.php +++ /dev/null @@ -1,15 +0,0 @@ -data() ); - } - - /** - * Get the base64 encoded URI of the image. - * - * @return string - */ - public function base64_uri(): string { - return "data:image/{$this->ext()};base64,{$this->base64_data()}"; - } -} diff --git a/src/Resources/Script.php b/src/Resources/Script.php deleted file mode 100644 index 403511f..0000000 --- a/src/Resources/Script.php +++ /dev/null @@ -1,50 +0,0 @@ - array( - 'in_footer' => true, - ), - ); - } - - public function register(): bool { - if ( ! parent::register() ) { - return false; - } - - \do_action( "{$this->bundle->id()}_localize_{$this->type()}", $this->name(), $this ); - - if ( ! \has_filter( "localize_params_{$this->handle()}" ) ) { - return true; - } - - $args = array( - 'handle' => $this->handle(), - 'l10n' => array(), - 'object_name' => $this->name(), - ); - - $args = \apply_filters( "localize_params_{$this->handle()}", $args, $this ); - - \wp_localize_script( ...$args ); - - return true; - } -} diff --git a/src/Resources/Style.php b/src/Resources/Style.php deleted file mode 100644 index 15c1bd3..0000000 --- a/src/Resources/Style.php +++ /dev/null @@ -1,34 +0,0 @@ - 'all', - ); - } -} diff --git a/src/Retriever.php b/src/Retriever.php index b2babeb..c87018f 100644 --- a/src/Retriever.php +++ b/src/Retriever.php @@ -10,84 +10,9 @@ /** * Retriever trait. + * + * @deprecated 5.0.0 Use \XWP_Asset_Retriever instead. */ trait Retriever { - /** - * Bundle ID. - * - * @var string - */ - private string $bundle_id; - - /** - * Load the bundle configuration. - * - * @param string $path Path to the bundle configuration file. - * @return void - */ - protected function load_bundle_config( string $path ): void { - $config = include $path; - $this->bundle_id = $config['id']; - - \xwp_add_dependency_bundle( $this->bundle_id, $config ); - } - - /** - * Get the bundle instance. - * - * @return Bundle Bundle instance. - */ - private function bundle(): Bundle { - return Loader::instance()->get_bundle( $this->bundle_id ); - } - - /** - * Get the cache-busted file path. - * - * @param string $asset Asset path. - * @return string - */ - public function asset_path( string $asset ): string { - return $this->bundle()[ $asset ]->path(); - } - - /** - * Get the cache-busted file URI. - * - * @param string $asset Asset URI. - * @return string - */ - public function asset_uri( string $asset ): string { - return $this->bundle()[ $asset ]->uri(); - } - - /** - * Get the base64 encoded file URI. - * - * @param string $asset Asset path. - * @return string - */ - public function asset_base64_uri( string $asset ): string { - return $this->bundle()[ $asset ]->base64_uri(); - } - - /** - * Get the cache-busted file data. - * - * @param string $asset Asset path. - * @return string - */ - public function asset_data( string $asset ): string { - return $this->bundle()[ $asset ]->data(); - } - - /** - * Get the base64 encoded file data. - * - * @param string $asset Asset path. - * @return string - */ - public function asset_base64_data( string $asset ): string { - return $this->bundle()[ $asset ]->base64_data(); - } + use \XWP_Asset_Retriever; } diff --git a/src/Utils/Manifest.php b/src/Utils/Manifest.php deleted file mode 100644 index 5e02719..0000000 --- a/src/Utils/Manifest.php +++ /dev/null @@ -1,117 +0,0 @@ - static::read_manifest_php( $file ), - \file_exists( "{$file}.json" ) => static::read_manifest_json( $file ), - default => array(), - }; - } catch ( \Throwable ) { - return array(); - } - } - - /** - * Read a PHP manifest file - * - * @param string $file Path to the manifest file. - * @return array - */ - protected static function read_manifest_php( string $file ): array { - return require "{$file}.php"; - } - - /** - * Read a JSON manifest file - * - * @param string $file Path to the manifest file. - * @return array - */ - protected static function read_manifest_json( string $file ): array { - return \json_decode( - \wp_load_filesystem()->get_contents( "{$file}.json" ), - true, - 512, - \JSON_THROW_ON_ERROR, - ); - } -} diff --git a/src/Utils/xwp-dep-loader-fns.php b/src/Utils/xwp-dep-loader-fns.php index 1803c9c..6b183dc 100644 --- a/src/Utils/xwp-dep-loader-fns.php +++ b/src/Utils/xwp-dep-loader-fns.php @@ -13,13 +13,7 @@ * @param array $config Bundle configuration. */ function xwp_add_dependency_bundle( string $id, array $config ): void { - add_filter( - 'xwp_dependency_bundles', - static function ( array $bundles ) use ( $id, $config ): array { - $bundles[ $id ] = $config; - return $bundles; - }, - 10, - 1, - ); + $config['id'] = $id; + + XWP_Asset_Loader::load_bundle( $config ); } diff --git a/src/Utils/xwp-dep-loader-init.php b/src/Utils/xwp-dep-loader-init.php deleted file mode 100644 index 51ee660..0000000 --- a/src/Utils/xwp-dep-loader-init.php +++ /dev/null @@ -1,11 +0,0 @@ -