Skip to content
This repository has been archived by the owner on Aug 12, 2021. It is now read-only.
/ evas-example Public archive

๐Ÿ“ƒ Examples of applications with evas php framework

License

Notifications You must be signed in to change notification settings

evas-php/evas-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

34 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

evas-example

Example of application with evas php framework

System requirements

PHP 7.2+

Installation

  1. Install Composer https://getcomposer.org/download/

  2. Run command

composer install

Routing info

Handlers policy

  1. File handler:
$router->get('/login', 'login.php');
  1. Callable handler:
$router->get('/login', function () {});
  1. Class method handler:
$router->post('/login', [AuthController::class => 'login']);
  1. Handlers list:
$router->get('/login', [
    AuthController::class => 'login',
    'login.php',
]);

For use url parts in handler args

$router
    ->alias(':id', '(:int') // set alias for id
    ->get('/user/:id', function ($user_id) {
        echo "user with id = $user_id<br>";
    })

Map and Auto Router, grouping

  1. The main router is Map router
(new Router) // init Router
    ->post('/login', [AuthController::class => 'login']) // set handler to POST /login
    ->routingByRequst(App::request()) // routing by request
    ->handle(); // handle routing result
  1. Set inner Map and Auto router
(new Router) // init Router
    ->default('404.php') // set default handler
    ->middlewares([ // set global middlewares
        [Tracker::class => 'trackVisit'],
        [AuthController::class => 'setAuthUser']
    ])
    ->post('/login', [AuthController::class => 'login']) // set handler to POST /login
    ->routingByRequst(App::request()) // routing by request
    ->map('/api/v4') // set child map router to ALL /api/v4
        ->default('apiV4_404.php') // set child map router default handler
        ->middleware(function () {  // set middleware to child map router
            // check access
        })
        ->map('/user', 'GET') // set child map router to GET /api/v4/user
            ->get('/list', [UserController::class => 'list'])
            ->next() // move to parent router
        ->next() // move to parent router
    ->autoByFile('/', 'GET') // set child auto router to GET /
        ->filePostfix('.php') // set auto router file postfix
        ->next() // move to parent router
    ->handle(); // handle routing result

Database

Init

Create db.php in ./config with:

return [
    'dbname' => 'database_name',
    'username' => 'username_database',
    'password' => 'password_database',
];

Evas\Orm\Integrate\AppDbTrait has methods for getting, setting and initial single database

Evas\Orm\Integrate\AppDbsTrait has methods for getting, setting and initial multiple database

Usage this trait in your App

class App extends \Evas\Web\App
{
    use \Evas\Orm\Integrate\AppDbTrait;
}

$qr = App::db()->query('SELECT * FROM users');
var_dump($qr->assocArrayAll());

query() returned Evas\Orm\QueryResult object

Get the number of rows returned.

$rowCount = $qr->rowCount();

Get the record as a numbered array.

$numericArray = $qr->numericArray();

Get all records as an array of numbered arrays.

$numericArrayAll = $qr->numericArrayAll();

Get the record as a associative array.

$assocArray = $qr->assocArray();

Get all records as an array of associative arrays.

$assocArrayAll = $qr->assocArrayAll();

Get the record as a class object.

$classObject = $qr->classObject();

Get all records as class objects.

$classObjectAll = $qr->classObjectAll();

About

๐Ÿ“ƒ Examples of applications with evas php framework

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published