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

Senior Full-Time Laravel Developer (REMOTE)
Remote, ANYWHERE
Vue School
Senior Laravel Developer
Remote, USA & Canada Only
Givecloud
Backend Software Engineer
Remote, USA Only
CommentSold
Backend PHP Developer
Hamburg
ABOUT YOU GmbH
Senior Developer
Remote
Shelterluv

Newsletter

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