Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3bdb091
commit 5a58361
Showing
6 changed files
with
80 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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())); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters