dann95 / slim3-controller-strategy
Customize the way Slim3 loads controllers with your rules
Installs: 12
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:package
Requires
- slim/slim: ^3.0
This package is auto-updated.
Last update: 2024-10-20 04:22:46 UTC
README
This package will help you to change the way Slim 3 loads your project controllers, it’s a little boring to bind every each controller into Slim\Container to make it after behind scenes Slim determine the Controller and Method, with this package you can write your own rules to determine which controller and method that the router is looking for.
Installation
composer require dann95/slim3-controller-strategy
Usage
<?php require 'vendor/autoload.php'; // composer autoload use Dann95\SlimController\Contracts\ControllerSolver; class MyControllerSolver implements ControllerSolver { public function solve($toResolve) { // Here we have the code to find and make new instance of class (this is just an example, you must build your logic) $explode = explode("@", $toResolve); // You must return an array like: [$instanceOfController, $methodName]; $controller = new $explode[0]; // $explode[0] == TheControllerImLookingFor return [$controller, $explode[1]]; // $explode[1] == theMethodName } } $myControllerSolver = new MyControllerSolver; $container = new Dann95\SlimController\Container($myControllerSolver); $app = new Slim\App($container); $app->get('/', 'TheControllerImLookingFor@theMethodName'); $app->run();