Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closes #6550 Delegate creation of the dependencies to the container #7215

Open
wants to merge 49 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
1c52650
update service providers
remyperona Dec 3, 2024
a242a2d
Merge branch 'develop' into chore/6550-container-dependencies-creation
remyperona Jan 6, 2025
061b87e
update classes instantiation
remyperona Jan 6, 2025
dec5443
fix naming
remyperona Jan 10, 2025
248b3f2
revert alias removal
remyperona Jan 10, 2025
6b5153f
update some classes instantiation
remyperona Jan 10, 2025
aa8abdc
revert alias removal
remyperona Jan 10, 2025
6ba6c46
revert alias removals
remyperona Jan 10, 2025
36db2b6
fix code styling
remyperona Jan 10, 2025
a23f89e
use StringArgument
remyperona Jan 10, 2025
2aba49a
update arguments declaration
remyperona Jan 10, 2025
be485f3
update arguments declaration
remyperona Jan 10, 2025
757ea89
update arguments declaration
remyperona Jan 10, 2025
a56f3cc
update arguments declaration
remyperona Jan 10, 2025
e918bcc
update arguments declaration
remyperona Jan 10, 2025
a3d6ad2
update arguments declaration
remyperona Jan 10, 2025
626c9cb
update arguments declaration
remyperona Jan 10, 2025
bd0b31d
update arguments declaration
remyperona Jan 10, 2025
8dc2191
update arguments declaration
remyperona Jan 10, 2025
1b8a48a
add strict type
remyperona Jan 10, 2025
f0fc598
add strict type
remyperona Jan 10, 2025
5d00660
update arguments declaration
remyperona Jan 10, 2025
9efa3b5
update arguments declaration
remyperona Jan 10, 2025
b926b0f
update arguments declaration
remyperona Jan 10, 2025
db08cbb
update arguments declaration
remyperona Jan 10, 2025
f6e1a24
update arguments declaration and fix naming
remyperona Jan 10, 2025
d29739b
update arguments declaration
remyperona Jan 10, 2025
5a33b58
use StringArgument
remyperona Jan 10, 2025
7f92ac9
update arguments declaration
remyperona Jan 10, 2025
1a08616
update arguments declaration
remyperona Jan 10, 2025
3aff24e
update arguments declaration
remyperona Jan 10, 2025
09f681c
update arguments declaration
remyperona Jan 10, 2025
301cb14
update arguments declaration
remyperona Jan 10, 2025
81f2a05
update arguments declaration
remyperona Jan 10, 2025
37fe62c
update arguments declaration
remyperona Jan 10, 2025
4cf6ba4
update arguments declaration
remyperona Jan 10, 2025
426305b
update arguments declaration
remyperona Jan 10, 2025
7a0ee66
update arguments declaration
remyperona Jan 10, 2025
8c67993
update arguments declaration
remyperona Jan 10, 2025
bf22782
update arguments declaration
remyperona Jan 10, 2025
d5bed5a
update arguments declaration
remyperona Jan 10, 2025
31325ed
update arguments declaration
remyperona Jan 10, 2025
03660b0
update arguments declaration
remyperona Jan 10, 2025
df5e179
update arguments declaration
remyperona Jan 10, 2025
8899342
update arguments declaration
remyperona Jan 10, 2025
4badbe0
update arguments declaration
remyperona Jan 10, 2025
4e075f8
Merge branch 'develop' into chore/6550-container-dependencies-creation
remyperona Jan 10, 2025
0bb6273
fix code styling
remyperona Jan 10, 2025
70550c2
Merge branch 'develop' into chore/6550-container-dependencies-creation
remyperona Jan 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 19 additions & 15 deletions inc/Addon/Cloudflare/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class ServiceProvider extends AbstractServiceProvider {
* @var array
*/
protected $provides = [
'cloudflare_api_key_factory',
'cloudflare_client',
'cloudflare_endpoints',
'cloudflare',
Expand All @@ -42,26 +43,29 @@ public function provides( string $id ): bool {
* Registers items with the container
*/
public function register(): void {
$options = $this->getContainer()->get( 'options' );

$this->getContainer()->add( 'cloudflare_auth_factory', APIKeyFactory::class )->addArgument( $options );
$this->getContainer()->add( 'cloudflare_api_key_factory', APIKeyFactory::class )->addArgument( 'options' );

$this->getContainer()->add( 'cloudflare_client', Client::class )
->addArgument( $this->getContainer()->get( 'cloudflare_auth_factory' )->create() );
->addArgument( $this->getContainer()->get( 'cloudflare_api_key_factory' )->create() );
$this->getContainer()->add( 'cloudflare_endpoints', Endpoints::class )
->addArgument( $this->getContainer()->get( 'cloudflare_client' ) );
->addArgument( 'cloudflare_client' );

$this->getContainer()->add( 'cloudflare', Cloudflare::class )
->addArgument( $options )
->addArgument( $this->getContainer()->get( 'cloudflare_endpoints' ) );
->addArguments(
[
'options',
'cloudflare_endpoints',
]
);
$this->getContainer()->addShared( 'cloudflare_subscriber', CloudflareSubscriber::class )
->addArgument( $this->getContainer()->get( 'cloudflare' ) )
->addArgument( $options )
->addArgument( $this->getContainer()->get( 'options_api' ) )
->addArgument( $this->getContainer()->get( 'cloudflare_auth_factory' ) );
$this->getContainer()->addShared(
'cloudflare_admin_subscriber',
CloudflareAdminSubscriber::class
);
->addArguments(
[
'cloudflare',
'options',
'options_api',
'cloudflare_api_key_factory',
]
);
$this->getContainer()->addShared( 'cloudflare_admin_subscriber', CloudflareAdminSubscriber::class );
}
}
27 changes: 17 additions & 10 deletions inc/Addon/ServiceProvider.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);

namespace WP_Rocket\Addon;

use WP_Rocket\Addon\Sucuri\Subscriber as SucuriSubscriber;
Expand Down Expand Up @@ -36,20 +38,25 @@ public function provides( string $id ): bool {
* Registers items with the container
*/
public function register(): void {
$options = $this->getContainer()->get( 'options' );

// Sucuri Addon.
$this->getContainer()->addShared( 'sucuri_subscriber', SucuriSubscriber::class )
->addArgument( $options );
->addArgument( 'options' );

$this->getContainer()->addShared( 'webp_admin_subscriber', WebPAdminSubscriber::class )
->addArgument( $options )
->addArgument( $this->getContainer()->get( 'cdn_subscriber' ) )
->addArgument( $this->getContainer()->get( 'beacon' ) );
->addArguments(
[
'options',
'cdn_subscriber',
'beacon',
]
);

$this->getContainer()->addShared( 'webp_subscriber', WebPSubscriber::class )
->addArgument( $options )
->addArgument( $this->getContainer()->get( 'options_api' ) )
->addArgument( $this->getContainer()->get( 'cdn_subscriber' ) );
->addArguments(
[
'options',
'options_api',
'cdn_subscriber',
]
);
}
}
10 changes: 8 additions & 2 deletions inc/Addon/Varnish/ServiceProvider.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);

