Download the PHP package rgsone/slim-lazy-controller-connector without Composer

On this page you can find all versions of the php package rgsone/slim-lazy-controller-connector. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package slim-lazy-controller-connector

[DEPRECATED] > Look at new Slim version

slim-lazy-controller-connector

Slim LazyControllerConnector is an extension for Slim Framework who provides a simple way to connect and 'lazy load' controllers & middlewares with Slim routes.

Features

Install

With Composer.

"require": {
    "slim/slim": "~2.4",
    "rgsone/slim-lazy-controller-connector": "dev-master"
}

Usage

LazyControllerConnector provides two ways to connect Slim routes with controllers. Provides also a simple way to call a method's controller.

Single route way

Setup

<?php

$slim = new \Slim\Slim();
// LazyControllerConnector needs a Slim instance
$connector = new \Rgsone\Slim\LazyControllerConnector( $slim );

Basic usage

// connects route '/' with 'MyController' and calls his 'myAction' method via GET method
$connector->connect( 'GET', '/', '\MyController:myAction' );

// anothers examples
$connector->connect( 'GET', '/foo/', '\MyOtherController:myAction' );
// with namespace
$connector->connect( 'GET', '/foo/bar/', '\Foo\Bar\Controller:myAction' );

Also accepts an array of middlewares to call in additional parameters

$connector->connect(
    'GET',
    '/middleware/',
    '\MyController:myAction',
    array(
        function() { echo 'middleware'; },
        function() { echo 'another middleware'; },
        // middlewares can also to be called like this
        '\MyMiddleware:myAction'
        // or in any callable forms
    )
);

LazyControllerConnector::connect method returns an \Slim\Route instance, so it is possible to add a route name and/or a route conditions like Slim routing system

$connector->connect( 'GET', '/bar/', '\MyController:myAction' )
    ->name( 'my.route.name' );

$connector->connect( 'GET', '/bar/:id', '\MyController:myAction' )
    ->conditions( array( 'id' => '[0-9]+' ) )
    ->name( 'my.route.with.id.name' );

It also possible to bind multiples HTTP methods on a same route

// binds with GET and POST methods
$connector->connect( 'GET|POST', '/foo/bar', '\MyController:myAction' );

// binds with GET, POST, DELETE and PUT methods
$connector->connect( 'GET|POST|DELETE|PUT', '/foo/bar', '\MyController:myAction' );

Multiple routes for a same controller

Setup

<?php

$slim = new \Slim\Slim();
// LazyControllerConnector needs a Slim instance
$connector = new \Rgsone\Slim\LazyControllerConnector( $slim );

Basic usage, the only required parameter for each route is action, all others are optionnal by default, if the method parameter is not present, the default HTTP method is GET

$connector->connectRoutes(

    // controller
    '\MyController',

    // route list
    array(
        '/' => array(
            'action' => 'myAction'
        ),
        '/foo' => array(
            'action' => 'myAction',
            'method' => 'GET'
        ),
        '/bar' => array(
            'action' => 'myAction',
            'method' => 'POST'
        )
    )

);

It is possible to bind multiples HTTP methods for a same route, like LazyControllerConnector::connect each method must be separated by a pipe |

$connector->connectRoutes(

    '\Foo\MyController',

    array(
        '/foo/foo' => array(
            'action' => 'myAction',
            // binds GET, POST and PUT methods with this route
            'method' => 'GET|POST|PUT'
        )
    )

);

In addition, it is possible to name route, add conditions and add a middlewares for the same route

$connector->connectRoutes(

    '\MyController',

    array(
        '/foo/:id' => array(
            'action' => 'myAction',
            'method' => 'GET|POST',
            // add conditions for :id
            'conditions' => array(
                'id' => '[0-9]+'
            ),
            // names this route
            'name' => 'route.foo.name',
            // middlewares accepts any callable
            'middlewares' => array(
                function() { echo 'route middleware'; },
                // middlewares can also be called like this
                '\Middlewares\MyMiddleware:myAction'
            )
        )
    )

);

As a last, a globals middlewares can be defined, a global middleware is a middleware who is binded with each declared route

$connector->connectRoutes(

    '\MyController',

    array(
        '/foo/bar' => array(
            'action' => 'myAction'
        ),
        '/bar/foo' => array(
            'action' => 'myOtherAction'
        )
    ),

    // these middlewares will be called for '/foo/bar' and '/bar/foo' routes
    function() { echo 'global middleware'; },
    '\MyMiddleware:myAction'

);

Full example

$connector->connectRoutes(

    '\Foo\Bar\MyController',

    array(
        '/foobar' => array(
            'method' => 'GET',
            'action' => 'myAction',
            'name' => 'route.foobar',
            'middlewares' => array(
                '\Middlewares\MyMiddleware:myAction'
            )
        ),
        '/foobar/:id' => array(
            'method' => 'GET|POST',
            'action' => 'myOtherAction',
            'name' => 'route.foobar.id',
            'conditions' => array( 'id' => '[0-9]+' ),
            'middlewares' => array(
                function() { echo 'single route middleware'; }
            )
        )
    ),

    function() { echo 'global middleware'; },
    '\MyMiddleware:myAction'

);

Calls a method from a controller

Setup

<?php

$slim = new \Slim\Slim();
// LazyControllerConnector needs a Slim instance
$connector = new \Rgsone\Slim\LazyControllerConnector( $slim );

Basic usage is to call an action/method from a controller

// calls myAction from MyController
$connector->callAction( '\MyController', 'myAction' );
// it also possible to pass args to the called method
$connector->callAction( '\MyController', 'myAction', array( 'my', 'parameters', 11 ) );

LazyControllerConnector::callAction is useful particularly for Slim::notFound method

$slim->notFound( function() use ( $connector ) {
    $connector->callAction( '\Controllers\MyNotFoundController', 'do404' );
});

Addition

A \Slim\Slim instance is passed in constructor parameters of each controller

<?php

// example of controller
class MyController
{
    private $_slimApp;

    public function __construct( \Slim\Slim $slim )
    {
        $this->_slimApp = $slim;
    }
}

Author

rgsone aka Rudy Marc

Thanks

to Josh Lockhart for Slim Framework.

License

Slim LazyControllerConnector is released under the MIT public license.


All versions of slim-lazy-controller-connector with dependencies

PHP Build Version
Package Version
Requires php Version >=5.4.0
slim/slim Version ~2.4
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package rgsone/slim-lazy-controller-connector contains the following files

Loading the files please wait ....