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
Laravel News Partners

Laravel Jobs

Backend Software Engineer (PHP Developer)
Austin TX, Bonita Springs FL
Certified eSupport Corp
Laravel Developer
Glendale, CA (COVID Remote)
Jogg, Inc
Full-Stack Engineer (Mid to Senior)
Remote (EST, CST)
Voxie
Senior Laravel Developer (AI Applications)
Remote from anywhere in the UK or from our London office
GreenShoot Labs
Full Stack Engineer
Remote
Shelterluv

Newsletter

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