2017 © Pedro Peláez
 

library engine

TkachInc Engine

image

tkachinc/engine

TkachInc Engine

  • Monday, August 7, 2017
  • by gollariel
  • Repository
  • 0 Watchers
  • 0 Stars
  • 558 Installations
  • 2 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 79 Versions
  • 0 % Grown

The README.md

Codacy Badge, (*1)

Base engine to web-service

This is base package, it does not have any helpers to DB or Session., (*2)

More helpers you can see in tkachinc/core package., (*3)

Package include only most popular and useful functional., (*4)

This package include base application, container, base controller, and services:, (*5)

Services:, (*6)

  • AlgorithmsForCoding
  • Attributes
  • Config
  • Handler
  • Helpers
  • Request
  • Response
  • Secure
  • Validator
  • Facade
  • Singelton
  • Multiton
  • Registry, (*7)

    and this package has relations to tkachinc/cli, (*8)

You can view example, (*9)

Install

To install TkachInc\Engine - file composer.json your project must be entered in the unit require:, (*10)

"tkachinc/engine": "~2.1"

After that, if you have already installed composer execute:, (*11)

$ php composer.phar install tkachinc/engine

If not, then you must install the composer:, (*12)

curl -sS https://getcomposer.org/installer | php

Create file compose.json, (*13)

{
    "require": {
        "tkachinc/engine": "~2.2"
    }
}

And execute command:, (*14)

$ php composer.phar install tkachinc/engine

Routing

Routing is waiting at the entrance of the line router. Output object containing data Parsed, (*15)

Example

if(isset($_GET['request_uri']))
{
    $route = $_GET['request_uri'];
    unset($_GET['request_uri']);
}
else
{
    $route = '';
}
Config::getInstance()->append(['route' => $route]);
$router = new DeepRouter();
$router->setDefaultController('MyApp\BaseApiController');
$router->setDefaultMethod('index');
$router->setUrlMap(
[
    'api' => [
        '_controller'    => 'MyApp\BaseApiController',
        '_defaultMethod' => 'page404',
        '_data'          => [
            '%s' => [
                '_name' => 'version',
                '_data' => [
                    'auth' => [
                        '_controller'    => 'MyApp\User\Model\Controller\AuthController',
                    ],
                ]
            ]
        ]
    ]
]
);
$router->setPrefixes(Config::getInstance()->get(['lang', 'list'], ['ru'=>1, 'en'=>1]));
$route = $router->parseRoute($route, true);

$className = $route->getClassName();
$methodName = $route->getMethodName();
$_GET['lang'] = $route->getPrefix();

if(class_exists($className))
{
    $object = new $className($route);
    call_user_func_array([$object, $methodName], []);
}

The result of parsing - the object Route. It contains the class, method, language after parsing., (*16)

Configuration urlMap

UrlMap Standard configuration includes only one key controller - responsible for the name of the controller, the respective identifier Route Extra options: - _defaultMethod - the standard method for the request - _method - called method, controller - _controller - controller namespace - _data - part from url - _name - name params, (*17)

Example

There url: /user/123 And configurations urlMap:, (*18)

[
    'user' => [
         '_controller' => 'Example/User',
         '_method' => 'get',
         '_data' => ['%s' => ['_name' => 'id']]
    ]
]

After parsing the Router will contain: controller - Example/User method - get arguments - id => 123, (*19)

Additionally when specifying a method argument second parseRoute - true key id with a value of 123 would be in the array $_REQUEST, (*20)

Alternative router

Example

$router = new ClosureRouter('/test/123', 'GET');

