Skip to content

Application & Container ​

The Application class (WPSocialReviews\Framework\Foundation\Application, which extends Container) is the heart of the plugin. It is created once in boot/app.php and passed to every integration through the bootstrap hooks.

Booting ​

boot/app.php returns a closure that:

  1. Instantiates the Application with the main plugin file.
  2. Registers activation / deactivation handlers (ActivationHandler, DeactivationHandler).
  3. On plugins_loaded, checks the PHP version, then fires the bootstrap actions:
php
add_action('plugins_loaded', function () use ($app) {
    if (substr(phpversion(), 0, 3) == '7.0') {
        // admin notice: PHP 7.0 not supported
    } else {
        do_action('wp_social_reviews_loaded', $app);
        do_action('wp_social_reviews_loaded_v2', $app);
    }
});

Both wp_social_reviews_loaded and wp_social_reviews_loaded_v2 receive the $app container instance. Pro and integrations hook here to register their own services. Prefer wp_social_reviews_loaded_v2 for new code.

Resolving services ​

Because Application extends Container, you can bind and resolve services:

php
// Resolve a bound component
$router   = $app->router;      // Http\Router
$request  = $app->request;     // current request
$response = $app->response;    // response helper

// Or resolve by key
$app->make('some.binding');

Many core components are bound during bootstrapApplication() (paths, URLs, router, request/response, middleware stack). The container also resolves controllers and policies by their short names using the app-level namespaces configured on the Application.

The ready() callback ​

Use Application::ready() to defer work until WordPress init:

php
$app->ready(function ($app) {
    // runs on `init`, after the container is fully booted
});

Global accessor ​

Outside the container you can reach the app through the global helper wpsrSocialReviews() (defined in boot/globals.php). See Global Helpers.

WARNING

boot/globals.php loads before the framework, so helpers there must not call framework services. Use the bootstrap hooks or ready() for anything that needs the container.

WP Social Ninja Developer Documentation