-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: view command clear and cache (compailer)
- Loading branch information
1 parent
2a28eb6
commit f8efb33
Showing
3 changed files
with
109 additions
and
0 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,66 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace System\Integrate\Console; | ||
|
||
use System\Console\Command; | ||
use System\Console\Traits\PrintHelpTrait; | ||
|
||
use function System\Console\ok; | ||
use function System\Console\warn; | ||
|
||
class ViewCommand extends Command | ||
{ | ||
use PrintHelpTrait; | ||
|
||
/** | ||
* Register command. | ||
* | ||
* @var array<int, array<string, mixed>> | ||
*/ | ||
public static $command = [ | ||
[ | ||
'pattern' => 'view:cache', | ||
'fn' => [ViewCommand::class, 'cache'], | ||
], [ | ||
'pattern' => 'view:clear', | ||
'fn' => [ViewCommand::class, 'clear'], | ||
], | ||
]; | ||
|
||
/** | ||
* @return array<string, array<string, string|string[]>> | ||
*/ | ||
public function printHelp() | ||
{ | ||
return [ | ||
'commands' => [ | ||
'view:cache' => 'Create all templator template (optimize)', | ||
'view:clear' => 'Clear all cached view file', | ||
], | ||
'options' => [], | ||
'relation' => [], | ||
]; | ||
} | ||
|
||
public function cache(): int | ||
{ | ||
return 0; | ||
} | ||
|
||
public function clear(): int | ||
{ | ||
warn('Clear cache file in `{cache_path()}`.')->out(false); | ||
$files = glob(cache_path() . '/*.php'); | ||
foreach ($files as $file) { | ||
if (is_file($file)) { | ||
unlink($file); | ||
} | ||
} | ||
|
||
ok('Finish clear cache.')->out(); | ||
|
||
return 0; | ||
} | ||
} |
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,42 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace System\Test\Integrate\Commands; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use System\Integrate\Application; | ||
use System\Integrate\Console\ViewCommand; | ||
|
||
final class ViewCommandsTest extends TestCase | ||
{ | ||
/** | ||
* @test | ||
*/ | ||
public function itCanCompileFromTemplatorFiles(): void | ||
{ | ||
$this->markTestIncomplete('Wait new PR for handle tempaltor::compailer.'); | ||
$view_command = new ViewCommand(['php', 'cli', 'view:cache']); | ||
ob_start(); | ||
$exit = $view_command->cache(); | ||
ob_get_clean(); | ||
$this->assertEquals(0, $exit); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function itCanClearCompiledViewFile(): void | ||
{ | ||
// tests\Integrate\Commands\assets\view_cache | ||
(new Application(''))->setCachePath(__DIR__ . DIRECTORY_SEPARATOR . 'assets' . DIRECTORY_SEPARATOR . 'view_cache' . DIRECTORY_SEPARATOR); | ||
|
||
file_put_contents(cache_path() . 'test01.php', ''); | ||
file_put_contents(cache_path() . 'test02.php', ''); | ||
$view_command = new ViewCommand(['php', 'cli', 'view:clear']); | ||
ob_start(); | ||
$exit = $view_command->clear(); | ||
ob_get_clean(); | ||
$this->assertEquals(0, $exit); | ||
} | ||
} |
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 @@ | ||
*.php |