$router->scope(function(ClosureRouter $router, $params){
    $router->single('test', function(\TkachInc\Engine\Router\ClosureRouter $router, $params){
        $router->single('123', function(\TkachInc\Engine\Router\ClosureRouter $router, $params){
            var_dump('test');
        });
    }, 'POST');
    $router->single('test', function(\TkachInc\Engine\Router\ClosureRouter $router, $params){
        $router->single(':id', function(\TkachInc\Engine\Router\ClosureRouter $router, $params){
            var_dump($router->attributes());
            var_dump('test_2');
        });
        $router->single('123', function(\TkachInc\Engine\Router\ClosureRouter $router, $params){
            var_dump('test3');
        });
    }, 'GET');
    $router->single(':id', function(\TkachInc\Engine\Router\ClosureRouter $router, $params){
        var_dump('test_2');
    });
});

Output

array(1) {
  ["id"]=>
  string(3) "123"
}
string(6) "test_2"

Nginx config example

    server {
        listen      *:80;        # порт http
        #listen     *:443;        # порт http

        #include    /etc/nginx/ssl.conf; # подключение конфигурации ssl

        server_name example.host;

        root   /path/to/dir;

        charset utf-8;

        #access_log /path/to/access.log;
        log_not_found off;
        #access_log off;
        #error_log  /path/to/error.log warn;

        location / {
            index  index.php;
           try_files $uri $uri @front_rewrite;
        }


        ## Images and static content is treated different
        location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|xml|swf)$ {
          access_log        off;
          expires           30d;
        }

       location @front_rewrite {
          # Some modules enforce no slash (/) at the end of the URL
          # Else this rewrite block wouldn't be needed (GlobalRedirect)
          rewrite  ^/(.*)$  /index.php?request_uri=$1  last;
       }

       location ~ /\. {
           deny  all;
       }

        location ~ .php$ {
        fastcgi_index  index.php;
            fastcgi_split_path_info ^(.+\.php)(.*)$;
            fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
            #fastcgi_pass   php-fpm:9000;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include fastcgi_params;
            fastcgi_param  QUERY_STRING     $query_string;
            fastcgi_param  REQUEST_METHOD   $request_method;
            fastcgi_param  CONTENT_TYPE     $content_type;
            fastcgi_param  CONTENT_LENGTH   $content_length;
            fastcgi_intercept_errors        on;
            fastcgi_ignore_client_abort     off;
            fastcgi_connect_timeout 60;
            fastcgi_send_timeout 180;
            fastcgi_read_timeout 180;
            fastcgi_buffer_size 128k;
            fastcgi_buffers 4 256k;
            fastcgi_busy_buffers_size 256k;
            fastcgi_temp_file_write_size 256k;
        }
    }

Autoloader

Recommended autoloader A more simple and fast autoloader than the one that goes to the composer., (*21)

  • Connection time autoloader this file is ~ 0.00060 (0.00322 ~ complete initialization)
  • Composer autoloader ~ 0.008054 (0.01221 ~ complete initialization)

Setting Example

It should be at the project to create a file autoload.php (an example can be taken from the example\autoload\autoload.php) This file contains two arrays, the first array - the connection of individual classes of non-standard directory. The second array - connect all libraries namespace (in support for PSR-0 and PSR-4), (*22)

Example

