<commit_before>Slim3-controller
=================

[![Build Status](https://travis-ci.org/brtriver/slim3-controller.svg)](https://travis-ci.org/brtriver/slim3-controller)

Anonymous controller and trait for Slim3 with PHP7.

Requirements
------------

* PHP 7.0 or later.
* Slim3

Install
--------

install via composer

```bash
composer require brtriver/slim3-controller
```

Usage
-------

you can read [example code](https://github.com/brtriver/slim3-controller/blob/master/examples/web/index.php).

sample code is blow:

```php
use Brtriver\Controller\Controller;

$app->get('/hello/{name}', new class($app) extends Controller {

        public function action($args)
        {
            return $this->render($this->container['greet'] . $args['name']);
        }
});
```

* Controller class has these methods and variables.
  * methods:
    * action($args): you should write your controller logic in this method.
    * render($output): helper method to render the $output with 200 status
	* render404($output): helper method to render the $output with 404 status
  * variables.
    * $this->request
    * $this->response
    * $this->app
	* $this->container

If use Template engine (PHP or Twig etc...), a renderWithT method in Templatable trait is available:

```php<commit_msg>Fix typo<commit_after>Slim3-controller
=================

[![Build Status](https://travis-ci.org/brtriver/slim3-controller.svg)](https://travis-ci.org/brtriver/slim3-controller)

Anonymous controller and trait for Slim3 with PHP7.

Requirements
------------

* PHP 7.0 or later.
* Slim3

Install
--------

install via composer

```bash
composer require brtriver/slim3-controller
```

Usage
-------

you can read [example code](https://github.com/brtriver/slim3-controller/blob/master/examples/web/index.php).

sample code is blow:

```php
use Brtriver\Controller\Controller;

$app->get('/hello/{name}', new class($app) extends Controller {

        public function action($args)
        {
            return $this->render($this->container['greet'] . $args['name']);
        }
});
```

* Controller class has these methods and class properties.
  * methods:
    * action($args): you should write your controller logic in this method.
    * render($output): helper method to render the $output with 200 status
	* render404($output): helper method to render the $output with 404 status
  * properties:
    * $this->request
    * $this->response
    * $this->app
	* $this->container

If use Template engine (PHP or Twig etc...), a renderWithT method in Templatable trait is available:

```php
{'fraction_non_alphanumeric': 0.16090167120093277, 'fraction_numerical': 0.014768752429071124, 'mean_word_length': 3.453287197231834, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, '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': '3413109', 'n_tokens_mistral': 802, 'n_tokens_neox': 767, 'n_words': 219}