diff --git a/.gitattributes b/.gitattributes index 7d92ee940d..f7fa86e5fc 100644 --- a/.gitattributes +++ b/.gitattributes @@ -7,7 +7,6 @@ /gulp-tasks export-ignore /lang export-ignore /tests export-ignore -/vendor/ export-ignore /node_modules export-ignore /.babelrc export-ignore diff --git a/.github/workflows/build-and-tag.yml b/.github/workflows/build-and-tag.yml index 397993c837..2587b42195 100644 --- a/.github/workflows/build-and-tag.yml +++ b/.github/workflows/build-and-tag.yml @@ -12,6 +12,15 @@ jobs: - name: Checkout code uses: actions/checkout@v3 + - name: Set PHP version + uses: shivammathur/setup-php@v2 + with: + php-version: '7.0' # Minimum required version + coverage: none + + - name: composer install + run: composer install --no-dev -o + - name: install node v18 uses: actions/setup-node@v3 with: diff --git a/composer.json b/composer.json index fa7c47e825..4cdd8fb141 100644 --- a/composer.json +++ b/composer.json @@ -29,7 +29,8 @@ ], "require": { "php": ">=7.0", - "composer/installers": "^1.0 || ^2.0" + "composer/installers": "^1.0 || ^2.0", + "psr/container": "^1.0 || ^2.0" }, "require-dev": { "10up/phpcs-composer": "dev-master", diff --git a/composer.lock b/composer.lock index 369da8a481..e11d5f07c2 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "ff870c75078541fd7f71487b281ddd46", + "content-hash": "cdb2b0fa9e6fcd5faa3d1cde9e40827b", "packages": [ { "name": "composer/installers", @@ -150,6 +150,59 @@ } ], "time": "2022-08-20T06:45:11+00:00" + }, + { + "name": "psr/container", + "version": "2.0.2", + "source": { + "type": "git", + "url": "https://github.com/php-fig/container.git", + "reference": "c71ecc56dfe541dbd90c5360474fbc405f8d5963" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/container/zipball/c71ecc56dfe541dbd90c5360474fbc405f8d5963", + "reference": "c71ecc56dfe541dbd90c5360474fbc405f8d5963", + "shasum": "" + }, + "require": { + "php": ">=7.4.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Container\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "https://www.php-fig.org/" + } + ], + "description": "Common Container Interface (PHP FIG PSR-11)", + "homepage": "https://github.com/php-fig/container", + "keywords": [ + "PSR-11", + "container", + "container-interface", + "container-interop", + "psr" + ], + "support": { + "issues": "https://github.com/php-fig/container/issues", + "source": "https://github.com/php-fig/container/tree/2.0.2" + }, + "time": "2021-11-05T16:47:00+00:00" } ], "packages-dev": [ diff --git a/elasticpress.php b/elasticpress.php index 8ea0af3380..9a3bd39874 100644 --- a/elasticpress.php +++ b/elasticpress.php @@ -29,6 +29,11 @@ exit; // Exit if accessed directly. } +// Require Composer autoloader if it exists. +if ( file_exists( __DIR__ . '/vendor/autoload.php' ) ) { + require_once __DIR__ . '/vendor/autoload.php'; +} + define( 'EP_URL', plugin_dir_url( __FILE__ ) ); define( 'EP_PATH', plugin_dir_path( __FILE__ ) ); define( 'EP_FILE', plugin_basename( __FILE__ ) ); diff --git a/includes/classes/Container.php b/includes/classes/Container.php index 8bb34b7b55..b324d95ca4 100644 --- a/includes/classes/Container.php +++ b/includes/classes/Container.php @@ -9,12 +9,13 @@ namespace ElasticPress; +use \Psr\Container\ContainerInterface; +use \Psr\Container\NotFoundExceptionInterface; + /** - * (semi-)PSR11 compliant container class - * - * Although type hinting will work, we do not implement the interfaces yet. + * PSR11 compliant container class */ -final class Container { +final class Container implements ContainerInterface { /** * Hold all instances * @@ -27,13 +28,13 @@ final class Container { * * @param string $id Identifier of the entry to look for. * - * @throws \Exception No entry was found for **this** identifier. + * @throws NotFoundExceptionInterface No entry was found for **this** identifier. * * @return mixed Entry. */ public function get( string $id ) { if ( ! isset( $this->instances[ $id ] ) ) { - throw new \Exception( 'Class not found' ); + throw new NotFoundExceptionInterface( 'Class not found' ); } return $this->instances[ $id ];