Skip to content

Application

Axios edited this page Dec 14, 2020 · 5 revisions

Handler

Use default server handler

\tpr\App::default();

Use workerman server handler

Need install tpr-workerman library.

composer require axios/tpr-workerman

write follow code in the entry of program. public/index.php for example

\tpr\App::registerServer('workerman', \tpr\server\WorkermanServer::class);

// start application
\tpr\App::drive('workerman')->run();
// or
\tpr\App::workerman()->run();

register some other custom server handlers

\tpr\App::registerServer('custom-server-name', CustomServerHandlerClassName::class)

Configuration

Get details from the AppModel code.

Run application on debug mode

will cache config&routes data on the debug mode.

\tpr\App::debugMode(true);

Set configuration of application

\tpr\App::default()
    ->config([
        'namespace' => 'app'
    ]);

Supported options

option name intro default
name the name of application. 'app'
namespace the base namespace of application. 'App'
lang the name of default language set. 'zh-cn'
cache_time global cache time for config&route data. 60
default_content_type_cgi default content-type on cgi mode. 'html'
default_content_type_ajax default content-type on api request. 'json'
default_content_type_cli default output format of data on cli mode. 'text'
force_route forces use routes for dispatch request. false
controller_rule the spelling rule of controller namespace. '{app_namespace}\\{module}\\controller\\{controller}'
remove_headers emove some header before send response. [] empty array
server_options the configuration of custom server handler. [] empty array
response_config the global configuration of response. [] empty array