<commit_before># RKA Slim Controller

An extension to [Slim][1] that allows you use to dynamically instantiated
controllers with action methods wherever you would use a closure when routing.

The controller can optionally be loaded from Slim's DI container, allowing you
to inject dependencies as required.


## Installation

    composer require rka/rka-slim-controller

[1]: http://www.slimframework.com/


## Usage

Use the string format `{controller class name}:{action method name}` wherever you
would usually use a closure:

e.g.

    $app = new \RkaSc\Slim();
    $app->get('/hello:name', 'App\Controller\IndexController:homeAction');


You can also register the controller with Slim's DI container:

    $app = new \RkaSc\Slim();
    $app->container->singleton('App\IndexController', function ($container) {
        // Retrieve any required dependencies from the container and
        // inject into the constructor of the controller

        return new \App\Controller\IndexController();
    });

    $app->get('/', 'App\IndexController:indexAction');


## Controller class methods

*RKA Slim Controller* will call the controller's `setApp()`, `setRequest()` and
`setResponse()` methods if they exist and populate appropriately.

Hence, a typical controller may look like:

    <?php
    namespace App\Controller;

    class IndexController
    {
        protected $app;
        protected $request;
        protected $response;

        public function indexAction()
        {
            echo "This is the home page";
        }

        public function helloAction($name)
        {
            echo "Hello, $name";
        }

        public function setApp($app)
        {
            $this->app = $app;
        }

        public function setRequest($request)
        {
            $this->request = $request;
        }

        public function setResponse($response)
        {
            $this->response = $response;
        }
    }
<commit_msg>Fix README.<commit_after># RKA Slim Controller

An extension to [Slim][1] that allows you use to dynamically instantiated
controllers with action methods wherever you would use a closure when routing.

The controller can optionally be loaded from Slim's DI container, allowing you
to inject dependencies as required.


## Installation

    composer require akrabat/rka-slim-controller

[1]: http://www.slimframework.com/


## Usage

Use the string format `{controller class name}:{action method name}` wherever you
would usually use a closure:

e.g.

    $app = new \RkaSc\Slim();
    $app->get('/hello:name', 'App\Controller\IndexController:homeAction');


You can also register the controller with Slim's DI container:

    $app = new \RkaSc\Slim();
    $app->container->singleton('App\IndexController', function ($container) {
        // Retrieve any required dependencies from the container and
        // inject into the constructor of the controller

        return new \App\Controller\IndexController();
    });

    $app->get('/', 'App\IndexController:indexAction');


## Controller class methods

*RKA Slim Controller* will call the controller's `setApp()`, `setRequest()` and
`setResponse()` methods if they exist and populate appropriately.

Hence, a typical controller may look like:

    <?php
    namespace App\Controller;

    class IndexController
    {
        protected $app;
        protected $request;
        protected $response;

        public function indexAction()
        {
            echo "This is the home page";
        }

        public function helloAction($name)
        {
            echo "Hello, $name";
        }

        public function setApp($app)
        {
            $this->app = $app;
        }

        public function setRequest($request)
        {
            $this->request = $request;
        }

        public function setResponse($response)
        {
            $this->response = $response;
        }
    }


## Example project

Look at [slim-di](https://github.com/akrabat/slim-di).

{'fraction_non_alphanumeric': 0.10122776246554749, 'fraction_numerical': 0.0010022550739163117, 'mean_word_length': 2.609403254972875, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, 'https://': 1, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1808269', 'n_tokens_mistral': 1098, 'n_tokens_neox': 1034, 'n_words': 362}