studiow/plates-http-factory

PSR-7 HTTP消息工厂的Plates适配器

v1.0.0 2018-11-28 09:23 UTC

This package is auto-updated.

Last update: 2024-08-28 23:34:51 UTC


README

PSR-17中定义的ResponseFactories的Plates适配器

安装

推荐使用 Composer 安装此包

composer require studiow/plates-http-factory

您还需要一个实现PSR-17的包: https://packagist.org.cn/providers/psr/http-factory-implementation

用法

所有示例都使用 http-interop/http-factory-guzzle.

基本用法

$factory = new \Studiow\Plates\ResponseFactory(
    new \League\Plates\Engine('/path/to/templates'), //the plates engine
    new \Http\Factory\Guzzle\ResponseFactory()      //a psr-17 compatible response factory
);

//rendering the template at /path/to/templates/pages/home.php with additional data
$response = $factory->createResponse(
    'pages/home',
    ['title'=>'home']
);

使用HTTP响应代码

$factory = new \Studiow\Plates\ResponseFactory(
    new \League\Plates\Engine('/path/to/templates'),
    new \Http\Factory\Guzzle\ResponseFactory()
);

$response = $factory->createResponse(
    'error/page-not-found', //name of the template
    ['title'=>'Page not found!'], //data to be passed to the template
    404,     //http status code
    'Not Found' //http reason phrase
);