<?php
require_once(__DIR__."/SimpleAutoload.php");
$autoinclude = [
    VENDOR_PATH.'/react/promise/src/functions_include.php',
];
$classMap = [
    'LightOpenID' => VENDOR_PATH.'/lightopenid/lightopenid/openid.php',
];
$fallbackDirs = [
    'Evenement'                             => VENDOR_PATH.'/evenement/evenement/src',
    'Symfony'                               => VENDOR_PATH.'/gollariel/km-core/src',
    'Symfony\\Component\\HttpFoundation\\'  => VENDOR_PATH.'/symfony/http-foundation',
    'Symfony\\Component\\Filesystem\\'      => VENDOR_PATH.'/symfony/filesystem',
    'Symfony\\Component\\EventDispatcher\\' => VENDOR_PATH.'/symfony/event-dispatcher',
    'Twig'                                  => VENDOR_PATH.'/twig/twig/lib',
    //'Ratchet'                               => VENDOR_PATH.'/cboden/ratchet/src',
    'React\\Stream\\'                       => VENDOR_PATH.'/react/stream/src',
    'React\\Socket\\'                       => VENDOR_PATH.'/react/socket/src',
    'React\\SocketClient\\'                 => VENDOR_PATH.'/react/socket-client/src',
    'React\\Promise\\'                      => VENDOR_PATH.'/react/promise/src',
    'React\\Http\\'                         => VENDOR_PATH.'/react/http/src',
    'React\\HttpClient\\'                   => VENDOR_PATH.'/react/http-client/src',
    'React\\EventLoop\\'                    => VENDOR_PATH.'/react/event-loop',
    'React\\Dns\\'                          => VENDOR_PATH.'/react/dns',
    'React\\ChildProcess\\'                 => VENDOR_PATH.'/react/child-process',
    'React\\Cache\\'                        => VENDOR_PATH.'/react/cache',
    'React\\ZMQ'                            => VENDOR_PATH.'/react/zmq/src',
    'Ratchet\\'                             => VENDOR_PATH.'/cboden/ratchet/src/Ratchet',
    'Guzzle\\Stream'                        => VENDOR_PATH.'/guzzle/stream',
    'Guzzle\\Parser'                        => VENDOR_PATH.'/guzzle/parser',
    'Guzzle\\Http'                          => VENDOR_PATH.'/guzzle/http',
    'Guzzle\\Common'                        => VENDOR_PATH.'/guzzle/common',
];
foreach ($autoinclude as $item)
{
    if(file_exists($item))
    {
        include $item;
    }
}
$autoloader = new SimpleAutoload($classMap, $fallbackDirs);
spl_autoload_register([$autoloader, 'loadClass']);

** File scaner.php - can create autoload.php file **, (*23)

The Versions

07/08 2017

dev-master

9999999-dev https://bitbucket.org/tkachinc/engine

TkachInc Engine

  Sources   Download

PHP

The Requires

 

by Maxim Tkach

engine tkachinc

07/08 2017

2.3.1

2.3.1.0 https://bitbucket.org/tkachinc/engine

TkachInc Engine

  Sources   Download

PHP

The Requires

 

by Maxim Tkach

engine tkachinc

07/08 2017

dev-develop

dev-develop https://bitbucket.org/tkachinc/engine

TkachInc Engine

  Sources   Download

PHP

The Requires

 

by Maxim Tkach

engine tkachinc

07/08 2017

2.3.0

2.3.0.0 https://bitbucket.org/tkachinc/engine

TkachInc Engine

  Sources   Download

PHP

The Requires

 

by Maxim Tkach

engine tkachinc

30/07 2017

2.2.4

2.2.4.0 https://bitbucket.org/tkachinc/engine

TkachInc Engine

  Sources   Download

PHP

The Requires

 

by Maxim Tkach

engine tkachinc

07/07 2017

2.2.2

2.2.2.0 https://bitbucket.org/tkachinc/engine

TkachInc Engine

  Sources   Download

PHP

The Requires

 

by Maxim Tkach

engine tkachinc

07/07 2017

2.2.3

2.2.3.0 https://bitbucket.org/tkachinc/engine

TkachInc Engine

  Sources   Download

PHP

The Requires

 

by Maxim Tkach

engine tkachinc

07/07 2017

2.2.1

2.2.1.0 https://bitbucket.org/tkachinc/engine

TkachInc Engine

  Sources   Download

PHP

The Requires

 

by Maxim Tkach

engine tkachinc

07/07 2017

2.2.0

2.2.0.0 https://bitbucket.org/tkachinc/engine

TkachInc Engine

  Sources   Download

PHP

The Requires

 

by Maxim Tkach

engine tkachinc

10/06 2017

2.1.12

2.1.12.0 https://bitbucket.org/tkachinc/engine

TkachInc Engine

  Sources   Download

PHP

The Requires

 

by Maxim Tkach

engine tkachinc

