Skip to content

Commit

Permalink
Bring in the Psr\Container package
Browse files Browse the repository at this point in the history
  • Loading branch information
felipeelia committed Jul 26, 2023
1 parent 2977f56 commit c43a017
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 9 deletions.
1 change: 0 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
/gulp-tasks export-ignore
/lang export-ignore
/tests export-ignore
/vendor/ export-ignore
/node_modules export-ignore

/.babelrc export-ignore
Expand Down
9 changes: 9 additions & 0 deletions .github/workflows/build-and-tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
55 changes: 54 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions elasticpress.php
Original file line number Diff line number Diff line change
Expand Up @@ -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__ ) );
Expand Down
13 changes: 7 additions & 6 deletions includes/classes/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -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 ];
Expand Down

0 comments on commit c43a017

Please sign in to comment.