namespace WP_Rocket\Addon\Varnish;

use WP_Rocket\Dependencies\League\Container\ServiceProvider\AbstractServiceProvider;
Expand Down Expand Up @@ -36,7 +38,11 @@ public function provides( string $id ): bool {
public function register(): void {
$this->getContainer()->add( 'varnish', Varnish::class );
$this->getContainer()->addShared( 'varnish_subscriber', Subscriber::class )
->addArgument( $this->getContainer()->get( 'varnish' ) )
->addArgument( $this->getContainer()->get( 'options' ) );
->addArguments(
[
'varnish',
'options',
]
);
}
}
3 changes: 2 additions & 1 deletion inc/Engine/Activation/Activation.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace WP_Rocket\Engine\Activation;

use WP_Rocket\Admin\Options;
use WP_Rocket\Dependencies\League\Container\Argument\Literal\StringArgument;
use WP_Rocket\Dependencies\League\Container\Container;
use WP_Rocket\Engine\Common\PerformanceHints\Activation\ServiceProvider as PerformanceHintsActivationServiceProvider;
use WP_Rocket\Engine\License\ServiceProvider as LicenseServiceProvider;
Expand Down Expand Up @@ -44,7 +45,7 @@ public static function activate_plugin() {
$container = new Container();
$event_manager = new Event_Manager();

$container->add( 'template_path', WP_ROCKET_PATH . 'views' );
$container->add( 'template_path', new StringArgument( rocket_get_constant( 'WP_ROCKET_PATH', '' ) . 'views' ) );
$options_api = new Options( 'wp_rocket_' );
$container->add( 'options_api', $options_api );
$container->addServiceProvider( new OptionsServiceProvider() );
Expand Down
11 changes: 9 additions & 2 deletions inc/Engine/Activation/ServiceProvider.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<?php
declare(strict_types=1);

namespace WP_Rocket\Engine\Activation;

use WP_Rocket\Dependencies\League\Container\Argument\Literal\StringArgument;
use WP_Rocket\Dependencies\League\Container\ServiceProvider\AbstractServiceProvider;
use WP_Rocket\Dependencies\League\Container\ServiceProvider\BootableServiceProviderInterface;
use WP_Rocket\Engine\Cache\AdvancedCache;
Expand Down Expand Up @@ -53,8 +56,12 @@ public function register(): void {
$filesystem = rocket_direct_filesystem();

$this->getContainer()->add( 'advanced_cache', AdvancedCache::class )
->addArgument( $this->getContainer()->get( 'template_path' ) . '/cache/' )
->addArgument( $filesystem );
->addArguments(
[
new StringArgument( $this->getContainer()->get( 'template_path' ) . '/cache/' ),
$filesystem,
]
);
$this->getContainer()->add( 'capabilities_manager', Manager::class );
$this->getContainer()->add( 'wp_cache', WPCache::class )
->addArgument( $filesystem );
Expand Down
1 change: 1 addition & 0 deletions inc/Engine/Admin/API/ServiceProvider.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

namespace WP_Rocket\Engine\Admin\API;

Expand Down
13 changes: 10 additions & 3 deletions inc/Engine/Admin/Beacon/ServiceProvider.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<?php
declare(strict_types=1);

namespace WP_Rocket\Engine\Admin\Beacon;

use WP_Rocket\Dependencies\League\Container\Argument\Literal\StringArgument;
use WP_Rocket\Dependencies\League\Container\ServiceProvider\AbstractServiceProvider;

/**
Expand Down Expand Up @@ -34,8 +37,12 @@ public function provides( string $id ): bool {
*/
public function register(): void {
$this->getContainer()->addShared( 'beacon', Beacon::class )
->addArgument( $this->getContainer()->get( 'options' ) )
->addArgument( $this->getContainer()->get( 'template_path' ) . '/settings' )
->addArgument( $this->getContainer()->get( 'support_data' ) );
->addArguments(
[
'options',
new StringArgument( $this->getContainer()->get( 'template_path' ) . '/settings' ),
'support_data',
]
);
}
}
13 changes: 10 additions & 3 deletions inc/Engine/Admin/Database/ServiceProvider.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<?php
declare(strict_types=1);

namespace WP_Rocket\Engine\Admin\Database;

use WP_Rocket\Admin\Options_Data;
use WP_Rocket\Dependencies\League\Container\ServiceProvider\AbstractServiceProvider;

/**
Expand Down Expand Up @@ -37,9 +40,13 @@ public function provides( string $id ): bool {
public function register(): void {
$this->getContainer()->add( 'db_optimization_process', OptimizationProcess::class );
$this->getContainer()->add( 'db_optimization', Optimization::class )
->addArgument( $this->getContainer()->get( 'db_optimization_process' ) );
->addArgument( 'db_optimization_process' );
$this->getContainer()->addShared( 'db_optimization_subscriber', Subscriber::class )
->addArgument( $this->getContainer()->get( 'db_optimization' ) )
->addArgument( $this->getContainer()->get( 'options' ) );
->addArguments(
[
'db_optimization',
'options',
]
);
}
}
12 changes: 9 additions & 3 deletions inc/Engine/Admin/DomainChange/ServiceProvider.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?php
declare(strict_types=1);

namespace WP_Rocket\Engine\Admin\DomainChange;

use WP_Rocket\Dependencies\League\Container\ServiceProvider\AbstractServiceProvider;

use WP_Rocket\Engine\Common\Ajax\AjaxHandler;

class ServiceProvider extends AbstractServiceProvider {
Expand Down Expand Up @@ -34,8 +36,12 @@ public function provides( string $id ): bool {
*/
public function register(): void {
$this->getContainer()->add( 'ajax_handler', AjaxHandler::class );
$this->getContainer()->add( 'domain_change_subscriber', Subscriber::class )
->addArgument( $this->getContainer()->get( 'ajax_handler' ) )
->addArgument( $this->getContainer()->get( 'beacon' ) );
$this->getContainer()->addShared( 'domain_change_subscriber', Subscriber::class )
->addArguments(
[
'ajax_handler',
'beacon',
]
);
}
}
25 changes: 17 additions & 8 deletions inc/Engine/Admin/ServiceProvider.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<?php
declare(strict_types=1);

