2021-04-07 23:50:11 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace Snowflake;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
use Console\Command;
|
2021-04-14 17:47:10 +08:00
|
|
|
use Exception;
|
2021-04-07 23:50:11 +08:00
|
|
|
use Snowflake\Abstracts\Input;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2021-04-09 09:55:30 +08:00
|
|
|
* Class Runtime
|
2021-04-07 23:50:11 +08:00
|
|
|
* @package Snowflake
|
|
|
|
|
*/
|
|
|
|
|
class Runtime extends Command
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
2021-05-18 10:28:04 +08:00
|
|
|
public string $command = 'runtime:builder';
|
2021-04-07 23:50:11 +08:00
|
|
|
|
2021-05-18 10:28:04 +08:00
|
|
|
public string $description = 'create app file cache';
|
2021-04-09 09:55:30 +08:00
|
|
|
|
2021-04-07 23:50:11 +08:00
|
|
|
|
2021-05-18 10:28:04 +08:00
|
|
|
const CACHE_NAME = '.runtime.cache';
|
|
|
|
|
const CONFIG_NAME = '.config.cache';
|
2021-05-04 03:43:22 +08:00
|
|
|
|
|
|
|
|
|
2021-04-09 09:51:17 +08:00
|
|
|
/**
|
|
|
|
|
* @param Input $dtl
|
2021-07-13 16:20:09 +08:00
|
|
|
* @return string
|
2021-04-14 17:47:10 +08:00
|
|
|
* @throws Exception
|
2021-04-09 09:51:17 +08:00
|
|
|
*/
|
2021-07-13 16:20:09 +08:00
|
|
|
public function onHandler(Input $dtl): string
|
2021-05-18 10:28:04 +08:00
|
|
|
{
|
|
|
|
|
// TODO: Implement onHandler() method.
|
|
|
|
|
$annotation = Snowflake::app()->getAnnotation();
|
|
|
|
|
|
|
|
|
|
$runtime = storage(static::CACHE_NAME);
|
2021-05-18 14:10:39 +08:00
|
|
|
$config = storage(static::CONFIG_NAME);
|
2021-05-18 10:28:04 +08:00
|
|
|
|
2021-05-18 14:10:39 +08:00
|
|
|
Snowflake::writeFile($config, $this->configEach());
|
2021-05-18 10:28:04 +08:00
|
|
|
Snowflake::writeFile($runtime, serialize($annotation->getLoader()));
|
2021-05-18 14:15:50 +08:00
|
|
|
|
|
|
|
|
return 'ok';
|
2021-05-18 10:28:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2021-05-18 14:10:39 +08:00
|
|
|
* @return string
|
2021-05-18 10:28:04 +08:00
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
2021-05-18 14:10:39 +08:00
|
|
|
public function configEach(): string
|
2021-05-18 10:28:04 +08:00
|
|
|
{
|
|
|
|
|
$array = [];
|
|
|
|
|
$configs = Snowflake::app()->getConfig();
|
|
|
|
|
foreach ($configs->getData() as $key => $datum) {
|
|
|
|
|
if ($datum instanceof \Closure) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (is_array($datum)) {
|
|
|
|
|
$array[$key] = $this->arrayEach($datum);
|
|
|
|
|
} else {
|
|
|
|
|
$array[$key] = $datum;
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-05-18 14:10:39 +08:00
|
|
|
return serialize($array);
|
2021-05-18 10:28:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param array $value
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
private function arrayEach(array $value): array
|
|
|
|
|
{
|
|
|
|
|
$array = [];
|
|
|
|
|
foreach ($value as $key => $item) {
|
|
|
|
|
if ($item instanceof \Closure) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (is_array($item)) {
|
|
|
|
|
$array[$key] = $this->arrayEach($item);
|
|
|
|
|
} else {
|
|
|
|
|
$array[$key] = $item;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return $array;
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-07 23:50:11 +08:00
|
|
|
|
|
|
|
|
}
|