2017 © Pedro Peláez
 

package slim3-controller-strategy

Customize the way Slim3 loads controllers with your rules

image

dann95/slim3-controller-strategy

Customize the way Slim3 loads controllers with your rules

  • Tuesday, June 20, 2017
  • by thusk
  • Repository
  • 1 Watchers
  • 0 Stars
  • 6 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Slim 3 Controller Strategy

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., (*1)

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();

The Versions

20/06 2017

dev-master

9999999-dev

Customize the way Slim3 loads controllers with your rules

  Sources   Download

MIT

The Requires

 

by Daniel Rubin