wearesho-team/yii-http

Yii2 Web 扩展,用于内部 Wearesho Team 项目使用

安装: 998

依赖者: 2

建议者: 0

安全性: 0

星标: 0

关注者: 4

分支: 0

开放问题: 1

类型:专有

1.16.6 2023-05-19 14:59 UTC

README

Latest Stable Version Total Downloads Build Status codecov

HTTP 的替代工作

内容

查看

实现您的视图

<?php

namespace App\Views;

use Wearesho\Yii\Http\View;

class EntityView extends View {
    /** @var string  */
    protected $foo;
    
    /** @var \SomeClass  */
    protected $dependency;
    
    public function __construct(string $foo, \SomeClass $dependency) {
        $this->foo = $foo;
        $this->dependency = $dependency;
    }
    
    protected function renderInstantiated(): array {
        return [
            'bar' => $this->foo,
        ];
    }
}

然后使用它

<?php

use App\Views\EntityView;

$argument = 'foo';
$output = EntityView::render($argument);

print_r($output);

/**
 * Will output: 
 * Array
  (
      [bar] => 1
  )
 */
// or if you have multiple data
$arguments = [
    '1',
    '2',
];
$output = EntityView::multiple($arguments);

/**
 * Will output
 * Array
   (
       [0] => Array
           (
               [bar] => 1
           )
   
       [1] => Array
           (
               [bar] => 2
           )
   
   )
 */

GetParamsBehavior [示例]

从 \yii\web\Request::get() 中填充面板属性。

安装

composer require wearesho-team/yii-http

添加到您的 DI 容器中

<?php
\Yii::$container->setSingleton(
    \yii\web\Response::class,
    \Wearesho\Yii\Http\Response::class
);
\Yii::$container->set(
    \yii\web\ErrorHandler::class,
    \Wearesho\Yii\Http\ErrorHandler::class
);
\Yii::$container->setSingleton(\yii\db\Connection::class);

待办事项

  1. 文档
  2. 测试

许可协议

MIT