Skip to content

Commit 5a58361

Browse files
committedDec 24, 2022
更新:全面支持模板缓存
·
v2.7.7v2.1.7
1 parent 3bdb091 commit 5a58361

File tree

6 files changed

+80
-5
lines changed

6 files changed

+80
-5
lines changed
 

‎app/Command/ViewEngineCache.php

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* This file is part of zhuchunshu.
6+
* @link https://github.com/zhuchunshu
7+
* @document https://github.com/zhuchunshu/super-forum
8+
* @contact laravel@88.com
9+
* @license https://github.com/zhuchunshu/super-forum/blob/master/LICENSE
10+
*/
11+
namespace App\Command;
12+
13+
use Hyperf\Command\Annotation\Command;
14+
use Hyperf\Command\Command as HyperfCommand;
15+
use Hyperf\Contract\ConfigInterface;
16+
use Hyperf\ViewEngine\Compiler\CompilerInterface;
17+
use Psr\Container\ContainerInterface;
18+
use Symfony\Component\Finder\Finder;
19+
20+
/**
21+
* @Command
22+
*/
23+
#[Command]
24+
class ViewEngineCache extends HyperfCommand
25+
{
26+
/**
27+
* @var ContainerInterface
28+
*/
29+
protected $container;
30+
31+
public function __construct(ContainerInterface $container)
32+
{
33+
$this->container = $container;
34+
35+
parent::__construct('CodeFec:view-engine-cache');
36+
}
37+
38+
public function configure()
39+
{
40+
parent::configure();
41+
$this->setDescription('view-engine-cache');
42+
}
43+
44+
public function handle()
45+
{
46+
$plugins = BASE_PATH . '/app/Plugins/';
47+
$all = [];
48+
foreach (plugins()->getEnPlugins() as $plugin) {
49+
if (is_dir($plugins . $plugin)) {
50+
$all[] = $plugins . $plugin . '/';
51+
}
52+
}
53+
$all[] = BASE_PATH . '/app/Themes/';
54+
$all[] = $this->container->get(ConfigInterface::class)->get('view.config.view_path');
55+
foreach ($all as $item) {
56+
$this->make($item);
57+
}
58+
}
59+
60+
/**
61+
* 生成缓存.
62+
* @param $dir
63+
* @throws \Psr\Container\ContainerExceptionInterface
64+
* @throws \Psr\Container\NotFoundExceptionInterface
65+
*/
66+
private function make($dir)
67+
{
68+
$finder = Finder::create()->in($dir)->files()->name('*.blade.php');
69+
$compiler = $this->container->get(CompilerInterface::class);
70+
foreach ($finder as $item) {
71+
$compiler->compile($item->getRealPath());
72+
$this->info(sprintf('File `%s` cache generation completed', $item->getRealPath()));
73+
}
74+
}
75+
}

‎app/Plugins/Topic/resources/views/create.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
</div>
8181
</div>
8282
<div class="col-12">
83-
@csrf()
83+
<x-csrf/>()
8484
<button class="btn btn-primary" type="submit">提交</button>
8585
</div>
8686
</div>

‎app/Plugins/Topic/resources/views/edit.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
</div>
8383
</div>
8484
<div class="col-12">
85-
@csrf()
85+
<x-csrf/>()
8686
<button timeout="1500" auto-event="disabled" class="btn btn-primary" type="submit">提交</button>
8787
</div>
8888
</div>

‎app/Plugins/User/resources/views/Admin/Users/edit.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
</div>
1515
<div class="card-body">
1616
<form action="/admin/users/{{$user->id}}/edit" method="post">
17-
@csrf()
17+
<x-csrf/>()
1818
<div class="mb-3">
1919
<label for="" class="form-label">用户名</label>
2020
<input class="form-control" type="text" name="username" value="{{$user->username}}">

‎app/Themes/CodeFec/resources/views/Pay/Paying/SFPay.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<a href="." class="navbar-brand navbar-brand-autodark"><img src="./static/logo.svg" height="36" alt=""></a>
1010
</div>
1111
<form class="card card-md" action="" method="post" autocomplete="off" novalidate>
12-
@csrf()
12+
<x-csrf/>()
1313
<div class="card-body text-center">
1414
<div class="mb-3">
1515
<h2 class="card-title">支付锁</h2>

‎app/View/Component/CsrfToken.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
class CsrfToken extends Component
99
{
10-
public $token;
10+
public mixed $token;
1111
public function __construct()
1212
{
1313
$this->token = csrf_token();

0 commit comments

Comments
 (0)
Please sign in to comment.