Manager Pattern Package for Laravel

Manager Pattern Package for Laravel

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.

Filed in: News / packages

Newsletter

Join 31,000+ others and never miss out on new tips, tutorials, and more.

Laravel News Partners

Laravel Jobs

Senior Full Stack PHP Developer (Laravel)
Remote
MAPPEN
Senior Laravel Developer
Remote
ACTO
Senior Full-Stack Engineer
[REMOTE: USA Only]
Curricula
Developers for B2B eCommerce SaaS, AWS serverless, Laravel, Vue, Python
Remote, full time EU only
ES Tech Group
Senior PHP Developer (Laravel)
Remote
The Interaction Design Foundation