The DeGraciaMathieu/Manager package is an implementation of the Manager pattern for the Laravel framework. The job of this package is to make it convenient to create various implementations that adhere to an interface and a manager class to resolve them:
use DeGraciaMathieu/Manager/Manager;
class LoggerManager extends Manager {
public function createMonologDriver(): LoggerDriver
{
return new MonologDriver();
}
public function createMockDriver(): LoggerDriver
{
return new MockDriver();
}
public function getDefaultDriver()
{
return 'monolog';
}
}
Here’s an example of how you can use the manager class to do anything the interface allows conveniently:
(new LoggerManager())->doAnything();
// Or pick a driver
(new LoggerManager())->driver('monolog')->doAnything();
Imagine that you wanted to allow consumers to define a default implementation (similar to things like the DatabaseManager in Laravel):
public function getDefaultDriver()
{
return config('some_package.default');
}
To learn more about the package, the author provides a manager-examples GitHub repo. Check out this package on GitHub at DeGraciaMathieu/Manager.
0 comments:
Post a Comment
Thanks