29/05 2017

2.1.11

2.1.11.0 https://bitbucket.org/tkachinc/engine

TkachInc Engine

  Sources   Download

PHP

The Requires

 

by Maxim Tkach

engine tkachinc

21/04 2017

2.1.10

2.1.10.0 https://bitbucket.org/tkachinc/engine

TkachInc Engine

  Sources   Download

PHP

The Requires

 

by Maxim Tkach

engine tkachinc

01/04 2017

2.1.9

2.1.9.0

TkachInc Engine

  Sources   Download

PHP

The Requires

 

by Maxim Tkach

engine tkachinc

22/02 2017

2.1.8

2.1.8.0

TkachInc Engine

  Sources   Download

PHP

The Requires

 

by Maxim Tkach

engine tkachinc

16/02 2017

2.1.7

2.1.7.0

TkachInc Engine

  Sources   Download

PHP

The Requires

 

by Maxim Tkach

engine tkachinc

16/02 2017

2.1.6

2.1.6.0

TkachInc Engine

  Sources   Download

PHP

The Requires

 

by Maxim Tkach

engine tkachinc

15/02 2017

2.1.5

2.1.5.0

TkachInc Engine

  Sources   Download

PHP

The Requires

 

by Maxim Tkach

engine tkachinc

12/02 2017

2.1.4

2.1.4.0

TkachInc Engine

  Sources   Download

PHP

The Requires

 

by Maxim Tkach

engine tkachinc

10/02 2017

2.1.3

2.1.3.0

TkachInc Engine

  Sources   Download

PHP

The Requires

 

by Maxim Tkach

engine tkachinc

06/02 2017

2.1.2

2.1.2.0

TkachInc Engine

  Sources   Download

PHP

The Requires

 

by Maxim Tkach

engine tkachinc

06/02 2017

2.1.1

2.1.1.0

TkachInc Engine

  Sources   Download

PHP

The Requires

 

by Maxim Tkach

engine tkachinc

06/02 2017

2.1.0

2.1.0.0

TkachInc Engine

  Sources   Download

PHP

The Requires

 

by Maxim Tkach

engine tkachinc

02/02 2017

2.0.5

2.0.5.0

TkachInc Engine

  Sources   Download

PHP

The Requires

 

by Maxim Tkach

engine tkachinc

02/02 2017

2.0.4

2.0.4.0

TkachInc Engine

  Sources   Download

PHP

The Requires

 

by Maxim Tkach

engine tkachinc

01/02 2017

dev-support

dev-support

TkachInc Engine

  Sources   Download

PHP

The Requires

 

by Maxim Tkach

engine tkachinc

01/02 2017

1.8.6

1.8.6.0

TkachInc Engine

  Sources   Download

PHP

The Requires

 

by Maxim Tkach

engine tkachinc

01/02 2017

2.0.3

2.0.3.0

TkachInc Engine

  Sources   Download

PHP

The Requires

 

by Maxim Tkach

engine tkachinc

31/01 2017

2.0.2

2.0.2.0

TkachInc Engine

  Sources   Download

PHP

The Requires

 

by Maxim Tkach

engine tkachinc

31/01 2017

2.0.1

2.0.1.0

TkachInc Engine

  Sources   Download

PHP

The Requires

 

by Maxim Tkach

engine tkachinc

31/01 2017

2.0.0

2.0.0.0

TkachInc Engine

  Sources   Download

PHP

The Requires

 

by Maxim Tkach

engine tkachinc

30/01 2017

1.8.5

1.8.5.0

TkachInc Engine

  Sources   Download

PHP

The Requires

 

by Maxim Tkach

engine tkachinc

28/01 2017

1.8.4

1.8.4.0

TkachInc Engine

  Sources   Download

PHP

The Requires

 

by Maxim Tkach

engine tkachinc

28/01 2017

1.8.3

1.8.3.0

TkachInc Engine

  Sources   Download

PHP

