Skip to content

Commit

Permalink
Merge pull request #433 from stellarwp/bugfix/563052/container-not-fo…
Browse files Browse the repository at this point in the history
…und-exception

Bugfix: container not found exception
  • Loading branch information
kadencewp authored Feb 16, 2024
2 parents 6da3833 + 014f9f5 commit 5a32db3
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 26 deletions.
2 changes: 1 addition & 1 deletion composer.lock

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

4 changes: 4 additions & 0 deletions includes/resources/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
namespace KadenceWP\KadenceBlocks;

use InvalidArgumentException;
use KadenceWP\KadenceBlocks\Adbar\Dot;
use KadenceWP\KadenceBlocks\Cache\Cache_Provider;
use KadenceWP\KadenceBlocks\Image_Downloader\Image_Downloader_Provider;
use KadenceWP\KadenceBlocks\Shutdown\Shutdown_Provider;
use KadenceWP\KadenceBlocks\StellarWP\ContainerContract\ContainerInterface;
use KadenceWP\KadenceBlocks\StellarWP\ProphecyMonorepo\Container\Contracts\Container;
use KadenceWP\KadenceBlocks\StellarWP\ProphecyMonorepo\Container\Contracts\Providable;
use KadenceWP\KadenceBlocks\Uplink\Uplink_Provider;
Expand Down Expand Up @@ -69,6 +71,8 @@ public function container(): Container {

private function init(): void {
$this->container->bind( Container::class, $this->container );
$this->container->bind( ContainerInterface::class, $this->container );
$this->container->singleton( Dot::class, new Dot() );

foreach ( $this->providers as $provider ) {
$this->container->register( $provider );
Expand Down
8 changes: 2 additions & 6 deletions includes/resources/Cache/Cache_Provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ private function register_block_library_storage(): void {

$this->container->when( Block_Library_Cache::class )
->needs( Storage::class )
->give( static function ( $c ) use ( $path ) {
return new LocalStorage( $c->get( Filesystem::class ), $path );
} );
->give( new LocalStorage( $this->container->get( Filesystem::class ), $path ) );

$this->container->singleton( Block_Library_Cache::class, Block_Library_Cache::class );
}
Expand All @@ -41,9 +39,7 @@ private function register_ai_storage(): void {

$this->container->when( Ai_Cache::class )
->needs( Storage::class )
->give( static function ( $c ) use ( $path ) {
return new LocalStorage( $c->get( Filesystem::class ), $path );
} );
->give( new LocalStorage( $this->container->get( Filesystem::class ), $path ) );

$this->container->singleton( Ai_Cache::class, Ai_Cache::class );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ private function register_logging(): void {
->needs( '$level' )
->give( LogLevel::fromName( $log_level ) );

$this->container->bind( LoggerInterface::class, static function ( $c ) {
$this->container->bind( LoggerInterface::class, function () {
$logger = new Logger( 'kadence' );
$handler = $c->get( ErrorLogHandler::class );
$handler->setFormatter( $c->get( ColoredLineFormatter::class ) );
$handler = $this->container->get( ErrorLogHandler::class );
$handler->setFormatter( $this->container->get( ColoredLineFormatter::class ) );
$logger->pushHandler( $handler );

return $logger;
Expand Down
14 changes: 6 additions & 8 deletions includes/resources/Shutdown/Shutdown_Provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,13 @@ final class Shutdown_Provider extends Provider {
public function register(): void {
$this->container->when( Shutdown_Collection::class )
->needs( '$tasks' )
->give( static function ( $c ): array {
->give( [
// Add any terminable tasks to the collection to run on shutdown.
// Important: these will run in the order provided!
return [
$c->get( Cache_Primer::class ),
$c->get( Block_Library_Cache::class ),
$c->get( Ai_Cache::class ),
];
} );
// Important: these will run in the order provided.
$this->container->get( Cache_Primer::class ),
$this->container->get( Block_Library_Cache::class ),
$this->container->get( Ai_Cache::class ),
] );

add_action( 'shutdown', $this->container->callback( Shutdown_Handler::class, 'handle' ), 1 );
}
Expand Down
16 changes: 8 additions & 8 deletions kadence-blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,26 @@
use KadenceWP\KadenceBlocks\StellarWP\ProphecyMonorepo\Container\ContainerAdapter;
use KadenceWP\KadenceBlocks\StellarWP\Telemetry\Config;
use KadenceWP\KadenceBlocks\StellarWP\Telemetry\Core as Telemetry;
use KadenceWP\KadenceBlocks\Container;
use KadenceWP\KadenceBlocks\StellarWP\Uplink\Config as UplinkConfig;
use KadenceWP\KadenceBlocks\StellarWP\Uplink\Uplink;
use KadenceWP\KadenceBlocks\StellarWP\Uplink\Register;
use KadenceWP\KadenceBlocks\StellarWP\Uplink\Uplink;

/**
* Add a check before redirecting
*/
function kadence_blocks_activate() {
function kadence_blocks_activate(): void {
add_option( 'kadence_blocks_redirect_on_activation', true );
}
register_activation_hook( __FILE__, 'kadence_blocks_activate' );

/**
* Load Plugin
*/
function kadence_blocks_init() {
$container = new Container();
function kadence_blocks_init(): void {
$container = new ContainerAdapter( new \KadenceWP\KadenceBlocks\lucatume\DI52\Container() );

// The Kadence Blocks Application.
App::instance( new ContainerAdapter( $container->container() ) );
App::instance( $container );

require_once KADENCE_BLOCKS_PATH . 'includes/init.php';
require_once KADENCE_BLOCKS_PATH . 'includes/form-ajax.php';
Expand Down Expand Up @@ -146,7 +146,7 @@ function kadence_blocks_init() {
add_filter( 'stellarwp/uplink/kadence-blocks/prevent_update_check', '__return_true' );
add_filter(
'stellarwp/uplink/kadence-blocks/api_get_base_url',
static function() {
static function () {
return 'https://licensing.kadencewp.com';
},
10,
Expand All @@ -158,7 +158,7 @@ static function() {
/**
* Load the plugin textdomain
*/
function kadence_blocks_lang() {
function kadence_blocks_lang(): void {
load_plugin_textdomain( 'kadence-blocks', false, basename( dirname( __FILE__ ) ) . '/languages' );
}
add_action( 'init', 'kadence_blocks_lang' );

0 comments on commit 5a32db3

Please sign in to comment.