The documentation of this project is still under active development. New features are still being added to this project.

Documentation


Getting started


Installation

You can use Composer to create a new Tufu project. This is the equivalent of doing a git clone/svn checkout followed by a "composer install".

composer create-project ready24it/tufu -s dev {folder-name}

Configuration

You should never store sensitive credentials in your code. To protect us we use Dotenv. (.env)

BASE_URL=http://someurl.com #Optional

 APP_DEBUG=false #Optional
 DB_DRIVER=mysql
 DB_HOST=localhost
 DB_DATABASE=tufu
 DB_USERNAME=root
 DB_PASSWORD=somepass

 JWT_PUB_KEY=12345
 JWT_PRI_KEY=12345
 JWT_EXPIRES_AFTER=20
In our config file (config/config.php) we associate the sensitive credentials, but may we need to extend it for our convenience.

Routing


Routes file

You should save our routes in the config/routes.php file.

...

 // static routes
 $routesManager->addGetRoute('/', 'App\Controller\Home@welcomeAction');
 $routesManager->addGetRoute('/documentation', 'App\Controller\Documentation@indexAction');

 // generic routes
 $routesManager->addGetRoute('/user/{id}', 'App\Controller\Test@userAction'); // id => .*

Controller


Annotation Interceptors

You should use Annotations for Request and Response Interceptors.

/**
  * @ResponseListener('App\Interceptor\JwtResponseInterceptor')
  * @RequestListener('App\Interceptor\JwtRequestInterceptor')
  *
  * @return JsonResponse
  */
 public function usersAction()
 {
    $users = User::all();
    $headers = array(
        'Access-Control-Allow-Origin' => 'http://localhost:4200'
    );
    return new JsonResponse($users, 200, $headers);
 }

The ResponseListener adds an Authorization: Bearer e0yYJSd... to the Response.
The RequestListener requires an X-Auth-Token: e0yYJSd... in the Request-Header.
You can add many interceptors as needed.

Template


Twig

Twig is a modern template engine for PHP. More information can be found on the official Page.

Twig extensions

Here is a list of integrated filter and extensions.

truncate
Use the truncate filter to cut off a string after limit is reached
wordwrap
Use the wordwrap filter to split your text in lines with equal length.
route
Use the route extension to retrieve the right route-url.
asset
Use the asset extension to generate the right asset source path.
dump
Use the dump extension to dump in twig.
has_error
Use the has_error extension to determinate if field contains an error.

Resources

A resources is everything else expect php that is required for our application.