PHP code example of tsaotai / tsaotai-pro

1. Go to this page and download the library: Download tsaotai/tsaotai-pro 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/ */

    

tsaotai / tsaotai-pro example snippets


Route::any('api/pro/:plugin/:name/:action', 'Your\\ProController@dispatch')
    ->pattern(['plugin' => '[\w\-]+', 'name' => '[\w\-]+', 'action' => '[\w\-]+']);

use tsaotai\pro\Http\ProGateway;
use tsaotai\pro\Contracts\Responder;

class ProController implements Responder
{
    public function dispatch()
    {
        return ProGateway::dispatch(
            (string) $this->request->param('plugin', ''),
            (string) $this->request->param('name', ''),
            (string) $this->request->param('action', ''),
            $this
        );
    }

    public function ok($data = null, string $msg = '') { /* JSON ok */ }
    public function fail(string $msg, int $code = 1, $data = null) { /* JSON fail */ }
    public function 

use tsaotai\pro\Resource\ProResource;

ProResource::define('tag', [
    'table' => 'pro_demo_tag',
    'pk' => 'id',
    'capabilities' => ['core', 'batch', 'import-export', 'reorder'],
    'search' => ['name', 'status'],
    'searchLike' => ['name'],
    'filters' => ['status'],
    'fillable' => ['name', 'status', 'amount'],
    'sortable' => ['id', 'name', 'amount'],
    // 'db' => fn () => ...,
    // 'hooks' => ['authorize' => ..., 'scopeQuery' => ...],
]);

\tsaotai\pro\ProHost::boot([
    'translator'  => fn (string $s) => translate($s),
    'runtime'     => runtime_path(),
    'addons_root' => root_path() . '/addons',
    'auditor'     => fn (string $action, array $ctx) => { /* 写审计 */ },
    'config'      => fn (string $key, $default = null) => config($key) ?? $default,
]);
text
src/
  ProHost.php · Service.php
  Contracts/ · Resource/ · Http/ · Query/ · Io/
config.php
tests/
VERSION · README.md · PACKAGING.md · CHANGELOG.md · LICENSE