Skip to content

Commit

Permalink
chore: update some style, add some util methods
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Nov 5, 2021
1 parent af72751 commit 466ddff
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 8 deletions.
10 changes: 5 additions & 5 deletions app/Console/Command/ExprCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,18 @@ public function getFunctions(): array
* @options
* -i, --interactive bool;Start an interactive shell environment
*
* @param Input $input
* @param Output $output
*
* @return int
* @throws Throwable
* @example
* <code>$ {binWithCmd} -i</code>
* Expr > 45 + 45
* 90
* Expr > ret * 2
* 180
*
* @param Input $input
* @param Output $output
*
* @return int
* @throws Throwable
*/
protected function execute(Input $input, Output $output): int
{
Expand Down
25 changes: 25 additions & 0 deletions app/Helper/KiteUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,38 @@
use Toolkit\Stdlib\OS;
use Toolkit\Stdlib\Str;
use function dirname;
use function in_array;
use function is_file;

/**
* class KiteUtil
*/
class KiteUtil
{
public const STDIN_ALIAS = ['@i','@stdin',];
public const STDOUT_ALIAS = ['@o','@stdout',];

public const CLIPBOARD_ALIAS = ['@c','@cb','@clip','@clipboard',];

/**
* @param string $str
*
* @return bool
*/
public static function isStdinAlias(string $str): bool
{
return in_array($str, self::CLIPBOARD_ALIAS, true);
}

/**
* @param string $str
*
* @return bool
*/
public static function isClipboardAlias(string $str): bool
{
return in_array($str, self::CLIPBOARD_ALIAS, true);
}

/**
* @param string $path
Expand Down
8 changes: 6 additions & 2 deletions app/Lib/Generate/AbstractJsonToCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,13 @@ protected function readSourceFromFile(): string
// check from tplDir
if ($this->tplDir && !is_file($tplFile)) {
$tplDir = $this->resolvePath($this->tplDir);
$tplFile = File::joinPath($tplDir, $tplFile);
$dirFile = File::joinPath($tplDir, $tplFile);

File::assertIsFile($tplFile);
if (!is_file($dirFile)) {
throw new InvalidArgumentException("No such file: $tplFile");
}

$tplFile = $dirFile;
}

return File::readAll($tplFile);
Expand Down
15 changes: 15 additions & 0 deletions app/Lib/Stream/ListStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,21 @@ public function eachTo(callable $func, BaseStream $new): BaseStream
return $new;
}

/**
* @param callable(array): array $func
*
* @return array
*/
public function eachToArray(callable $func): array
{
$arr = [];
foreach ($this as $item) {
$arr[] = $func($item);
}

return $arr;
}

/**
* @param callable(array): array $func
* @param MapStream $new
Expand Down
2 changes: 1 addition & 1 deletion config/config.cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
],
// @see app/Console/Controller/PhpController.php
'php:serve' => [
'hce-file' => 'test/clienttest/http-client.env.json',
'hce-file' => 'test/httptest/http-client.env.json',
'hce-env' => getenv('APP_ENV') ?: 'development',
// 'entry' => 'public/index.php',
// document root
Expand Down

0 comments on commit 466ddff

Please sign in to comment.