namespace WP_Rocket\Engine\Admin;

use WP_Rocket\Dependencies\League\Container\ServiceProvider\AbstractServiceProvider;
use WP_Rocket\Dependencies\League\Container\Argument\Literal\StringArgument;
use WP_Rocket\Engine\Admin\Deactivation\{DeactivationIntent, Subscriber};
use WP_Rocket\Engine\Admin\Metaboxes\PostEditOptionsSubscriber;
use WP_Rocket\ThirdParty\Plugins\Optimization\Hummingbird;
Expand Down Expand Up @@ -40,19 +43,25 @@ public function provides( string $id ): bool {
* @return void
*/
public function register(): void {
$options = $this->getContainer()->get( 'options' );

$this->getContainer()->add( 'deactivation_intent', DeactivationIntent::class )
->addArgument( $this->getContainer()->get( 'template_path' ) . '/deactivation-intent' )
->addArgument( $this->getContainer()->get( 'options_api' ) )
->addArgument( $options );
->addArguments(
[
new StringArgument( $this->getContainer()->get( 'template_path' ) . '/deactivation-intent' ),
'options_api',
'options',
]
);
$this->getContainer()->addShared( 'deactivation_intent_subscriber', Subscriber::class )
->addArgument( $this->getContainer()->get( 'deactivation_intent' ) );
$this->getContainer()->addShared( 'hummingbird_subscriber', Hummingbird::class )
->addArgument( $options );
->addArgument( 'options' );
$this->getContainer()->addShared( 'actionscheduler_admin_subscriber', ActionSchedulerSubscriber::class );
$this->getContainer()->addShared( 'post_edit_options_subscriber', PostEditOptionsSubscriber::class )
->addArgument( $options )
->addArgument( $this->getContainer()->get( 'template_path' ) . '/metaboxes' );
->addArguments(
[
'options',
new StringArgument( $this->getContainer()->get( 'template_path' ) . '/metaboxes' ),
]
);
}
}
39 changes: 27 additions & 12 deletions inc/Engine/Admin/Settings/ServiceProvider.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<?php
declare(strict_types=1);

