Skip to content

Commit

Permalink
更新:全面支持模板缓存
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuchunshu committed Dec 24, 2022
1 parent 3bdb091 commit 5a58361
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 5 deletions.
75 changes: 75 additions & 0 deletions app/Command/ViewEngineCache.php
@@ -0,0 +1,75 @@
<?php

declare(strict_types=1);
/**
* This file is part of zhuchunshu.
* @link https://github.com/zhuchunshu
* @document https://github.com/zhuchunshu/super-forum
* @contact laravel@88.com
* @license https://github.com/zhuchunshu/super-forum/blob/master/LICENSE
*/
namespace App\Command;

use Hyperf\Command\Annotation\Command;
use Hyperf\Command\Command as HyperfCommand;
use Hyperf\Contract\ConfigInterface;
use Hyperf\ViewEngine\Compiler\CompilerInterface;
use Psr\Container\ContainerInterface;
use Symfony\Component\Finder\Finder;

/**
* @Command
*/
#[Command]
class ViewEngineCache extends HyperfCommand
{
/**
* @var ContainerInterface
*/
protected $container;

public function __construct(ContainerInterface $container)
{
$this->container = $container;

parent::__construct('CodeFec:view-engine-cache');
}

public function configure()
{
parent::configure();
$this->setDescription('view-engine-cache');
}

public function handle()
{
$plugins = BASE_PATH . '/app/Plugins/';
$all = [];
foreach (plugins()->getEnPlugins() as $plugin) {
if (is_dir($plugins . $plugin)) {
$all[] = $plugins . $plugin . '/';
}
}
$all[] = BASE_PATH . '/app/Themes/';
$all[] = $this->container->get(ConfigInterface::class)->get('view.config.view_path');
foreach ($all as $item) {
$this->make($item);
}
}

/**
* 生成缓存.
* @param $dir
* @throws \Psr\Container\ContainerExceptionInterface
* @throws \Psr\Container\NotFoundExceptionInterface
*/
private function make($dir)
{
$finder = Finder::create()->in($dir)->files()->name('*.blade.php');
$compiler = $this->container->get(CompilerInterface::class);
foreach ($finder as $item) {
$compiler->compile($item->getRealPath());
$this->info(sprintf('File `%s` cache generation completed', $item->getRealPath()));
}
}
}
2 changes: 1 addition & 1 deletion app/Plugins/Topic/resources/views/create.blade.php
Expand Up @@ -80,7 +80,7 @@
</div>
</div>
<div class="col-12">
@csrf()
<x-csrf/>()
<button class="btn btn-primary" type="submit">提交</button>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/Plugins/Topic/resources/views/edit.blade.php
Expand Up @@ -82,7 +82,7 @@
</div>
</div>
<div class="col-12">
@csrf()
<x-csrf/>()
<button timeout="1500" auto-event="disabled" class="btn btn-primary" type="submit">提交</button>
</div>
</div>
Expand Down
Expand Up @@ -14,7 +14,7 @@
</div>
<div class="card-body">
<form action="/admin/users/{{$user->id}}/edit" method="post">
@csrf()
<x-csrf/>()
<div class="mb-3">
<label for="" class="form-label">用户名</label>
<input class="form-control" type="text" name="username" value="{{$user->username}}">
Expand Down
Expand Up @@ -9,7 +9,7 @@
<a href="." class="navbar-brand navbar-brand-autodark"><img src="./static/logo.svg" height="36" alt=""></a>
</div>
<form class="card card-md" action="" method="post" autocomplete="off" novalidate>
@csrf()
<x-csrf/>()
<div class="card-body text-center">
<div class="mb-3">
<h2 class="card-title">支付锁</h2>
Expand Down
2 changes: 1 addition & 1 deletion app/View/Component/CsrfToken.php
Expand Up @@ -7,7 +7,7 @@

class CsrfToken extends Component
{
public $token;
public mixed $token;
public function __construct()
{
$this->token = csrf_token();
Expand Down

0 comments on commit 5a58361

Please sign in to comment.