The Requires

 

by Maxim Tkach

engine tkachinc

28/01 2017

1.8.2

1.8.2.0

TkachInc Engine

  Sources   Download

PHP

The Requires

 

by Maxim Tkach

engine tkachinc

28/01 2017

1.8.1

1.8.1.0

TkachInc Engine

  Sources   Download

PHP

The Requires

 

by Maxim Tkach

engine tkachinc

28/01 2017

1.8.0

1.8.0.0

TkachInc Engine

  Sources   Download

PHP

The Requires

 

by Maxim Tkach

engine tkachinc

28/01 2017

1.7.0

1.7.0.0

TkachInc Engine

  Sources   Download

PHP

The Requires

 

by Maxim Tkach

engine tkachinc

27/01 2017

1.6.6

1.6.6.0

TkachInc Engine

  Sources   Download

PHP

The Requires

 

by Maxim Tkach

engine tkachinc

26/01 2017

1.6.5

1.6.5.0

TkachInc Engine

  Sources   Download

PHP

The Requires

 

by Maxim Tkach

engine tkachinc

26/01 2017

1.6.4

1.6.4.0

TkachInc Engine

  Sources   Download

PHP

The Requires

 

by Maxim Tkach

engine tkachinc

26/01 2017

1.6.3

1.6.3.0

TkachInc Engine

  Sources   Download

PHP

The Requires

 

by Maxim Tkach

engine tkachinc

26/01 2017

1.6.2

1.6.2.0

TkachInc Engine

  Sources   Download

PHP

The Requires

 

by Maxim Tkach

engine tkachinc

26/01 2017

1.6.1

1.6.1.0

TkachInc Engine

  Sources   Download

PHP

The Requires

 

by Maxim Tkach

engine tkachinc

26/01 2017

1.6.0

1.6.0.0

TkachInc Engine

  Sources   Download

PHP

The Requires

 

by Maxim Tkach

engine tkachinc

24/01 2017

1.5.0

1.5.0.0

TkachInc Engine

  Sources   Download

PHP

The Requires

 

by Maxim Tkach

engine tkachinc

07/01 2017

1.4.3

1.4.3.0

TkachInc Engine

  Sources   Download

PHP

The Requires

 

by Maxim Tkach

engine tkachinc

05/01 2017

1.4.2

1.4.2.0

TkachInc Engine

  Sources   Download

PHP

The Requires

 

by Maxim Tkach

engine tkachinc

05/01 2017

1.4.1

1.4.1.0

TkachInc Engine

  Sources   Download

PHP

The Requires

 

by Maxim Tkach

engine tkachinc

04/01 2017

1.4.0

1.4.0.0

TkachInc Engine

  Sources   Download

PHP

The Requires

 

by Maxim Tkach

engine tkachinc

04/01 2017

1.3.10

1.3.10.0

TkachInc Engine

  Sources   Download

PHP

The Requires

 

by Maxim Tkach

engine tkachinc

02/01 2017

1.3.9

1.3.9.0

TkachInc Engine

  Sources   Download

PHP

The Requires

 

by Maxim Tkach

engine tkachinc

02/01 2017

1.3.8

1.3.8.0

TkachInc Engine

  Sources   Download

PHP

The Requires

 

by Maxim Tkach

engine tkachinc

26/12 2016

1.3.7

1.3.7.0

TkachInc Engine

  Sources   Download

PHP

The Requires

 

by Maxim Tkach

engine tkachinc

23/12 2016

1.3.6

1.3.6.0

TkachInc Engine

  Sources   Download

PHP

The Requires

 

by Maxim Tkach

engine tkachinc

22/12 2016

1.3.5

1.3.5.0

TkachInc Engine

  Sources   Download

PHP

The Requires

 

by Maxim Tkach

engine tkachinc

21/12 2016

1.3.4

1.3.4.0

TkachInc Engine

  Sources   Download

PHP

The Requires

 

