1. Go to this page and download the library: Download degraciamathieu/manager library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
degraciamathieu / manager example snippets
namespace App\Managers;
use DeGraciaMathieu\Manager\Manager;
class WeatherManager extends Manager {
public function createOpenweathermapDriver()
{
return new Openweathermap();
}
public function getDefaultDriver(): string
{
return 'openweathermap';
}
}
namespace App\Managers;
class Openweathermap {
public function itsRainingNow(string $city): bool
{
// call Openweathermap api to know if it is raining in this city
return true;
}
}
(new WeatherManager())->itsRainingNow('Paris'); // true
(new WeatherManager())->driver('openweathermap')->itsRainingNow('Paris');
namespace App\Managers;
use DeGraciaMathieu\Manager\Manager;
class WeatherManager extends Manager {
public function createOpenweathermapDriver()
{
return new Openweathermap();
}
public function createAerisweatherDriver()
{
return new Aerisweather();
}
public function getDefaultDriver(): string
{
return 'openweathermap';
}
}
namespace App\Managers;
interface Driver {
public function itsRainingNow(string $city): bool;
}
namespace App\Managers;
use DeGraciaMathieu\Manager\Manager;
class WeatherManager extends Manager {
public function createOpenweathermapDriver(): Driver
{
return new Openweathermap();
}
public function createAerisweatherDriver(): Driver
{
return new Aerisweather();
}
public function getDefaultDriver(): string
{
return 'openweathermap';
}
}
namespace App\Managers;
use DeGraciaMathieu\Manager\Manager;
class WeatherManager extends Manager {
public function createOpenweathermapDriver(): Repository
{
$driver = new Openweathermap();
return new Repository($driver);
}
public function createAerisweatherDriver(): Repository
{
$driver = new Aerisweather();
return new Repository($driver);
}
public function getDefaultDriver(): string
{
return 'openweathermap';
}
}
namespace App\Managers;
class Repository {
public function __construct(
private Driver $driver,
){}
public function itsRainingNow(string $city): bool
{
return $this->driver->itsRainingNow($city);
}
}
$weatherManager = new WeatherManager(singleton: true);
$weatherManager->driver('openweathermap')->itsRainingNow('Paris');
$weatherManager->driver('openweathermap')->itsRainingNow('Paris');
$weatherManager->driver('openweathermap')->itsRainingNow('Paris');
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.