repository_name stringlengths 5 67 | func_path_in_repository stringlengths 4 234 | func_name stringlengths 0 314 | whole_func_string stringlengths 52 3.87M | language stringclasses 6
values | func_code_string stringlengths 52 3.87M | func_code_tokens listlengths 15 672k | func_documentation_string stringlengths 1 47.2k | func_documentation_tokens listlengths 1 3.92k | split_name stringclasses 1
value | func_code_url stringlengths 85 339 |
|---|---|---|---|---|---|---|---|---|---|---|
inhere/php-console | src/BuiltIn/PharController.php | PharController.unpackCommand | public function unpackCommand($in, $out): int
{
if (!$path = $in->getSameOpt(['f', 'file'])) {
return $out->error("Please input the phar file path by option '-f|--file'");
}
$basePath = $in->getPwd();
$file = \realpath($basePath . '/' . $path);
if (!\file_exists... | php | public function unpackCommand($in, $out): int
{
if (!$path = $in->getSameOpt(['f', 'file'])) {
return $out->error("Please input the phar file path by option '-f|--file'");
}
$basePath = $in->getPwd();
$file = \realpath($basePath . '/' . $path);
if (!\file_exists... | [
"public",
"function",
"unpackCommand",
"(",
"$",
"in",
",",
"$",
"out",
")",
":",
"int",
"{",
"if",
"(",
"!",
"$",
"path",
"=",
"$",
"in",
"->",
"getSameOpt",
"(",
"[",
"'f'",
",",
"'file'",
"]",
")",
")",
"{",
"return",
"$",
"out",
"->",
"erro... | unpack a phar package to a directory
@usage {fullCommand} -f FILE [-d DIR]
@options
-f, --file STRING The packed phar file path
-d, --dir STRING The output dir on extract phar package.
-y, --yes BOOL Whether display goon tips message.
--overwrite BOOL Whether overwrite exists files on extract phar
@example... | [
"unpack",
"a",
"phar",
"package",
"to",
"a",
"directory"
] | train | https://github.com/inhere/php-console/blob/d08a0a70fbcfecf6289db6b1a23582eeff32d4a7/src/BuiltIn/PharController.php#L163-L190 |
inhere/php-console | src/Component/Progress/SimpleTextBar.php | SimpleTextBar.gen | public static function gen(int $total, string $msg, string $doneMsg = ''): \Generator
{
$current = 0;
$finished = false;
$tpl = (Cli::isSupportColor() ? "\x0D\x1B[2K" : "\x0D\r") . "%' 3d%% %s";
$msg = Console::style()->render($msg);
$doneMsg = $doneMsg ? Console:... | php | public static function gen(int $total, string $msg, string $doneMsg = ''): \Generator
{
$current = 0;
$finished = false;
$tpl = (Cli::isSupportColor() ? "\x0D\x1B[2K" : "\x0D\r") . "%' 3d%% %s";
$msg = Console::style()->render($msg);
$doneMsg = $doneMsg ? Console:... | [
"public",
"static",
"function",
"gen",
"(",
"int",
"$",
"total",
",",
"string",
"$",
"msg",
",",
"string",
"$",
"doneMsg",
"=",
"''",
")",
":",
"\\",
"Generator",
"{",
"$",
"current",
"=",
"0",
";",
"$",
"finished",
"=",
"false",
";",
"$",
"tpl",
... | Render a simple text progress bar by 'yield'
@param int $total
@param string $msg
@param string $doneMsg
@return \Generator | [
"Render",
"a",
"simple",
"text",
"progress",
"bar",
"by",
"yield"
] | train | https://github.com/inhere/php-console/blob/d08a0a70fbcfecf6289db6b1a23582eeff32d4a7/src/Component/Progress/SimpleTextBar.php#L22-L62 |
inhere/php-console | src/Component/Interact/Checkbox.php | Checkbox.select | public static function select(string $description, $options, $default = null, $allowExit = true): array
{
if (!$description = \trim($description)) {
Show::error('Please provide a description text!', 1);
}
$sep = ','; // ',' ' '
$options = \is_array($options) ? $optio... | php | public static function select(string $description, $options, $default = null, $allowExit = true): array
{
if (!$description = \trim($description)) {
Show::error('Please provide a description text!', 1);
}
$sep = ','; // ',' ' '
$options = \is_array($options) ? $optio... | [
"public",
"static",
"function",
"select",
"(",
"string",
"$",
"description",
",",
"$",
"options",
",",
"$",
"default",
"=",
"null",
",",
"$",
"allowExit",
"=",
"true",
")",
":",
"array",
"{",
"if",
"(",
"!",
"$",
"description",
"=",
"\\",
"trim",
"("... | List multiple options and allow multiple selections
@param string $description
@param string|array $options
@param null|mixed $default
@param bool $allowExit
@return array | [
"List",
"multiple",
"options",
"and",
"allow",
"multiple",
"selections"
] | train | https://github.com/inhere/php-console/blob/d08a0a70fbcfecf6289db6b1a23582eeff32d4a7/src/Component/Interact/Checkbox.php#L25-L76 |
inhere/php-console | src/BuiltIn/DevServerCommand.php | DevServerCommand.execute | public function execute($in, $out)
{
if (!$server = $this->getOpt('S')) {
$server = $this->getSameOpt(['H', 'host'], '127.0.0.1');
}
if (!\strpos($server, ':')) {
$port = $this->getSameOpt(['p', 'port'], 8552);
$server .= ':' . $port;
}
$... | php | public function execute($in, $out)
{
if (!$server = $this->getOpt('S')) {
$server = $this->getSameOpt(['H', 'host'], '127.0.0.1');
}
if (!\strpos($server, ':')) {
$port = $this->getSameOpt(['p', 'port'], 8552);
$server .= ':' . $port;
}
$... | [
"public",
"function",
"execute",
"(",
"$",
"in",
",",
"$",
"out",
")",
"{",
"if",
"(",
"!",
"$",
"server",
"=",
"$",
"this",
"->",
"getOpt",
"(",
"'S'",
")",
")",
"{",
"$",
"server",
"=",
"$",
"this",
"->",
"getSameOpt",
"(",
"[",
"'H'",
",",
... | start a php built-in http server for development
@usage
{command} [-S HOST:PORT]
{command} [-H HOST] [-p PORT]
{command} [-S HOST:PORT] [file=]web/index.php
@options
-S STRING The http server address. e.g 127.0.0.1:8552
-t STRING The document root dir for server(<comment>web</comment>)
-H,--... | [
"start",
"a",
"php",
"built",
"-",
"in",
"http",
"server",
"for",
"development"
] | train | https://github.com/inhere/php-console/blob/d08a0a70fbcfecf6289db6b1a23582eeff32d4a7/src/BuiltIn/DevServerCommand.php#L48-L84 |
inhere/php-console | src/Component/Formatter/Panel.php | Panel.show | public static function show($data, string $title = 'Information Panel', array $opts = []): int
{
if (!$data) {
Console::write('<info>No data to display!</info>');
return -2;
}
$opts = \array_merge([
'borderChar' => '*',
'ucFirst' => true,
... | php | public static function show($data, string $title = 'Information Panel', array $opts = []): int
{
if (!$data) {
Console::write('<info>No data to display!</info>');
return -2;
}
$opts = \array_merge([
'borderChar' => '*',
'ucFirst' => true,
... | [
"public",
"static",
"function",
"show",
"(",
"$",
"data",
",",
"string",
"$",
"title",
"=",
"'Information Panel'",
",",
"array",
"$",
"opts",
"=",
"[",
"]",
")",
":",
"int",
"{",
"if",
"(",
"!",
"$",
"data",
")",
"{",
"Console",
"::",
"write",
"(",... | Show information data panel
@param mixed $data
@param string $title
@param array $opts
@return int | [
"Show",
"information",
"data",
"panel"
] | train | https://github.com/inhere/php-console/blob/d08a0a70fbcfecf6289db6b1a23582eeff32d4a7/src/Component/Formatter/Panel.php#L81-L178 |
inhere/php-console | src/Component/Symbol/ArtFont.php | ArtFont.loadInternalFonts | protected function loadInternalFonts(): void
{
$path = \dirname(__DIR__) . '/BuiltIn/Resources/art-fonts/';
$group = self::INTERNAL_GROUP;
foreach (self::$internalFonts as $font) {
$this->fonts[$group][$font] = $path . $font . '%s.txt';
}
$this->groups[$group] =... | php | protected function loadInternalFonts(): void
{
$path = \dirname(__DIR__) . '/BuiltIn/Resources/art-fonts/';
$group = self::INTERNAL_GROUP;
foreach (self::$internalFonts as $font) {
$this->fonts[$group][$font] = $path . $font . '%s.txt';
}
$this->groups[$group] =... | [
"protected",
"function",
"loadInternalFonts",
"(",
")",
":",
"void",
"{",
"$",
"path",
"=",
"\\",
"dirname",
"(",
"__DIR__",
")",
".",
"'/BuiltIn/Resources/art-fonts/'",
";",
"$",
"group",
"=",
"self",
"::",
"INTERNAL_GROUP",
";",
"foreach",
"(",
"self",
"::... | load Internal Fonts | [
"load",
"Internal",
"Fonts"
] | train | https://github.com/inhere/php-console/blob/d08a0a70fbcfecf6289db6b1a23582eeff32d4a7/src/Component/Symbol/ArtFont.php#L75-L85 |
inhere/php-console | src/Component/Symbol/ArtFont.php | ArtFont.showInternal | public function showInternal(string $name, array $opts = []): int
{
return $this->show($name, self::INTERNAL_GROUP, $opts);
} | php | public function showInternal(string $name, array $opts = []): int
{
return $this->show($name, self::INTERNAL_GROUP, $opts);
} | [
"public",
"function",
"showInternal",
"(",
"string",
"$",
"name",
",",
"array",
"$",
"opts",
"=",
"[",
"]",
")",
":",
"int",
"{",
"return",
"$",
"this",
"->",
"show",
"(",
"$",
"name",
",",
"self",
"::",
"INTERNAL_GROUP",
",",
"$",
"opts",
")",
";"... | display the internal art font
@param string $name
@param array $opts
@return int | [
"display",
"the",
"internal",
"art",
"font"
] | train | https://github.com/inhere/php-console/blob/d08a0a70fbcfecf6289db6b1a23582eeff32d4a7/src/Component/Symbol/ArtFont.php#L93-L96 |
inhere/php-console | src/Component/Symbol/ArtFont.php | ArtFont.show | public function show(string $name, string $group = null, array $opts = []): int
{
$opts = array_merge([
'type' => '',
'indent' => 2,
'style' => '',
], $opts);
$type = $opts['type'];
$pfxType = $type ? '_' . $type : '';
$txt = '';
... | php | public function show(string $name, string $group = null, array $opts = []): int
{
$opts = array_merge([
'type' => '',
'indent' => 2,
'style' => '',
], $opts);
$type = $opts['type'];
$pfxType = $type ? '_' . $type : '';
$txt = '';
... | [
"public",
"function",
"show",
"(",
"string",
"$",
"name",
",",
"string",
"$",
"group",
"=",
"null",
",",
"array",
"$",
"opts",
"=",
"[",
"]",
")",
":",
"int",
"{",
"$",
"opts",
"=",
"array_merge",
"(",
"[",
"'type'",
"=>",
"''",
",",
"'indent'",
... | display the art font
@param string $name
@param string $group
@param array $opts
contains:
- type => '', // 'italic'
- indent => 2,
- style => '', // 'info' 'error'
@return int | [
"display",
"the",
"art",
"font"
] | train | https://github.com/inhere/php-console/blob/d08a0a70fbcfecf6289db6b1a23582eeff32d4a7/src/Component/Symbol/ArtFont.php#L122-L160 |
inhere/php-console | src/Traits/SimpleEventTrait.php | SimpleEventTrait.on | public function on(string $event, callable $handler, $once = false): void
{
if (self::isSupportedEvent($event)) {
self::$eventHandlers[$event][] = $handler;
if (!isset(self::$events[$event])) {
self::$events[$event] = (bool)$once;
}
}
} | php | public function on(string $event, callable $handler, $once = false): void
{
if (self::isSupportedEvent($event)) {
self::$eventHandlers[$event][] = $handler;
if (!isset(self::$events[$event])) {
self::$events[$event] = (bool)$once;
}
}
} | [
"public",
"function",
"on",
"(",
"string",
"$",
"event",
",",
"callable",
"$",
"handler",
",",
"$",
"once",
"=",
"false",
")",
":",
"void",
"{",
"if",
"(",
"self",
"::",
"isSupportedEvent",
"(",
"$",
"event",
")",
")",
"{",
"self",
"::",
"$",
"even... | register a event handler
@param $event
@param callable $handler
@param bool $once | [
"register",
"a",
"event",
"handler"
] | train | https://github.com/inhere/php-console/blob/d08a0a70fbcfecf6289db6b1a23582eeff32d4a7/src/Traits/SimpleEventTrait.php#L48-L57 |
inhere/php-console | src/Traits/SimpleEventTrait.php | SimpleEventTrait.once | public function once(string $event, callable $handler): void
{
$this->on($event, $handler, true);
} | php | public function once(string $event, callable $handler): void
{
$this->on($event, $handler, true);
} | [
"public",
"function",
"once",
"(",
"string",
"$",
"event",
",",
"callable",
"$",
"handler",
")",
":",
"void",
"{",
"$",
"this",
"->",
"on",
"(",
"$",
"event",
",",
"$",
"handler",
",",
"true",
")",
";",
"}"
] | register a once event handler
@param $event
@param callable $handler | [
"register",
"a",
"once",
"event",
"handler"
] | train | https://github.com/inhere/php-console/blob/d08a0a70fbcfecf6289db6b1a23582eeff32d4a7/src/Traits/SimpleEventTrait.php#L64-L67 |
inhere/php-console | src/Traits/SimpleEventTrait.php | SimpleEventTrait.fire | public function fire(string $event, ...$args): bool
{
if (!isset(self::$events[$event])) {
return false;
}
// call event handlers of the event.
foreach ((array)self::$eventHandlers[$event] as $cb) {
// return FALSE to stop go on handle.
if (false ... | php | public function fire(string $event, ...$args): bool
{
if (!isset(self::$events[$event])) {
return false;
}
// call event handlers of the event.
foreach ((array)self::$eventHandlers[$event] as $cb) {
// return FALSE to stop go on handle.
if (false ... | [
"public",
"function",
"fire",
"(",
"string",
"$",
"event",
",",
"...",
"$",
"args",
")",
":",
"bool",
"{",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"events",
"[",
"$",
"event",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"// call eve... | trigger event
@param string $event
@param array ...$args
@return bool | [
"trigger",
"event"
] | train | https://github.com/inhere/php-console/blob/d08a0a70fbcfecf6289db6b1a23582eeff32d4a7/src/Traits/SimpleEventTrait.php#L75-L95 |
inhere/php-console | src/Traits/SimpleEventTrait.php | SimpleEventTrait.off | public function off(string $event): bool
{
if ($this->hasEvent($event)) {
unset(self::$events[$event], self::$eventHandlers[$event]);
return true;
}
return false;
} | php | public function off(string $event): bool
{
if ($this->hasEvent($event)) {
unset(self::$events[$event], self::$eventHandlers[$event]);
return true;
}
return false;
} | [
"public",
"function",
"off",
"(",
"string",
"$",
"event",
")",
":",
"bool",
"{",
"if",
"(",
"$",
"this",
"->",
"hasEvent",
"(",
"$",
"event",
")",
")",
"{",
"unset",
"(",
"self",
"::",
"$",
"events",
"[",
"$",
"event",
"]",
",",
"self",
"::",
"... | remove event and it's handlers
@param $event
@return bool | [
"remove",
"event",
"and",
"it",
"s",
"handlers"
] | train | https://github.com/inhere/php-console/blob/d08a0a70fbcfecf6289db6b1a23582eeff32d4a7/src/Traits/SimpleEventTrait.php#L102-L111 |
inhere/php-console | src/Traits/SimpleEventTrait.php | SimpleEventTrait.isSupportedEvent | public static function isSupportedEvent(string $event): bool
{
if (!$event || !preg_match('/[a-zA-z][\w-]+/', $event)) {
return false;
}
if ($ets = self::$supportedEvents) {
return \in_array($event, $ets, true);
}
return true;
} | php | public static function isSupportedEvent(string $event): bool
{
if (!$event || !preg_match('/[a-zA-z][\w-]+/', $event)) {
return false;
}
if ($ets = self::$supportedEvents) {
return \in_array($event, $ets, true);
}
return true;
} | [
"public",
"static",
"function",
"isSupportedEvent",
"(",
"string",
"$",
"event",
")",
":",
"bool",
"{",
"if",
"(",
"!",
"$",
"event",
"||",
"!",
"preg_match",
"(",
"'/[a-zA-z][\\w-]+/'",
",",
"$",
"event",
")",
")",
"{",
"return",
"false",
";",
"}",
"i... | check $name is a supported event name
@param string $event
@return bool | [
"check",
"$name",
"is",
"a",
"supported",
"event",
"name"
] | train | https://github.com/inhere/php-console/blob/d08a0a70fbcfecf6289db6b1a23582eeff32d4a7/src/Traits/SimpleEventTrait.php#L140-L151 |
inhere/php-console | src/Component/Style/Style.php | Style.loadDefaultStyles | protected function loadDefaultStyles(): void
{
$this
->addByArray(self::NORMAL, ['fg' => 'normal'])
// 不明显的 浅灰色的
->addByArray(self::FAINTLY, ['fg' => 'normal', 'options' => ['italic']])
->addByArray(self::BOLD, ['options' => ['bold']])
->addByArray... | php | protected function loadDefaultStyles(): void
{
$this
->addByArray(self::NORMAL, ['fg' => 'normal'])
// 不明显的 浅灰色的
->addByArray(self::FAINTLY, ['fg' => 'normal', 'options' => ['italic']])
->addByArray(self::BOLD, ['options' => ['bold']])
->addByArray... | [
"protected",
"function",
"loadDefaultStyles",
"(",
")",
":",
"void",
"{",
"$",
"this",
"->",
"addByArray",
"(",
"self",
"::",
"NORMAL",
",",
"[",
"'fg'",
"=>",
"'normal'",
"]",
")",
"// 不明显的 浅灰色的",
"->",
"addByArray",
"(",
"self",
"::",
"FAINTLY",
",",
"... | Adds predefined color styles to the Color styles
default primary success info warning danger | [
"Adds",
"predefined",
"color",
"styles",
"to",
"the",
"Color",
"styles",
"default",
"primary",
"success",
"info",
"warning",
"danger"
] | train | https://github.com/inhere/php-console/blob/d08a0a70fbcfecf6289db6b1a23582eeff32d4a7/src/Component/Style/Style.php#L116-L141 |
inhere/php-console | src/Component/Style/Style.php | Style.apply | public function apply(string $style, string $text): string
{
return $this->format(self::wrap($text, $style));
} | php | public function apply(string $style, string $text): string
{
return $this->format(self::wrap($text, $style));
} | [
"public",
"function",
"apply",
"(",
"string",
"$",
"style",
",",
"string",
"$",
"text",
")",
":",
"string",
"{",
"return",
"$",
"this",
"->",
"format",
"(",
"self",
"::",
"wrap",
"(",
"$",
"text",
",",
"$",
"style",
")",
")",
";",
"}"
] | Process a string use style
@param string $style
@param string $text
@return string | [
"Process",
"a",
"string",
"use",
"style"
] | train | https://github.com/inhere/php-console/blob/d08a0a70fbcfecf6289db6b1a23582eeff32d4a7/src/Component/Style/Style.php#L149-L152 |
inhere/php-console | src/Component/Style/Style.php | Style.replaceColor | protected function replaceColor($text, $tag, $match, $style): string
{
$replace = self::$noColor ? $match : sprintf("\033[%sm%s\033[0m", $style, $match);
return \str_replace("<$tag>$match</$tag>", $replace, $text);
// return sprintf("\033[%sm%s\033[%sm", implode(';', $setCodes), $text, impl... | php | protected function replaceColor($text, $tag, $match, $style): string
{
$replace = self::$noColor ? $match : sprintf("\033[%sm%s\033[0m", $style, $match);
return \str_replace("<$tag>$match</$tag>", $replace, $text);
// return sprintf("\033[%sm%s\033[%sm", implode(';', $setCodes), $text, impl... | [
"protected",
"function",
"replaceColor",
"(",
"$",
"text",
",",
"$",
"tag",
",",
"$",
"match",
",",
"$",
"style",
")",
":",
"string",
"{",
"$",
"replace",
"=",
"self",
"::",
"$",
"noColor",
"?",
"$",
"match",
":",
"sprintf",
"(",
"\"\\033[%sm%s\\033[0m... | Replace color tags in a string.
@param string $text
@param string $tag The matched tag.
@param string $match The match.
@param string $style The color style to apply.
@return string | [
"Replace",
"color",
"tags",
"in",
"a",
"string",
"."
] | train | https://github.com/inhere/php-console/blob/d08a0a70fbcfecf6289db6b1a23582eeff32d4a7/src/Component/Style/Style.php#L216-L222 |
inhere/php-console | src/Component/Style/Style.php | Style.add | public function add(string $name, $fg = '', $bg = '', array $options = [], bool $extra = false): self
{
if (\is_array($fg)) {
return $this->addByArray($name, $fg);
}
if (\is_object($fg) && $fg instanceof Color) {
$this->styles[$name] = $fg;
} else {
... | php | public function add(string $name, $fg = '', $bg = '', array $options = [], bool $extra = false): self
{
if (\is_array($fg)) {
return $this->addByArray($name, $fg);
}
if (\is_object($fg) && $fg instanceof Color) {
$this->styles[$name] = $fg;
} else {
... | [
"public",
"function",
"add",
"(",
"string",
"$",
"name",
",",
"$",
"fg",
"=",
"''",
",",
"$",
"bg",
"=",
"''",
",",
"array",
"$",
"options",
"=",
"[",
"]",
",",
"bool",
"$",
"extra",
"=",
"false",
")",
":",
"self",
"{",
"if",
"(",
"\\",
"is_a... | Add a style.
@param string $name
@param string|Color|array $fg 前景色|Color对象|也可以是style配置数组(@see self::addByArray())
当它为Color对象或配置数组时,后面两个参数无效
@param string $bg 背景色
@param array $options 其它选项
@param bool $extra
@return $this | [
"Add",
"a",
"style",
"."
] | train | https://github.com/inhere/php-console/blob/d08a0a70fbcfecf6289db6b1a23582eeff32d4a7/src/Component/Style/Style.php#L248-L261 |
inhere/php-console | src/Component/Style/Style.php | Style.addByArray | public function addByArray(string $name, array $styleConfig): self
{
$style = [
'fg' => '',
'bg' => '',
'extra' => false,
'options' => []
];
$config = \array_merge($style, $styleConfig);
[$fg, $bg, $extra, $options] = \arra... | php | public function addByArray(string $name, array $styleConfig): self
{
$style = [
'fg' => '',
'bg' => '',
'extra' => false,
'options' => []
];
$config = \array_merge($style, $styleConfig);
[$fg, $bg, $extra, $options] = \arra... | [
"public",
"function",
"addByArray",
"(",
"string",
"$",
"name",
",",
"array",
"$",
"styleConfig",
")",
":",
"self",
"{",
"$",
"style",
"=",
"[",
"'fg'",
"=>",
"''",
",",
"'bg'",
"=>",
"''",
",",
"'extra'",
"=>",
"false",
",",
"'options'",
"=>",
"[",
... | Add a style by an array config
@param string $name
@param array $styleConfig 样式设置信息
e.g
[
'fg' => 'white',
'bg' => 'black',
'extra' => true,
'options' => ['bold', 'underscore']
]
@return $this | [
"Add",
"a",
"style",
"by",
"an",
"array",
"config"
] | train | https://github.com/inhere/php-console/blob/d08a0a70fbcfecf6289db6b1a23582eeff32d4a7/src/Component/Style/Style.php#L276-L291 |
inhere/php-console | src/Component/Formatter/MultiList.php | MultiList.show | public static function show(array $data, array $opts = []): void
{
$stringList = [];
$ignoreEmpty = $opts['ignoreEmpty'] ?? true;
$lastNewline = true;
$opts['returned'] = true;
if (isset($opts['lastNewline'])) {
$lastNewline = $opts['lastNewline'];
un... | php | public static function show(array $data, array $opts = []): void
{
$stringList = [];
$ignoreEmpty = $opts['ignoreEmpty'] ?? true;
$lastNewline = true;
$opts['returned'] = true;
if (isset($opts['lastNewline'])) {
$lastNewline = $opts['lastNewline'];
un... | [
"public",
"static",
"function",
"show",
"(",
"array",
"$",
"data",
",",
"array",
"$",
"opts",
"=",
"[",
"]",
")",
":",
"void",
"{",
"$",
"stringList",
"=",
"[",
"]",
";",
"$",
"ignoreEmpty",
"=",
"$",
"opts",
"[",
"'ignoreEmpty'",
"]",
"??",
"true"... | Format and render multi list
```php
[
'list1 title' => [
'name' => 'value text',
'name2' => 'value text 2',
],
'list2 title' => [
'name' => 'value text',
'name2' => 'value text 2',
],
... ...
]
```
@param array $data
@param array $opts | [
"Format",
"and",
"render",
"multi",
"list"
] | train | https://github.com/inhere/php-console/blob/d08a0a70fbcfecf6289db6b1a23582eeff32d4a7/src/Component/Formatter/MultiList.php#L33-L54 |
inhere/php-console | examples/demo/sf2_color.php | OutputFormatterStyle.setForeground | public function setForeground($color = null)
{
if (null === $color) {
$this->foreground = null;
return;
}
if (!isset(static::$availableForegroundColors[$color])) {
throw new \InvalidArgumentException(sprintf(
'Invalid foreground color speci... | php | public function setForeground($color = null)
{
if (null === $color) {
$this->foreground = null;
return;
}
if (!isset(static::$availableForegroundColors[$color])) {
throw new \InvalidArgumentException(sprintf(
'Invalid foreground color speci... | [
"public",
"function",
"setForeground",
"(",
"$",
"color",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"color",
")",
"{",
"$",
"this",
"->",
"foreground",
"=",
"null",
";",
"return",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"static",
"::",
... | Sets style foreground color.
@param string|null $color The color name
@throws \InvalidArgumentException When the color name isn't defined | [
"Sets",
"style",
"foreground",
"color",
"."
] | train | https://github.com/inhere/php-console/blob/d08a0a70fbcfecf6289db6b1a23582eeff32d4a7/examples/demo/sf2_color.php#L77-L91 |
inhere/php-console | examples/demo/sf2_color.php | OutputFormatterStyle.setBackground | public function setBackground($color = null)
{
if (null === $color) {
$this->background = null;
return;
}
if (!isset(static::$availableBackgroundColors[$color])) {
throw new \InvalidArgumentException(sprintf(
'Invalid background color speci... | php | public function setBackground($color = null)
{
if (null === $color) {
$this->background = null;
return;
}
if (!isset(static::$availableBackgroundColors[$color])) {
throw new \InvalidArgumentException(sprintf(
'Invalid background color speci... | [
"public",
"function",
"setBackground",
"(",
"$",
"color",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"color",
")",
"{",
"$",
"this",
"->",
"background",
"=",
"null",
";",
"return",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"static",
"::",
... | Sets style background color.
@param string|null $color The color name
@throws \InvalidArgumentException When the color name isn't defined | [
"Sets",
"style",
"background",
"color",
"."
] | train | https://github.com/inhere/php-console/blob/d08a0a70fbcfecf6289db6b1a23582eeff32d4a7/examples/demo/sf2_color.php#L99-L113 |
inhere/php-console | examples/demo/sf2_color.php | OutputFormatterStyle.setOption | public function setOption($option)
{
if (!isset(static::$availableOptions[$option])) {
throw new \InvalidArgumentException(sprintf(
'Invalid option specified: "%s". Expected one of (%s)',
$option,
implode(', ', array_keys(static::$availableOptions)... | php | public function setOption($option)
{
if (!isset(static::$availableOptions[$option])) {
throw new \InvalidArgumentException(sprintf(
'Invalid option specified: "%s". Expected one of (%s)',
$option,
implode(', ', array_keys(static::$availableOptions)... | [
"public",
"function",
"setOption",
"(",
"$",
"option",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"static",
"::",
"$",
"availableOptions",
"[",
"$",
"option",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Inval... | Sets some specific style option.
@param string $option The option name
@throws \InvalidArgumentException When the option name isn't defined | [
"Sets",
"some",
"specific",
"style",
"option",
"."
] | train | https://github.com/inhere/php-console/blob/d08a0a70fbcfecf6289db6b1a23582eeff32d4a7/examples/demo/sf2_color.php#L121-L133 |
inhere/php-console | examples/demo/sf2_color.php | OutputFormatterStyle.unsetOption | public function unsetOption($option)
{
if (!isset(static::$availableOptions[$option])) {
throw new \InvalidArgumentException(sprintf(
'Invalid option specified: "%s". Expected one of (%s)',
$option,
implode(', ', array_keys(static::$availableOption... | php | public function unsetOption($option)
{
if (!isset(static::$availableOptions[$option])) {
throw new \InvalidArgumentException(sprintf(
'Invalid option specified: "%s". Expected one of (%s)',
$option,
implode(', ', array_keys(static::$availableOption... | [
"public",
"function",
"unsetOption",
"(",
"$",
"option",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"static",
"::",
"$",
"availableOptions",
"[",
"$",
"option",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Inv... | Unsets some specific style option.
@param string $option The option name
@throws \InvalidArgumentException When the option name isn't defined | [
"Unsets",
"some",
"specific",
"style",
"option",
"."
] | train | https://github.com/inhere/php-console/blob/d08a0a70fbcfecf6289db6b1a23582eeff32d4a7/examples/demo/sf2_color.php#L141-L154 |
inhere/php-console | examples/demo/sf2_color.php | OutputFormatterStyle.apply | public function apply($text)
{
$setCodes = array();
$unsetCodes = array();
if (null !== $this->foreground) {
$setCodes[] = $this->foreground['set'];
$unsetCodes[] = $this->foreground['unset'];
}
if (null !== $this->background) {
$setCodes[]... | php | public function apply($text)
{
$setCodes = array();
$unsetCodes = array();
if (null !== $this->foreground) {
$setCodes[] = $this->foreground['set'];
$unsetCodes[] = $this->foreground['unset'];
}
if (null !== $this->background) {
$setCodes[]... | [
"public",
"function",
"apply",
"(",
"$",
"text",
")",
"{",
"$",
"setCodes",
"=",
"array",
"(",
")",
";",
"$",
"unsetCodes",
"=",
"array",
"(",
")",
";",
"if",
"(",
"null",
"!==",
"$",
"this",
"->",
"foreground",
")",
"{",
"$",
"setCodes",
"[",
"]... | Applies the style to a given text.
@param string $text The text to style
@return string | [
"Applies",
"the",
"style",
"to",
"a",
"given",
"text",
"."
] | train | https://github.com/inhere/php-console/blob/d08a0a70fbcfecf6289db6b1a23582eeff32d4a7/examples/demo/sf2_color.php#L174-L196 |
inhere/php-console | src/Util/Interact.php | Interact.readln | public static function readln($message = null, $nl = false, array $opts = []): string
{
if ($message) {
Console::write($message, $nl);
}
$stream = $opts['stream'] ?? \STDIN;
return \trim(fgets($stream));
} | php | public static function readln($message = null, $nl = false, array $opts = []): string
{
if ($message) {
Console::write($message, $nl);
}
$stream = $opts['stream'] ?? \STDIN;
return \trim(fgets($stream));
} | [
"public",
"static",
"function",
"readln",
"(",
"$",
"message",
"=",
"null",
",",
"$",
"nl",
"=",
"false",
",",
"array",
"$",
"opts",
"=",
"[",
"]",
")",
":",
"string",
"{",
"if",
"(",
"$",
"message",
")",
"{",
"Console",
"::",
"write",
"(",
"$",
... | read line from CLI input
@param mixed $message
@param bool $nl
@param array $opts
[
'stream' => \STDIN
]
@return string | [
"read",
"line",
"from",
"CLI",
"input"
] | train | https://github.com/inhere/php-console/blob/d08a0a70fbcfecf6289db6b1a23582eeff32d4a7/src/Util/Interact.php#L35-L44 |
inhere/php-console | src/Util/Interact.php | Interact.select | public static function select(string $description, $options, $default = null, bool $allowExit = true): string
{
return self::choice($description, $options, $default, $allowExit);
} | php | public static function select(string $description, $options, $default = null, bool $allowExit = true): string
{
return self::choice($description, $options, $default, $allowExit);
} | [
"public",
"static",
"function",
"select",
"(",
"string",
"$",
"description",
",",
"$",
"options",
",",
"$",
"default",
"=",
"null",
",",
"bool",
"$",
"allowExit",
"=",
"true",
")",
":",
"string",
"{",
"return",
"self",
"::",
"choice",
"(",
"$",
"descri... | alias of the `select()`
@param string $description 说明
@param string|array $options 选项数据
@param int|string $default 默认选项
@param bool $allowExit 有退出选项 默认 true
@return string | [
"alias",
"of",
"the",
"select",
"()"
] | train | https://github.com/inhere/php-console/blob/d08a0a70fbcfecf6289db6b1a23582eeff32d4a7/src/Util/Interact.php#L85-L88 |
inhere/php-console | src/Util/Interact.php | Interact.choice | public static function choice(string $description, $options, $default = null, bool $allowExit = true): string
{
return Choose::one($description, $options, $default, $allowExit);
} | php | public static function choice(string $description, $options, $default = null, bool $allowExit = true): string
{
return Choose::one($description, $options, $default, $allowExit);
} | [
"public",
"static",
"function",
"choice",
"(",
"string",
"$",
"description",
",",
"$",
"options",
",",
"$",
"default",
"=",
"null",
",",
"bool",
"$",
"allowExit",
"=",
"true",
")",
":",
"string",
"{",
"return",
"Choose",
"::",
"one",
"(",
"$",
"descrip... | Choose one of several options
@param string $description
@param string|array $options Option data
e.g
[
// option => value
'1' => 'chengdu',
'2' => 'beijing'
]
@param string|int $default Default option
@param bool $allowExit
@return string | [
"Choose",
"one",
"of",
"several",
"options"
] | train | https://github.com/inhere/php-console/blob/d08a0a70fbcfecf6289db6b1a23582eeff32d4a7/src/Util/Interact.php#L104-L107 |
inhere/php-console | src/Util/Interact.php | Interact.checkbox | public static function checkbox(string $description, $options, $default = null, bool $allowExit = true): array
{
return self::multiSelect($description, $options, $default, $allowExit);
} | php | public static function checkbox(string $description, $options, $default = null, bool $allowExit = true): array
{
return self::multiSelect($description, $options, $default, $allowExit);
} | [
"public",
"static",
"function",
"checkbox",
"(",
"string",
"$",
"description",
",",
"$",
"options",
",",
"$",
"default",
"=",
"null",
",",
"bool",
"$",
"allowExit",
"=",
"true",
")",
":",
"array",
"{",
"return",
"self",
"::",
"multiSelect",
"(",
"$",
"... | alias of the `multiSelect()`
@param string $description
@param string|array $options
@param null|mixed $default
@param bool $allowExit
@return array | [
"alias",
"of",
"the",
"multiSelect",
"()"
] | train | https://github.com/inhere/php-console/blob/d08a0a70fbcfecf6289db6b1a23582eeff32d4a7/src/Util/Interact.php#L117-L120 |
inhere/php-console | src/Util/Interact.php | Interact.multiSelect | public static function multiSelect(string $description, $options, $default = null, bool $allowExit = true): array
{
return Checkbox::select($description, $options, $default, $allowExit);
} | php | public static function multiSelect(string $description, $options, $default = null, bool $allowExit = true): array
{
return Checkbox::select($description, $options, $default, $allowExit);
} | [
"public",
"static",
"function",
"multiSelect",
"(",
"string",
"$",
"description",
",",
"$",
"options",
",",
"$",
"default",
"=",
"null",
",",
"bool",
"$",
"allowExit",
"=",
"true",
")",
":",
"array",
"{",
"return",
"Checkbox",
"::",
"select",
"(",
"$",
... | List multiple options and allow multiple selections
@param string $description
@param string|array $options
@param null|mixed $default
@param bool $allowExit
@return array | [
"List",
"multiple",
"options",
"and",
"allow",
"multiple",
"selections"
] | train | https://github.com/inhere/php-console/blob/d08a0a70fbcfecf6289db6b1a23582eeff32d4a7/src/Util/Interact.php#L131-L134 |
inhere/php-console | src/Util/Interact.php | Interact.answerIsYes | public static function answerIsYes(bool $default = null): bool
{
$mark = ' [yes|no]: ';
if ($default !== null) {
$defMsg = $default ? 'yes' : 'no';
$mark = \sprintf(' [yes|no](default <cyan>%s</cyan>): ', $defMsg);
}
if ($answer = Console::readFirst($mark)... | php | public static function answerIsYes(bool $default = null): bool
{
$mark = ' [yes|no]: ';
if ($default !== null) {
$defMsg = $default ? 'yes' : 'no';
$mark = \sprintf(' [yes|no](default <cyan>%s</cyan>): ', $defMsg);
}
if ($answer = Console::readFirst($mark)... | [
"public",
"static",
"function",
"answerIsYes",
"(",
"bool",
"$",
"default",
"=",
"null",
")",
":",
"bool",
"{",
"$",
"mark",
"=",
"' [yes|no]: '",
";",
"if",
"(",
"$",
"default",
"!==",
"null",
")",
"{",
"$",
"defMsg",
"=",
"$",
"default",
"?",
"'yes... | Usage:
```php
echo "are you ok?";
$ok = Interact::answerIsYes();
```
@param bool|null $default
@return bool | [
"Usage",
":"
] | train | https://github.com/inhere/php-console/blob/d08a0a70fbcfecf6289db6b1a23582eeff32d4a7/src/Util/Interact.php#L158-L183 |
inhere/php-console | src/Util/Interact.php | Interact.ask | public static function ask(string $question, string $default = '', \Closure $validator = null): ?string
{
return self::question($question, $default, $validator);
} | php | public static function ask(string $question, string $default = '', \Closure $validator = null): ?string
{
return self::question($question, $default, $validator);
} | [
"public",
"static",
"function",
"ask",
"(",
"string",
"$",
"question",
",",
"string",
"$",
"default",
"=",
"''",
",",
"\\",
"Closure",
"$",
"validator",
"=",
"null",
")",
":",
"?",
"string",
"{",
"return",
"self",
"::",
"question",
"(",
"$",
"question"... | alias of the `question()`
@param string $question question message
@param string $default default value
@param \Closure $validator The validate callback. It must return bool.
@return string|null | [
"alias",
"of",
"the",
"question",
"()"
] | train | https://github.com/inhere/php-console/blob/d08a0a70fbcfecf6289db6b1a23582eeff32d4a7/src/Util/Interact.php#L192-L195 |
inhere/php-console | src/Util/Interact.php | Interact.question | public static function question(string $question, string $default = '', \Closure $validator = null): string
{
return Question::ask($question, $default, $validator);
} | php | public static function question(string $question, string $default = '', \Closure $validator = null): string
{
return Question::ask($question, $default, $validator);
} | [
"public",
"static",
"function",
"question",
"(",
"string",
"$",
"question",
",",
"string",
"$",
"default",
"=",
"''",
",",
"\\",
"Closure",
"$",
"validator",
"=",
"null",
")",
":",
"string",
"{",
"return",
"Question",
"::",
"ask",
"(",
"$",
"question",
... | Ask a question, ask for results; return the result of the input
@see Question::ask()
@param string $question
@param string $default
@param \Closure|null $validator Validator, must return bool.
@return string | [
"Ask",
"a",
"question",
"ask",
"for",
"results",
";",
"return",
"the",
"result",
"of",
"the",
"input"
] | train | https://github.com/inhere/php-console/blob/d08a0a70fbcfecf6289db6b1a23582eeff32d4a7/src/Util/Interact.php#L205-L208 |
inhere/php-console | src/Util/Interact.php | Interact.limitedAsk | public static function limitedAsk(
string $question,
string $default = '',
\Closure $validator = null,
int $times = 3
): string {
return LimitedAsk::ask($question, $default, $validator, $times);
} | php | public static function limitedAsk(
string $question,
string $default = '',
\Closure $validator = null,
int $times = 3
): string {
return LimitedAsk::ask($question, $default, $validator, $times);
} | [
"public",
"static",
"function",
"limitedAsk",
"(",
"string",
"$",
"question",
",",
"string",
"$",
"default",
"=",
"''",
",",
"\\",
"Closure",
"$",
"validator",
"=",
"null",
",",
"int",
"$",
"times",
"=",
"3",
")",
":",
"string",
"{",
"return",
"Limited... | Ask a question, ask for a limited number of times
@see LimitedAsk::ask()
@param string $question 问题
@param string $default 默认值
@param \Closure $validator (默认验证输入是否为空)自定义回调验证输入是否符合要求; 验证成功返回true 否则 可返回错误消息
@param int $times Allow input times
@return string | [
"Ask",
"a",
"question",
"ask",
"for",
"a",
"limited",
"number",
"of",
"times"
] | train | https://github.com/inhere/php-console/blob/d08a0a70fbcfecf6289db6b1a23582eeff32d4a7/src/Util/Interact.php#L219-L226 |
inhere/php-console | src/Component/PharCompiler.php | PharCompiler.pack | public function pack(string $pharFile, $refresh = true): string
{
if (!$this->directories) {
throw new \RuntimeException("Please setting the 'directories' want building directories by 'in()'");
}
$exists = \file_exists($pharFile);
if ($refresh && $exists) {
... | php | public function pack(string $pharFile, $refresh = true): string
{
if (!$this->directories) {
throw new \RuntimeException("Please setting the 'directories' want building directories by 'in()'");
}
$exists = \file_exists($pharFile);
if ($refresh && $exists) {
... | [
"public",
"function",
"pack",
"(",
"string",
"$",
"pharFile",
",",
"$",
"refresh",
"=",
"true",
")",
":",
"string",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"directories",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"\"Please setting the 'direc... | Compiles composer into a single phar file
@param string $pharFile The full path to the file to create
@param bool $refresh
@return string
@throws \UnexpectedValueException
@throws \BadMethodCallException
@throws \RuntimeException
@throws \Exception | [
"Compiles",
"composer",
"into",
"a",
"single",
"phar",
"file"
] | train | https://github.com/inhere/php-console/blob/d08a0a70fbcfecf6289db6b1a23582eeff32d4a7/src/Component/PharCompiler.php#L331-L409 |
inhere/php-console | src/Component/PharCompiler.php | PharCompiler.findChangedByGit | public function findChangedByGit(): ?\Generator
{
// -u expand dir's files
[, $output,] = Sys::run('git status -s -u', $this->basePath);
// 'D some.file' deleted
// ' M some.file' modified
// '?? some.file' new file
foreach (\explode("\n", \trim($output)) as $... | php | public function findChangedByGit(): ?\Generator
{
// -u expand dir's files
[, $output,] = Sys::run('git status -s -u', $this->basePath);
// 'D some.file' deleted
// ' M some.file' modified
// '?? some.file' new file
foreach (\explode("\n", \trim($output)) as $... | [
"public",
"function",
"findChangedByGit",
"(",
")",
":",
"?",
"\\",
"Generator",
"{",
"// -u expand dir's files",
"[",
",",
"$",
"output",
",",
"]",
"=",
"Sys",
"::",
"run",
"(",
"'git status -s -u'",
",",
"$",
"this",
"->",
"basePath",
")",
";",
"// 'D so... | find changed or new created files by git status.
@return \Generator | [
"find",
"changed",
"or",
"new",
"created",
"files",
"by",
"git",
"status",
"."
] | train | https://github.com/inhere/php-console/blob/d08a0a70fbcfecf6289db6b1a23582eeff32d4a7/src/Component/PharCompiler.php#L415-L440 |
inhere/php-console | src/Component/PharCompiler.php | PharCompiler.packFile | private function packFile(\Phar $phar, \SplFileInfo $file): void
{
// skip error
if (!\file_exists($file)) {
$this->reportError("File $file is not exists!");
return;
}
$this->counter++;
$path = $this->getRelativeFilePath($file);
$strip = $this... | php | private function packFile(\Phar $phar, \SplFileInfo $file): void
{
// skip error
if (!\file_exists($file)) {
$this->reportError("File $file is not exists!");
return;
}
$this->counter++;
$path = $this->getRelativeFilePath($file);
$strip = $this... | [
"private",
"function",
"packFile",
"(",
"\\",
"Phar",
"$",
"phar",
",",
"\\",
"SplFileInfo",
"$",
"file",
")",
":",
"void",
"{",
"// skip error",
"if",
"(",
"!",
"\\",
"file_exists",
"(",
"$",
"file",
")",
")",
"{",
"$",
"this",
"->",
"reportError",
... | Add a file to the Phar.
@param \Phar $phar
@param \SplFileInfo $file | [
"Add",
"a",
"file",
"to",
"the",
"Phar",
"."
] | train | https://github.com/inhere/php-console/blob/d08a0a70fbcfecf6289db6b1a23582eeff32d4a7/src/Component/PharCompiler.php#L460-L500 |
inhere/php-console | src/Component/PharCompiler.php | PharCompiler.collectInformation | private function collectInformation(): void
{
if (!$this->collectVersionInfo) {
return;
}
$basePath = $this->basePath;
[$code, $ret,] = Sys::run('git log --pretty="%H" -n1 HEAD', $basePath);
if ($code !== 0) {
throw new \RuntimeException(
... | php | private function collectInformation(): void
{
if (!$this->collectVersionInfo) {
return;
}
$basePath = $this->basePath;
[$code, $ret,] = Sys::run('git log --pretty="%H" -n1 HEAD', $basePath);
if ($code !== 0) {
throw new \RuntimeException(
... | [
"private",
"function",
"collectInformation",
"(",
")",
":",
"void",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"collectVersionInfo",
")",
"{",
"return",
";",
"}",
"$",
"basePath",
"=",
"$",
"this",
"->",
"basePath",
";",
"[",
"$",
"code",
",",
"$",
"ret... | auto collect project information by git log
@throws \RuntimeException
@throws \Exception | [
"auto",
"collect",
"project",
"information",
"by",
"git",
"log"
] | train | https://github.com/inhere/php-console/blob/d08a0a70fbcfecf6289db6b1a23582eeff32d4a7/src/Component/PharCompiler.php#L664-L703 |
inhere/php-console | src/Component/PharCompiler.php | PharCompiler.on | public function on(string $event, \Closure $closure): void
{
$this->events[$event] = $closure;
} | php | public function on(string $event, \Closure $closure): void
{
$this->events[$event] = $closure;
} | [
"public",
"function",
"on",
"(",
"string",
"$",
"event",
",",
"\\",
"Closure",
"$",
"closure",
")",
":",
"void",
"{",
"$",
"this",
"->",
"events",
"[",
"$",
"event",
"]",
"=",
"$",
"closure",
";",
"}"
] | add event handler
@param string $event
@param \Closure $closure | [
"add",
"event",
"handler"
] | train | https://github.com/inhere/php-console/blob/d08a0a70fbcfecf6289db6b1a23582eeff32d4a7/src/Component/PharCompiler.php#L735-L738 |
inhere/php-console | src/AbstractApplication.php | AbstractApplication.run | public function run(bool $exit = true)
{
$command = \trim($this->input->getCommand(), $this->delimiter);
$this->prepareRun();
// like: help, version, list
if ($this->filterSpecialCommand($command)) {
return 0;
}
// call 'onBeforeRun' service, if it is r... | php | public function run(bool $exit = true)
{
$command = \trim($this->input->getCommand(), $this->delimiter);
$this->prepareRun();
// like: help, version, list
if ($this->filterSpecialCommand($command)) {
return 0;
}
// call 'onBeforeRun' service, if it is r... | [
"public",
"function",
"run",
"(",
"bool",
"$",
"exit",
"=",
"true",
")",
"{",
"$",
"command",
"=",
"\\",
"trim",
"(",
"$",
"this",
"->",
"input",
"->",
"getCommand",
"(",
")",
",",
"$",
"this",
"->",
"delimiter",
")",
";",
"$",
"this",
"->",
"pre... | run application
@param bool $exit
@return int|mixed
@throws \InvalidArgumentException | [
"run",
"application"
] | train | https://github.com/inhere/php-console/blob/d08a0a70fbcfecf6289db6b1a23582eeff32d4a7/src/AbstractApplication.php#L172-L207 |
inhere/php-console | src/AbstractApplication.php | AbstractApplication.registerErrorHandle | protected function registerErrorHandle(): void
{
\set_error_handler([$this, 'handleError']);
\set_exception_handler([$this, 'handleException']);
\register_shutdown_function(function () {
if ($e = \error_get_last()) {
$this->handleError($e['type'], $e['message'], $... | php | protected function registerErrorHandle(): void
{
\set_error_handler([$this, 'handleError']);
\set_exception_handler([$this, 'handleException']);
\register_shutdown_function(function () {
if ($e = \error_get_last()) {
$this->handleError($e['type'], $e['message'], $... | [
"protected",
"function",
"registerErrorHandle",
"(",
")",
":",
"void",
"{",
"\\",
"set_error_handler",
"(",
"[",
"$",
"this",
",",
"'handleError'",
"]",
")",
";",
"\\",
"set_exception_handler",
"(",
"[",
"$",
"this",
",",
"'handleException'",
"]",
")",
";",
... | register error handle
@throws \InvalidArgumentException | [
"register",
"error",
"handle"
] | train | https://github.com/inhere/php-console/blob/d08a0a70fbcfecf6289db6b1a23582eeff32d4a7/src/AbstractApplication.php#L271-L280 |
inhere/php-console | src/AbstractApplication.php | AbstractApplication.handleError | public function handleError(int $num, string $str, string $file, int $line): void
{
$this->handleException(new \ErrorException($str, 0, $num, $file, $line));
$this->stop(-1);
} | php | public function handleError(int $num, string $str, string $file, int $line): void
{
$this->handleException(new \ErrorException($str, 0, $num, $file, $line));
$this->stop(-1);
} | [
"public",
"function",
"handleError",
"(",
"int",
"$",
"num",
",",
"string",
"$",
"str",
",",
"string",
"$",
"file",
",",
"int",
"$",
"line",
")",
":",
"void",
"{",
"$",
"this",
"->",
"handleException",
"(",
"new",
"\\",
"ErrorException",
"(",
"$",
"s... | 运行异常处理
@param int $num
@param string $str
@param string $file
@param int $line
@throws \InvalidArgumentException | [
"运行异常处理"
] | train | https://github.com/inhere/php-console/blob/d08a0a70fbcfecf6289db6b1a23582eeff32d4a7/src/AbstractApplication.php#L290-L294 |
inhere/php-console | src/Util/ProgressBar.php | ProgressBar.start | public function start($maxSteps = null): void
{
if ($this->started) {
throw new \LogicException('Progress bar already started.');
}
$this->startTime = time();
$this->step = 0;
$this->percent = 0.0;
$this->started = true;
if (null !== $maxSteps) {... | php | public function start($maxSteps = null): void
{
if ($this->started) {
throw new \LogicException('Progress bar already started.');
}
$this->startTime = time();
$this->step = 0;
$this->percent = 0.0;
$this->started = true;
if (null !== $maxSteps) {... | [
"public",
"function",
"start",
"(",
"$",
"maxSteps",
"=",
"null",
")",
":",
"void",
"{",
"if",
"(",
"$",
"this",
"->",
"started",
")",
"{",
"throw",
"new",
"\\",
"LogicException",
"(",
"'Progress bar already started.'",
")",
";",
"}",
"$",
"this",
"->",
... | 开始
@param null $maxSteps
@throws \LogicException | [
"开始"
] | train | https://github.com/inhere/php-console/blob/d08a0a70fbcfecf6289db6b1a23582eeff32d4a7/src/Util/ProgressBar.php#L119-L135 |
inhere/php-console | src/Util/ProgressBar.php | ProgressBar.advance | public function advance(int $step = 1): void
{
if (!$this->started) {
throw new \LogicException('Progress indicator has not yet been started.');
}
$this->advanceTo($this->step + $step);
} | php | public function advance(int $step = 1): void
{
if (!$this->started) {
throw new \LogicException('Progress indicator has not yet been started.');
}
$this->advanceTo($this->step + $step);
} | [
"public",
"function",
"advance",
"(",
"int",
"$",
"step",
"=",
"1",
")",
":",
"void",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"started",
")",
"{",
"throw",
"new",
"\\",
"LogicException",
"(",
"'Progress indicator has not yet been started.'",
")",
";",
"}",... | 前进,按步长前进几步
@param int $step 前进几步
@throws \LogicException | [
"前进,按步长前进几步"
] | train | https://github.com/inhere/php-console/blob/d08a0a70fbcfecf6289db6b1a23582eeff32d4a7/src/Util/ProgressBar.php#L142-L149 |
inhere/php-console | src/Util/ProgressBar.php | ProgressBar.advanceTo | public function advanceTo(int $step): void
{
if ($this->maxSteps && $step > $this->maxSteps) {
$this->maxSteps = $step;
} elseif ($step < 0) {
$step = 0;
}
$prevPeriod = (int)($this->step / $this->redrawFreq);
$currPeriod = (int)($step / $this->redraw... | php | public function advanceTo(int $step): void
{
if ($this->maxSteps && $step > $this->maxSteps) {
$this->maxSteps = $step;
} elseif ($step < 0) {
$step = 0;
}
$prevPeriod = (int)($this->step / $this->redrawFreq);
$currPeriod = (int)($step / $this->redraw... | [
"public",
"function",
"advanceTo",
"(",
"int",
"$",
"step",
")",
":",
"void",
"{",
"if",
"(",
"$",
"this",
"->",
"maxSteps",
"&&",
"$",
"step",
">",
"$",
"this",
"->",
"maxSteps",
")",
"{",
"$",
"this",
"->",
"maxSteps",
"=",
"$",
"step",
";",
"}... | 直接前进到第几步
@param int $step 第几步 | [
"直接前进到第几步"
] | train | https://github.com/inhere/php-console/blob/d08a0a70fbcfecf6289db6b1a23582eeff32d4a7/src/Util/ProgressBar.php#L155-L171 |
inhere/php-console | src/Util/ProgressBar.php | ProgressBar.finish | public function finish(): void
{
if (!$this->started) {
throw new \LogicException('Progress bar has not yet been started.');
}
if (!$this->maxSteps) {
$this->maxSteps = $this->step;
}
if ($this->step === $this->maxSteps && !$this->overwrite) {
... | php | public function finish(): void
{
if (!$this->started) {
throw new \LogicException('Progress bar has not yet been started.');
}
if (!$this->maxSteps) {
$this->maxSteps = $this->step;
}
if ($this->step === $this->maxSteps && !$this->overwrite) {
... | [
"public",
"function",
"finish",
"(",
")",
":",
"void",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"started",
")",
"{",
"throw",
"new",
"\\",
"LogicException",
"(",
"'Progress bar has not yet been started.'",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",... | Finishes the progress output.
@throws \LogicException | [
"Finishes",
"the",
"progress",
"output",
"."
] | train | https://github.com/inhere/php-console/blob/d08a0a70fbcfecf6289db6b1a23582eeff32d4a7/src/Util/ProgressBar.php#L177-L196 |
inhere/php-console | src/Util/ProgressBar.php | ProgressBar.display | public function display(): void
{
if (null === $this->format) {
$this->format = self::DEFAULT_FORMAT;
}
$this->render($this->buildLine());
} | php | public function display(): void
{
if (null === $this->format) {
$this->format = self::DEFAULT_FORMAT;
}
$this->render($this->buildLine());
} | [
"public",
"function",
"display",
"(",
")",
":",
"void",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"format",
")",
"{",
"$",
"this",
"->",
"format",
"=",
"self",
"::",
"DEFAULT_FORMAT",
";",
"}",
"$",
"this",
"->",
"render",
"(",
"$",
"this",... | Outputs the current progress string. | [
"Outputs",
"the",
"current",
"progress",
"string",
"."
] | train | https://github.com/inhere/php-console/blob/d08a0a70fbcfecf6289db6b1a23582eeff32d4a7/src/Util/ProgressBar.php#L201-L208 |
inhere/php-console | src/Util/ProgressBar.php | ProgressBar.render | public function render(string $text): void
{
if ($this->overwrite) {
if (!$this->firstRun) {
// \x0D - Move the cursor to the beginning of the line
// \x1B[2K - Erase the line
$this->output->write("\x0D\x1B[2K", false);
$this->outp... | php | public function render(string $text): void
{
if ($this->overwrite) {
if (!$this->firstRun) {
// \x0D - Move the cursor to the beginning of the line
// \x1B[2K - Erase the line
$this->output->write("\x0D\x1B[2K", false);
$this->outp... | [
"public",
"function",
"render",
"(",
"string",
"$",
"text",
")",
":",
"void",
"{",
"if",
"(",
"$",
"this",
"->",
"overwrite",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"firstRun",
")",
"{",
"// \\x0D - Move the cursor to the beginning of the line",
"// \\... | render
@param string $text | [
"render"
] | train | https://github.com/inhere/php-console/blob/d08a0a70fbcfecf6289db6b1a23582eeff32d4a7/src/Util/ProgressBar.php#L230-L245 |
inhere/php-console | src/Util/ProgressBar.php | ProgressBar.getParser | public function getParser(string $section, bool $throwException = false)
{
if (!self::$parsers) {
self::$parsers = self::loadDefaultParsers();
}
if (isset(self::$parsers[$section])) {
return self::$parsers[$section];
}
if ($throwException) {
... | php | public function getParser(string $section, bool $throwException = false)
{
if (!self::$parsers) {
self::$parsers = self::loadDefaultParsers();
}
if (isset(self::$parsers[$section])) {
return self::$parsers[$section];
}
if ($throwException) {
... | [
"public",
"function",
"getParser",
"(",
"string",
"$",
"section",
",",
"bool",
"$",
"throwException",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"self",
"::",
"$",
"parsers",
")",
"{",
"self",
"::",
"$",
"parsers",
"=",
"self",
"::",
"loadDefaultParsers",
... | get section Parser
@param string $section
@param bool|boolean $throwException
@return mixed
@throws \RuntimeException | [
"get",
"section",
"Parser"
] | train | https://github.com/inhere/php-console/blob/d08a0a70fbcfecf6289db6b1a23582eeff32d4a7/src/Util/ProgressBar.php#L288-L303 |
inhere/php-console | src/Util/ProgressBar.php | ProgressBar.setMaxSteps | private function setMaxSteps(int $maxSteps): void
{
$this->maxSteps = \max(0, $maxSteps);
$this->stepWidth = $this->maxSteps ? Str::len($this->maxSteps) : 2;
} | php | private function setMaxSteps(int $maxSteps): void
{
$this->maxSteps = \max(0, $maxSteps);
$this->stepWidth = $this->maxSteps ? Str::len($this->maxSteps) : 2;
} | [
"private",
"function",
"setMaxSteps",
"(",
"int",
"$",
"maxSteps",
")",
":",
"void",
"{",
"$",
"this",
"->",
"maxSteps",
"=",
"\\",
"max",
"(",
"0",
",",
"$",
"maxSteps",
")",
";",
"$",
"this",
"->",
"stepWidth",
"=",
"$",
"this",
"->",
"maxSteps",
... | Sets the progress bar maximal steps.
@param int $maxSteps The progress bar max steps | [
"Sets",
"the",
"progress",
"bar",
"maximal",
"steps",
"."
] | train | https://github.com/inhere/php-console/blob/d08a0a70fbcfecf6289db6b1a23582eeff32d4a7/src/Util/ProgressBar.php#L374-L378 |
inhere/php-console | src/Util/ProgressBar.php | ProgressBar.getCompleteChar | public function getCompleteChar(): string
{
if (null === $this->completeChar) {
return $this->maxSteps ? '=' : $this->completeChar;
}
return $this->completeChar;
} | php | public function getCompleteChar(): string
{
if (null === $this->completeChar) {
return $this->maxSteps ? '=' : $this->completeChar;
}
return $this->completeChar;
} | [
"public",
"function",
"getCompleteChar",
"(",
")",
":",
"string",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"completeChar",
")",
"{",
"return",
"$",
"this",
"->",
"maxSteps",
"?",
"'='",
":",
"$",
"this",
"->",
"completeChar",
";",
"}",
"return... | Gets the complete bar character.
@return string A character | [
"Gets",
"the",
"complete",
"bar",
"character",
"."
] | train | https://github.com/inhere/php-console/blob/d08a0a70fbcfecf6289db6b1a23582eeff32d4a7/src/Util/ProgressBar.php#L432-L439 |
inhere/php-console | examples/Controller/HomeController.php | HomeController.defArgConfigure | protected function defArgConfigure(): void
{
$this->createDefinition()
->setDescription('the command arg/opt config use defined configure, it like symfony console: argument define by position')
->addArgument('name', Input::ARG_REQUIRED, "description for the argument 'name'")
... | php | protected function defArgConfigure(): void
{
$this->createDefinition()
->setDescription('the command arg/opt config use defined configure, it like symfony console: argument define by position')
->addArgument('name', Input::ARG_REQUIRED, "description for the argument 'name'")
... | [
"protected",
"function",
"defArgConfigure",
"(",
")",
":",
"void",
"{",
"$",
"this",
"->",
"createDefinition",
"(",
")",
"->",
"setDescription",
"(",
"'the command arg/opt config use defined configure, it like symfony console: argument define by position'",
")",
"->",
"addArg... | command `defArgCommand` config
@throws \LogicException | [
"command",
"defArgCommand",
"config"
] | train | https://github.com/inhere/php-console/blob/d08a0a70fbcfecf6289db6b1a23582eeff32d4a7/examples/Controller/HomeController.php#L102-L109 |
inhere/php-console | examples/Controller/HomeController.php | HomeController.defArgCommand | public function defArgCommand(): void
{
$this->output->dump($this->input->getArgs(), $this->input->getOpts(), $this->input->getBoolOpt('y'));
} | php | public function defArgCommand(): void
{
$this->output->dump($this->input->getArgs(), $this->input->getOpts(), $this->input->getBoolOpt('y'));
} | [
"public",
"function",
"defArgCommand",
"(",
")",
":",
"void",
"{",
"$",
"this",
"->",
"output",
"->",
"dump",
"(",
"$",
"this",
"->",
"input",
"->",
"getArgs",
"(",
")",
",",
"$",
"this",
"->",
"input",
"->",
"getOpts",
"(",
")",
",",
"$",
"this",
... | the command arg/opt config use defined configure, it like symfony console: argument define by position | [
"the",
"command",
"arg",
"/",
"opt",
"config",
"use",
"defined",
"configure",
"it",
"like",
"symfony",
"console",
":",
"argument",
"define",
"by",
"position"
] | train | https://github.com/inhere/php-console/blob/d08a0a70fbcfecf6289db6b1a23582eeff32d4a7/examples/Controller/HomeController.php#L114-L117 |
inhere/php-console | examples/Controller/HomeController.php | HomeController.subRunCommand | public function subRunCommand(): void
{
$this->writeln('hello this is: ' . __METHOD__);
$this->getApp()->subRun('test', $this->input, $this->output);
} | php | public function subRunCommand(): void
{
$this->writeln('hello this is: ' . __METHOD__);
$this->getApp()->subRun('test', $this->input, $this->output);
} | [
"public",
"function",
"subRunCommand",
"(",
")",
":",
"void",
"{",
"$",
"this",
"->",
"writeln",
"(",
"'hello this is: '",
".",
"__METHOD__",
")",
";",
"$",
"this",
"->",
"getApp",
"(",
")",
"->",
"subRun",
"(",
"'test'",
",",
"$",
"this",
"->",
"input... | will run other command in the command. | [
"will",
"run",
"other",
"command",
"in",
"the",
"command",
"."
] | train | https://github.com/inhere/php-console/blob/d08a0a70fbcfecf6289db6b1a23582eeff32d4a7/examples/Controller/HomeController.php#L139-L144 |
inhere/php-console | examples/Controller/HomeController.php | HomeController.colorCheckCommand | public function colorCheckCommand(): void
{
// $char= '❤';
// $ret = ProcessUtil::run('echo ❤');
// var_dump($ret, trim($ret[1]), $char === trim($ret[1]));
//
// die;
$this->output->aList([
'basic color output?' => Cli::isSupportColor() ? '<info>Y</info>'... | php | public function colorCheckCommand(): void
{
// $char= '❤';
// $ret = ProcessUtil::run('echo ❤');
// var_dump($ret, trim($ret[1]), $char === trim($ret[1]));
//
// die;
$this->output->aList([
'basic color output?' => Cli::isSupportColor() ? '<info>Y</info>'... | [
"public",
"function",
"colorCheckCommand",
"(",
")",
":",
"void",
"{",
"// $char= '❤';",
"// $ret = ProcessUtil::run('echo ❤');",
"// var_dump($ret, trim($ret[1]), $char === trim($ret[1]));",
"//",
"// die;",
"$",
"this",
"->",
"output",
"->",
"aList",
"(",
"[",
"'basic col... | check color support for current env. | [
"check",
"color",
"support",
"for",
"current",
"env",
"."
] | train | https://github.com/inhere/php-console/blob/d08a0a70fbcfecf6289db6b1a23582eeff32d4a7/examples/Controller/HomeController.php#L157-L171 |
inhere/php-console | examples/Controller/HomeController.php | HomeController.artFontCommand | public function artFontCommand(): int
{
$name = $this->input->getLongOpt('font', '404');
if (!ArtFont::isInternalFont($name)) {
return $this->output->liteError("Your input font name: $name, is not exists. Please use '-h' see allowed.");
}
ArtFont::create()->show($name, ... | php | public function artFontCommand(): int
{
$name = $this->input->getLongOpt('font', '404');
if (!ArtFont::isInternalFont($name)) {
return $this->output->liteError("Your input font name: $name, is not exists. Please use '-h' see allowed.");
}
ArtFont::create()->show($name, ... | [
"public",
"function",
"artFontCommand",
"(",
")",
":",
"int",
"{",
"$",
"name",
"=",
"$",
"this",
"->",
"input",
"->",
"getLongOpt",
"(",
"'font'",
",",
"'404'",
")",
";",
"if",
"(",
"!",
"ArtFont",
"::",
"isInternalFont",
"(",
"$",
"name",
")",
")",... | output art font text
@options
--font Set the art font name(allow: {internalFonts}).
--italic Set the art font type is italic.
--style Set the art font style.
@return int | [
"output",
"art",
"font",
"text"
] | train | https://github.com/inhere/php-console/blob/d08a0a70fbcfecf6289db6b1a23582eeff32d4a7/examples/Controller/HomeController.php#L181-L195 |
inhere/php-console | examples/Controller/HomeController.php | HomeController.counterCommand | public function counterCommand(): int
{
$total = 120;
$ctt = Show::counterTxt('handling ...', 'handled.');
$this->write('Counter:');
while ($total - 1) {
$ctt->send(1);
usleep(30000);
$total--;
}
// end of the counter.
$... | php | public function counterCommand(): int
{
$total = 120;
$ctt = Show::counterTxt('handling ...', 'handled.');
$this->write('Counter:');
while ($total - 1) {
$ctt->send(1);
usleep(30000);
$total--;
}
// end of the counter.
$... | [
"public",
"function",
"counterCommand",
"(",
")",
":",
"int",
"{",
"$",
"total",
"=",
"120",
";",
"$",
"ctt",
"=",
"Show",
"::",
"counterTxt",
"(",
"'handling ...'",
",",
"'handled.'",
")",
";",
"$",
"this",
"->",
"write",
"(",
"'Counter:'",
")",
";",
... | dynamic notice message show: counterTxt. It is like progress txt, but no max value.
@example
{script} {command}
@return int | [
"dynamic",
"notice",
"message",
"show",
":",
"counterTxt",
".",
"It",
"is",
"like",
"progress",
"txt",
"but",
"no",
"max",
"value",
"."
] | train | https://github.com/inhere/php-console/blob/d08a0a70fbcfecf6289db6b1a23582eeff32d4a7/examples/Controller/HomeController.php#L203-L221 |
inhere/php-console | examples/Controller/HomeController.php | HomeController.spinnerCommand | public function spinnerCommand(): void
{
$total = 5000;
while ($total--) {
Show::spinner('Data handling ');
usleep(100);
}
Show::spinner('Done', true);
} | php | public function spinnerCommand(): void
{
$total = 5000;
while ($total--) {
Show::spinner('Data handling ');
usleep(100);
}
Show::spinner('Done', true);
} | [
"public",
"function",
"spinnerCommand",
"(",
")",
":",
"void",
"{",
"$",
"total",
"=",
"5000",
";",
"while",
"(",
"$",
"total",
"--",
")",
"{",
"Show",
"::",
"spinner",
"(",
"'Data handling '",
")",
";",
"usleep",
"(",
"100",
")",
";",
"}",
"Show",
... | dynamic spinner message, by Show::spinner() | [
"dynamic",
"spinner",
"message",
"by",
"Show",
"::",
"spinner",
"()"
] | train | https://github.com/inhere/php-console/blob/d08a0a70fbcfecf6289db6b1a23582eeff32d4a7/examples/Controller/HomeController.php#L226-L236 |
inhere/php-console | examples/Controller/HomeController.php | HomeController.pendingCommand | public function pendingCommand(): void
{
$total = 800;
while ($total--) {
Show::pending();
usleep(20000);
}
Show::pending('Done', true);
} | php | public function pendingCommand(): void
{
$total = 800;
while ($total--) {
Show::pending();
usleep(20000);
}
Show::pending('Done', true);
} | [
"public",
"function",
"pendingCommand",
"(",
")",
":",
"void",
"{",
"$",
"total",
"=",
"800",
";",
"while",
"(",
"$",
"total",
"--",
")",
"{",
"Show",
"::",
"pending",
"(",
")",
";",
"usleep",
"(",
"20000",
")",
";",
"}",
"Show",
"::",
"pending",
... | dynamic notice message show: pending | [
"dynamic",
"notice",
"message",
"show",
":",
"pending"
] | train | https://github.com/inhere/php-console/blob/d08a0a70fbcfecf6289db6b1a23582eeff32d4a7/examples/Controller/HomeController.php#L241-L251 |
inhere/php-console | examples/Controller/HomeController.php | HomeController.pointingCommand | public function pointingCommand(): void
{
$total = 100;
while ($total--) {
Show::pointing();
usleep(10000);
}
Show::pointing('Done', true);
} | php | public function pointingCommand(): void
{
$total = 100;
while ($total--) {
Show::pointing();
usleep(10000);
}
Show::pointing('Done', true);
} | [
"public",
"function",
"pointingCommand",
"(",
")",
":",
"void",
"{",
"$",
"total",
"=",
"100",
";",
"while",
"(",
"$",
"total",
"--",
")",
"{",
"Show",
"::",
"pointing",
"(",
")",
";",
"usleep",
"(",
"10000",
")",
";",
"}",
"Show",
"::",
"pointing"... | dynamic notice message show: pointing | [
"dynamic",
"notice",
"message",
"show",
":",
"pointing"
] | train | https://github.com/inhere/php-console/blob/d08a0a70fbcfecf6289db6b1a23582eeff32d4a7/examples/Controller/HomeController.php#L256-L266 |
inhere/php-console | examples/Controller/HomeController.php | HomeController.dynamicTextCommand | public function dynamicTextCommand(): void
{
$dt = Show::dynamicText('Complete', 'Download file: xyz.zip ... ');
$dt->send('Start');
foreach (['Request', 'Downloading', 'Save'] as $txt) {
\sleep(2);
$dt->send($txt);
}
\sleep(2);
$dt->send(fal... | php | public function dynamicTextCommand(): void
{
$dt = Show::dynamicText('Complete', 'Download file: xyz.zip ... ');
$dt->send('Start');
foreach (['Request', 'Downloading', 'Save'] as $txt) {
\sleep(2);
$dt->send($txt);
}
\sleep(2);
$dt->send(fal... | [
"public",
"function",
"dynamicTextCommand",
"(",
")",
":",
"void",
"{",
"$",
"dt",
"=",
"Show",
"::",
"dynamicText",
"(",
"'Complete'",
",",
"'Download file: xyz.zip ... '",
")",
";",
"$",
"dt",
"->",
"send",
"(",
"'Start'",
")",
";",
"foreach",
"(",
"[",
... | dynamic text message example, by Show::dynamicText | [
"dynamic",
"text",
"message",
"example",
"by",
"Show",
"::",
"dynamicText"
] | train | https://github.com/inhere/php-console/blob/d08a0a70fbcfecf6289db6b1a23582eeff32d4a7/examples/Controller/HomeController.php#L271-L283 |
inhere/php-console | examples/Controller/HomeController.php | HomeController.progressCommand | public function progressCommand($input): int
{
$i = 0;
$total = 120;
if ($input->getOpt('type') === 'bar') {
$bar = $this->output->progressBar($total, [
'msg' => 'Msg Text',
'doneMsg' => 'Done Msg Text',
'doneChar' => $inp... | php | public function progressCommand($input): int
{
$i = 0;
$total = 120;
if ($input->getOpt('type') === 'bar') {
$bar = $this->output->progressBar($total, [
'msg' => 'Msg Text',
'doneMsg' => 'Done Msg Text',
'doneChar' => $inp... | [
"public",
"function",
"progressCommand",
"(",
"$",
"input",
")",
":",
"int",
"{",
"$",
"i",
"=",
"0",
";",
"$",
"total",
"=",
"120",
";",
"if",
"(",
"$",
"input",
"->",
"getOpt",
"(",
"'type'",
")",
"===",
"'bar'",
")",
"{",
"$",
"bar",
"=",
"$... | a progress bar example show, by Show::progressBar()
@options
--type the progress type, allow: bar,txt. <cyan>txt</cyan>
--done-char the done show char. <info>=</info>
--wait-char the waiting show char. <info>-</info>
--sign-char the sign char show. <info>></info>
@example
{script} {command}
{script} {command} --do... | [
"a",
"progress",
"bar",
"example",
"show",
"by",
"Show",
"::",
"progressBar",
"()"
] | train | https://github.com/inhere/php-console/blob/d08a0a70fbcfecf6289db6b1a23582eeff32d4a7/examples/Controller/HomeController.php#L298-L323 |
inhere/php-console | examples/Controller/HomeController.php | HomeController.progressBarCommand | public function progressBarCommand(): void
{
$i = 0;
$total = 120;
$bar = new ProgressBar();
$bar->start(120);
while ($i <= $total) {
$bar->advance();
usleep(50000);
$i++;
}
$bar->finish();
} | php | public function progressBarCommand(): void
{
$i = 0;
$total = 120;
$bar = new ProgressBar();
$bar->start(120);
while ($i <= $total) {
$bar->advance();
usleep(50000);
$i++;
}
$bar->finish();
} | [
"public",
"function",
"progressBarCommand",
"(",
")",
":",
"void",
"{",
"$",
"i",
"=",
"0",
";",
"$",
"total",
"=",
"120",
";",
"$",
"bar",
"=",
"new",
"ProgressBar",
"(",
")",
";",
"$",
"bar",
"->",
"start",
"(",
"120",
")",
";",
"while",
"(",
... | a progress bar example show, by class ProgressBar
@throws \LogicException | [
"a",
"progress",
"bar",
"example",
"show",
"by",
"class",
"ProgressBar"
] | train | https://github.com/inhere/php-console/blob/d08a0a70fbcfecf6289db6b1a23582eeff32d4a7/examples/Controller/HomeController.php#L329-L343 |
inhere/php-console | examples/Controller/HomeController.php | HomeController.listCommand | public function listCommand(): void
{
$list = [
'The is a list line 0',
'The is a list line 1',
'The is a list line 2',
'The is a list line 3',
];
Show::aList($list, 'a List show(No key)');
$commands = [
'version' => 'Show... | php | public function listCommand(): void
{
$list = [
'The is a list line 0',
'The is a list line 1',
'The is a list line 2',
'The is a list line 3',
];
Show::aList($list, 'a List show(No key)');
$commands = [
'version' => 'Show... | [
"public",
"function",
"listCommand",
"(",
")",
":",
"void",
"{",
"$",
"list",
"=",
"[",
"'The is a list line 0'",
",",
"'The is a list line 1'",
",",
"'The is a list line 2'",
",",
"'The is a list line 3'",
",",
"]",
";",
"Show",
"::",
"aList",
"(",
"$",
"list",... | output format message: list | [
"output",
"format",
"message",
":",
"list"
] | train | https://github.com/inhere/php-console/blob/d08a0a70fbcfecf6289db6b1a23582eeff32d4a7/examples/Controller/HomeController.php#L348-L367 |
inhere/php-console | examples/Controller/HomeController.php | HomeController.tableCommand | public function tableCommand(): void
{
$data = [
[
'id' => 1,
'name' => 'john',
'status' => 2,
'email' => 'john@email.com',
],
[
'id' => 2,
'name' => 'tom',
... | php | public function tableCommand(): void
{
$data = [
[
'id' => 1,
'name' => 'john',
'status' => 2,
'email' => 'john@email.com',
],
[
'id' => 2,
'name' => 'tom',
... | [
"public",
"function",
"tableCommand",
"(",
")",
":",
"void",
"{",
"$",
"data",
"=",
"[",
"[",
"'id'",
"=>",
"1",
",",
"'name'",
"=>",
"'john'",
",",
"'status'",
"=>",
"2",
",",
"'email'",
"=>",
"'john@email.com'",
",",
"]",
",",
"[",
"'id'",
"=>",
... | output format message: table | [
"output",
"format",
"message",
":",
"table"
] | train | https://github.com/inhere/php-console/blob/d08a0a70fbcfecf6289db6b1a23582eeff32d4a7/examples/Controller/HomeController.php#L399-L450 |
inhere/php-console | examples/Controller/HomeController.php | HomeController.useArgCommand | public function useArgCommand(): void
{
$this->write('input arguments:');
$this->output->dump($this->input->getArgs());
$this->write('input options:');
$this->output->dump($this->input->getOpts());
$this->write('raw argv:');
$this->output->dump($this->input->getToke... | php | public function useArgCommand(): void
{
$this->write('input arguments:');
$this->output->dump($this->input->getArgs());
$this->write('input options:');
$this->output->dump($this->input->getOpts());
$this->write('raw argv:');
$this->output->dump($this->input->getToke... | [
"public",
"function",
"useArgCommand",
"(",
")",
":",
"void",
"{",
"$",
"this",
"->",
"write",
"(",
"'input arguments:'",
")",
";",
"$",
"this",
"->",
"output",
"->",
"dump",
"(",
"$",
"this",
"->",
"input",
"->",
"getArgs",
"(",
")",
")",
";",
"$",
... | a example for use arguments on command
@usage home:useArg [arg1=val1 arg2=arg2] [options]
@example
home:useArg status=2 name=john arg0 -s=test --page=23 -d -rf --debug --test=false -a v1 --ab -c -g --cd val -h '' -i stat=online
home:useArg status=2 name=john name=tom name=jack arg0 -s=test --page=23 --id=23 --id=154 --... | [
"a",
"example",
"for",
"use",
"arguments",
"on",
"command"
] | train | https://github.com/inhere/php-console/blob/d08a0a70fbcfecf6289db6b1a23582eeff32d4a7/examples/Controller/HomeController.php#L473-L486 |
inhere/php-console | examples/Controller/HomeController.php | HomeController.envCommand | public function envCommand(): void
{
$info = [
'phpVersion' => PHP_VERSION,
'env' => 'test',
'debug' => true,
];
Show::panel($info);
echo Php::printVars($_SERVER);
} | php | public function envCommand(): void
{
$info = [
'phpVersion' => PHP_VERSION,
'env' => 'test',
'debug' => true,
];
Show::panel($info);
echo Php::printVars($_SERVER);
} | [
"public",
"function",
"envCommand",
"(",
")",
":",
"void",
"{",
"$",
"info",
"=",
"[",
"'phpVersion'",
"=>",
"PHP_VERSION",
",",
"'env'",
"=>",
"'test'",
",",
"'debug'",
"=>",
"true",
",",
"]",
";",
"Show",
"::",
"panel",
"(",
"$",
"info",
")",
";",
... | output current env info | [
"output",
"current",
"env",
"info"
] | train | https://github.com/inhere/php-console/blob/d08a0a70fbcfecf6289db6b1a23582eeff32d4a7/examples/Controller/HomeController.php#L491-L502 |
inhere/php-console | examples/Controller/HomeController.php | HomeController.downCommand | public function downCommand(): int
{
$url = $this->input->getArg('url');
if (!$url) {
$this->output->liteError('Please input you want to downloaded file url, use: url=[url]', 1);
}
$saveAs = $this->input->getArg('saveAs');
$type = $this->input->getArg('type', ... | php | public function downCommand(): int
{
$url = $this->input->getArg('url');
if (!$url) {
$this->output->liteError('Please input you want to downloaded file url, use: url=[url]', 1);
}
$saveAs = $this->input->getArg('saveAs');
$type = $this->input->getArg('type', ... | [
"public",
"function",
"downCommand",
"(",
")",
":",
"int",
"{",
"$",
"url",
"=",
"$",
"this",
"->",
"input",
"->",
"getArg",
"(",
"'url'",
")",
";",
"if",
"(",
"!",
"$",
"url",
")",
"{",
"$",
"this",
"->",
"output",
"->",
"liteError",
"(",
"'Plea... | This is a demo for download a file to local
@usage {command} url=url saveTo=[saveAs] type=[bar|text]
@example {command} url=https://github.com/inhere/php-console/archive/master.zip type=bar | [
"This",
"is",
"a",
"demo",
"for",
"download",
"a",
"file",
"to",
"local"
] | train | https://github.com/inhere/php-console/blob/d08a0a70fbcfecf6289db6b1a23582eeff32d4a7/examples/Controller/HomeController.php#L509-L536 |
inhere/php-console | src/Component/Interact/Confirm.php | Confirm.ask | public static function ask(string $question, bool $default = true): bool
{
if (!$question = \trim($question)) {
Show::warning('Please provide a question message!', 1);
return false;
}
$defText = $default ? 'yes' : 'no';
$question = \ucfirst(\trim($question, ... | php | public static function ask(string $question, bool $default = true): bool
{
if (!$question = \trim($question)) {
Show::warning('Please provide a question message!', 1);
return false;
}
$defText = $default ? 'yes' : 'no';
$question = \ucfirst(\trim($question, ... | [
"public",
"static",
"function",
"ask",
"(",
"string",
"$",
"question",
",",
"bool",
"$",
"default",
"=",
"true",
")",
":",
"bool",
"{",
"if",
"(",
"!",
"$",
"question",
"=",
"\\",
"trim",
"(",
"$",
"question",
")",
")",
"{",
"Show",
"::",
"warning"... | Send a message request confirmation
@param string $question The question message
@param bool $default Default value
@return bool | [
"Send",
"a",
"message",
"request",
"confirmation"
] | train | https://github.com/inhere/php-console/blob/d08a0a70fbcfecf6289db6b1a23582eeff32d4a7/src/Component/Interact/Confirm.php#L21-L49 |
inhere/php-console | examples/Command/DemoCommand.php | DemoCommand.configure | protected function configure(): void
{
$this->createDefinition()
->setExample($this->parseCommentsVars('{script} {command} john male 43 --opt1 value1'))
->addArgument('name', Input::ARG_REQUIRED, 'description for the argument [name], is required')
->addArgument('sex', Inp... | php | protected function configure(): void
{
$this->createDefinition()
->setExample($this->parseCommentsVars('{script} {command} john male 43 --opt1 value1'))
->addArgument('name', Input::ARG_REQUIRED, 'description for the argument [name], is required')
->addArgument('sex', Inp... | [
"protected",
"function",
"configure",
"(",
")",
":",
"void",
"{",
"$",
"this",
"->",
"createDefinition",
"(",
")",
"->",
"setExample",
"(",
"$",
"this",
"->",
"parseCommentsVars",
"(",
"'{script} {command} john male 43 --opt1 value1'",
")",
")",
"->",
"addArgument... | {@inheritDoc}
@throws \LogicException | [
"{"
] | train | https://github.com/inhere/php-console/blob/d08a0a70fbcfecf6289db6b1a23582eeff32d4a7/examples/Command/DemoCommand.php#L28-L39 |
inhere/php-console | src/Component/Formatter/Padding.php | Padding.show | public static function show(array $data, string $title = '', array $opts = []): void
{
if (!$data) {
return;
}
$string = $title ? ColorTag::wrap(\ucfirst($title), 'comment') . ":\n" : '';
$opts = \array_merge([
'char' => '.',
'indent' ... | php | public static function show(array $data, string $title = '', array $opts = []): void
{
if (!$data) {
return;
}
$string = $title ? ColorTag::wrap(\ucfirst($title), 'comment') . ":\n" : '';
$opts = \array_merge([
'char' => '.',
'indent' ... | [
"public",
"static",
"function",
"show",
"(",
"array",
"$",
"data",
",",
"string",
"$",
"title",
"=",
"''",
",",
"array",
"$",
"opts",
"=",
"[",
"]",
")",
":",
"void",
"{",
"if",
"(",
"!",
"$",
"data",
")",
"{",
"return",
";",
"}",
"$",
"string"... | ```php
$data = [
'Eggs' => '$1.99',
'Oatmeal' => '$4.99',
'Bacon' => '$2.99',
];
```
@param array $data
@param string $title
@param array $opts | [
"php",
"$data",
"=",
"[",
"Eggs",
"=",
">",
"$1",
".",
"99",
"Oatmeal",
"=",
">",
"$4",
".",
"99",
"Bacon",
"=",
">",
"$2",
".",
"99",
"]",
";"
] | train | https://github.com/inhere/php-console/blob/d08a0a70fbcfecf6289db6b1a23582eeff32d4a7/src/Component/Formatter/Padding.php#L29-L52 |
inhere/php-console | examples/Controller/InteractController.php | InteractController.selectCommand | public function selectCommand(): void
{
$opts = ['john', 'simon', 'rose'];
// can also: $this->select();
$a = Interact::select('you name is', $opts);
$this->write('Your answer is: ' . $opts[$a]);
} | php | public function selectCommand(): void
{
$opts = ['john', 'simon', 'rose'];
// can also: $this->select();
$a = Interact::select('you name is', $opts);
$this->write('Your answer is: ' . $opts[$a]);
} | [
"public",
"function",
"selectCommand",
"(",
")",
":",
"void",
"{",
"$",
"opts",
"=",
"[",
"'john'",
",",
"'simon'",
",",
"'rose'",
"]",
";",
"// can also: $this->select();",
"$",
"a",
"=",
"Interact",
"::",
"select",
"(",
"'you name is'",
",",
"$",
"opts",... | This is a demo for use <magenta>Interact::select()</magenta> method | [
"This",
"is",
"a",
"demo",
"for",
"use",
"<magenta",
">",
"Interact",
"::",
"select",
"()",
"<",
"/",
"magenta",
">",
"method"
] | train | https://github.com/inhere/php-console/blob/d08a0a70fbcfecf6289db6b1a23582eeff32d4a7/examples/Controller/InteractController.php#L57-L64 |
inhere/php-console | examples/Controller/InteractController.php | InteractController.multiSelectCommand | public function multiSelectCommand(): void
{
$opts = ['john', 'simon', 'rose', 'tom'];
// can also: $a = Interact::multiSelect('Your friends are', $opts);
$a = $this->multiSelect('Your friends are', $opts);
$this->write('Your answer is: ' . json_encode($a));
} | php | public function multiSelectCommand(): void
{
$opts = ['john', 'simon', 'rose', 'tom'];
// can also: $a = Interact::multiSelect('Your friends are', $opts);
$a = $this->multiSelect('Your friends are', $opts);
$this->write('Your answer is: ' . json_encode($a));
} | [
"public",
"function",
"multiSelectCommand",
"(",
")",
":",
"void",
"{",
"$",
"opts",
"=",
"[",
"'john'",
",",
"'simon'",
",",
"'rose'",
",",
"'tom'",
"]",
";",
"// can also: $a = Interact::multiSelect('Your friends are', $opts);",
"$",
"a",
"=",
"$",
"this",
"->... | This is a demo for use <magenta>Interact::multiSelect()</magenta> method | [
"This",
"is",
"a",
"demo",
"for",
"use",
"<magenta",
">",
"Interact",
"::",
"multiSelect",
"()",
"<",
"/",
"magenta",
">",
"method"
] | train | https://github.com/inhere/php-console/blob/d08a0a70fbcfecf6289db6b1a23582eeff32d4a7/examples/Controller/InteractController.php#L69-L77 |
inhere/php-console | examples/Controller/InteractController.php | InteractController.askCommand | public function askCommand(): void
{
$a = Interact::ask('you name is: ', '', function ($val, &$err) {
if (!preg_match('/^\w{2,}$/', $val)) {
$err = 'Your input must match /^\w{2,}$/';
return false;
}
return true;
});
$this... | php | public function askCommand(): void
{
$a = Interact::ask('you name is: ', '', function ($val, &$err) {
if (!preg_match('/^\w{2,}$/', $val)) {
$err = 'Your input must match /^\w{2,}$/';
return false;
}
return true;
});
$this... | [
"public",
"function",
"askCommand",
"(",
")",
":",
"void",
"{",
"$",
"a",
"=",
"Interact",
"::",
"ask",
"(",
"'you name is: '",
",",
"''",
",",
"function",
"(",
"$",
"val",
",",
"&",
"$",
"err",
")",
"{",
"if",
"(",
"!",
"preg_match",
"(",
"'/^\\w{... | This is a demo for use <magenta>Interact::ask()</magenta> method | [
"This",
"is",
"a",
"demo",
"for",
"use",
"<magenta",
">",
"Interact",
"::",
"ask",
"()",
"<",
"/",
"magenta",
">",
"method"
] | train | https://github.com/inhere/php-console/blob/d08a0a70fbcfecf6289db6b1a23582eeff32d4a7/examples/Controller/InteractController.php#L82-L94 |
inhere/php-console | examples/Controller/InteractController.php | InteractController.limitedAskCommand | public function limitedAskCommand(): void
{
$times = (int)$this->input->getOpt('limit', 3);
if ($this->input->getBoolOpt('nv')) {
$a = Interact::limitedAsk('you name is: ', '', null, $times);
} else {
$a = Interact::limitedAsk('you name is: ', '', function ($val) {
... | php | public function limitedAskCommand(): void
{
$times = (int)$this->input->getOpt('limit', 3);
if ($this->input->getBoolOpt('nv')) {
$a = Interact::limitedAsk('you name is: ', '', null, $times);
} else {
$a = Interact::limitedAsk('you name is: ', '', function ($val) {
... | [
"public",
"function",
"limitedAskCommand",
"(",
")",
":",
"void",
"{",
"$",
"times",
"=",
"(",
"int",
")",
"$",
"this",
"->",
"input",
"->",
"getOpt",
"(",
"'limit'",
",",
"3",
")",
";",
"if",
"(",
"$",
"this",
"->",
"input",
"->",
"getBoolOpt",
"(... | This is a demo for use <magenta>Interact::limitedAsk()</magenta> method
@options
--nv Not use validator.
--limit limit times.(default: 3) | [
"This",
"is",
"a",
"demo",
"for",
"use",
"<magenta",
">",
"Interact",
"::",
"limitedAsk",
"()",
"<",
"/",
"magenta",
">",
"method"
] | train | https://github.com/inhere/php-console/blob/d08a0a70fbcfecf6289db6b1a23582eeff32d4a7/examples/Controller/InteractController.php#L102-L120 |
inhere/php-console | examples/Controller/InteractController.php | InteractController.cursorCommand | public function cursorCommand(): void
{
$this->write('hello, this in ' . __METHOD__);
$this->write('this is a message text.', false);
sleep(1);
Terminal::make()->cursor(Terminal::CUR_BACKWARD, 6);
sleep(1);
Terminal::make()->cursor(Terminal::CUR_FORWARD, 3);
... | php | public function cursorCommand(): void
{
$this->write('hello, this in ' . __METHOD__);
$this->write('this is a message text.', false);
sleep(1);
Terminal::make()->cursor(Terminal::CUR_BACKWARD, 6);
sleep(1);
Terminal::make()->cursor(Terminal::CUR_FORWARD, 3);
... | [
"public",
"function",
"cursorCommand",
"(",
")",
":",
"void",
"{",
"$",
"this",
"->",
"write",
"(",
"'hello, this in '",
".",
"__METHOD__",
")",
";",
"$",
"this",
"->",
"write",
"(",
"'this is a message text.'",
",",
"false",
")",
";",
"sleep",
"(",
"1",
... | This is a demo for show cursor move on the Terminal screen | [
"This",
"is",
"a",
"demo",
"for",
"show",
"cursor",
"move",
"on",
"the",
"Terminal",
"screen"
] | train | https://github.com/inhere/php-console/blob/d08a0a70fbcfecf6289db6b1a23582eeff32d4a7/examples/Controller/InteractController.php#L136-L165 |
inhere/php-console | src/Traits/NameAliasTrait.php | NameAliasTrait.setAlias | public function setAlias(string $name, $alias): void
{
foreach ((array)$alias as $aliasName) {
if (!isset($this->aliases[$aliasName])) {
$this->aliases[$aliasName] = $name;
}
}
} | php | public function setAlias(string $name, $alias): void
{
foreach ((array)$alias as $aliasName) {
if (!isset($this->aliases[$aliasName])) {
$this->aliases[$aliasName] = $name;
}
}
} | [
"public",
"function",
"setAlias",
"(",
"string",
"$",
"name",
",",
"$",
"alias",
")",
":",
"void",
"{",
"foreach",
"(",
"(",
"array",
")",
"$",
"alias",
"as",
"$",
"aliasName",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"aliases",
... | set name alias(es)
@param string $name
@param string|array $alias | [
"set",
"name",
"alias",
"(",
"es",
")"
] | train | https://github.com/inhere/php-console/blob/d08a0a70fbcfecf6289db6b1a23582eeff32d4a7/src/Traits/NameAliasTrait.php#L27-L34 |
inhere/php-console | src/Component/Progress/CounterText.php | CounterText.gen | public static function gen(string $msg, $doneMsg = ''): \Generator
{
$counter = 0;
$finished = false;
$tpl = (Cli::isSupportColor() ? "\x0D\x1B[2K" : "\x0D\r") . '%d %s';
$msg = Console::style()->render($msg);
$doneMsg = $doneMsg ? Console::style()->render($doneMsg) : '';
... | php | public static function gen(string $msg, $doneMsg = ''): \Generator
{
$counter = 0;
$finished = false;
$tpl = (Cli::isSupportColor() ? "\x0D\x1B[2K" : "\x0D\r") . '%d %s';
$msg = Console::style()->render($msg);
$doneMsg = $doneMsg ? Console::style()->render($doneMsg) : '';
... | [
"public",
"static",
"function",
"gen",
"(",
"string",
"$",
"msg",
",",
"$",
"doneMsg",
"=",
"''",
")",
":",
"\\",
"Generator",
"{",
"$",
"counter",
"=",
"0",
";",
"$",
"finished",
"=",
"false",
";",
"$",
"tpl",
"=",
"(",
"Cli",
"::",
"isSupportColo... | 与文本进度条相比,没有 total
```php
$total = 120;
$ctt = Show::counterTxt('handling ...', 'handled.');
$this->write('Counter:');
while ($total - 1) {
$ctt->send(1);
usleep(30000);
$total--;
}
// end of the counter.
$ctt->send(-1);
```
@param string $msg
@param string $doneMsg
@return \Generator | [
"与文本进度条相比,没有",
"total"
] | train | https://github.com/inhere/php-console/blob/d08a0a70fbcfecf6289db6b1a23582eeff32d4a7/src/Component/Progress/CounterText.php#L35-L69 |
inhere/php-console | src/IO/Input.php | Input.read | public function read(string $question = '', bool $nl = false): string
{
if ($question) {
\fwrite(\STDOUT, $question . ($nl ? "\n" : ''));
}
return \trim(\fgets($this->inputStream));
} | php | public function read(string $question = '', bool $nl = false): string
{
if ($question) {
\fwrite(\STDOUT, $question . ($nl ? "\n" : ''));
}
return \trim(\fgets($this->inputStream));
} | [
"public",
"function",
"read",
"(",
"string",
"$",
"question",
"=",
"''",
",",
"bool",
"$",
"nl",
"=",
"false",
")",
":",
"string",
"{",
"if",
"(",
"$",
"question",
")",
"{",
"\\",
"fwrite",
"(",
"\\",
"STDOUT",
",",
"$",
"question",
".",
"(",
"$"... | Read input information
@param string $question 若不为空,则先输出文本消息
@param bool $nl true 会添加换行符 false 原样输出,不添加换行符
@return string | [
"Read",
"input",
"information"
] | train | https://github.com/inhere/php-console/blob/d08a0a70fbcfecf6289db6b1a23582eeff32d4a7/src/IO/Input.php#L75-L82 |
inhere/php-console | src/Util/FormatUtil.php | FormatUtil.wrapText | public static function wrapText($text, $indent = 0, $width = 0): string
{
if (!$text) {
return $text;
}
if ((int)$width <= 0) {
$size = Sys::getScreenSize();
if ($size === false || $size[0] <= $indent) {
return $text;
}
... | php | public static function wrapText($text, $indent = 0, $width = 0): string
{
if (!$text) {
return $text;
}
if ((int)$width <= 0) {
$size = Sys::getScreenSize();
if ($size === false || $size[0] <= $indent) {
return $text;
}
... | [
"public",
"static",
"function",
"wrapText",
"(",
"$",
"text",
",",
"$",
"indent",
"=",
"0",
",",
"$",
"width",
"=",
"0",
")",
":",
"string",
"{",
"if",
"(",
"!",
"$",
"text",
")",
"{",
"return",
"$",
"text",
";",
"}",
"if",
"(",
"(",
"int",
"... | Word wrap text with indentation to fit the screen size
If screen size could not be detected, or the indentation is greater than the screen size, the text will not be wrapped.
The first line will **not** be indented, so `wrapText("Lorem ipsum dolor sit amet.", 4)` will result in the
following output, given the screen ... | [
"Word",
"wrap",
"text",
"with",
"indentation",
"to",
"fit",
"the",
"screen",
"size"
] | train | https://github.com/inhere/php-console/blob/d08a0a70fbcfecf6289db6b1a23582eeff32d4a7/src/Util/FormatUtil.php#L80-L109 |
inhere/php-console | src/Util/FormatUtil.php | FormatUtil.howLongAgo | public static function howLongAgo(int $secs): string
{
static $timeFormats = [
[0, '< 1 sec'],
[1, '1 sec'],
[2, 'secs', 1],
[60, '1 min'],
[120, 'mins', 60],
[3600, '1 hr'],
[7200, 'hrs', 3600],
[86400, '1 day']... | php | public static function howLongAgo(int $secs): string
{
static $timeFormats = [
[0, '< 1 sec'],
[1, '1 sec'],
[2, 'secs', 1],
[60, '1 min'],
[120, 'mins', 60],
[3600, '1 hr'],
[7200, 'hrs', 3600],
[86400, '1 day']... | [
"public",
"static",
"function",
"howLongAgo",
"(",
"int",
"$",
"secs",
")",
":",
"string",
"{",
"static",
"$",
"timeFormats",
"=",
"[",
"[",
"0",
",",
"'< 1 sec'",
"]",
",",
"[",
"1",
",",
"'1 sec'",
"]",
",",
"[",
"2",
",",
"'secs'",
",",
"1",
"... | format timestamp to how long ago
@param int $secs
@return string | [
"format",
"timestamp",
"to",
"how",
"long",
"ago"
] | train | https://github.com/inhere/php-console/blob/d08a0a70fbcfecf6289db6b1a23582eeff32d4a7/src/Util/FormatUtil.php#L172-L201 |
inhere/php-console | src/Util/FormatUtil.php | FormatUtil.spliceKeyValue | public static function spliceKeyValue(array $data, array $opts = []): string
{
$text = '';
$opts = \array_merge([
'leftChar' => '', // e.g ' ', ' * '
'sepChar' => ' ', // e.g ' | ' OUT: key | value
'keyStyle' => '', // e.g 'info','comment'
... | php | public static function spliceKeyValue(array $data, array $opts = []): string
{
$text = '';
$opts = \array_merge([
'leftChar' => '', // e.g ' ', ' * '
'sepChar' => ' ', // e.g ' | ' OUT: key | value
'keyStyle' => '', // e.g 'info','comment'
... | [
"public",
"static",
"function",
"spliceKeyValue",
"(",
"array",
"$",
"data",
",",
"array",
"$",
"opts",
"=",
"[",
"]",
")",
":",
"string",
"{",
"$",
"text",
"=",
"''",
";",
"$",
"opts",
"=",
"\\",
"array_merge",
"(",
"[",
"'leftChar'",
"=>",
"''",
... | splice Array
@param array $data
e.g [
'system' => 'Linux',
'version' => '4.4.5',
]
@param array $opts
@return string | [
"splice",
"Array"
] | train | https://github.com/inhere/php-console/blob/d08a0a70fbcfecf6289db6b1a23582eeff32d4a7/src/Util/FormatUtil.php#L213-L273 |
inhere/php-console | src/Component/Progress/SimpleBar.php | SimpleBar.gen | public static function gen(int $total, array $opts = []): \Generator
{
$current = 0;
$finished = false;
$tplPrefix = Cli::isSupportColor() ? "\x0D\x1B[2K" : "\x0D\r";
$opts = \array_merge([
'doneChar' => '=',
'waitChar' => ' ',
'signChar' => '>... | php | public static function gen(int $total, array $opts = []): \Generator
{
$current = 0;
$finished = false;
$tplPrefix = Cli::isSupportColor() ? "\x0D\x1B[2K" : "\x0D\r";
$opts = \array_merge([
'doneChar' => '=',
'waitChar' => ' ',
'signChar' => '>... | [
"public",
"static",
"function",
"gen",
"(",
"int",
"$",
"total",
",",
"array",
"$",
"opts",
"=",
"[",
"]",
")",
":",
"\\",
"Generator",
"{",
"$",
"current",
"=",
"0",
";",
"$",
"finished",
"=",
"false",
";",
"$",
"tplPrefix",
"=",
"Cli",
"::",
"i... | Render a simple progress bar by 'yield'
```php
$i = 0;
$total = 120;
$bar = Show::progressBar($total, [
'msg' => 'Msg Text',
'doneChar' => '#'
]);
echo "progress:\n";
while ($i <= $total) {
$bar->send(1); // 发送步进长度,通常是 1
usleep(50000);
$i++;
}
```
@param int $total
@param array $opts
@internal int $current
@return ... | [
"Render",
"a",
"simple",
"progress",
"bar",
"by",
"yield"
] | train | https://github.com/inhere/php-console/blob/d08a0a70fbcfecf6289db6b1a23582eeff32d4a7/src/Component/Progress/SimpleBar.php#L38-L96 |
inhere/php-console | src/Component/Formatter/Table.php | Table.show | public static function show(array $data, string $title = 'Data Table', array $opts = []): int
{
if (!$data) {
return -2;
}
$buf = new StrBuffer();
$opts = \array_merge([
'showBorder' => true,
'leftIndent' => ' ',
'titlePos' ... | php | public static function show(array $data, string $title = 'Data Table', array $opts = []): int
{
if (!$data) {
return -2;
}
$buf = new StrBuffer();
$opts = \array_merge([
'showBorder' => true,
'leftIndent' => ' ',
'titlePos' ... | [
"public",
"static",
"function",
"show",
"(",
"array",
"$",
"data",
",",
"string",
"$",
"title",
"=",
"'Data Table'",
",",
"array",
"$",
"opts",
"=",
"[",
"]",
")",
":",
"int",
"{",
"if",
"(",
"!",
"$",
"data",
")",
"{",
"return",
"-",
"2",
";",
... | Tabular data display
@param array $data
@param string $title
@param array $opts
@example
```php
// like from database query's data.
$data = [
[ col1 => value1, col2 => value2, col3 => value3, ... ], // first row
[ col1 => value4, col2 => value5, col3 => value6, ... ], // second row
... ...
];
Show::table($data, ... | [
"Tabular",
"data",
"display"
] | train | https://github.com/inhere/php-console/blob/d08a0a70fbcfecf6289db6b1a23582eeff32d4a7/src/Component/Formatter/Table.php#L74-L217 |
inhere/php-console | src/Component/Interact/Question.php | Question.ask | public static function ask(string $question, string $default = '', \Closure $validator = null): string
{
if (!$question = \trim($question)) {
Show::error('Please provide a question text!', 1);
}
$defText = '' !== $default ? "(default: <info>$default</info>)" : '';
$messa... | php | public static function ask(string $question, string $default = '', \Closure $validator = null): string
{
if (!$question = \trim($question)) {
Show::error('Please provide a question text!', 1);
}
$defText = '' !== $default ? "(default: <info>$default</info>)" : '';
$messa... | [
"public",
"static",
"function",
"ask",
"(",
"string",
"$",
"question",
",",
"string",
"$",
"default",
"=",
"''",
",",
"\\",
"Closure",
"$",
"validator",
"=",
"null",
")",
":",
"string",
"{",
"if",
"(",
"!",
"$",
"question",
"=",
"\\",
"trim",
"(",
... | Ask a question, ask for results; return the result of the input
@example This is an example
```php
$answer = Interact::ask('Please input your name?', null, function ($answer) {
if (!preg_match('/\w{2,}/', $answer)) {
// output error tips.
Interact::error('The name must match "/\w{2,}/"');
return false;
}
return true;
... | [
"Ask",
"a",
"question",
"ask",
"for",
"results",
";",
"return",
"the",
"result",
"of",
"the",
"input",
"@example",
"This",
"is",
"an",
"example",
"php",
"$answer",
"=",
"Interact",
"::",
"ask",
"(",
"Please",
"input",
"your",
"name?",
"null",
"function",
... | train | https://github.com/inhere/php-console/blob/d08a0a70fbcfecf6289db6b1a23582eeff32d4a7/src/Component/Interact/Question.php#L52-L89 |
inhere/php-console | src/IO/InputDefinition.php | InputDefinition.addArg | public function addArg(string $name, int $mode = null, string $description = '', $default = null): self
{
return $this->addArgument($name, $mode, $description, $default);
} | php | public function addArg(string $name, int $mode = null, string $description = '', $default = null): self
{
return $this->addArgument($name, $mode, $description, $default);
} | [
"public",
"function",
"addArg",
"(",
"string",
"$",
"name",
",",
"int",
"$",
"mode",
"=",
"null",
",",
"string",
"$",
"description",
"=",
"''",
",",
"$",
"default",
"=",
"null",
")",
":",
"self",
"{",
"return",
"$",
"this",
"->",
"addArgument",
"(",
... | alias of the addArgument
@param string $name
@param int|null $mode
@param string $description
@param null $default
@return InputDefinition | [
"alias",
"of",
"the",
"addArgument"
] | train | https://github.com/inhere/php-console/blob/d08a0a70fbcfecf6289db6b1a23582eeff32d4a7/src/IO/InputDefinition.php#L106-L109 |
inhere/php-console | src/IO/InputDefinition.php | InputDefinition.addArgument | public function addArgument(string $name, int $mode = null, string $description = '', $default = null): self
{
if (null === $mode) {
$mode = Input::ARG_OPTIONAL;
} elseif (!\is_int($mode) || $mode > 7 || $mode < 1) {
throw new \InvalidArgumentException(sprintf('Argument mode ... | php | public function addArgument(string $name, int $mode = null, string $description = '', $default = null): self
{
if (null === $mode) {
$mode = Input::ARG_OPTIONAL;
} elseif (!\is_int($mode) || $mode > 7 || $mode < 1) {
throw new \InvalidArgumentException(sprintf('Argument mode ... | [
"public",
"function",
"addArgument",
"(",
"string",
"$",
"name",
",",
"int",
"$",
"mode",
"=",
"null",
",",
"string",
"$",
"description",
"=",
"''",
",",
"$",
"default",
"=",
"null",
")",
":",
"self",
"{",
"if",
"(",
"null",
"===",
"$",
"mode",
")"... | Adds an argument.
@param string $name The argument name
@param int $mode The argument mode: InputArgument::REQUIRED or InputArgument::OPTIONAL
@param string $description A description text
@param mixed $default The default value (for InputArgument::OPTIONAL mode only)
@return $this
@throws \LogicException | [
"Adds",
"an",
"argument",
"."
] | train | https://github.com/inhere/php-console/blob/d08a0a70fbcfecf6289db6b1a23582eeff32d4a7/src/IO/InputDefinition.php#L121-L174 |
inhere/php-console | src/IO/InputDefinition.php | InputDefinition.setOptions | public function setOptions(array $options = []): void
{
$this->options = $this->shortcuts = [];
$this->addOptions($options);
} | php | public function setOptions(array $options = []): void
{
$this->options = $this->shortcuts = [];
$this->addOptions($options);
} | [
"public",
"function",
"setOptions",
"(",
"array",
"$",
"options",
"=",
"[",
"]",
")",
":",
"void",
"{",
"$",
"this",
"->",
"options",
"=",
"$",
"this",
"->",
"shortcuts",
"=",
"[",
"]",
";",
"$",
"this",
"->",
"addOptions",
"(",
"$",
"options",
")"... | Sets the options
@param array[] $options An array of InputOption objects
@throws \LogicException
@throws \InvalidArgumentException | [
"Sets",
"the",
"options"
] | train | https://github.com/inhere/php-console/blob/d08a0a70fbcfecf6289db6b1a23582eeff32d4a7/src/IO/InputDefinition.php#L241-L245 |
inhere/php-console | src/IO/InputDefinition.php | InputDefinition.addOptions | public function addOptions(array $options = []): void
{
foreach ($options as $name => $opt) {
$opt = $this->mergeArgOptConfig($opt);
$this->addOption($name, $opt['mode'], $opt['description'], $opt['default']);
}
} | php | public function addOptions(array $options = []): void
{
foreach ($options as $name => $opt) {
$opt = $this->mergeArgOptConfig($opt);
$this->addOption($name, $opt['mode'], $opt['description'], $opt['default']);
}
} | [
"public",
"function",
"addOptions",
"(",
"array",
"$",
"options",
"=",
"[",
"]",
")",
":",
"void",
"{",
"foreach",
"(",
"$",
"options",
"as",
"$",
"name",
"=>",
"$",
"opt",
")",
"{",
"$",
"opt",
"=",
"$",
"this",
"->",
"mergeArgOptConfig",
"(",
"$"... | Adds an array of option
@param array
@throws \LogicException
@throws \InvalidArgumentException | [
"Adds",
"an",
"array",
"of",
"option"
] | train | https://github.com/inhere/php-console/blob/d08a0a70fbcfecf6289db6b1a23582eeff32d4a7/src/IO/InputDefinition.php#L254-L260 |
inhere/php-console | src/IO/InputDefinition.php | InputDefinition.addOpt | public function addOpt(
string $name,
string $shortcut = null,
int $mode = null,
string $description = '',
$default = null
): self {
return $this->addOption($name, $shortcut, $mode, $description, $default);
} | php | public function addOpt(
string $name,
string $shortcut = null,
int $mode = null,
string $description = '',
$default = null
): self {
return $this->addOption($name, $shortcut, $mode, $description, $default);
} | [
"public",
"function",
"addOpt",
"(",
"string",
"$",
"name",
",",
"string",
"$",
"shortcut",
"=",
"null",
",",
"int",
"$",
"mode",
"=",
"null",
",",
"string",
"$",
"description",
"=",
"''",
",",
"$",
"default",
"=",
"null",
")",
":",
"self",
"{",
"r... | alias of the addOption
{@inheritdoc}
@return InputDefinition | [
"alias",
"of",
"the",
"addOption",
"{"
] | train | https://github.com/inhere/php-console/blob/d08a0a70fbcfecf6289db6b1a23582eeff32d4a7/src/IO/InputDefinition.php#L267-L275 |
inhere/php-console | src/IO/InputDefinition.php | InputDefinition.addOption | public function addOption(
string $name,
string $shortcut = null,
int $mode = null,
string $description = '',
$default = null
): self {
if (0 === \strpos($name, '-')) {
$name = \trim($name, '-');
}
if (empty($name)) {
throw new... | php | public function addOption(
string $name,
string $shortcut = null,
int $mode = null,
string $description = '',
$default = null
): self {
if (0 === \strpos($name, '-')) {
$name = \trim($name, '-');
}
if (empty($name)) {
throw new... | [
"public",
"function",
"addOption",
"(",
"string",
"$",
"name",
",",
"string",
"$",
"shortcut",
"=",
"null",
",",
"int",
"$",
"mode",
"=",
"null",
",",
"string",
"$",
"description",
"=",
"''",
",",
"$",
"default",
"=",
"null",
")",
":",
"self",
"{",
... | Adds an option.
@param string|bool $name The option name, must is a string
@param string|array|null $shortcut The shortcut (can be null)
@param int $mode The option mode: One of the Input::OPT_* constants
@param string $description A description text
@param mixed $default The... | [
"Adds",
"an",
"option",
"."
] | train | https://github.com/inhere/php-console/blob/d08a0a70fbcfecf6289db6b1a23582eeff32d4a7/src/IO/InputDefinition.php#L290-L368 |
inhere/php-console | src/IO/InputDefinition.php | InputDefinition.getSynopsis | public function getSynopsis(bool $short = false): array
{
$elements = $args = $opts = [];
if ($short && $this->options) {
$elements[] = '[options]';
} elseif (!$short) {
foreach ($this->options as $name => $option) {
$value = '';
if (... | php | public function getSynopsis(bool $short = false): array
{
$elements = $args = $opts = [];
if ($short && $this->options) {
$elements[] = '[options]';
} elseif (!$short) {
foreach ($this->options as $name => $option) {
$value = '';
if (... | [
"public",
"function",
"getSynopsis",
"(",
"bool",
"$",
"short",
"=",
"false",
")",
":",
"array",
"{",
"$",
"elements",
"=",
"$",
"args",
"=",
"$",
"opts",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"short",
"&&",
"$",
"this",
"->",
"options",
")",
"{",
... | Gets the synopsis.
@param bool $short 简化版显示
@return array | [
"Gets",
"the",
"synopsis",
"."
] | train | https://github.com/inhere/php-console/blob/d08a0a70fbcfecf6289db6b1a23582eeff32d4a7/src/IO/InputDefinition.php#L451-L508 |
inhere/php-console | src/Component/Formatter/SingleList.php | SingleList.show | public static function show($data, string $title = '', array $opts = [])
{
$string = '';
$opts = \array_merge([
'leftChar' => ' ',
// 'sepChar' => ' ',
'keyStyle' => 'info',
'keyMinWidth' => 8,
'titleStyle' => 'comment',
... | php | public static function show($data, string $title = '', array $opts = [])
{
$string = '';
$opts = \array_merge([
'leftChar' => ' ',
// 'sepChar' => ' ',
'keyStyle' => 'info',
'keyMinWidth' => 8,
'titleStyle' => 'comment',
... | [
"public",
"static",
"function",
"show",
"(",
"$",
"data",
",",
"string",
"$",
"title",
"=",
"''",
",",
"array",
"$",
"opts",
"=",
"[",
"]",
")",
"{",
"$",
"string",
"=",
"''",
";",
"$",
"opts",
"=",
"\\",
"array_merge",
"(",
"[",
"'leftChar'",
"=... | Format and render a single list
```php
$title = 'list title';
$data = [
'name' => 'value text',
'name2' => 'value text 2',
];
```
@param array $data
@param string $title
@param array $opts More {@see FormatUtil::spliceKeyValue()}
@return int|string | [
"Format",
"and",
"render",
"a",
"single",
"list"
] | train | https://github.com/inhere/php-console/blob/d08a0a70fbcfecf6289db6b1a23582eeff32d4a7/src/Component/Formatter/SingleList.php#L32-L60 |
inhere/php-console | src/Traits/RuntimeProfileTrait.php | RuntimeProfileTrait.profile | public static function profile($name, array $context = [], $category = 'application'): void
{
$data = [
'_profile_stats' => [
'startTime' => \microtime(true),
'startMem' => \memory_get_usage(),
],
'_profile_start' => $context,
... | php | public static function profile($name, array $context = [], $category = 'application'): void
{
$data = [
'_profile_stats' => [
'startTime' => \microtime(true),
'startMem' => \memory_get_usage(),
],
'_profile_start' => $context,
... | [
"public",
"static",
"function",
"profile",
"(",
"$",
"name",
",",
"array",
"$",
"context",
"=",
"[",
"]",
",",
"$",
"category",
"=",
"'application'",
")",
":",
"void",
"{",
"$",
"data",
"=",
"[",
"'_profile_stats'",
"=>",
"[",
"'startTime'",
"=>",
"\\"... | mark data analysis start
@param $name
@param array $context
@param string $category
@throws \InvalidArgumentException | [
"mark",
"data",
"analysis",
"start"
] | train | https://github.com/inhere/php-console/blob/d08a0a70fbcfecf6289db6b1a23582eeff32d4a7/src/Traits/RuntimeProfileTrait.php#L43-L63 |
inhere/php-console | src/Component/Formatter/Tree.php | Tree.show | public static function show(array $data, array $opts = []): void
{
static $counter = 0;
static $started = 1;
if ($started) {
$started = 0;
$opts = \array_merge([
// 'char' => Cli::isSupportColor() ? '─' : '-', // ——
'char' =>... | php | public static function show(array $data, array $opts = []): void
{
static $counter = 0;
static $started = 1;
if ($started) {
$started = 0;
$opts = \array_merge([
// 'char' => Cli::isSupportColor() ? '─' : '-', // ——
'char' =>... | [
"public",
"static",
"function",
"show",
"(",
"array",
"$",
"data",
",",
"array",
"$",
"opts",
"=",
"[",
"]",
")",
":",
"void",
"{",
"static",
"$",
"counter",
"=",
"0",
";",
"static",
"$",
"started",
"=",
"1",
";",
"if",
"(",
"$",
"started",
")",
... | Render data like tree
├ ─ ─
└ ─
@param array $data
@param array $opts | [
"Render",
"data",
"like",
"tree",
"├",
"─",
"─",
"└",
"─"
] | train | https://github.com/inhere/php-console/blob/d08a0a70fbcfecf6289db6b1a23582eeff32d4a7/src/Component/Formatter/Tree.php#L35-L78 |
vinkla/instagram | src/Instagram.php | Instagram.get | protected function get(string $path, array $parameters = []): object
{
$url = $this->buildApiUrl($path, $parameters);
$request = $this->requestFactory->createRequest('GET', $url);
$response = $this->httpClient->sendRequest($request);
$body = json_decode((string) $response->getBody(... | php | protected function get(string $path, array $parameters = []): object
{
$url = $this->buildApiUrl($path, $parameters);
$request = $this->requestFactory->createRequest('GET', $url);
$response = $this->httpClient->sendRequest($request);
$body = json_decode((string) $response->getBody(... | [
"protected",
"function",
"get",
"(",
"string",
"$",
"path",
",",
"array",
"$",
"parameters",
"=",
"[",
"]",
")",
":",
"object",
"{",
"$",
"url",
"=",
"$",
"this",
"->",
"buildApiUrl",
"(",
"$",
"path",
",",
"$",
"parameters",
")",
";",
"$",
"reques... | Send a get request.
@param string $path
@param array $parameters
@throws \Vinkla\Instagram\InstagramException
@return object | [
"Send",
"a",
"get",
"request",
"."
] | train | https://github.com/vinkla/instagram/blob/b1c09e0190aee5e4f074036350deb2abcf6b31f1/src/Instagram.php#L122-L144 |
vinkla/instagram | src/Instagram.php | Instagram.buildApiUrl | protected function buildApiUrl(string $path, array $parameters): string
{
$parameters = array_merge([
'access_token' => $this->accessToken,
], $parameters);
$query = http_build_query($parameters, '', '&');
return 'https://api.instagram.com/v1/'.$path.'?'.$query;
} | php | protected function buildApiUrl(string $path, array $parameters): string
{
$parameters = array_merge([
'access_token' => $this->accessToken,
], $parameters);
$query = http_build_query($parameters, '', '&');
return 'https://api.instagram.com/v1/'.$path.'?'.$query;
} | [
"protected",
"function",
"buildApiUrl",
"(",
"string",
"$",
"path",
",",
"array",
"$",
"parameters",
")",
":",
"string",
"{",
"$",
"parameters",
"=",
"array_merge",
"(",
"[",
"'access_token'",
"=>",
"$",
"this",
"->",
"accessToken",
",",
"]",
",",
"$",
"... | Add access token and escape parameters.
@param string $path
@param array $parameters
@return string | [
"Add",
"access",
"token",
"and",
"escape",
"parameters",
"."
] | train | https://github.com/vinkla/instagram/blob/b1c09e0190aee5e4f074036350deb2abcf6b31f1/src/Instagram.php#L154-L163 |
wp-cli/scaffold-command | src/Scaffold_Command.php | Scaffold_Command.post_type | public function post_type( $args, $assoc_args ) {
if ( strlen( $args[0] ) > 20 ) {
WP_CLI::error( 'Post type slugs cannot exceed 20 characters in length.' );
}
$defaults = array(
'textdomain' => '',
'dashicon' => 'admin-post',
);
$templates = array(
'post_type.mustache',
'post_type_extende... | php | public function post_type( $args, $assoc_args ) {
if ( strlen( $args[0] ) > 20 ) {
WP_CLI::error( 'Post type slugs cannot exceed 20 characters in length.' );
}
$defaults = array(
'textdomain' => '',
'dashicon' => 'admin-post',
);
$templates = array(
'post_type.mustache',
'post_type_extende... | [
"public",
"function",
"post_type",
"(",
"$",
"args",
",",
"$",
"assoc_args",
")",
"{",
"if",
"(",
"strlen",
"(",
"$",
"args",
"[",
"0",
"]",
")",
">",
"20",
")",
"{",
"WP_CLI",
"::",
"error",
"(",
"'Post type slugs cannot exceed 20 characters in length.'",
... | Generates PHP code for registering a custom post type.
## OPTIONS
<slug>
: The internal name of the post type.
[--label=<label>]
: The text used to translate the update messages.
[--textdomain=<textdomain>]
: The textdomain to use for the labels.
[--dashicon=<dashicon>]
: The dashicon to use in the menu.
[--theme... | [
"Generates",
"PHP",
"code",
"for",
"registering",
"a",
"custom",
"post",
"type",
"."
] | train | https://github.com/wp-cli/scaffold-command/blob/9c6450e9ccf2d032913fced69f3188bc8ec4e3e6/src/Scaffold_Command.php#L69-L86 |
wp-cli/scaffold-command | src/Scaffold_Command.php | Scaffold_Command.taxonomy | public function taxonomy( $args, $assoc_args ) {
$defaults = array(
'textdomain' => '',
'post_types' => "'post'",
);
if ( isset( $assoc_args['post_types'] ) ) {
$assoc_args['post_types'] = $this->quote_comma_list_elements( $assoc_args['post_types'] );
}
$templates = array(
'taxonomy.mustache',
... | php | public function taxonomy( $args, $assoc_args ) {
$defaults = array(
'textdomain' => '',
'post_types' => "'post'",
);
if ( isset( $assoc_args['post_types'] ) ) {
$assoc_args['post_types'] = $this->quote_comma_list_elements( $assoc_args['post_types'] );
}
$templates = array(
'taxonomy.mustache',
... | [
"public",
"function",
"taxonomy",
"(",
"$",
"args",
",",
"$",
"assoc_args",
")",
"{",
"$",
"defaults",
"=",
"array",
"(",
"'textdomain'",
"=>",
"''",
",",
"'post_types'",
"=>",
"\"'post'\"",
",",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"assoc_args",
"[... | Generates PHP code for registering a custom taxonomy.
## OPTIONS
<slug>
: The internal name of the taxonomy.
[--post_types=<post-types>]
: Post types to register for use with the taxonomy.
[--label=<label>]
: The text used to translate the update messages.
[--textdomain=<textdomain>]
: The textdomain to use for th... | [
"Generates",
"PHP",
"code",
"for",
"registering",
"a",
"custom",
"taxonomy",
"."
] | train | https://github.com/wp-cli/scaffold-command/blob/9c6450e9ccf2d032913fced69f3188bc8ec4e3e6/src/Scaffold_Command.php#L127-L143 |
wp-cli/scaffold-command | src/Scaffold_Command.php | Scaffold_Command.block | public function block( $args, $assoc_args ) {
$slug = $args[0];
if ( ! preg_match( '/^[a-z][a-z0-9\-]*$/', $slug ) ) {
WP_CLI::error( 'Invalid block slug specified. Block slugs can contain only lowercase alphanumeric characters or dashes, and start with a letter.' );
}
$defaults = array(
'title' => s... | php | public function block( $args, $assoc_args ) {
$slug = $args[0];
if ( ! preg_match( '/^[a-z][a-z0-9\-]*$/', $slug ) ) {
WP_CLI::error( 'Invalid block slug specified. Block slugs can contain only lowercase alphanumeric characters or dashes, and start with a letter.' );
}
$defaults = array(
'title' => s... | [
"public",
"function",
"block",
"(",
"$",
"args",
",",
"$",
"assoc_args",
")",
"{",
"$",
"slug",
"=",
"$",
"args",
"[",
"0",
"]",
";",
"if",
"(",
"!",
"preg_match",
"(",
"'/^[a-z][a-z0-9\\-]*$/'",
",",
"$",
"slug",
")",
")",
"{",
"WP_CLI",
"::",
"er... | Generates PHP, JS and CSS code for registering a Gutenberg block for a plugin or theme.
Blocks are the fundamental element of the Gutenberg editor. They are the primary way in which plugins and themes can register their own functionality and extend the capabilities of the editor.
Visit the [Gutenberg handbook](https:... | [
"Generates",
"PHP",
"JS",
"and",
"CSS",
"code",
"for",
"registering",
"a",
"Gutenberg",
"block",
"for",
"a",
"plugin",
"or",
"theme",
"."
] | train | https://github.com/wp-cli/scaffold-command/blob/9c6450e9ccf2d032913fced69f3188bc8ec4e3e6/src/Scaffold_Command.php#L266-L321 |
wp-cli/scaffold-command | src/Scaffold_Command.php | Scaffold_Command.underscores | public function underscores( $args, $assoc_args ) {
$theme_slug = $args[0];
$theme_path = WP_CONTENT_DIR . '/themes';
$url = 'https://underscores.me';
$timeout = 30;
if ( ! preg_match( '/^[a-z_]\w+$/i', str_replace( '-', '_', $theme_slug ) ) ) {
WP_CLI::error( 'Invalid theme slug specified. The... | php | public function underscores( $args, $assoc_args ) {
$theme_slug = $args[0];
$theme_path = WP_CONTENT_DIR . '/themes';
$url = 'https://underscores.me';
$timeout = 30;
if ( ! preg_match( '/^[a-z_]\w+$/i', str_replace( '-', '_', $theme_slug ) ) ) {
WP_CLI::error( 'Invalid theme slug specified. The... | [
"public",
"function",
"underscores",
"(",
"$",
"args",
",",
"$",
"assoc_args",
")",
"{",
"$",
"theme_slug",
"=",
"$",
"args",
"[",
"0",
"]",
";",
"$",
"theme_path",
"=",
"WP_CONTENT_DIR",
".",
"'/themes'",
";",
"$",
"url",
"=",
"'https://underscores.me'",
... | Generates starter code for a theme based on _s.
See the [Underscores website](https://underscores.me/) for more details.
## OPTIONS
<slug>
: The slug for the new theme, used for prefixing functions.
[--activate]
: Activate the newly downloaded theme.
[--enable-network]
: Enable the newly downloaded theme for the e... | [
"Generates",
"starter",
"code",
"for",
"a",
"theme",
"based",
"on",
"_s",
"."
] | train | https://github.com/wp-cli/scaffold-command/blob/9c6450e9ccf2d032913fced69f3188bc8ec4e3e6/src/Scaffold_Command.php#L365-L467 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.