Skip to content

Commit

Permalink
update: update some plugin logic
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Nov 8, 2021
1 parent 0f32934 commit bc57878
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 26 deletions.
24 changes: 0 additions & 24 deletions app/Common/IdeaHttp/BodyData.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,30 +52,6 @@ public function getValType(mixed $val): string
return Type::get($val);
}

/**
* @param array $data
*/
public function override(array $data): void
{
$this->exchangeArray($data);
}

/**
* @param array $data
* @param bool $override
*/
public function load(array $data, bool $override = false): void
{
if ($override) {
$this->override($data);
return;
}

foreach ($data as $key => $val) {
$this->offsetSet($key, $val);
}
}

/**
* @param int $limit
*
Expand Down
2 changes: 1 addition & 1 deletion app/Console/Controller/PhpController.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ public function csFixCommand(FlagsParser $fs, Output $output): void
*/
public function serveCommand(FlagsParser $fs, Output $output): void
{
$conf = $this->app->getArrayParam('php:serve');
$conf = $this->app->getArrayParam('php_serve');
if ($conf) {
$conf = array_merge(self::DEF_SERVE_CONF, $conf);

Expand Down
35 changes: 35 additions & 0 deletions app/Console/Plugin/AbstractPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Inhere\Console\Application;
use Inhere\Console\GlobalOption;
use Inhere\Console\IO\Output;
use Inhere\Kite\Lib\Template\SimpleTemplate;
use Toolkit\PFlag\Flags;
use Toolkit\PFlag\FlagsParser;
use Toolkit\Stdlib\Helper\DataHelper;
Expand Down Expand Up @@ -42,6 +43,11 @@ abstract class AbstractPlugin implements PluginInterface
*/
protected array $metadata = [];

public function __construct()
{
$this->createFlags();
}

public function init(): void
{
$this->metadata = array_merge([
Expand All @@ -64,6 +70,11 @@ protected function createAndInitFlags(): void
$fs->setExample($this->metadata['example']);
$fs->addOptsByRules(GlobalOption::getCommonOptions());

// replace help tpl vars
$fs->setBeforePrintHelp(function (string $help): string {
return $this->applyHelpVars($help);
});

$loaded = false;
if ($optRules = $this->options()) {
$loaded = true;
Expand Down Expand Up @@ -132,6 +143,16 @@ protected function arguments(): array
];
}

/**
* @return array
*/
protected function helpTplVars(): array
{
return [
'plugName' => $this->name,
];
}

/**
* @return array
*/
Expand Down Expand Up @@ -208,6 +229,20 @@ public function run(Application $app, array $args = []): void
*/
abstract public function exec(Application $app, Output $output): void;

/**
* replace help tpl vars
*
* @param string $help
*
* @return string
*/
protected function applyHelpVars(string $help): string
{
$tpl = SimpleTemplate::new(['format' => '${%s}']);

return $tpl->renderString($help, $this->helpTplVars());
}

/**
* @return string
*/
Expand Down
8 changes: 7 additions & 1 deletion app/Kite.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
use Monolog\Logger;
use Toolkit\FsUtil\Dir;
use Toolkit\Stdlib\Obj\ObjectBox;
use Toolkit\Stdlib\OS;
use const BASE_PATH;
use const IN_PHAR;

/**
* Class Kite
Expand Down Expand Up @@ -132,7 +134,11 @@ public static function basePath(bool $rmPharMark = true): string
*/
public static function getTmpPath(string $path): string
{
// TODO tmp path 不该跟着 kite 执行文件
if (IN_PHAR) {
// see app/boot.php
return self::resolve('@user-tmp');
}

return self::getPath("tmp/$path");
}

Expand Down

0 comments on commit bc57878

Please sign in to comment.