Skip to content

Commit

Permalink
Properly load the plugin using strauss and with a container
Browse files Browse the repository at this point in the history
  • Loading branch information
bordoni committed Apr 20, 2024
1 parent ade7cf5 commit a809e7f
Show file tree
Hide file tree
Showing 11 changed files with 148 additions and 98 deletions.
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"prefer-stable": true,
"autoload": {
"files": [
"src/functions/load.php",
"src/functions/container.php",
"src/functions/date.php",
"src/functions/variables.php",
Expand All @@ -40,7 +39,7 @@
},
"scripts": {
"strauss": [
"test -f ./bin/strauss.phar || mkdir -p ./bin/ && curl -o bin/strauss.phar -L -C - https://github.com/BrianHenryIE/strauss/releases/download/0.14.0/strauss.phar",
"test -f ./bin/strauss.phar || mkdir -p ./bin/ && curl -o bin/strauss.phar -L -C - https://github.com/BrianHenryIE/strauss/releases/download/0.17.0/strauss.phar",
"@php -d display_errors=on bin/strauss.phar"
],
"post-install-cmd": [
Expand Down
9 changes: 2 additions & 7 deletions fakerpress.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,7 @@
deactivate_plugins( __FP_FILE__ );
}
} else {
// Load Composer Vendor Modules
require_once plugin_dir_path( __FP_FILE__ ) . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';

// Load Composer Vendor Modules
require_once plugin_dir_path( __FP_FILE__ ) . 'vendor-prefixed' . DIRECTORY_SEPARATOR . 'autoload.php';

require_once dirname( __FP_FILE__ ) . '/src/functions/load.php';
// Add a second action to handle the case where Common is not loaded, we still want to let the user know what is happening.
add_action( 'plugins_loaded', '\FakerPress\load_plugin', 50 );
add_action( 'plugins_loaded', 'fakerpress_load_plugin', 50 );
}
5 changes: 3 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Contributors: bordoni
Tags: generator, dummy content, dummy data, lorem ipsun, admin, exemples, testing, images, attachments, featured image, taxonomies, users, post type, faker, fake data, random, developer, dev, development, test, tests
Requires at least: 5.5
Tested up to: 6.2
Tested up to: 6.5.2
Requires PHP: 7.4
Stable tag: 0.6.2
License: GPLv2 or later
Expand Down Expand Up @@ -99,9 +99,10 @@ Thank you for wanting to make FakerPress better for everyone! [We salute you](ht

== Changelog ==

= 0.6.2 — 10 of July 2023 =
= 0.6.2 — 22 of April 2024 =

* Version - Updated composer dependency `fakerphp/faker` to version `1.23`.
* Tweak - Include properly use Composer for autoloading and dependencies without conflicting with other plugins.
* Tweak - Include `lucatume/di52` and `nesbot/carbon` Strauss dependencies, which prevents conflicts with other plugins.
* Fix - Prevent namespace problems with nonexistent classes, specially around Exceptions.
* Fix - Resolve a problem with Numbers Meta throwing errors on PHP 8.0+ [#168]
Expand Down
2 changes: 2 additions & 0 deletions src/FakerPress/Assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
class Assets extends Service_Provider {

public function register() {
singleton( static::class, $this );

$admin = make( Admin::class );

// Register a global CSS files
Expand Down
24 changes: 23 additions & 1 deletion src/FakerPress/Contracts/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,17 @@
use FakerPress\ThirdParty\lucatume\DI52\Container as DI52_Container;

class Container extends DI52_Container {
/**
* @since 0.6.2
*
* @var Container
*/
protected static Container $instance;

/**
* Finds an entry of the container by its identifier and returns it.
*
* @since TBD
* @since 0.6.2
*
* @throws Not_Bound_Exception Error while retrieving the entry.
*
Expand All @@ -26,4 +33,19 @@ public function get( $id ) {
throw new Not_Bound_Exception( $e->getMessage(), $e->getCode() );
}
}

/**
* Creates the first instance of the container, it should be used for all the subsequent calls.
*
* @since 0.6.2
*
* @return Container
*/
public static function init(): self {
if ( empty( self::$instance ) ) {
self::$instance = new self;
}

return static::$instance;
}
}
4 changes: 2 additions & 2 deletions src/FakerPress/Fields/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace FakerPress\Fields;

use lucatume\DI52\ServiceProvider;
use FakerPress\Contracts\Service_Provider;
use function FakerPress\get;
use function FakerPress\make;

Expand All @@ -13,7 +13,7 @@
*
* @package FakerPress\Fields
*/
class Factory extends ServiceProvider {
class Factory extends Service_Provider {
protected $types = [];

/**
Expand Down
2 changes: 2 additions & 0 deletions src/FakerPress/Hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ class Hooks extends Service_Provider {
* @since 0.6.0
*/
public function register() {
singleton( static::class, $this );

$this->add_actions();
$this->add_filters();
}
Expand Down
4 changes: 2 additions & 2 deletions src/FakerPress/Module/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace FakerPress\Module;

use lucatume\DI52\ServiceProvider;
use FakerPress\Contracts\Service_Provider;

/**
* Class Factory
Expand All @@ -11,7 +11,7 @@
*
* @package FakerPress\Module
*/
class Factory extends ServiceProvider {
class Factory extends Service_Provider {
/**
* Store the modules that were initialized.
*
Expand Down
Loading

0 comments on commit a809e7f

Please sign in to comment.