Skip to content

Commit

Permalink
update: update some for plugin config and run
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Nov 11, 2021
1 parent 6aeb326 commit b7832fb
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 22 deletions.
19 changes: 12 additions & 7 deletions app/Kite.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
namespace Inhere\Kite;

use BadMethodCallException;
use Composer\Autoload\ClassLoader;
use Inhere\Kite\Component\ScriptRunner;
use Inhere\Kite\Concern\StaticPathAliasTrait;
use Inhere\Kite\Console\CliApplication;
Expand All @@ -22,7 +23,6 @@
use Monolog\Logger;
use Toolkit\FsUtil\Dir;
use Toolkit\Stdlib\Obj\ObjectBox;
use Toolkit\Stdlib\OS;
use const BASE_PATH;
use const IN_PHAR;

Expand Down Expand Up @@ -50,19 +50,24 @@ class Kite
public const MODE_WEB = 'web';

/**
* @var ObjectBox
* @var ObjectBox|null
*/
private static $box;
private static ?ObjectBox $box = null;

/**
* @var CliApplication
*/
private static $cliApp;
private static CliApplication $cliApp;

/**
* @var WebApplication
*/
private static $webApp;
private static WebApplication $webApp;

/**
* @var ClassLoader
*/
// public static ClassLoader $loader;

/**
* @return ObjectBox
Expand Down Expand Up @@ -94,9 +99,9 @@ public static function __callStatic(string $method, array $args = [])
/**
* @param string $id
*
* @return mixed|object
* @return mixed
*/
public static function get(string $id)
public static function get(string $id): mixed
{
return self::box()->get($id);
}
Expand Down
5 changes: 2 additions & 3 deletions app/Lib/Generate/AbstractJsonToCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,6 @@ public function prepare(): self
protected function renderTplText(): string
{
$tplText = $this->readSourceFromFile();
$tplEng = KiteUtil::newTplEngine();

$settings = array_merge([
'lang' => 'java',
'user' => OS::getUserName(),
Expand All @@ -116,7 +114,8 @@ protected function renderTplText(): string
// 'fields' => $this->fields,
// ];

return $tplEng->renderString($tplText, $settings);
$tpl = KiteUtil::newTplEngine();
return $tpl->renderString($tplText, $settings);
}

/**
Expand Down
28 changes: 17 additions & 11 deletions app/Lib/Generate/Json5Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
*/
class Json5Data extends AbstractObj
{
/**
* @var array<string, mixed>
*/
private array $settings = [];

/**
Expand All @@ -33,13 +36,7 @@ class Json5Data extends AbstractObj
*/
public function loadFrom(string $json): self
{
// auto add quote char
if ($json[0] !== '{') {
$json = '{' . $json . "\n}";
}

$comments = [];
$jsonData = Json5Decoder::decode($json, true);

// has comments chars
if (str_contains($json, '//')) {
Expand All @@ -52,23 +49,32 @@ public function loadFrom(string $json): self
$header = substr($header, $pos + 4);
$header = str_replace("\n//", '', $header);
}

return $header;
})
->parse();

$comments = $p->getStringMap('field', 'comment');
$this->setSettings($p->getSettings());
// get no header json
$json = $p->getTextBody();
}

// auto add quote char
if ($json[0] !== '{') {
$json = '{' . $json . "\n}";
}

$jsonData = Json5Decoder::decode($json, true);
foreach ($jsonData as $key => $value) {
$this->fields[$key] = JsonField::new([
'name' => $key,
'type' => gettype($value),
'desc' => $comments[$key] ?? $key,
'name' => $key,
'type' => gettype($value),
'comment' => $comments[$key] ?? $key,
]);
}

return $this;
return $this;
}

/**
Expand All @@ -88,7 +94,7 @@ public function setSettings(array $settings): void
}

/**
* @return JsonField[]
* @return array<string, JsonField>
*/
public function getFields(): array
{
Expand Down
2 changes: 1 addition & 1 deletion app/Lib/Stream/ListStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function eachToMapStream(callable $func, MapStream $new): MapStream
}

/**
* @param callable(array): array $func
* @param callable(array): array{string, mixed} $func
*
* @return array<string, mixed>
*/
Expand Down
15 changes: 15 additions & 0 deletions app/Lib/Stream/MapStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,21 @@ public function eachTo(callable $func, BaseStream $new): BaseStream
return $new;
}

/**
* @param callable(array): mixed $func
*
* @return array<string, mixed>
*/
public function eachToMap(callable $func): array
{
$map = [];
foreach ($this as $key => $item) {
$map[$key] = $func($item);
}

return $map;
}

/**
* @param callable(array): bool $func
* @param bool|mixed $apply
Expand Down
4 changes: 4 additions & 0 deletions app/boot.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
$loader->addPsr4("PhpPkg\\EasyTpl\\", $baseDir . '/vendor/phppkg/easytpl/src/');
$loader->addPsr4("PhpPkg\\Config\\", $baseDir . '/vendor/phppkg/config/src/');
$loader->addPsr4("PhpPkg\\Ini\\", $baseDir . '/vendor/phppkg/ini/src/');
$loader->addPsr4("Custom\\Lib\\", $baseDir . '/custom/lib/');

// save loader for plugin manager
// Kite::$loader = $loader;

// user kite dirs
Kite::setAliases([
Expand Down
2 changes: 2 additions & 0 deletions config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@
// BASE_PATH . '/plugin'
$basePath . '/plugin',
$basePath . '/custom/plugin',
// dir => namespace. TODO
// $basePath . '/custom/plugin' => "Custom\\Plugin\\",
],
],
/** @see \Inhere\Kite\Component\ScriptRunner */
Expand Down

0 comments on commit b7832fb

Please sign in to comment.