namespace WP_Rocket\Engine\Admin\Settings;

use WP_Rocket\Dependencies\League\Container\Argument\Literal\{ArrayArgument, StringArgument};
use WP_Rocket\Dependencies\League\Container\ServiceProvider\AbstractServiceProvider;
use WP_Rocket\Dependencies\WPMedia\PluginFamily\Model\PluginFamily as PluginFamilyModel;
use WP_Rocket\Dependencies\WPMedia\PluginFamily\Controller\PluginFamily as PluginFamilyController;
Expand All @@ -15,6 +18,8 @@ class ServiceProvider extends AbstractServiceProvider {
* @var array
*/
protected $provides = [
'plugin_family_model',
'plugin_family_controller',
'settings',
'settings_render',
'settings_page',
Expand Down Expand Up @@ -42,28 +47,38 @@ public function register(): void {
$this->getContainer()->add( 'plugin_family_controller', PluginFamilyController::class );

$this->getContainer()->add( 'settings', Settings::class )
->addArgument( $this->getContainer()->get( 'options' ) );
->addArgument( 'options' );
$this->getContainer()->add( 'settings_render', Render::class )
->addArguments(
[
$this->getContainer()->get( 'template_path' ) . '/settings',
new StringArgument( $this->getContainer()->get( 'template_path' ) . '/settings' ),
'plugin_family_model',
]
);
$this->getContainer()->add( 'settings_page', Page::class )
->addArgument( $this->getContainer()->get( 'settings_page_config' ) )
->addArgument( $this->getContainer()->get( 'settings' ) )
->addArgument( $this->getContainer()->get( 'settings_render' ) )
->addArgument( $this->getContainer()->get( 'beacon' ) )
->addArgument( $this->getContainer()->get( 'db_optimization' ) )
->addArgument( $this->getContainer()->get( 'user_client' ) )
->addArgument( $this->getContainer()->get( 'delay_js_sitelist' ) )
->addArgument( $this->getContainer()->get( 'template_path' ) )
->addArgument( $this->getContainer()->get( 'options' ) );
->addArguments(
[
new ArrayArgument(
[
'slug' => WP_ROCKET_PLUGIN_SLUG,
'title' => WP_ROCKET_PLUGIN_NAME,
'capability' => 'rocket_manage_options',
]
),
'settings',
'settings_render',
'beacon',
'db_optimization',
'user_client',
'delay_js_sitelist',
'template_path',
'options',
]
);
$this->getContainer()->addShared( 'settings_page_subscriber', Subscriber::class )
->addArguments(
[
$this->getContainer()->get( 'settings_page' ),
'settings_page',
'plugin_family_controller',
]
);
Expand Down
Loading
Loading