-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.php
74 lines (65 loc) · 2.45 KB
/
test.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact [email protected]
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace App\Factory;
use Hyperf\Di\Container;
use Hyperf\Support\Filesystem\Filesystem;
use Hyperf\ViewEngine\Blade;
use Hyperf\ViewEngine\Compiler\BladeCompiler;
use App\Model\Vod;
class BladeCompilerFactory
{
public function __invoke(Container $container)
{
$blade = new BladeCompiler(
$container->get(Filesystem::class),
Blade::config('config.cache_path')
);
$blade->directive('vod_list', function ($expression) {
return "<?php if(true):?>
<?php \$queryParams=$expression;
\$query=App\Model\Vod::query();
foreach(\$queryParams as \$k=>\$v){
if(\$k=='page'||\$k=='limit'){
continue;
}
if(\$k=='type_id'){
\$vodTypes= Hyperf\DbConnection\Db::table('vod_type')->select(['id'])->where('parent_id','=',\$v)->get();
\$typeIds=\$vodTypes->pluck('id')->toArray();
if(empty(\$typeIds)){
\$query->where('type_id','=',\$v)
}else{
\$query->whereIn('type_id',\$typeIds);
}
continue;
}
if(is_array(\$v)){
\$query->where(\$k,\$v[0],\$v[1]);
}else{
\$query->where(\$k,'=',\$v);
}
}
\$limit=\$queryParams['limit']??15;
\$page=\$queryParams['page']??1;
\$query->offset((\$page-1)*\$limit)->limit(\$limit);
\$vods=\$query->get();?>
<?php foreach(\$vods as \$vod):?>";
});
$blade->directive('end_vod_list', function ($expression) {
return '<?php endforeach ?> <?php endif;?>';
});
// register view components
foreach ((array) Blade::config('components', []) as $alias => $class) {
$blade->component($class, $alias);
}
$blade->setComponentAutoload((array) Blade::config('autoload', ['classes' => [], 'components' => []]));
return $blade;
}
}