Skip to content
This repository was archived by the owner on Dec 30, 2022. It is now read-only.

Added possibility to gather behaviors into plugins#6

Open
dropdevcoding wants to merge 1 commit intomasterfrom
feature/plugins
Open

Added possibility to gather behaviors into plugins#6
dropdevcoding wants to merge 1 commit intomasterfrom
feature/plugins

Conversation

@dropdevcoding
Copy link
Copy Markdown
Contributor

@dropdevcoding dropdevcoding commented Aug 11, 2016

With this feature you may implement your own plugins and attach them to Adrenaline. This feature is helpful when you want to define a set of middlewares which should work together although they use different hooks of adrenaline.

Simple example:

final class ActionExecutionTimeLoggerPlugin implements Plugin
{
    public function applyTo(Adrenaline $adrenaline) 
    {
        $adrenaline->beforeExecuteAction(function (ServerRequestInterface $request, ResponseInterface $response, callable $next = null)  {
            $request = $request->withAttribute(self::class, time()); 
            if ($next) {
                $response = $next($request, $response);
            }
            return $response;
        });

        $adrenaline->beforeResolveResponder(function (ServerRequestInterface $request, ResponseInterface $response, callable $next = null) use ($start) {
            $duration = time() - $request->getAttribute(self::class);
            // log the execution time
            if ($next) {
                $response = $next($request, $response);
            }
            return $response;
        });
    }
}

$adrenaline->attach(new ActionExecutionTimeLoggerPlugin());

Sure, this example is a very simple one but it demonstrates how cross-middleware functionalities may be bundled when one of the middlewares wouldn't make any sense standalone.

@shochdoerfer
Copy link
Copy Markdown
Member

I like the idea and would love to see a way to configure routes in the plugin as well. That way we could plugins for a slice/module/bundle etc - no need for configuration via DI (or other means) any more.

Still undecided if I like the name plugin or not. Will think about it.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants