Launchpad
Launchpad
Launchpad
  • Introduction
  • General
    • Installation
    • Creating a subscriber
    • Contributing
  • Tutorials
    • Beginner documentation
      • Beginner handbook
        • Creating subscribers
        • Wiring subscribers
        • Installing local environment
        • Adding front-end
        • Building the plugin
      • Plugin life circle
        • Activation
        • Deactivation
        • Uninstall
    • Starting with the framework
    • Migrating to Launchpad
    • Notions
      • Framework concepts
        • Inversion of control
        • Subscribers
        • Dispatcher
      • Good practices
        • Hooks
          • Preventing magic constants
          • Decouple features
          • Sanitize filters output
      • Testing
        • Organize tests
  • CLI
    • Commands
    • Creating a command
  • Testing
    • Unit test
    • Fixtures
    • Integration test
  • Container
    • Architecture
    • Parameters
    • Providers
    • Auto wiring
    • Manual wiring
    • Activation/Deactivation
    • Inflectors
  • Modules
    • Definition
    • Listing
      • Action Scheduler
      • BerlinDB
      • Bus
      • Options
      • Renderer
      • Logger
      • Uninstaller
      • Filesystem
      • Front-end
      • Hook extractor
    • Creating a module
Powered by GitBook
On this page
  • Wiring classes
  • Registering subscribers
  1. Container

Manual wiring

Wiring classes

With the manual strategy you have to indicate the application what is the dependency tree between classes.

For that you will have to implement the define method.

To register a class you will have to use the method register_service.

This method only takes the name of the class as parameter when the class has no dependencies.

However, when the instantiation is more complex it takes a method as second parameters that pass as parameter the definition of the class.

Inside that function you can use the container to get dependencies and pass them to the class as following:

class Provider extends AbstractServiceProvider {
   public function define() {
    $this->register_service(MyClass::class, function($defintion) {
     $definition->addArgument($this->getContainer()->get(MyDependency::class));
    });
   }
}

Registering subscribers

With Launchpad default behavior we have 4 subscriber types:

  • Common subscribers: Subscribers that load on any context.

  • Administrative subscribers: Subscribers that load only when the admin dashboard is loaded.

  • Front-end subscribers: Subscribers that load only on pages visible by regular users.

  • Initialisation subscribers: Subscribers loading before other to modify the loading logic.

To define the type from we need to register subscribers in the method matching the right type:

Type
Method

common

get_common_subscribers

admin

get_admin_subscribers

front

get_front_subscribers

init

get_init_subscribers

PreviousAuto wiringNextActivation/Deactivation

Last updated 5 months ago