PHP code example of tigerb / easy-php

1. Go to this page and download the library: Download tigerb/easy-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

tigerb / easy-php example snippets


Entry file ----> Register autoload function
           ----> Register error(and exception) function
           ----> Load config file
           ----> Request
           ----> Router
           ----> (Controller <----> Model)
           ----> Response
           ----> Json
           ----> View

$request = App::$container->get('request');
$request->check('username', 'er');

├── router                      [datebase object relation map class directory]
      ├── RouterInterface.php   [router strategy interface]
      ├── General.php           [general strategy class]
      ├── Pathinfo.php          [pathinfo strategy class]
      ├── Userdefined.php       [userdefined strategy class]
      ├── Micromonomer.php      [micromonomer strategy class]
      ├── Job.php               [job strategy class]
      └── EasyRouter.php        [router strategy entrance class]

domain/index.php?module=Demo&contoller=Index&action=test&username=test

// config/moduleName/route.php, this 'this' point to RouterHandle instance
$this->get('v1/user/info', function (Framework\App $app) {
    return 'Hello Get Router';
});

gateway                     [gateway directory in logics]
  ├── Check.php             [interface]
  ├── CheckAppkey.php       [check app key]
  ├── CheckArguments.php    [check  └── Entrance.php          [entrance file]

/**
 * register user-defined behavior
 *
 * @var array
 */
private $map = [
    // for example, loading user-defined gateway
    'App\Demo\Logics\Gateway\Entrance'
];

├── orm                         
│      ├── Interpreter.php      [sql Interpreter]
│      ├── DB.php               [database operate class]
│      ├── Model.php            [base model class]
│      └── db                   
│          └── Mysql.php        [mysql class]

/**
 * DB operation example
 *
 * findAll
 *
 * @return void
 */
public function dbFindAllDemo()
{
    $where = [
        'id'   => ['>=', 2],
    ];
    $instance = DB::table('user');
    $res      = $instance->where($where)
                         ->orderBy('id asc')
                         ->limit(5)
                         ->findAll(['id','create_at']);
    $sql      = $instance->sql;

    return $res;
}

class Demo
{
    public function __construct ()
    {
        // the demo directly dependent on RelyClassName
        $instance = new RelyClassName ();
    }
}

// env config
[log]
path = /runtime/logs/
name = easy-php
size = 512
level= debug


// How to use in your logic
Log::debug('EASY PHP');
Log::notice('EASY PHP');
Log::warning('EASY PHP');
Log::error('EASY PHP');

cd public && php server.php


namespace Jobs\Demo;

/**
 * Demo Jobs
 *
 * @author TIERGB <https://github.com/TIGERB>
 */
class Demo
{
    /**
     * job
     *
     * @example php cli --jobs=demo.demo.test
     */
    public function test()
    {
        echo 'Hello Easy PHP Jobs';
    }
}


php cli --job=demo.demo.test

/**
 * test assertion example
 */
public function testDemo()
{
    $this->assertEquals(
        'Hello Easy PHP',
        // assert the result by run hello function in demo/Index controller
        App::$app->get('demo/index/hello')
    );
}

runtime/build/App.20170505085503.phar


// );


cd bin && php cli --run

php cli --method=<module.controller.action> --<arguments>=<value> ...

For example, php cli --method=demo.index.get --username=easy-php

cd public && php server.php