Download the PHP package degraciamathieu/manager without Composer
On this page you can find all versions of the php package degraciamathieu/manager. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download degraciamathieu/manager
More information about degraciamathieu/manager
Files in degraciamathieu/manager
Package manager
Short Description Implementation of the Manager pattern existing in Laravel framework.
License MIT
Homepage https://github.com/degraciamathieu/manager
Informations about the package manager
DeGraciaMathieu/Manager
Implementation of the Manager pattern existing in Laravel framework.
- Installation
- Usage
- Work with singleton
- Example with Laravel
Installation
Manager | 3.* | 2.* | 1.* |
---|---|---|---|
php ^8.1 | :white_check_mark: | :x: | :x: |
php 8.0.* | :white_check_mark: | :white_check_mark: | :x: |
php 7.* | :x: | :x: | :white_check_mark: |
Usage
This package offers an abstract class DeGraciaMathieu\Manager\Manager
which needs to be extended to implement the creation of various Driver classes :
A driver is a class integrating all the logic of an implementation, in our examples the interactions with the APIs of Openweathermap :
From now on, you can directly call the method of a driver directly from the manager :
The manager will call the itsRainingNow
method of the default driver configured by the getDefaultDriver
method.
You can also call any driver from the manager's driver
method :
Now if you want to create a new implementation, for example if you want to use Aerisweather APIs, you just have to create a new driver in your manager :
Tip, the
getDefaultDriver
method is the perfect place to use a configuration or environment variable !
Add an interface to the drivers
For more consistency it is advisable to implement an interface to the different drivers :
You obviously need to add this interface to your drivers.
Now you will be assured that each driver instantiated by the manager will have the same interface.
Repository class
To control side effects of drivers, it is advisable to create a class encapsulating the instance of a driver, this class is usually called Repository
:
The repository is a class providing a bridge between your application and the driver :
This repository class is an anti-corruption layer
Thus, your application will never be aware of which driver it is handling, because it will always be encapsulated in a class repository.
The repository is also a good place if you need to add specific logic for all drivers.
Work with singleton
You can also cache the creation of Drivers with the $singleton
property.
With the singleton
property you will only create one instance of Openweathermap
driver :
by default, singleton property value is False
Example with Laravel
Usage example of the pattern manager in a Laravel project.