by Maxim Tkach

engine tkachinc

20/12 2016

1.3.3

1.3.3.0

TkachInc Engine

  Sources   Download

PHP

The Requires

 

by Maxim Tkach

engine tkachinc

20/12 2016

1.3.2

1.3.2.0

TkachInc Engine

  Sources   Download

PHP

The Requires

 

by Maxim Tkach

engine tkachinc

20/12 2016

1.3.1

1.3.1.0

TkachInc Engine

  Sources   Download

PHP

The Requires

 

by Maxim Tkach

engine tkachinc

20/12 2016

1.3.0

1.3.0.0

TkachInc Engine

  Sources   Download

PHP

The Requires

 

by Maxim Tkach

engine tkachinc

19/12 2016

1.2.1

1.2.1.0

TkachInc Engine

  Sources   Download

PHP

The Requires

 

by Maxim Tkach

engine tkachinc

16/12 2016

1.2.0

1.2.0.0

TkachInc Engine

  Sources   Download

PHP

The Requires

 

by Maxim Tkach

engine tkachinc

13/12 2016

1.1.6

1.1.6.0

TkachInc Engine

  Sources   Download

PHP

The Requires

 

by Maxim Tkach

engine tkachinc

12/12 2016

1.1.5

1.1.5.0

TkachInc Engine

  Sources   Download

PHP

The Requires

 

by Maxim Tkach

engine tkachinc

11/12 2016

1.1.4

1.1.4.0

TkachInc Engine

  Sources   Download

PHP

The Requires

 

by Maxim Tkach

engine tkachinc

11/12 2016

1.1.3

1.1.3.0

TkachInc Engine

  Sources   Download

PHP

The Requires

 

by Maxim Tkach

engine tkachinc

08/12 2016

1.1.2

1.1.2.0

TkachInc Engine

  Sources   Download

PHP

The Requires

 

by Maxim Tkach

engine tkachinc

08/12 2016

1.1.1

1.1.1.0

TkachInc Engine

  Sources   Download

PHP

The Requires

 

by Maxim Tkach

engine tkachinc

05/12 2016

1.1.0

1.1.0.0

TkachInc Engine

  Sources   Download

PHP

The Requires

 

by Maxim Tkach

engine tkachinc

05/12 2016

1.0.9

1.0.9.0

TkachInc Engine

  Sources   Download

PHP

The Requires

 

by Maxim Tkach

engine tkachinc

04/12 2016

1.0.8

1.0.8.0

TkachInc Engine

  Sources   Download

PHP

The Requires

 

by Maxim Tkach

engine tkachinc

04/12 2016

1.0.7

1.0.7.0

TkachInc Engine

  Sources   Download

PHP

The Requires

 

by Maxim Tkach

engine tkachinc

04/12 2016

1.0.6

1.0.6.0

TkachInc Engine

  Sources   Download

PHP

The Requires

 

by Maxim Tkach

engine tkachinc

02/12 2016

1.0.5

1.0.5.0

TkachInc Engine

  Sources   Download

PHP

The Requires

 

by Maxim Tkach

engine tkachinc

02/12 2016

1.0.4

1.0.4.0

TkachInc Engine

  Sources   Download

PHP

The Requires

 

by Maxim Tkach

engine tkachinc

02/12 2016

1.0.3

1.0.3.0

TkachInc Engine

  Sources   Download

PHP

The Requires

 

by Maxim Tkach

engine tkachinc

02/12 2016

1.0.2

1.0.2.0

TkachInc Engine

  Sources   Download

PHP

The Requires

 

by Maxim Tkach

engine tkachinc

02/12 2016

1.0.1

1.0.1.0

TkachInc Engine

  Sources   Download

PHP

The Requires

 

by Maxim Tkach

engine tkachinc

02/12 2016

1.0.0

1.0.0.0

TkachInc Engine

  Sources   Download

PHP

The Requires

 

by Maxim Tkach

engine tkachinc