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:
1use DeGraciaMathieu/Manager/Manager; 2 3class LoggerManager extends Manager { 4 5 public function createMonologDriver(): LoggerDriver 6 { 7 return new MonologDriver(); 8 } 9 10 public function createMockDriver(): LoggerDriver11 {12 return new MockDriver();13 }14 15 public function getDefaultDriver()16 {17 return 'monolog';18 }19}
Here’s an example of how you can use the manager class to do anything the interface allows conveniently:
1(new LoggerManager())->doAnything();2 3// Or pick a driver4(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):
1public function getDefaultDriver()2{3 return config('some_package.default');4}
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