repo stringlengths 6 63 | path stringlengths 5 140 | func_name stringlengths 3 151 | original_string stringlengths 84 13k | language stringclasses 1
value | code stringlengths 84 13k | code_tokens list | docstring stringlengths 3 47.2k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 91 247 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
thephpleague/climate | src/TerminalObject/Dynamic/Animation.php | Animation.setupKeyframes | protected function setupKeyframes()
{
$this->keyframes->parser($this->parser);
$this->keyframes->util($this->util);
} | php | protected function setupKeyframes()
{
$this->keyframes->parser($this->parser);
$this->keyframes->util($this->util);
} | [
"protected",
"function",
"setupKeyframes",
"(",
")",
"{",
"$",
"this",
"->",
"keyframes",
"->",
"parser",
"(",
"$",
"this",
"->",
"parser",
")",
";",
"$",
"this",
"->",
"keyframes",
"->",
"util",
"(",
"$",
"this",
"->",
"util",
")",
";",
"}"
] | Set up the necessary properties on the Keyframe class | [
"Set",
"up",
"the",
"necessary",
"properties",
"on",
"the",
"Keyframe",
"class"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/TerminalObject/Dynamic/Animation.php#L147-L151 | train |
thephpleague/climate | src/TerminalObject/Dynamic/Animation.php | Animation.animate | protected function animate(array $keyframes)
{
$count = 0;
foreach ($keyframes as $lines) {
$this->writeKeyFrame($lines, $count);
$this->sleeper->sleep();
$count = count($lines);
}
} | php | protected function animate(array $keyframes)
{
$count = 0;
foreach ($keyframes as $lines) {
$this->writeKeyFrame($lines, $count);
$this->sleeper->sleep();
$count = count($lines);
}
} | [
"protected",
"function",
"animate",
"(",
"array",
"$",
"keyframes",
")",
"{",
"$",
"count",
"=",
"0",
";",
"foreach",
"(",
"$",
"keyframes",
"as",
"$",
"lines",
")",
"{",
"$",
"this",
"->",
"writeKeyFrame",
"(",
"$",
"lines",
",",
"$",
"count",
")",
... | Animate the given keyframes
@param array $keyframes Array of arrays | [
"Animate",
"the",
"given",
"keyframes"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/TerminalObject/Dynamic/Animation.php#L158-L167 | train |
thephpleague/climate | src/TerminalObject/Dynamic/Animation.php | Animation.writeKeyFrame | protected function writeKeyFrame(array $lines, $count)
{
foreach ($lines as $key => $line) {
$content = $this->getLineFormatted($line, $key, $count);
$this->output->write($this->parser->apply($content));
}
} | php | protected function writeKeyFrame(array $lines, $count)
{
foreach ($lines as $key => $line) {
$content = $this->getLineFormatted($line, $key, $count);
$this->output->write($this->parser->apply($content));
}
} | [
"protected",
"function",
"writeKeyFrame",
"(",
"array",
"$",
"lines",
",",
"$",
"count",
")",
"{",
"foreach",
"(",
"$",
"lines",
"as",
"$",
"key",
"=>",
"$",
"line",
")",
"{",
"$",
"content",
"=",
"$",
"this",
"->",
"getLineFormatted",
"(",
"$",
"lin... | Write the current keyframe to the terminal, line by line
@param array $lines
@param integer $count | [
"Write",
"the",
"current",
"keyframe",
"to",
"the",
"terminal",
"line",
"by",
"line"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/TerminalObject/Dynamic/Animation.php#L175-L181 | train |
thephpleague/climate | src/TerminalObject/Dynamic/Animation.php | Animation.getLineFormatted | protected function getLineFormatted($line, $key, $last_frame_count)
{
// If this is the first thing we're writing, just return the line
if ($last_frame_count == 0) {
return $line;
}
$content = '';
// If this is the first line of the frame,
// move the cursor up the total number of previous lines from the previous frame
if ($key == 0) {
$content .= $this->util->cursor->up($last_frame_count);
}
$content .= $this->util->cursor->startOfCurrentLine();
$content .= $this->util->cursor->deleteCurrentLine();
$content .= $line;
return $content;
} | php | protected function getLineFormatted($line, $key, $last_frame_count)
{
// If this is the first thing we're writing, just return the line
if ($last_frame_count == 0) {
return $line;
}
$content = '';
// If this is the first line of the frame,
// move the cursor up the total number of previous lines from the previous frame
if ($key == 0) {
$content .= $this->util->cursor->up($last_frame_count);
}
$content .= $this->util->cursor->startOfCurrentLine();
$content .= $this->util->cursor->deleteCurrentLine();
$content .= $line;
return $content;
} | [
"protected",
"function",
"getLineFormatted",
"(",
"$",
"line",
",",
"$",
"key",
",",
"$",
"last_frame_count",
")",
"{",
"// If this is the first thing we're writing, just return the line",
"if",
"(",
"$",
"last_frame_count",
"==",
"0",
")",
"{",
"return",
"$",
"line... | Format the line to re-write previous lines, if necessary
@param string $line
@param integer $key
@param integer $last_frame_count
@return string | [
"Format",
"the",
"line",
"to",
"re",
"-",
"write",
"previous",
"lines",
"if",
"necessary"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/TerminalObject/Dynamic/Animation.php#L192-L212 | train |
thephpleague/climate | src/Util/System/System.php | System.exec | public function exec($command, $full = false)
{
if ($full) {
exec($command, $output);
return $output;
}
return exec($command);
} | php | public function exec($command, $full = false)
{
if ($full) {
exec($command, $output);
return $output;
}
return exec($command);
} | [
"public",
"function",
"exec",
"(",
"$",
"command",
",",
"$",
"full",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"full",
")",
"{",
"exec",
"(",
"$",
"command",
",",
"$",
"output",
")",
";",
"return",
"$",
"output",
";",
"}",
"return",
"exec",
"(",
... | Wraps exec function, allowing the dimension methods to decouple
@param string $command
@param boolean $full
@return string|array | [
"Wraps",
"exec",
"function",
"allowing",
"the",
"dimension",
"methods",
"to",
"decouple"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/Util/System/System.php#L58-L67 | train |
thephpleague/climate | src/TerminalObject/Basic/ClearLine.php | ClearLine.result | public function result()
{
$string = "";
while ($this->count > 0) {
$string .= $this->util->cursor->startOfCurrentLine();
$string .= $this->util->cursor->deleteCurrentLine();
--$this->count;
$string .= $this->util->cursor->up();
}
$string .= $this->util->cursor->down();
return $string;
} | php | public function result()
{
$string = "";
while ($this->count > 0) {
$string .= $this->util->cursor->startOfCurrentLine();
$string .= $this->util->cursor->deleteCurrentLine();
--$this->count;
$string .= $this->util->cursor->up();
}
$string .= $this->util->cursor->down();
return $string;
} | [
"public",
"function",
"result",
"(",
")",
"{",
"$",
"string",
"=",
"\"\"",
";",
"while",
"(",
"$",
"this",
"->",
"count",
">",
"0",
")",
"{",
"$",
"string",
".=",
"$",
"this",
"->",
"util",
"->",
"cursor",
"->",
"startOfCurrentLine",
"(",
")",
";",... | Clear the lines.
@return string | [
"Clear",
"the",
"lines",
"."
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/TerminalObject/Basic/ClearLine.php#L12-L26 | train |
thephpleague/climate | src/Util/System/Windows.php | Windows.getDimension | protected function getDimension($key)
{
$index = array_search($key, ['height', 'width']);
$dimensions = $this->getDimensions();
return (!empty($dimensions[$index])) ? $dimensions[$index] : null;
} | php | protected function getDimension($key)
{
$index = array_search($key, ['height', 'width']);
$dimensions = $this->getDimensions();
return (!empty($dimensions[$index])) ? $dimensions[$index] : null;
} | [
"protected",
"function",
"getDimension",
"(",
"$",
"key",
")",
"{",
"$",
"index",
"=",
"array_search",
"(",
"$",
"key",
",",
"[",
"'height'",
",",
"'width'",
"]",
")",
";",
"$",
"dimensions",
"=",
"$",
"this",
"->",
"getDimensions",
"(",
")",
";",
"r... | Get specified terminal dimension
@param string $key
@return integer|null | [
"Get",
"specified",
"terminal",
"dimension"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/Util/System/Windows.php#L35-L41 | train |
thephpleague/climate | src/Util/System/Windows.php | Windows.getDimensions | protected function getDimensions()
{
$output = $this->exec('mode CON', true);
if (!is_array($output)) {
return [];
}
$output = implode("\n", $output);
preg_match_all('/.*:\s*(\d+)/', $output, $matches);
return (!empty($matches[1])) ? $matches[1] : [];
} | php | protected function getDimensions()
{
$output = $this->exec('mode CON', true);
if (!is_array($output)) {
return [];
}
$output = implode("\n", $output);
preg_match_all('/.*:\s*(\d+)/', $output, $matches);
return (!empty($matches[1])) ? $matches[1] : [];
} | [
"protected",
"function",
"getDimensions",
"(",
")",
"{",
"$",
"output",
"=",
"$",
"this",
"->",
"exec",
"(",
"'mode CON'",
",",
"true",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"output",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
"$",
"o... | Get information about the dimensions of the terminal
@return array | [
"Get",
"information",
"about",
"the",
"dimensions",
"of",
"the",
"terminal"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/Util/System/Windows.php#L48-L61 | train |
thephpleague/climate | src/TerminalObject/Dynamic/Progress.php | Progress.current | public function current($current, $label = null)
{
if ($this->total == 0) {
// Avoid dividing by 0
throw new UnexpectedValueException('The progress total must be greater than zero.');
}
if ($current > $this->total) {
throw new UnexpectedValueException('The current is greater than the total.');
}
$this->drawProgressBar($current, $label);
$this->current = $current;
$this->label = $label;
} | php | public function current($current, $label = null)
{
if ($this->total == 0) {
// Avoid dividing by 0
throw new UnexpectedValueException('The progress total must be greater than zero.');
}
if ($current > $this->total) {
throw new UnexpectedValueException('The current is greater than the total.');
}
$this->drawProgressBar($current, $label);
$this->current = $current;
$this->label = $label;
} | [
"public",
"function",
"current",
"(",
"$",
"current",
",",
"$",
"label",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"total",
"==",
"0",
")",
"{",
"// Avoid dividing by 0",
"throw",
"new",
"UnexpectedValueException",
"(",
"'The progress total must be ... | Determines the current percentage we are at and re-writes the progress bar
@param integer $current
@param mixed $label
@return void
@throws UnexpectedValueException | [
"Determines",
"the",
"current",
"percentage",
"we",
"are",
"at",
"and",
"re",
"-",
"writes",
"the",
"progress",
"bar"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/TerminalObject/Dynamic/Progress.php#L100-L115 | train |
thephpleague/climate | src/TerminalObject/Dynamic/Progress.php | Progress.advance | public function advance($increment = 1, $label = null)
{
$this->current($this->current + $increment, $label);
} | php | public function advance($increment = 1, $label = null)
{
$this->current($this->current + $increment, $label);
} | [
"public",
"function",
"advance",
"(",
"$",
"increment",
"=",
"1",
",",
"$",
"label",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"current",
"(",
"$",
"this",
"->",
"current",
"+",
"$",
"increment",
",",
"$",
"label",
")",
";",
"}"
] | Increments the current position we are at and re-writes the progress bar
@param integer $increment The number of items to increment by
@param string $label | [
"Increments",
"the",
"current",
"position",
"we",
"are",
"at",
"and",
"re",
"-",
"writes",
"the",
"progress",
"bar"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/TerminalObject/Dynamic/Progress.php#L123-L126 | train |
thephpleague/climate | src/TerminalObject/Dynamic/Progress.php | Progress.each | public function each($items, callable $callback = null)
{
if ($items instanceof \Traversable) {
$items = iterator_to_array($items);
}
$total = count($items);
if (!$total) {
return;
}
$this->total($total);
foreach ($items as $key => $item) {
if ($callback) {
$label = $callback($item, $key);
} else {
$label = null;
}
$this->advance(1, $label);
}
} | php | public function each($items, callable $callback = null)
{
if ($items instanceof \Traversable) {
$items = iterator_to_array($items);
}
$total = count($items);
if (!$total) {
return;
}
$this->total($total);
foreach ($items as $key => $item) {
if ($callback) {
$label = $callback($item, $key);
} else {
$label = null;
}
$this->advance(1, $label);
}
} | [
"public",
"function",
"each",
"(",
"$",
"items",
",",
"callable",
"$",
"callback",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"items",
"instanceof",
"\\",
"Traversable",
")",
"{",
"$",
"items",
"=",
"iterator_to_array",
"(",
"$",
"items",
")",
";",
"}",
... | Update a progress bar using an iterable.
@param iterable $items Array or any other iterable object
@param callable $callback A handler to run on each item | [
"Update",
"a",
"progress",
"bar",
"using",
"an",
"iterable",
"."
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/TerminalObject/Dynamic/Progress.php#L148-L169 | train |
thephpleague/climate | src/TerminalObject/Dynamic/Progress.php | Progress.drawProgressBar | protected function drawProgressBar($current, $label)
{
$percentage = $this->percentageFormatted($current / $this->total);
if ($this->shouldRedraw($percentage, $label)) {
$progress_bar = $this->getProgressBar($current, $label);
$this->output->write($this->parser->apply($progress_bar));
}
$this->current_percentage = $percentage;
} | php | protected function drawProgressBar($current, $label)
{
$percentage = $this->percentageFormatted($current / $this->total);
if ($this->shouldRedraw($percentage, $label)) {
$progress_bar = $this->getProgressBar($current, $label);
$this->output->write($this->parser->apply($progress_bar));
}
$this->current_percentage = $percentage;
} | [
"protected",
"function",
"drawProgressBar",
"(",
"$",
"current",
",",
"$",
"label",
")",
"{",
"$",
"percentage",
"=",
"$",
"this",
"->",
"percentageFormatted",
"(",
"$",
"current",
"/",
"$",
"this",
"->",
"total",
")",
";",
"if",
"(",
"$",
"this",
"->"... | Draw the progress bar, if necessary
@param string $current
@param string $label | [
"Draw",
"the",
"progress",
"bar",
"if",
"necessary"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/TerminalObject/Dynamic/Progress.php#L178-L188 | train |
thephpleague/climate | src/TerminalObject/Dynamic/Progress.php | Progress.getProgressBar | protected function getProgressBar($current, $label)
{
if ($this->first_line) {
// Drop down a line, we are about to
// re-write this line for the progress bar
$this->output->write('');
$this->first_line = false;
}
// Move the cursor up and clear it to the end
$line_count = $this->has_label_line ? 2 : 1;
$progress_bar = $this->util->cursor->up($line_count);
$progress_bar .= $this->util->cursor->startOfCurrentLine();
$progress_bar .= $this->util->cursor->deleteCurrentLine();
$progress_bar .= $this->getProgressBarStr($current, $label);
// If this line has a label then set that this progress bar has a label line
if (strlen($label) > 0) {
$this->has_label_line = true;
}
return $progress_bar;
} | php | protected function getProgressBar($current, $label)
{
if ($this->first_line) {
// Drop down a line, we are about to
// re-write this line for the progress bar
$this->output->write('');
$this->first_line = false;
}
// Move the cursor up and clear it to the end
$line_count = $this->has_label_line ? 2 : 1;
$progress_bar = $this->util->cursor->up($line_count);
$progress_bar .= $this->util->cursor->startOfCurrentLine();
$progress_bar .= $this->util->cursor->deleteCurrentLine();
$progress_bar .= $this->getProgressBarStr($current, $label);
// If this line has a label then set that this progress bar has a label line
if (strlen($label) > 0) {
$this->has_label_line = true;
}
return $progress_bar;
} | [
"protected",
"function",
"getProgressBar",
"(",
"$",
"current",
",",
"$",
"label",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"first_line",
")",
"{",
"// Drop down a line, we are about to",
"// re-write this line for the progress bar",
"$",
"this",
"->",
"output",
"->"... | Build the progress bar str and return it
@param integer $current
@param string $label
@return string | [
"Build",
"the",
"progress",
"bar",
"str",
"and",
"return",
"it"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/TerminalObject/Dynamic/Progress.php#L198-L221 | train |
thephpleague/climate | src/TerminalObject/Dynamic/Progress.php | Progress.getBar | protected function getBar($length)
{
$bar = str_repeat('=', $length);
$padding = str_repeat(' ', $this->getBarStrLen() - $length);
return "{$bar}>{$padding}";
} | php | protected function getBar($length)
{
$bar = str_repeat('=', $length);
$padding = str_repeat(' ', $this->getBarStrLen() - $length);
return "{$bar}>{$padding}";
} | [
"protected",
"function",
"getBar",
"(",
"$",
"length",
")",
"{",
"$",
"bar",
"=",
"str_repeat",
"(",
"'='",
",",
"$",
"length",
")",
";",
"$",
"padding",
"=",
"str_repeat",
"(",
"' '",
",",
"$",
"this",
"->",
"getBarStrLen",
"(",
")",
"-",
"$",
"le... | Get the string for the actual bar based on the current length
@param integer $length
@return string | [
"Get",
"the",
"string",
"for",
"the",
"actual",
"bar",
"based",
"on",
"the",
"current",
"length"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/TerminalObject/Dynamic/Progress.php#L258-L264 | train |
thephpleague/climate | src/TerminalObject/Dynamic/Progress.php | Progress.getBarStrLen | protected function getBarStrLen()
{
if (!$this->bar_str_len) {
// Subtract 10 because of the '> 100%' plus some padding, max 100
$this->bar_str_len = min($this->util->width() - 10, 100);
}
return $this->bar_str_len;
} | php | protected function getBarStrLen()
{
if (!$this->bar_str_len) {
// Subtract 10 because of the '> 100%' plus some padding, max 100
$this->bar_str_len = min($this->util->width() - 10, 100);
}
return $this->bar_str_len;
} | [
"protected",
"function",
"getBarStrLen",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"bar_str_len",
")",
"{",
"// Subtract 10 because of the '> 100%' plus some padding, max 100",
"$",
"this",
"->",
"bar_str_len",
"=",
"min",
"(",
"$",
"this",
"->",
"util",
... | Get the length of the bar string based on the width of the terminal window
@return integer | [
"Get",
"the",
"length",
"of",
"the",
"bar",
"string",
"based",
"on",
"the",
"width",
"of",
"the",
"terminal",
"window"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/TerminalObject/Dynamic/Progress.php#L271-L279 | train |
thephpleague/climate | src/TerminalObject/Dynamic/Progress.php | Progress.labelFormatted | protected function labelFormatted($label)
{
return "\n" . $this->util->cursor->startOfCurrentLine() . $this->util->cursor->deleteCurrentLine() . $label;
} | php | protected function labelFormatted($label)
{
return "\n" . $this->util->cursor->startOfCurrentLine() . $this->util->cursor->deleteCurrentLine() . $label;
} | [
"protected",
"function",
"labelFormatted",
"(",
"$",
"label",
")",
"{",
"return",
"\"\\n\"",
".",
"$",
"this",
"->",
"util",
"->",
"cursor",
"->",
"startOfCurrentLine",
"(",
")",
".",
"$",
"this",
"->",
"util",
"->",
"cursor",
"->",
"deleteCurrentLine",
"(... | Format the label so it is positioned correctly
@param string $label
@return string | [
"Format",
"the",
"label",
"so",
"it",
"is",
"positioned",
"correctly"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/TerminalObject/Dynamic/Progress.php#L298-L301 | train |
thephpleague/climate | src/TerminalObject/Dynamic/Progress.php | Progress.shouldRedraw | protected function shouldRedraw($percentage, $label)
{
return ($this->force_redraw || $percentage != $this->current_percentage || $label != $this->label);
} | php | protected function shouldRedraw($percentage, $label)
{
return ($this->force_redraw || $percentage != $this->current_percentage || $label != $this->label);
} | [
"protected",
"function",
"shouldRedraw",
"(",
"$",
"percentage",
",",
"$",
"label",
")",
"{",
"return",
"(",
"$",
"this",
"->",
"force_redraw",
"||",
"$",
"percentage",
"!=",
"$",
"this",
"->",
"current_percentage",
"||",
"$",
"label",
"!=",
"$",
"this",
... | Determine whether the progress bar has changed and we need to redrew
@param string $percentage
@param string $label
@return boolean | [
"Determine",
"whether",
"the",
"progress",
"bar",
"has",
"changed",
"and",
"we",
"need",
"to",
"redrew"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/TerminalObject/Dynamic/Progress.php#L311-L314 | train |
thephpleague/climate | src/TerminalObject/Basic/Table.php | Table.result | public function result()
{
$this->column_widths = $this->getColumnWidths();
$this->table_width = $this->getWidth();
$this->border = $this->getBorder();
$this->buildHeaderRow();
foreach ($this->data as $columns) {
$this->addLine($this->buildRow($columns));
$this->addLine($this->border);
}
return $this->rows;
} | php | public function result()
{
$this->column_widths = $this->getColumnWidths();
$this->table_width = $this->getWidth();
$this->border = $this->getBorder();
$this->buildHeaderRow();
foreach ($this->data as $columns) {
$this->addLine($this->buildRow($columns));
$this->addLine($this->border);
}
return $this->rows;
} | [
"public",
"function",
"result",
"(",
")",
"{",
"$",
"this",
"->",
"column_widths",
"=",
"$",
"this",
"->",
"getColumnWidths",
"(",
")",
";",
"$",
"this",
"->",
"table_width",
"=",
"$",
"this",
"->",
"getWidth",
"(",
")",
";",
"$",
"this",
"->",
"bord... | Return the built rows
@return array | [
"Return",
"the",
"built",
"rows"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/TerminalObject/Basic/Table.php#L100-L114 | train |
thephpleague/climate | src/TerminalObject/Basic/Table.php | Table.getWidth | protected function getWidth()
{
$first_row = reset($this->data);
$first_row = $this->buildRow($first_row);
return $this->lengthWithoutTags($first_row);
} | php | protected function getWidth()
{
$first_row = reset($this->data);
$first_row = $this->buildRow($first_row);
return $this->lengthWithoutTags($first_row);
} | [
"protected",
"function",
"getWidth",
"(",
")",
"{",
"$",
"first_row",
"=",
"reset",
"(",
"$",
"this",
"->",
"data",
")",
";",
"$",
"first_row",
"=",
"$",
"this",
"->",
"buildRow",
"(",
"$",
"first_row",
")",
";",
"return",
"$",
"this",
"->",
"lengthW... | Determine the width of the table
@return integer | [
"Determine",
"the",
"width",
"of",
"the",
"table"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/TerminalObject/Basic/Table.php#L134-L140 | train |
thephpleague/climate | src/TerminalObject/Basic/Table.php | Table.buildRow | protected function buildRow($columns)
{
$row = [];
foreach ($columns as $key => $column) {
$row[] = $this->buildCell($key, $column);
}
$row = implode($this->column_divider, $row);
return trim($this->column_divider . $row . $this->column_divider);
} | php | protected function buildRow($columns)
{
$row = [];
foreach ($columns as $key => $column) {
$row[] = $this->buildCell($key, $column);
}
$row = implode($this->column_divider, $row);
return trim($this->column_divider . $row . $this->column_divider);
} | [
"protected",
"function",
"buildRow",
"(",
"$",
"columns",
")",
"{",
"$",
"row",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"columns",
"as",
"$",
"key",
"=>",
"$",
"column",
")",
"{",
"$",
"row",
"[",
"]",
"=",
"$",
"this",
"->",
"buildCell",
"(",
... | Get table row
@param mixed $columns
@return string | [
"Get",
"table",
"row"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/TerminalObject/Basic/Table.php#L172-L183 | train |
thephpleague/climate | src/TerminalObject/Basic/Table.php | Table.getHeaderRow | protected function getHeaderRow()
{
$first_item = reset($this->data);
$keys = array_keys($first_item);
$first_key = reset($keys);
// We have an associative array (probably), let's have a header row
if (!is_int($first_key)) {
return array_combine($keys, $keys);
}
return false;
} | php | protected function getHeaderRow()
{
$first_item = reset($this->data);
$keys = array_keys($first_item);
$first_key = reset($keys);
// We have an associative array (probably), let's have a header row
if (!is_int($first_key)) {
return array_combine($keys, $keys);
}
return false;
} | [
"protected",
"function",
"getHeaderRow",
"(",
")",
"{",
"$",
"first_item",
"=",
"reset",
"(",
"$",
"this",
"->",
"data",
")",
";",
"$",
"keys",
"=",
"array_keys",
"(",
"$",
"first_item",
")",
";",
"$",
"first_key",
"=",
"reset",
"(",
"$",
"keys",
")"... | Get the header row for the table if it's an associative array or object
@return mixed | [
"Get",
"the",
"header",
"row",
"for",
"the",
"table",
"if",
"it",
"s",
"an",
"associative",
"array",
"or",
"object"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/TerminalObject/Basic/Table.php#L203-L216 | train |
thephpleague/climate | src/TerminalObject/Basic/Table.php | Table.getColumnWidths | protected function getColumnWidths()
{
$first_row = reset($this->data);
// Create an array with the columns as keys and values of zero
$column_widths = $this->getDefaultColumnWidths($first_row);
foreach ($this->data as $columns) {
foreach ($columns as $key => $column) {
$column_widths[$key] = $this->getCellWidth($column_widths[$key], $column);
}
}
return $column_widths;
} | php | protected function getColumnWidths()
{
$first_row = reset($this->data);
// Create an array with the columns as keys and values of zero
$column_widths = $this->getDefaultColumnWidths($first_row);
foreach ($this->data as $columns) {
foreach ($columns as $key => $column) {
$column_widths[$key] = $this->getCellWidth($column_widths[$key], $column);
}
}
return $column_widths;
} | [
"protected",
"function",
"getColumnWidths",
"(",
")",
"{",
"$",
"first_row",
"=",
"reset",
"(",
"$",
"this",
"->",
"data",
")",
";",
"// Create an array with the columns as keys and values of zero",
"$",
"column_widths",
"=",
"$",
"this",
"->",
"getDefaultColumnWidths... | Determine the width of each column
@return array | [
"Determine",
"the",
"width",
"of",
"each",
"column"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/TerminalObject/Basic/Table.php#L223-L237 | train |
thephpleague/climate | src/TerminalObject/Basic/Table.php | Table.getDefaultColumnWidths | protected function getDefaultColumnWidths(array $columns)
{
$widths = $this->arrayOfStrLens(array_keys($columns));
return array_combine(array_keys($columns), $widths);
} | php | protected function getDefaultColumnWidths(array $columns)
{
$widths = $this->arrayOfStrLens(array_keys($columns));
return array_combine(array_keys($columns), $widths);
} | [
"protected",
"function",
"getDefaultColumnWidths",
"(",
"array",
"$",
"columns",
")",
"{",
"$",
"widths",
"=",
"$",
"this",
"->",
"arrayOfStrLens",
"(",
"array_keys",
"(",
"$",
"columns",
")",
")",
";",
"return",
"array_combine",
"(",
"array_keys",
"(",
"$",... | Set up an array of default column widths
@param array $columns
@return array | [
"Set",
"up",
"an",
"array",
"of",
"default",
"column",
"widths"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/TerminalObject/Basic/Table.php#L246-L251 | train |
thephpleague/climate | src/TerminalObject/Router/Router.php | Router.addExtension | public function addExtension($key, $class)
{
$extension = new ExtensionCollection($key, $class);
foreach ($extension->collection() as $obj_type => $collection) {
foreach ($collection as $obj_key => $obj_class) {
$this->{$obj_type}->addExtension($obj_key, $obj_class);
}
}
} | php | public function addExtension($key, $class)
{
$extension = new ExtensionCollection($key, $class);
foreach ($extension->collection() as $obj_type => $collection) {
foreach ($collection as $obj_key => $obj_class) {
$this->{$obj_type}->addExtension($obj_key, $obj_class);
}
}
} | [
"public",
"function",
"addExtension",
"(",
"$",
"key",
",",
"$",
"class",
")",
"{",
"$",
"extension",
"=",
"new",
"ExtensionCollection",
"(",
"$",
"key",
",",
"$",
"class",
")",
";",
"foreach",
"(",
"$",
"extension",
"->",
"collection",
"(",
")",
"as",... | Register a custom class with the router
@param string $key
@param string $class | [
"Register",
"a",
"custom",
"class",
"with",
"the",
"router"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/TerminalObject/Router/Router.php#L48-L57 | train |
thephpleague/climate | src/TerminalObject/Router/Router.php | Router.exists | public function exists($name)
{
return ($this->basic->exists($name) || $this->dynamic->exists($name));
} | php | public function exists($name)
{
return ($this->basic->exists($name) || $this->dynamic->exists($name));
} | [
"public",
"function",
"exists",
"(",
"$",
"name",
")",
"{",
"return",
"(",
"$",
"this",
"->",
"basic",
"->",
"exists",
"(",
"$",
"name",
")",
"||",
"$",
"this",
"->",
"dynamic",
"->",
"exists",
"(",
"$",
"name",
")",
")",
";",
"}"
] | Check if the name matches an existing terminal object
@param string $name
@return boolean | [
"Check",
"if",
"the",
"name",
"matches",
"an",
"existing",
"terminal",
"object"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/TerminalObject/Router/Router.php#L66-L69 | train |
thephpleague/climate | src/TerminalObject/Router/Router.php | Router.execute | public function execute($name, $arguments)
{
$router = $this->getRouter($name);
$router->output($this->output);
$obj = $this->getObject($router, $name, $arguments);
$obj->parser($this->parser);
$obj->util($this->util);
// If the object needs any settings, import them
foreach ($obj->settings() as $obj_setting) {
$setting = $this->settings->get($obj_setting);
if ($setting) {
$obj->importSetting($setting);
}
}
return $router->execute($obj);
} | php | public function execute($name, $arguments)
{
$router = $this->getRouter($name);
$router->output($this->output);
$obj = $this->getObject($router, $name, $arguments);
$obj->parser($this->parser);
$obj->util($this->util);
// If the object needs any settings, import them
foreach ($obj->settings() as $obj_setting) {
$setting = $this->settings->get($obj_setting);
if ($setting) {
$obj->importSetting($setting);
}
}
return $router->execute($obj);
} | [
"public",
"function",
"execute",
"(",
"$",
"name",
",",
"$",
"arguments",
")",
"{",
"$",
"router",
"=",
"$",
"this",
"->",
"getRouter",
"(",
"$",
"name",
")",
";",
"$",
"router",
"->",
"output",
"(",
"$",
"this",
"->",
"output",
")",
";",
"$",
"o... | Execute a terminal object using given arguments
@param string $name
@param mixed $arguments
@return null|\League\CLImate\TerminalObject\Basic\BasicTerminalObjectInterface | [
"Execute",
"a",
"terminal",
"object",
"using",
"given",
"arguments"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/TerminalObject/Router/Router.php#L79-L100 | train |
thephpleague/climate | src/TerminalObject/Router/Router.php | Router.getObject | protected function getObject($router, $name, $arguments)
{
$obj = $router->path($name);
if (is_string($obj)) {
$obj = (new \ReflectionClass($obj))->newInstanceArgs($arguments);
}
if (method_exists($obj, 'arguments')) {
call_user_func_array([$obj, 'arguments'], $arguments);
}
return $obj;
} | php | protected function getObject($router, $name, $arguments)
{
$obj = $router->path($name);
if (is_string($obj)) {
$obj = (new \ReflectionClass($obj))->newInstanceArgs($arguments);
}
if (method_exists($obj, 'arguments')) {
call_user_func_array([$obj, 'arguments'], $arguments);
}
return $obj;
} | [
"protected",
"function",
"getObject",
"(",
"$",
"router",
",",
"$",
"name",
",",
"$",
"arguments",
")",
"{",
"$",
"obj",
"=",
"$",
"router",
"->",
"path",
"(",
"$",
"name",
")",
";",
"if",
"(",
"is_string",
"(",
"$",
"obj",
")",
")",
"{",
"$",
... | Get the object whether it's a string or already instantiated
@param \League\CLImate\TerminalObject\Router\RouterInterface $router
@param string $name
@param array $arguments
@return \League\CLImate\TerminalObject\Dynamic\DynamicTerminalObjectInterface|\League\CLImate\TerminalObject\Basic\BasicTerminalObjectInterface | [
"Get",
"the",
"object",
"whether",
"it",
"s",
"a",
"string",
"or",
"already",
"instantiated"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/TerminalObject/Router/Router.php#L111-L124 | train |
thephpleague/climate | src/TerminalObject/Router/Router.php | Router.getRouter | protected function getRouter($name)
{
if ($this->basic->exists($name)) {
return $this->basic;
}
if ($this->dynamic->exists($name)) {
return $this->dynamic;
}
} | php | protected function getRouter($name)
{
if ($this->basic->exists($name)) {
return $this->basic;
}
if ($this->dynamic->exists($name)) {
return $this->dynamic;
}
} | [
"protected",
"function",
"getRouter",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"basic",
"->",
"exists",
"(",
"$",
"name",
")",
")",
"{",
"return",
"$",
"this",
"->",
"basic",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"dynamic",
"->... | Determine which type of router we are using and return it
@param string $name
@return \League\CLImate\TerminalObject\Router\RouterInterface|null | [
"Determine",
"which",
"type",
"of",
"router",
"we",
"are",
"using",
"and",
"return",
"it"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/TerminalObject/Router/Router.php#L133-L142 | train |
thephpleague/climate | src/TerminalObject/Router/BasicRouter.php | BasicRouter.execute | public function execute($obj)
{
$results = Helper::toArray($obj->result());
$this->output->persist();
foreach ($results as $result) {
if ($obj->sameLine()) {
$this->output->sameLine();
}
$this->output->write($obj->getParser()->apply($result));
}
$this->output->persist(false);
} | php | public function execute($obj)
{
$results = Helper::toArray($obj->result());
$this->output->persist();
foreach ($results as $result) {
if ($obj->sameLine()) {
$this->output->sameLine();
}
$this->output->write($obj->getParser()->apply($result));
}
$this->output->persist(false);
} | [
"public",
"function",
"execute",
"(",
"$",
"obj",
")",
"{",
"$",
"results",
"=",
"Helper",
"::",
"toArray",
"(",
"$",
"obj",
"->",
"result",
"(",
")",
")",
";",
"$",
"this",
"->",
"output",
"->",
"persist",
"(",
")",
";",
"foreach",
"(",
"$",
"re... | Execute a basic terminal object
@param \League\CLImate\TerminalObject\Basic\BasicTerminalObject $obj
@return void | [
"Execute",
"a",
"basic",
"terminal",
"object"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/TerminalObject/Router/BasicRouter.php#L26-L41 | train |
thephpleague/climate | src/CLImate.php | CLImate.hasOutput | protected function hasOutput($output)
{
if (!empty($output)) {
return true;
}
// Check for type first to avoid errors with objects/arrays/etc
return ((is_string($output) || is_numeric($output)) && strlen($output) > 0);
} | php | protected function hasOutput($output)
{
if (!empty($output)) {
return true;
}
// Check for type first to avoid errors with objects/arrays/etc
return ((is_string($output) || is_numeric($output)) && strlen($output) > 0);
} | [
"protected",
"function",
"hasOutput",
"(",
"$",
"output",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"output",
")",
")",
"{",
"return",
"true",
";",
"}",
"// Check for type first to avoid errors with objects/arrays/etc",
"return",
"(",
"(",
"is_string",
"(",
... | Check if we have valid output
@param mixed $output
@return boolean | [
"Check",
"if",
"we",
"have",
"valid",
"output"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/CLImate.php#L285-L293 | train |
thephpleague/climate | src/CLImate.php | CLImate.parseStyleMethod | protected function parseStyleMethod($method, $name)
{
// If the name starts with this method string...
if (substr($name, 0, strlen($method)) == $method) {
// ...remove the method name from the beginning of the string...
$name = substr($name, strlen($method));
// ...and trim off any of those underscores hanging around
$name = ltrim($name, '_');
$this->style->set($method);
}
return $name;
} | php | protected function parseStyleMethod($method, $name)
{
// If the name starts with this method string...
if (substr($name, 0, strlen($method)) == $method) {
// ...remove the method name from the beginning of the string...
$name = substr($name, strlen($method));
// ...and trim off any of those underscores hanging around
$name = ltrim($name, '_');
$this->style->set($method);
}
return $name;
} | [
"protected",
"function",
"parseStyleMethod",
"(",
"$",
"method",
",",
"$",
"name",
")",
"{",
"// If the name starts with this method string...",
"if",
"(",
"substr",
"(",
"$",
"name",
",",
"0",
",",
"strlen",
"(",
"$",
"method",
")",
")",
"==",
"$",
"method"... | Search for the method within the string
and route it if we find one.
@param string $method
@param string $name
@return string The new string without the executed method. | [
"Search",
"for",
"the",
"method",
"within",
"the",
"string",
"and",
"route",
"it",
"if",
"we",
"find",
"one",
"."
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/CLImate.php#L304-L318 | train |
thephpleague/climate | src/CLImate.php | CLImate.applyStyleMethods | protected function applyStyleMethods($name, $method_search = null)
{
// Get all of the possible style attributes
$method_search = $method_search ?: array_keys($this->style->all());
$new_name = $this->searchForStyleMethods($name, $method_search);
// While we still have a name left and we keep finding methods,
// loop through the possibilities
if (strlen($new_name) > 0 && $new_name != $name) {
return $this->applyStyleMethods($new_name, $method_search);
}
return $new_name;
} | php | protected function applyStyleMethods($name, $method_search = null)
{
// Get all of the possible style attributes
$method_search = $method_search ?: array_keys($this->style->all());
$new_name = $this->searchForStyleMethods($name, $method_search);
// While we still have a name left and we keep finding methods,
// loop through the possibilities
if (strlen($new_name) > 0 && $new_name != $name) {
return $this->applyStyleMethods($new_name, $method_search);
}
return $new_name;
} | [
"protected",
"function",
"applyStyleMethods",
"(",
"$",
"name",
",",
"$",
"method_search",
"=",
"null",
")",
"{",
"// Get all of the possible style attributes",
"$",
"method_search",
"=",
"$",
"method_search",
"?",
":",
"array_keys",
"(",
"$",
"this",
"->",
"style... | Search for any style methods within the name and apply them
@param string $name
@param array $method_search
@return string Anything left over after applying styles | [
"Search",
"for",
"any",
"style",
"methods",
"within",
"the",
"name",
"and",
"apply",
"them"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/CLImate.php#L328-L342 | train |
thephpleague/climate | src/CLImate.php | CLImate.searchForStyleMethods | protected function searchForStyleMethods($name, $search)
{
// Loop through the possible methods
foreach ($search as $method) {
// See if we found a valid method
$name = $this->parseStyleMethod($method, $name);
}
return $name;
} | php | protected function searchForStyleMethods($name, $search)
{
// Loop through the possible methods
foreach ($search as $method) {
// See if we found a valid method
$name = $this->parseStyleMethod($method, $name);
}
return $name;
} | [
"protected",
"function",
"searchForStyleMethods",
"(",
"$",
"name",
",",
"$",
"search",
")",
"{",
"// Loop through the possible methods",
"foreach",
"(",
"$",
"search",
"as",
"$",
"method",
")",
"{",
"// See if we found a valid method",
"$",
"name",
"=",
"$",
"thi... | Search for style methods in the current name
@param string $name
@param array $search
@return string | [
"Search",
"for",
"style",
"methods",
"in",
"the",
"current",
"name"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/CLImate.php#L351-L360 | train |
thephpleague/climate | src/CLImate.php | CLImate.buildTerminalObject | protected function buildTerminalObject($name, $arguments)
{
// Retrieve the parser for the current set of styles
$parser = $this->style->parser($this->util->system);
// Reset the styles
$this->style->reset();
// Execute the terminal object
$this->router->settings($this->settings);
$this->router->parser($parser);
$this->router->output($this->output);
$this->router->util($this->util);
return $this->router->execute($name, $arguments);
} | php | protected function buildTerminalObject($name, $arguments)
{
// Retrieve the parser for the current set of styles
$parser = $this->style->parser($this->util->system);
// Reset the styles
$this->style->reset();
// Execute the terminal object
$this->router->settings($this->settings);
$this->router->parser($parser);
$this->router->output($this->output);
$this->router->util($this->util);
return $this->router->execute($name, $arguments);
} | [
"protected",
"function",
"buildTerminalObject",
"(",
"$",
"name",
",",
"$",
"arguments",
")",
"{",
"// Retrieve the parser for the current set of styles",
"$",
"parser",
"=",
"$",
"this",
"->",
"style",
"->",
"parser",
"(",
"$",
"this",
"->",
"util",
"->",
"syst... | Build up the terminal object and return it
@param string $name
@param array $arguments
@return object|null | [
"Build",
"up",
"the",
"terminal",
"object",
"and",
"return",
"it"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/CLImate.php#L370-L385 | train |
thephpleague/climate | src/CLImate.php | CLImate.routeRemainingMethod | protected function routeRemainingMethod($name, array $arguments)
{
// If we still have something left, let's figure out what it is
if ($this->router->exists($name)) {
$obj = $this->buildTerminalObject($name, $arguments);
// If something was returned, return it
if (is_object($obj)) {
return $obj;
}
} elseif ($this->settings->exists($name)) {
$this->settings->add($name, reset($arguments));
// Handle passthroughs to the arguments manager.
} else {
// If we can't find it at this point, let's fail gracefully
$this->out(reset($arguments));
}
} | php | protected function routeRemainingMethod($name, array $arguments)
{
// If we still have something left, let's figure out what it is
if ($this->router->exists($name)) {
$obj = $this->buildTerminalObject($name, $arguments);
// If something was returned, return it
if (is_object($obj)) {
return $obj;
}
} elseif ($this->settings->exists($name)) {
$this->settings->add($name, reset($arguments));
// Handle passthroughs to the arguments manager.
} else {
// If we can't find it at this point, let's fail gracefully
$this->out(reset($arguments));
}
} | [
"protected",
"function",
"routeRemainingMethod",
"(",
"$",
"name",
",",
"array",
"$",
"arguments",
")",
"{",
"// If we still have something left, let's figure out what it is",
"if",
"(",
"$",
"this",
"->",
"router",
"->",
"exists",
"(",
"$",
"name",
")",
")",
"{",... | Route anything leftover after styles were applied
@param string $name
@param array $arguments
@return object|null | [
"Route",
"anything",
"leftover",
"after",
"styles",
"were",
"applied"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/CLImate.php#L395-L412 | train |
thephpleague/climate | src/TerminalObject/Dynamic/Animation/Keyframe.php | Keyframe.exitTo | public function exitTo($lines, $direction)
{
$lines = $this->adjustLines($lines, $direction);
$line_method = $this->getLineMethod($direction);
$direction_keyframes = $this->getDirectionFrames($direction, $lines, $line_method);
$keyframes = array_fill(0, 4, $lines);
$keyframes = array_merge($keyframes, $direction_keyframes);
$keyframes[] = array_fill(0, count($lines), '');
return $keyframes;
} | php | public function exitTo($lines, $direction)
{
$lines = $this->adjustLines($lines, $direction);
$line_method = $this->getLineMethod($direction);
$direction_keyframes = $this->getDirectionFrames($direction, $lines, $line_method);
$keyframes = array_fill(0, 4, $lines);
$keyframes = array_merge($keyframes, $direction_keyframes);
$keyframes[] = array_fill(0, count($lines), '');
return $keyframes;
} | [
"public",
"function",
"exitTo",
"(",
"$",
"lines",
",",
"$",
"direction",
")",
"{",
"$",
"lines",
"=",
"$",
"this",
"->",
"adjustLines",
"(",
"$",
"lines",
",",
"$",
"direction",
")",
";",
"$",
"line_method",
"=",
"$",
"this",
"->",
"getLineMethod",
... | Get the exit keyframes for the desired direction
@param array $lines
@param string $direction
@return array | [
"Get",
"the",
"exit",
"keyframes",
"for",
"the",
"desired",
"direction"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/TerminalObject/Dynamic/Animation/Keyframe.php#L34-L46 | train |
thephpleague/climate | src/TerminalObject/Dynamic/Animation/Keyframe.php | Keyframe.scroll | public function scroll($lines, $enter_from, $exit_to)
{
$keyframes = $this->enterFrom($lines, $enter_from);
$keyframes = array_merge($keyframes, $this->exitTo($lines, $exit_to));
$keyframes = array_unique($keyframes, SORT_REGULAR);
$keyframes[] = reset($keyframes);
return $keyframes;
} | php | public function scroll($lines, $enter_from, $exit_to)
{
$keyframes = $this->enterFrom($lines, $enter_from);
$keyframes = array_merge($keyframes, $this->exitTo($lines, $exit_to));
$keyframes = array_unique($keyframes, SORT_REGULAR);
$keyframes[] = reset($keyframes);
return $keyframes;
} | [
"public",
"function",
"scroll",
"(",
"$",
"lines",
",",
"$",
"enter_from",
",",
"$",
"exit_to",
")",
"{",
"$",
"keyframes",
"=",
"$",
"this",
"->",
"enterFrom",
"(",
"$",
"lines",
",",
"$",
"enter_from",
")",
";",
"$",
"keyframes",
"=",
"array_merge",
... | Get scroll keyframes
@param array $lines
@param string $enter_from
@param string $exit_to
@return array | [
"Get",
"scroll",
"keyframes"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/TerminalObject/Dynamic/Animation/Keyframe.php#L57-L65 | train |
thephpleague/climate | src/TerminalObject/Dynamic/Animation/Keyframe.php | Keyframe.adjustLines | protected function adjustLines(array $lines, $direction)
{
$adjust_method = 'adjust' . ucwords(strtolower($direction)) . 'Lines';
if (method_exists($this, $adjust_method)) {
return $this->$adjust_method($lines);
}
return $lines;
} | php | protected function adjustLines(array $lines, $direction)
{
$adjust_method = 'adjust' . ucwords(strtolower($direction)) . 'Lines';
if (method_exists($this, $adjust_method)) {
return $this->$adjust_method($lines);
}
return $lines;
} | [
"protected",
"function",
"adjustLines",
"(",
"array",
"$",
"lines",
",",
"$",
"direction",
")",
"{",
"$",
"adjust_method",
"=",
"'adjust'",
".",
"ucwords",
"(",
"strtolower",
"(",
"$",
"direction",
")",
")",
".",
"'Lines'",
";",
"if",
"(",
"method_exists",... | Adjust the array of lines if necessary
@param array $lines
@param string $direction
@return array | [
"Adjust",
"the",
"array",
"of",
"lines",
"if",
"necessary"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/TerminalObject/Dynamic/Animation/Keyframe.php#L86-L95 | train |
thephpleague/climate | src/TerminalObject/Dynamic/Animation/Keyframe.php | Keyframe.getDirectionFrames | protected function getDirectionFrames($direction, array $lines, $line_method)
{
$mapping = [
'exitHorizontalFrames' => ['left', 'right'],
'exitVerticalFrames' => ['top', 'bottom'],
];
foreach ($mapping as $method => $directions) {
if (in_array($direction, $directions)) {
return $this->$method($lines, $line_method);
}
}
// Fail gracefully, simply return an array
return [];
} | php | protected function getDirectionFrames($direction, array $lines, $line_method)
{
$mapping = [
'exitHorizontalFrames' => ['left', 'right'],
'exitVerticalFrames' => ['top', 'bottom'],
];
foreach ($mapping as $method => $directions) {
if (in_array($direction, $directions)) {
return $this->$method($lines, $line_method);
}
}
// Fail gracefully, simply return an array
return [];
} | [
"protected",
"function",
"getDirectionFrames",
"(",
"$",
"direction",
",",
"array",
"$",
"lines",
",",
"$",
"line_method",
")",
"{",
"$",
"mapping",
"=",
"[",
"'exitHorizontalFrames'",
"=>",
"[",
"'left'",
",",
"'right'",
"]",
",",
"'exitVerticalFrames'",
"=>"... | Get the keyframes appropriate for the animation direction
@param string $direction
@param array $lines
@param string $line_method
@return array | [
"Get",
"the",
"keyframes",
"appropriate",
"for",
"the",
"animation",
"direction"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/TerminalObject/Dynamic/Animation/Keyframe.php#L128-L143 | train |
thephpleague/climate | src/TerminalObject/Dynamic/Animation/Keyframe.php | Keyframe.exitHorizontalFrames | protected function exitHorizontalFrames(array $lines, $line_method)
{
$keyframes = [];
$length = mb_strlen($lines[0]);
for ($i = $length; $i > 0; $i--) {
$keyframes[] = $this->getHorizontalKeyframe($lines, $i, $line_method, $length);
}
return $keyframes;
} | php | protected function exitHorizontalFrames(array $lines, $line_method)
{
$keyframes = [];
$length = mb_strlen($lines[0]);
for ($i = $length; $i > 0; $i--) {
$keyframes[] = $this->getHorizontalKeyframe($lines, $i, $line_method, $length);
}
return $keyframes;
} | [
"protected",
"function",
"exitHorizontalFrames",
"(",
"array",
"$",
"lines",
",",
"$",
"line_method",
")",
"{",
"$",
"keyframes",
"=",
"[",
"]",
";",
"$",
"length",
"=",
"mb_strlen",
"(",
"$",
"lines",
"[",
"0",
"]",
")",
";",
"for",
"(",
"$",
"i",
... | Create horizontal exit animation keyframes for the art
@param array $lines
@param string $line_method
@return array | [
"Create",
"horizontal",
"exit",
"animation",
"keyframes",
"for",
"the",
"art"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/TerminalObject/Dynamic/Animation/Keyframe.php#L153-L163 | train |
thephpleague/climate | src/TerminalObject/Dynamic/Animation/Keyframe.php | Keyframe.getHorizontalKeyframe | protected function getHorizontalKeyframe(array $lines, $frame_number, $line_method, $length)
{
$keyframe = [];
foreach ($lines as $line) {
$keyframe[] = $this->$line_method($line, $frame_number, $length);
}
return $keyframe;
} | php | protected function getHorizontalKeyframe(array $lines, $frame_number, $line_method, $length)
{
$keyframe = [];
foreach ($lines as $line) {
$keyframe[] = $this->$line_method($line, $frame_number, $length);
}
return $keyframe;
} | [
"protected",
"function",
"getHorizontalKeyframe",
"(",
"array",
"$",
"lines",
",",
"$",
"frame_number",
",",
"$",
"line_method",
",",
"$",
"length",
")",
"{",
"$",
"keyframe",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"lines",
"as",
"$",
"line",
")",
"{... | Get the keyframe for a horizontal animation
@param array $lines
@param int $frame_number
@param string $line_method
@param int $length
@return array | [
"Get",
"the",
"keyframe",
"for",
"a",
"horizontal",
"animation"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/TerminalObject/Dynamic/Animation/Keyframe.php#L175-L184 | train |
thephpleague/climate | src/TerminalObject/Dynamic/Animation/Keyframe.php | Keyframe.exitVerticalFrames | protected function exitVerticalFrames(array $lines, $line_method)
{
$keyframes = [];
$line_count = count($lines);
for ($i = $line_count - 1; $i >= 0; $i--) {
$keyframes[] = $this->$line_method($lines, $line_count, $i);
}
return $keyframes;
} | php | protected function exitVerticalFrames(array $lines, $line_method)
{
$keyframes = [];
$line_count = count($lines);
for ($i = $line_count - 1; $i >= 0; $i--) {
$keyframes[] = $this->$line_method($lines, $line_count, $i);
}
return $keyframes;
} | [
"protected",
"function",
"exitVerticalFrames",
"(",
"array",
"$",
"lines",
",",
"$",
"line_method",
")",
"{",
"$",
"keyframes",
"=",
"[",
"]",
";",
"$",
"line_count",
"=",
"count",
"(",
"$",
"lines",
")",
";",
"for",
"(",
"$",
"i",
"=",
"$",
"line_co... | Create vertical exit animation keyframes for the art
@param array $lines
@param string $line_method
@return array | [
"Create",
"vertical",
"exit",
"animation",
"keyframes",
"for",
"the",
"art"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/TerminalObject/Dynamic/Animation/Keyframe.php#L194-L204 | train |
thephpleague/climate | src/TerminalObject/Dynamic/Animation/Keyframe.php | Keyframe.currentRightLine | protected function currentRightLine($line, $frame_number, $length)
{
return str_repeat(' ', $length - $frame_number) . mb_substr($line, 0, $frame_number);
} | php | protected function currentRightLine($line, $frame_number, $length)
{
return str_repeat(' ', $length - $frame_number) . mb_substr($line, 0, $frame_number);
} | [
"protected",
"function",
"currentRightLine",
"(",
"$",
"line",
",",
"$",
"frame_number",
",",
"$",
"length",
")",
"{",
"return",
"str_repeat",
"(",
"' '",
",",
"$",
"length",
"-",
"$",
"frame_number",
")",
".",
"mb_substr",
"(",
"$",
"line",
",",
"0",
... | Get the current line as it is exiting right
@param string $line
@param int $frame_number
@param int $length
@return string | [
"Get",
"the",
"current",
"line",
"as",
"it",
"is",
"exiting",
"right"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/TerminalObject/Dynamic/Animation/Keyframe.php#L229-L232 | train |
thephpleague/climate | src/TerminalObject/Dynamic/Animation/Keyframe.php | Keyframe.currentTopLine | protected function currentTopLine($lines, $total_lines, $current)
{
$keyframe = array_slice($lines, -$current, $current);
return array_merge($keyframe, array_fill(0, $total_lines - $current, ''));
} | php | protected function currentTopLine($lines, $total_lines, $current)
{
$keyframe = array_slice($lines, -$current, $current);
return array_merge($keyframe, array_fill(0, $total_lines - $current, ''));
} | [
"protected",
"function",
"currentTopLine",
"(",
"$",
"lines",
",",
"$",
"total_lines",
",",
"$",
"current",
")",
"{",
"$",
"keyframe",
"=",
"array_slice",
"(",
"$",
"lines",
",",
"-",
"$",
"current",
",",
"$",
"current",
")",
";",
"return",
"array_merge"... | Slice off X number of lines from the bottom and fill the rest with empty strings
@param array $lines
@param integer $total_lines
@param integer $current
@return array | [
"Slice",
"off",
"X",
"number",
"of",
"lines",
"from",
"the",
"bottom",
"and",
"fill",
"the",
"rest",
"with",
"empty",
"strings"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/TerminalObject/Dynamic/Animation/Keyframe.php#L243-L248 | train |
thephpleague/climate | src/TerminalObject/Dynamic/Animation/Keyframe.php | Keyframe.currentBottomLine | protected function currentBottomLine($lines, $total_lines, $current)
{
$keyframe = array_fill(0, $total_lines - $current, '');
return array_merge($keyframe, array_slice($lines, 0, $current));
} | php | protected function currentBottomLine($lines, $total_lines, $current)
{
$keyframe = array_fill(0, $total_lines - $current, '');
return array_merge($keyframe, array_slice($lines, 0, $current));
} | [
"protected",
"function",
"currentBottomLine",
"(",
"$",
"lines",
",",
"$",
"total_lines",
",",
"$",
"current",
")",
"{",
"$",
"keyframe",
"=",
"array_fill",
"(",
"0",
",",
"$",
"total_lines",
"-",
"$",
"current",
",",
"''",
")",
";",
"return",
"array_mer... | Slice off X number of lines from the top and fill the rest with empty strings
@param array $lines
@param integer $total_lines
@param integer $current
@return array | [
"Slice",
"off",
"X",
"number",
"of",
"lines",
"from",
"the",
"top",
"and",
"fill",
"the",
"rest",
"with",
"empty",
"strings"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/TerminalObject/Dynamic/Animation/Keyframe.php#L259-L264 | train |
thephpleague/climate | src/Decorator/Style.php | Style.all | public function all()
{
$all = [];
foreach ($this->style as $style) {
$all = array_merge($all, $this->convertToCodes($style->all()));
}
return $all;
} | php | public function all()
{
$all = [];
foreach ($this->style as $style) {
$all = array_merge($all, $this->convertToCodes($style->all()));
}
return $all;
} | [
"public",
"function",
"all",
"(",
")",
"{",
"$",
"all",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"style",
"as",
"$",
"style",
")",
"{",
"$",
"all",
"=",
"array_merge",
"(",
"$",
"all",
",",
"$",
"this",
"->",
"convertToCodes",
"(",
... | Get all of the styles available
@return array | [
"Get",
"all",
"of",
"the",
"styles",
"available"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/Decorator/Style.php#L58-L67 | train |
thephpleague/climate | src/Decorator/Style.php | Style.get | public function get($key)
{
foreach ($this->style as $style) {
if ($code = $style->get($key)) {
return $code;
}
}
return false;
} | php | public function get($key)
{
foreach ($this->style as $style) {
if ($code = $style->get($key)) {
return $code;
}
}
return false;
} | [
"public",
"function",
"get",
"(",
"$",
"key",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"style",
"as",
"$",
"style",
")",
"{",
"if",
"(",
"$",
"code",
"=",
"$",
"style",
"->",
"get",
"(",
"$",
"key",
")",
")",
"{",
"return",
"$",
"code",
"... | Attempt to get the corresponding code for the style
@param mixed $key
@return mixed | [
"Attempt",
"to",
"get",
"the",
"corresponding",
"code",
"for",
"the",
"style"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/Decorator/Style.php#L76-L85 | train |
thephpleague/climate | src/Decorator/Style.php | Style.set | public function set($key)
{
foreach ($this->style as $style) {
if ($code = $style->set($key)) {
return $this->validateCode($code);
}
}
return false;
} | php | public function set($key)
{
foreach ($this->style as $style) {
if ($code = $style->set($key)) {
return $this->validateCode($code);
}
}
return false;
} | [
"public",
"function",
"set",
"(",
"$",
"key",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"style",
"as",
"$",
"style",
")",
"{",
"if",
"(",
"$",
"code",
"=",
"$",
"style",
"->",
"set",
"(",
"$",
"key",
")",
")",
"{",
"return",
"$",
"this",
"... | Attempt to set some aspect of the styling,
return true if attempt was successful
@param string $key
@return boolean | [
"Attempt",
"to",
"set",
"some",
"aspect",
"of",
"the",
"styling",
"return",
"true",
"if",
"attempt",
"was",
"successful"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/Decorator/Style.php#L95-L104 | train |
thephpleague/climate | src/Decorator/Style.php | Style.parser | public function parser(System $system)
{
return ParserFactory::getInstance($system, $this->current(), new Tags($this->all()));
} | php | public function parser(System $system)
{
return ParserFactory::getInstance($system, $this->current(), new Tags($this->all()));
} | [
"public",
"function",
"parser",
"(",
"System",
"$",
"system",
")",
"{",
"return",
"ParserFactory",
"::",
"getInstance",
"(",
"$",
"system",
",",
"$",
"this",
"->",
"current",
"(",
")",
",",
"new",
"Tags",
"(",
"$",
"this",
"->",
"all",
"(",
")",
")",... | Get a new instance of the Parser class based on the current settings
@param \League\CLImate\Util\System\System $system
@return \League\CLImate\Decorator\Parser\Parser | [
"Get",
"a",
"new",
"instance",
"of",
"the",
"Parser",
"class",
"based",
"on",
"the",
"current",
"settings"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/Decorator/Style.php#L124-L127 | train |
thephpleague/climate | src/Decorator/Style.php | Style.current | public function current()
{
$full_current = [];
foreach ($this->style as $style) {
$full_current = array_merge($full_current, Helper::toArray($style->current()));
}
$full_current = array_filter($full_current);
return array_values($full_current);
} | php | public function current()
{
$full_current = [];
foreach ($this->style as $style) {
$full_current = array_merge($full_current, Helper::toArray($style->current()));
}
$full_current = array_filter($full_current);
return array_values($full_current);
} | [
"public",
"function",
"current",
"(",
")",
"{",
"$",
"full_current",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"style",
"as",
"$",
"style",
")",
"{",
"$",
"full_current",
"=",
"array_merge",
"(",
"$",
"full_current",
",",
"Helper",
"::",
... | Compile an array of the current codes
@return array | [
"Compile",
"an",
"array",
"of",
"the",
"current",
"codes"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/Decorator/Style.php#L134-L145 | train |
thephpleague/climate | src/Decorator/Style.php | Style.validateCode | protected function validateCode($code)
{
if (is_integer($code)) {
return true;
}
// Plug it back in and see what we get
if (is_string($code)) {
return $this->set($code);
}
if (is_array($code)) {
return $this->validateCodeArray($code);
}
return false;
} | php | protected function validateCode($code)
{
if (is_integer($code)) {
return true;
}
// Plug it back in and see what we get
if (is_string($code)) {
return $this->set($code);
}
if (is_array($code)) {
return $this->validateCodeArray($code);
}
return false;
} | [
"protected",
"function",
"validateCode",
"(",
"$",
"code",
")",
"{",
"if",
"(",
"is_integer",
"(",
"$",
"code",
")",
")",
"{",
"return",
"true",
";",
"}",
"// Plug it back in and see what we get",
"if",
"(",
"is_string",
"(",
"$",
"code",
")",
")",
"{",
... | Make sure that the code is an integer, if not let's try and get it there
@param mixed $code
@return boolean | [
"Make",
"sure",
"that",
"the",
"code",
"is",
"an",
"integer",
"if",
"not",
"let",
"s",
"try",
"and",
"get",
"it",
"there"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/Decorator/Style.php#L154-L170 | train |
thephpleague/climate | src/Decorator/Style.php | Style.validateCodeArray | protected function validateCodeArray(array $codes)
{
// Loop through it and add each of the properties
$adds = [];
foreach ($codes as $code) {
$adds[] = $this->set($code);
}
// If any of them came back true, we're good to go
return in_array(true, $adds);
} | php | protected function validateCodeArray(array $codes)
{
// Loop through it and add each of the properties
$adds = [];
foreach ($codes as $code) {
$adds[] = $this->set($code);
}
// If any of them came back true, we're good to go
return in_array(true, $adds);
} | [
"protected",
"function",
"validateCodeArray",
"(",
"array",
"$",
"codes",
")",
"{",
"// Loop through it and add each of the properties",
"$",
"adds",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"codes",
"as",
"$",
"code",
")",
"{",
"$",
"adds",
"[",
"]",
"=",
... | Validate an array of codes
@param array $codes
@return boolean | [
"Validate",
"an",
"array",
"of",
"codes"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/Decorator/Style.php#L179-L190 | train |
thephpleague/climate | src/Decorator/Style.php | Style.convertToCodes | protected function convertToCodes(array $codes)
{
foreach ($codes as $key => $code) {
if (is_int($code)) {
continue;
}
$codes[$key] = $this->getCode($code);
}
return $codes;
} | php | protected function convertToCodes(array $codes)
{
foreach ($codes as $key => $code) {
if (is_int($code)) {
continue;
}
$codes[$key] = $this->getCode($code);
}
return $codes;
} | [
"protected",
"function",
"convertToCodes",
"(",
"array",
"$",
"codes",
")",
"{",
"foreach",
"(",
"$",
"codes",
"as",
"$",
"key",
"=>",
"$",
"code",
")",
"{",
"if",
"(",
"is_int",
"(",
"$",
"code",
")",
")",
"{",
"continue",
";",
"}",
"$",
"codes",
... | Convert the array of codes to integers
@param array $codes
@return array | [
"Convert",
"the",
"array",
"of",
"codes",
"to",
"integers"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/Decorator/Style.php#L198-L209 | train |
thephpleague/climate | src/Decorator/Style.php | Style.getCode | protected function getCode($code)
{
if (is_array($code)) {
return $this->getCodeArray($code);
}
return $this->get($code);
} | php | protected function getCode($code)
{
if (is_array($code)) {
return $this->getCodeArray($code);
}
return $this->get($code);
} | [
"protected",
"function",
"getCode",
"(",
"$",
"code",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"code",
")",
")",
"{",
"return",
"$",
"this",
"->",
"getCodeArray",
"(",
"$",
"code",
")",
";",
"}",
"return",
"$",
"this",
"->",
"get",
"(",
"$",
"c... | Retrieve the integers from the mixed code input
@param string|array $code
@return integer|array | [
"Retrieve",
"the",
"integers",
"from",
"the",
"mixed",
"code",
"input"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/Decorator/Style.php#L218-L225 | train |
thephpleague/climate | src/Decorator/Style.php | Style.getCodeArray | protected function getCodeArray(array $codes)
{
foreach ($codes as $key => $code) {
$codes[$key] = $this->get($code);
}
return $codes;
} | php | protected function getCodeArray(array $codes)
{
foreach ($codes as $key => $code) {
$codes[$key] = $this->get($code);
}
return $codes;
} | [
"protected",
"function",
"getCodeArray",
"(",
"array",
"$",
"codes",
")",
"{",
"foreach",
"(",
"$",
"codes",
"as",
"$",
"key",
"=>",
"$",
"code",
")",
"{",
"$",
"codes",
"[",
"$",
"key",
"]",
"=",
"$",
"this",
"->",
"get",
"(",
"$",
"code",
")",
... | Retrieve an array of integers from the array of codes
@param array $codes
@return array | [
"Retrieve",
"an",
"array",
"of",
"integers",
"from",
"the",
"array",
"of",
"codes"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/Decorator/Style.php#L234-L241 | train |
thephpleague/climate | src/Decorator/Style.php | Style.add | protected function add($style, $key, $value)
{
$this->style[$style]->add($key, $value);
// If we are adding a color, make sure it gets added
// as a background color too
if ($style == 'color') {
$this->style['background']->add($key, $value);
}
} | php | protected function add($style, $key, $value)
{
$this->style[$style]->add($key, $value);
// If we are adding a color, make sure it gets added
// as a background color too
if ($style == 'color') {
$this->style['background']->add($key, $value);
}
} | [
"protected",
"function",
"add",
"(",
"$",
"style",
",",
"$",
"key",
",",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"style",
"[",
"$",
"style",
"]",
"->",
"add",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"// If we are adding a color, make sure it g... | Add a custom style
@param string $style
@param string $key
@param string $value | [
"Add",
"a",
"custom",
"style"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/Decorator/Style.php#L262-L271 | train |
thephpleague/climate | src/Decorator/Tags.php | Tags.value | public function value($key)
{
return (array_key_exists($key, $this->tags)) ? $this->tags[$key] : null;
} | php | public function value($key)
{
return (array_key_exists($key, $this->tags)) ? $this->tags[$key] : null;
} | [
"public",
"function",
"value",
"(",
"$",
"key",
")",
"{",
"return",
"(",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"tags",
")",
")",
"?",
"$",
"this",
"->",
"tags",
"[",
"$",
"key",
"]",
":",
"null",
";",
"}"
] | Get the value of the requested tag
@param string $key
@return string|null | [
"Get",
"the",
"value",
"of",
"the",
"requested",
"tag"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/Decorator/Tags.php#L48-L51 | train |
thephpleague/climate | src/Decorator/Tags.php | Tags.build | protected function build()
{
foreach ($this->keys as $tag => $code) {
$this->tags["<{$tag}>"] = $code;
$this->tags["</{$tag}>"] = $code;
$this->tags["<\\/{$tag}>"] = $code;
}
} | php | protected function build()
{
foreach ($this->keys as $tag => $code) {
$this->tags["<{$tag}>"] = $code;
$this->tags["</{$tag}>"] = $code;
$this->tags["<\\/{$tag}>"] = $code;
}
} | [
"protected",
"function",
"build",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"keys",
"as",
"$",
"tag",
"=>",
"$",
"code",
")",
"{",
"$",
"this",
"->",
"tags",
"[",
"\"<{$tag}>\"",
"]",
"=",
"$",
"code",
";",
"$",
"this",
"->",
"tags",
"[",... | Build the search and replace for all of the various style tags | [
"Build",
"the",
"search",
"and",
"replace",
"for",
"all",
"of",
"the",
"various",
"style",
"tags"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/Decorator/Tags.php#L68-L75 | train |
thephpleague/climate | src/Decorator/Component/Color.php | Color.get | public function get($val)
{
// If we already have the code, just return that
if (is_numeric($val)) {
return $val;
}
if (array_key_exists($val, $this->colors)) {
return $this->colors[$val];
}
return null;
} | php | public function get($val)
{
// If we already have the code, just return that
if (is_numeric($val)) {
return $val;
}
if (array_key_exists($val, $this->colors)) {
return $this->colors[$val];
}
return null;
} | [
"public",
"function",
"get",
"(",
"$",
"val",
")",
"{",
"// If we already have the code, just return that",
"if",
"(",
"is_numeric",
"(",
"$",
"val",
")",
")",
"{",
"return",
"$",
"val",
";",
"}",
"if",
"(",
"array_key_exists",
"(",
"$",
"val",
",",
"$",
... | Get the code for the color
@param string $val
@return string | [
"Get",
"the",
"code",
"for",
"the",
"color"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/Decorator/Component/Color.php#L67-L79 | train |
thephpleague/climate | src/Decorator/Component/BackgroundColor.php | BackgroundColor.get | public function get($val)
{
$color = parent::get($this->strip($val));
if ($color) {
$color += self::ADD;
}
return $color;
} | php | public function get($val)
{
$color = parent::get($this->strip($val));
if ($color) {
$color += self::ADD;
}
return $color;
} | [
"public",
"function",
"get",
"(",
"$",
"val",
")",
"{",
"$",
"color",
"=",
"parent",
"::",
"get",
"(",
"$",
"this",
"->",
"strip",
"(",
"$",
"val",
")",
")",
";",
"if",
"(",
"$",
"color",
")",
"{",
"$",
"color",
"+=",
"self",
"::",
"ADD",
";"... | Get the code for the requested color
@param mixed $val
@return mixed | [
"Get",
"the",
"code",
"for",
"the",
"requested",
"color"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/Decorator/Component/BackgroundColor.php#L22-L31 | train |
thephpleague/climate | src/Decorator/Component/BackgroundColor.php | BackgroundColor.all | public function all()
{
$colors = [];
foreach ($this->colors as $color => $code) {
$colors['background_' . $color] = $code + self::ADD;
}
return $colors;
} | php | public function all()
{
$colors = [];
foreach ($this->colors as $color => $code) {
$colors['background_' . $color] = $code + self::ADD;
}
return $colors;
} | [
"public",
"function",
"all",
"(",
")",
"{",
"$",
"colors",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"colors",
"as",
"$",
"color",
"=>",
"$",
"code",
")",
"{",
"$",
"colors",
"[",
"'background_'",
".",
"$",
"color",
"]",
"=",
"$",
... | Get all of the available background colors
@return array | [
"Get",
"all",
"of",
"the",
"available",
"background",
"colors"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/Decorator/Component/BackgroundColor.php#L50-L59 | train |
thephpleague/climate | src/Settings/Manager.php | Manager.add | public function add($name, $value)
{
$setting = $this->getPath($name);
$key = $this->getClassName($name);
// If the current key doesn't exist in the settings array, set it up
if (!array_key_exists($name, $this->settings)) {
$this->settings[$key] = new $setting();
}
$this->settings[$key]->add($value);
} | php | public function add($name, $value)
{
$setting = $this->getPath($name);
$key = $this->getClassName($name);
// If the current key doesn't exist in the settings array, set it up
if (!array_key_exists($name, $this->settings)) {
$this->settings[$key] = new $setting();
}
$this->settings[$key]->add($value);
} | [
"public",
"function",
"add",
"(",
"$",
"name",
",",
"$",
"value",
")",
"{",
"$",
"setting",
"=",
"$",
"this",
"->",
"getPath",
"(",
"$",
"name",
")",
";",
"$",
"key",
"=",
"$",
"this",
"->",
"getClassName",
"(",
"$",
"name",
")",
";",
"// If the ... | Add a setting
@param string $name
@param mixed $value | [
"Add",
"a",
"setting"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/Settings/Manager.php#L32-L43 | train |
thephpleague/climate | src/Settings/Manager.php | Manager.get | public function get($key)
{
if (array_key_exists($key, $this->settings)) {
return $this->settings[$key];
}
return false;
} | php | public function get($key)
{
if (array_key_exists($key, $this->settings)) {
return $this->settings[$key];
}
return false;
} | [
"public",
"function",
"get",
"(",
"$",
"key",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"settings",
")",
")",
"{",
"return",
"$",
"this",
"->",
"settings",
"[",
"$",
"key",
"]",
";",
"}",
"return",
"false",
... | Get the value of the requested setting if it exists
@param string $key
@return mixed | [
"Get",
"the",
"value",
"of",
"the",
"requested",
"setting",
"if",
"it",
"exists"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/Settings/Manager.php#L52-L59 | train |
thephpleague/climate | src/Util/System/Linux.php | Linux.systemHasAnsiSupport | protected function systemHasAnsiSupport()
{
if ('Hyper' === getenv('TERM_PROGRAM')) {
return true;
}
$stream = STDOUT;
if (function_exists('stream_isatty')) {
return @stream_isatty($stream);
}
if (function_exists('posix_isatty')) {
return @posix_isatty($stream);
}
$stat = @fstat($stream);
// Check if formatted mode is S_IFCHR
return $stat ? 0020000 === ($stat['mode'] & 0170000) : false;
} | php | protected function systemHasAnsiSupport()
{
if ('Hyper' === getenv('TERM_PROGRAM')) {
return true;
}
$stream = STDOUT;
if (function_exists('stream_isatty')) {
return @stream_isatty($stream);
}
if (function_exists('posix_isatty')) {
return @posix_isatty($stream);
}
$stat = @fstat($stream);
// Check if formatted mode is S_IFCHR
return $stat ? 0020000 === ($stat['mode'] & 0170000) : false;
} | [
"protected",
"function",
"systemHasAnsiSupport",
"(",
")",
"{",
"if",
"(",
"'Hyper'",
"===",
"getenv",
"(",
"'TERM_PROGRAM'",
")",
")",
"{",
"return",
"true",
";",
"}",
"$",
"stream",
"=",
"STDOUT",
";",
"if",
"(",
"function_exists",
"(",
"'stream_isatty'",
... | Check if the stream supports ansi escape characters.
Based on https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Console/Output/StreamOutput.php
@return bool | [
"Check",
"if",
"the",
"stream",
"supports",
"ansi",
"escape",
"characters",
"."
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/Util/System/Linux.php#L84-L103 | train |
thephpleague/climate | src/Decorator/Component/Command.php | Command.get | public function get($val)
{
if (array_key_exists($val, $this->commands)) {
return $this->commands[$val];
}
return null;
} | php | public function get($val)
{
if (array_key_exists($val, $this->commands)) {
return $this->commands[$val];
}
return null;
} | [
"public",
"function",
"get",
"(",
"$",
"val",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"val",
",",
"$",
"this",
"->",
"commands",
")",
")",
"{",
"return",
"$",
"this",
"->",
"commands",
"[",
"$",
"val",
"]",
";",
"}",
"return",
"null",
... | Get the style that corresponds to the command
@param string $val
@return string | [
"Get",
"the",
"style",
"that",
"corresponds",
"to",
"the",
"command"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/Decorator/Component/Command.php#L55-L62 | train |
thephpleague/climate | src/Util/Writer/File.php | File.write | public function write($content)
{
$resource = $this->getResource();
if ($this->use_locking) {
flock($resource, LOCK_EX);
}
gzwrite($resource, $content);
if ($this->use_locking) {
flock($resource, LOCK_UN);
}
} | php | public function write($content)
{
$resource = $this->getResource();
if ($this->use_locking) {
flock($resource, LOCK_EX);
}
gzwrite($resource, $content);
if ($this->use_locking) {
flock($resource, LOCK_UN);
}
} | [
"public",
"function",
"write",
"(",
"$",
"content",
")",
"{",
"$",
"resource",
"=",
"$",
"this",
"->",
"getResource",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"use_locking",
")",
"{",
"flock",
"(",
"$",
"resource",
",",
"LOCK_EX",
")",
";",
"}"... | Write the content to the stream
@param string $content | [
"Write",
"the",
"content",
"to",
"the",
"stream"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/Util/Writer/File.php#L52-L65 | train |
thephpleague/climate | src/TerminalObject/Dynamic/Checkbox/CheckboxGroup.php | CheckboxGroup.setCurrent | public function setCurrent($direction)
{
list($option, $key) = $this->getCurrent();
$option->setCurrent(false);
$new_key = $this->getCurrentKey($direction, $option, $key);
$this->checkboxes[$new_key]->setCurrent();
} | php | public function setCurrent($direction)
{
list($option, $key) = $this->getCurrent();
$option->setCurrent(false);
$new_key = $this->getCurrentKey($direction, $option, $key);
$this->checkboxes[$new_key]->setCurrent();
} | [
"public",
"function",
"setCurrent",
"(",
"$",
"direction",
")",
"{",
"list",
"(",
"$",
"option",
",",
"$",
"key",
")",
"=",
"$",
"this",
"->",
"getCurrent",
"(",
")",
";",
"$",
"option",
"->",
"setCurrent",
"(",
"false",
")",
";",
"$",
"new_key",
"... | Set the newly selected option based on the direction
@param string $direction 'previous' or 'next' | [
"Set",
"the",
"newly",
"selected",
"option",
"based",
"on",
"the",
"direction"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/TerminalObject/Dynamic/Checkbox/CheckboxGroup.php#L49-L58 | train |
thephpleague/climate | src/TerminalObject/Dynamic/Checkbox/CheckboxGroup.php | CheckboxGroup.getCurrent | protected function getCurrent()
{
foreach ($this->checkboxes as $key => $option) {
if ($option->isCurrent()) {
return [$option, $key];
}
}
} | php | protected function getCurrent()
{
foreach ($this->checkboxes as $key => $option) {
if ($option->isCurrent()) {
return [$option, $key];
}
}
} | [
"protected",
"function",
"getCurrent",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"checkboxes",
"as",
"$",
"key",
"=>",
"$",
"option",
")",
"{",
"if",
"(",
"$",
"option",
"->",
"isCurrent",
"(",
")",
")",
"{",
"return",
"[",
"$",
"option",
"... | Get the currently selected option
@return array | [
"Get",
"the",
"currently",
"selected",
"option"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/TerminalObject/Dynamic/Checkbox/CheckboxGroup.php#L119-L126 | train |
thephpleague/climate | src/TerminalObject/Dynamic/Checkbox/CheckboxGroup.php | CheckboxGroup.getCurrentKey | protected function getCurrentKey($direction, $option, $key)
{
$method = 'get' . ucwords($direction). 'Key';
return $this->{$method}($option, $key);
} | php | protected function getCurrentKey($direction, $option, $key)
{
$method = 'get' . ucwords($direction). 'Key';
return $this->{$method}($option, $key);
} | [
"protected",
"function",
"getCurrentKey",
"(",
"$",
"direction",
",",
"$",
"option",
",",
"$",
"key",
")",
"{",
"$",
"method",
"=",
"'get'",
".",
"ucwords",
"(",
"$",
"direction",
")",
".",
"'Key'",
";",
"return",
"$",
"this",
"->",
"{",
"$",
"method... | Retrieve the correct current key
@param string $direction 'previous' or 'next'
@param Checkbox $option
@param int $key
@return int | [
"Retrieve",
"the",
"correct",
"current",
"key"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/TerminalObject/Dynamic/Checkbox/CheckboxGroup.php#L137-L142 | train |
thephpleague/climate | src/Util/Reader/Stdin.php | Stdin.getStdIn | protected function getStdIn()
{
if ($this->stdIn && !feof($this->stdIn)) {
return $this->stdIn;
}
try {
$this->setStdIn();
} catch (\Error $e) {
throw new RuntimeException('Unable to read from STDIN', 0, $e);
}
return $this->stdIn;
} | php | protected function getStdIn()
{
if ($this->stdIn && !feof($this->stdIn)) {
return $this->stdIn;
}
try {
$this->setStdIn();
} catch (\Error $e) {
throw new RuntimeException('Unable to read from STDIN', 0, $e);
}
return $this->stdIn;
} | [
"protected",
"function",
"getStdIn",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"stdIn",
"&&",
"!",
"feof",
"(",
"$",
"this",
"->",
"stdIn",
")",
")",
"{",
"return",
"$",
"this",
"->",
"stdIn",
";",
"}",
"try",
"{",
"$",
"this",
"->",
"setStdIn... | Return a valid STDIN, even if it previously EOF'ed
Lazily re-opens STDIN after hitting an EOF
@return resource
@throws RuntimeException | [
"Return",
"a",
"valid",
"STDIN",
"even",
"if",
"it",
"previously",
"EOF",
"ed"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/Util/Reader/Stdin.php#L62-L75 | train |
thephpleague/climate | src/Util/Reader/Stdin.php | Stdin.setStdIn | protected function setStdIn()
{
if ($this->stdIn !== false) {
fclose($this->stdIn);
}
$this->stdIn = fopen('php://stdin', 'r');
if (!$this->stdIn) {
throw new RuntimeException('Unable to read from STDIN');
}
} | php | protected function setStdIn()
{
if ($this->stdIn !== false) {
fclose($this->stdIn);
}
$this->stdIn = fopen('php://stdin', 'r');
if (!$this->stdIn) {
throw new RuntimeException('Unable to read from STDIN');
}
} | [
"protected",
"function",
"setStdIn",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"stdIn",
"!==",
"false",
")",
"{",
"fclose",
"(",
"$",
"this",
"->",
"stdIn",
")",
";",
"}",
"$",
"this",
"->",
"stdIn",
"=",
"fopen",
"(",
"'php://stdin'",
",",
"'r'... | Attempt to set the stdin property
@return void
@throws RuntimeException | [
"Attempt",
"to",
"set",
"the",
"stdin",
"property"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/Util/Reader/Stdin.php#L83-L94 | train |
thephpleague/climate | src/Util/Helper.php | Helper.flatten | public static function flatten(array $arr)
{
$flattened = [];
array_walk_recursive($arr, function ($a) use (&$flattened) {
$flattened[] = $a;
});
return $flattened;
} | php | public static function flatten(array $arr)
{
$flattened = [];
array_walk_recursive($arr, function ($a) use (&$flattened) {
$flattened[] = $a;
});
return $flattened;
} | [
"public",
"static",
"function",
"flatten",
"(",
"array",
"$",
"arr",
")",
"{",
"$",
"flattened",
"=",
"[",
"]",
";",
"array_walk_recursive",
"(",
"$",
"arr",
",",
"function",
"(",
"$",
"a",
")",
"use",
"(",
"&",
"$",
"flattened",
")",
"{",
"$",
"fl... | Flatten a multi-dimensional array
@param array $arr
@return array | [
"Flatten",
"a",
"multi",
"-",
"dimensional",
"array"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/Util/Helper.php#L28-L37 | train |
thephpleague/climate | src/Decorator/Component/Format.php | Format.get | public function get($val)
{
// If we already have the code, just return that
if (is_numeric($val)) {
return $val;
}
if (array_key_exists($val, $this->formats)) {
return $this->formats[$val];
}
return null;
} | php | public function get($val)
{
// If we already have the code, just return that
if (is_numeric($val)) {
return $val;
}
if (array_key_exists($val, $this->formats)) {
return $this->formats[$val];
}
return null;
} | [
"public",
"function",
"get",
"(",
"$",
"val",
")",
"{",
"// If we already have the code, just return that",
"if",
"(",
"is_numeric",
"(",
"$",
"val",
")",
")",
"{",
"return",
"$",
"val",
";",
"}",
"if",
"(",
"array_key_exists",
"(",
"$",
"val",
",",
"$",
... | Get the code for the format
@param string $val
@return string | [
"Get",
"the",
"code",
"for",
"the",
"format"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/Decorator/Component/Format.php#L56-L68 | train |
thephpleague/climate | src/Decorator/Component/Format.php | Format.set | public function set($val)
{
$code = $this->get($val);
if ($code) {
$this->current[] = $code;
return true;
}
return false;
} | php | public function set($val)
{
$code = $this->get($val);
if ($code) {
$this->current[] = $code;
return true;
}
return false;
} | [
"public",
"function",
"set",
"(",
"$",
"val",
")",
"{",
"$",
"code",
"=",
"$",
"this",
"->",
"get",
"(",
"$",
"val",
")",
";",
"if",
"(",
"$",
"code",
")",
"{",
"$",
"this",
"->",
"current",
"[",
"]",
"=",
"$",
"code",
";",
"return",
"true",
... | Set the current format
@param string $val
@return boolean | [
"Set",
"the",
"current",
"format"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/Decorator/Component/Format.php#L77-L88 | train |
thephpleague/climate | src/TerminalObject/Dynamic/Confirm.php | Confirm.confirmed | public function confirmed()
{
if (in_array($this->default, ["y", "yes"], true)) {
$this->prompt .= " [Y/n]";
} else {
$this->prompt .= " [y/N]";
}
$this->accept(['y', 'yes', 'n', 'no'], false);
$response = strtolower($this->prompt());
return (substr($response, 0, 1) === 'y');
} | php | public function confirmed()
{
if (in_array($this->default, ["y", "yes"], true)) {
$this->prompt .= " [Y/n]";
} else {
$this->prompt .= " [y/N]";
}
$this->accept(['y', 'yes', 'n', 'no'], false);
$response = strtolower($this->prompt());
return (substr($response, 0, 1) === 'y');
} | [
"public",
"function",
"confirmed",
"(",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"this",
"->",
"default",
",",
"[",
"\"y\"",
",",
"\"yes\"",
"]",
",",
"true",
")",
")",
"{",
"$",
"this",
"->",
"prompt",
".=",
"\" [Y/n]\"",
";",
"}",
"else",
"{",
... | Let us know if the user confirmed.
@return bool | [
"Let",
"us",
"know",
"if",
"the",
"user",
"confirmed",
"."
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/TerminalObject/Dynamic/Confirm.php#L30-L43 | train |
thephpleague/climate | src/TerminalObject/Dynamic/Checkbox/Checkbox.php | Checkbox.buildCheckboxString | protected function buildCheckboxString()
{
$parts = [
($this->isCurrent()) ? $this->pointer() : ' ',
$this->checkbox($this->isChecked()),
$this->label,
];
$line = implode(' ', $parts);
return $line . $this->getPaddingString($line);
} | php | protected function buildCheckboxString()
{
$parts = [
($this->isCurrent()) ? $this->pointer() : ' ',
$this->checkbox($this->isChecked()),
$this->label,
];
$line = implode(' ', $parts);
return $line . $this->getPaddingString($line);
} | [
"protected",
"function",
"buildCheckboxString",
"(",
")",
"{",
"$",
"parts",
"=",
"[",
"(",
"$",
"this",
"->",
"isCurrent",
"(",
")",
")",
"?",
"$",
"this",
"->",
"pointer",
"(",
")",
":",
"' '",
",",
"$",
"this",
"->",
"checkbox",
"(",
"$",
"this"... | Build out basic checkbox string based on current options
@return string | [
"Build",
"out",
"basic",
"checkbox",
"string",
"based",
"on",
"current",
"options"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/TerminalObject/Dynamic/Checkbox/Checkbox.php#L154-L165 | train |
thephpleague/climate | src/TerminalObject/Dynamic/Spinner.php | Spinner.advance | public function advance($label = null)
{
if ($label === null) {
$label = $this->label;
}
if ($this->lastDrawn) {
$time = microtime(true) - $this->lastDrawn;
if ($time < $this->timeLimit) {
return;
}
}
++$this->current;
if ($this->current >= count($this->characters)) {
$this->current = 0;
}
$characters = $this->characters[$this->current];
$this->drawSpinner($characters, $label);
$this->lastDrawn = microtime(true);
} | php | public function advance($label = null)
{
if ($label === null) {
$label = $this->label;
}
if ($this->lastDrawn) {
$time = microtime(true) - $this->lastDrawn;
if ($time < $this->timeLimit) {
return;
}
}
++$this->current;
if ($this->current >= count($this->characters)) {
$this->current = 0;
}
$characters = $this->characters[$this->current];
$this->drawSpinner($characters, $label);
$this->lastDrawn = microtime(true);
} | [
"public",
"function",
"advance",
"(",
"$",
"label",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"label",
"===",
"null",
")",
"{",
"$",
"label",
"=",
"$",
"this",
"->",
"label",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"lastDrawn",
")",
"{",
"$",
"tim... | Re-writes the spinner
@param string $label
@return void | [
"Re",
"-",
"writes",
"the",
"spinner"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/TerminalObject/Dynamic/Spinner.php#L113-L134 | train |
thephpleague/climate | src/TerminalObject/Dynamic/Spinner.php | Spinner.drawSpinner | private function drawSpinner($characters, $label)
{
$spinner = "";
if ($this->firstLine) {
$this->firstLine = false;
} else {
$spinner .= $this->util->cursor->up(1);
$spinner .= $this->util->cursor->startOfCurrentLine();
$spinner .= $this->util->cursor->deleteCurrentLine();
}
$spinner .= trim("{$characters} {$label}");
$this->output->write($this->parser->apply($spinner));
} | php | private function drawSpinner($characters, $label)
{
$spinner = "";
if ($this->firstLine) {
$this->firstLine = false;
} else {
$spinner .= $this->util->cursor->up(1);
$spinner .= $this->util->cursor->startOfCurrentLine();
$spinner .= $this->util->cursor->deleteCurrentLine();
}
$spinner .= trim("{$characters} {$label}");
$this->output->write($this->parser->apply($spinner));
} | [
"private",
"function",
"drawSpinner",
"(",
"$",
"characters",
",",
"$",
"label",
")",
"{",
"$",
"spinner",
"=",
"\"\"",
";",
"if",
"(",
"$",
"this",
"->",
"firstLine",
")",
"{",
"$",
"this",
"->",
"firstLine",
"=",
"false",
";",
"}",
"else",
"{",
"... | Draw the spinner
@param string $characters
@param string $label | [
"Draw",
"the",
"spinner"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/TerminalObject/Dynamic/Spinner.php#L143-L158 | train |
thephpleague/climate | src/Argument/Summary.php | Summary.output | public function output()
{
// Print the description if it's defined.
if ($this->description) {
$this->climate->out($this->description)->br();
}
// Print the usage statement with the arguments without a prefix at the end.
$this->climate->out("Usage: {$this->command} "
. $this->short($this->getOrderedArguments()));
// Print argument details.
foreach (['required', 'optional'] as $type) {
$this->outputArguments($this->filter->{$type}(), $type);
}
} | php | public function output()
{
// Print the description if it's defined.
if ($this->description) {
$this->climate->out($this->description)->br();
}
// Print the usage statement with the arguments without a prefix at the end.
$this->climate->out("Usage: {$this->command} "
. $this->short($this->getOrderedArguments()));
// Print argument details.
foreach (['required', 'optional'] as $type) {
$this->outputArguments($this->filter->{$type}(), $type);
}
} | [
"public",
"function",
"output",
"(",
")",
"{",
"// Print the description if it's defined.",
"if",
"(",
"$",
"this",
"->",
"description",
")",
"{",
"$",
"this",
"->",
"climate",
"->",
"out",
"(",
"$",
"this",
"->",
"description",
")",
"->",
"br",
"(",
")",
... | Output the full summary for the program | [
"Output",
"the",
"full",
"summary",
"for",
"the",
"program"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/Argument/Summary.php#L82-L97 | train |
thephpleague/climate | src/Argument/Summary.php | Summary.argument | public function argument(Argument $argument)
{
$summary = $this->prefixedArguments($argument);
$printedName = mb_strstr($summary, ' ' . $argument->name());
// Print the argument name if it's not printed yet.
if (!$printedName && !$argument->noValue()) {
$summary .= $argument->name();
}
if ($defaults = $argument->defaultValue()) {
if (count($defaults) == 1) {
$summary .= " (default: {$defaults[0]})";
} else {
$summary .= ' (defaults: ' . implode(', ', $defaults) . ')';
}
}
return $summary;
} | php | public function argument(Argument $argument)
{
$summary = $this->prefixedArguments($argument);
$printedName = mb_strstr($summary, ' ' . $argument->name());
// Print the argument name if it's not printed yet.
if (!$printedName && !$argument->noValue()) {
$summary .= $argument->name();
}
if ($defaults = $argument->defaultValue()) {
if (count($defaults) == 1) {
$summary .= " (default: {$defaults[0]})";
} else {
$summary .= ' (defaults: ' . implode(', ', $defaults) . ')';
}
}
return $summary;
} | [
"public",
"function",
"argument",
"(",
"Argument",
"$",
"argument",
")",
"{",
"$",
"summary",
"=",
"$",
"this",
"->",
"prefixedArguments",
"(",
"$",
"argument",
")",
";",
"$",
"printedName",
"=",
"mb_strstr",
"(",
"$",
"summary",
",",
"' '",
".",
"$",
... | Build an argument's summary for use in a usage statement.
For example, "-u username, --user username", "--force", or
"-c count (default: 7)".
@param Argument $argument
@return string | [
"Build",
"an",
"argument",
"s",
"summary",
"for",
"use",
"in",
"a",
"usage",
"statement",
"."
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/Argument/Summary.php#L121-L140 | train |
thephpleague/climate | src/Argument/Summary.php | Summary.outputArguments | protected function outputArguments($arguments, $type)
{
if (count($arguments) == 0) {
return;
}
$this->climate->br()->out(mb_convert_case($type, MB_CASE_TITLE) . ' Arguments:');
foreach ($arguments as $argument) {
$this->climate->tab()->out($this->argument($argument));
if ($argument->description()) {
$this->climate->tab(2)->out($argument->description());
}
}
} | php | protected function outputArguments($arguments, $type)
{
if (count($arguments) == 0) {
return;
}
$this->climate->br()->out(mb_convert_case($type, MB_CASE_TITLE) . ' Arguments:');
foreach ($arguments as $argument) {
$this->climate->tab()->out($this->argument($argument));
if ($argument->description()) {
$this->climate->tab(2)->out($argument->description());
}
}
} | [
"protected",
"function",
"outputArguments",
"(",
"$",
"arguments",
",",
"$",
"type",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"arguments",
")",
"==",
"0",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"climate",
"->",
"br",
"(",
")",
"->",
"out",... | Print out the argument list
@param array $arguments
@param string $type | [
"Print",
"out",
"the",
"argument",
"list"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/Argument/Summary.php#L170-L185 | train |
thephpleague/climate | src/Argument/Summary.php | Summary.prefixedArguments | protected function prefixedArguments(Argument $argument)
{
$prefixes = [$argument->prefix(), $argument->longPrefix()];
$summary = [];
foreach ($prefixes as $key => $prefix) {
if (!$prefix) {
continue;
}
$sub = str_repeat('-', $key + 1) . $prefix;
if (!$argument->noValue()) {
$sub .= " {$argument->name()}";
}
$summary[] = $sub;
}
return implode(', ', $summary);
} | php | protected function prefixedArguments(Argument $argument)
{
$prefixes = [$argument->prefix(), $argument->longPrefix()];
$summary = [];
foreach ($prefixes as $key => $prefix) {
if (!$prefix) {
continue;
}
$sub = str_repeat('-', $key + 1) . $prefix;
if (!$argument->noValue()) {
$sub .= " {$argument->name()}";
}
$summary[] = $sub;
}
return implode(', ', $summary);
} | [
"protected",
"function",
"prefixedArguments",
"(",
"Argument",
"$",
"argument",
")",
"{",
"$",
"prefixes",
"=",
"[",
"$",
"argument",
"->",
"prefix",
"(",
")",
",",
"$",
"argument",
"->",
"longPrefix",
"(",
")",
"]",
";",
"$",
"summary",
"=",
"[",
"]",... | Builds the summary for any prefixed arguments
@param Argument $argument
@return string | [
"Builds",
"the",
"summary",
"for",
"any",
"prefixed",
"arguments"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/Argument/Summary.php#L194-L214 | train |
thephpleague/climate | src/TerminalObject/Router/ExtensionCollection.php | ExtensionCollection.getKey | protected function getKey($key, $class)
{
if ($key === null || !is_string($key)) {
$class_path = (is_string($class)) ? $class : get_class($class);
$key = explode('\\', $class_path);
$key = end($key);
}
return Helper::snakeCase($key);
} | php | protected function getKey($key, $class)
{
if ($key === null || !is_string($key)) {
$class_path = (is_string($class)) ? $class : get_class($class);
$key = explode('\\', $class_path);
$key = end($key);
}
return Helper::snakeCase($key);
} | [
"protected",
"function",
"getKey",
"(",
"$",
"key",
",",
"$",
"class",
")",
"{",
"if",
"(",
"$",
"key",
"===",
"null",
"||",
"!",
"is_string",
"(",
"$",
"key",
")",
")",
"{",
"$",
"class_path",
"=",
"(",
"is_string",
"(",
"$",
"class",
")",
")",
... | Determine the extension key based on the class
@param string|null $key
@param string|object $class
@return string | [
"Determine",
"the",
"extension",
"key",
"based",
"on",
"the",
"class"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/TerminalObject/Router/ExtensionCollection.php#L120-L130 | train |
thephpleague/climate | src/Decorator/Parser/Ansi.php | Ansi.start | protected function start($codes = null)
{
$codes = $codes ?: $this->currentCode();
$codes = $this->codeStr($codes);
return $this->wrapCodes($codes);
} | php | protected function start($codes = null)
{
$codes = $codes ?: $this->currentCode();
$codes = $this->codeStr($codes);
return $this->wrapCodes($codes);
} | [
"protected",
"function",
"start",
"(",
"$",
"codes",
"=",
"null",
")",
"{",
"$",
"codes",
"=",
"$",
"codes",
"?",
":",
"$",
"this",
"->",
"currentCode",
"(",
")",
";",
"$",
"codes",
"=",
"$",
"this",
"->",
"codeStr",
"(",
"$",
"codes",
")",
";",
... | Get the string that begins the style
@param string $codes
@return string | [
"Get",
"the",
"string",
"that",
"begins",
"the",
"style"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/Decorator/Parser/Ansi.php#L28-L34 | train |
thephpleague/climate | src/Decorator/Parser/Ansi.php | Ansi.end | protected function end($codes = null)
{
if (empty($codes)) {
$codes = [0];
} else {
$codes = Helper::toArray($codes);
// Reset everything back to normal up front
array_unshift($codes, 0);
}
return $this->wrapCodes($this->codeStr($codes));
} | php | protected function end($codes = null)
{
if (empty($codes)) {
$codes = [0];
} else {
$codes = Helper::toArray($codes);
// Reset everything back to normal up front
array_unshift($codes, 0);
}
return $this->wrapCodes($this->codeStr($codes));
} | [
"protected",
"function",
"end",
"(",
"$",
"codes",
"=",
"null",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"codes",
")",
")",
"{",
"$",
"codes",
"=",
"[",
"0",
"]",
";",
"}",
"else",
"{",
"$",
"codes",
"=",
"Helper",
"::",
"toArray",
"(",
"$",
"... | Get the string that ends the style
@param string|array $codes
@return string | [
"Get",
"the",
"string",
"that",
"ends",
"the",
"style"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/Decorator/Parser/Ansi.php#L42-L54 | train |
thephpleague/climate | src/Decorator/Parser/Ansi.php | Ansi.parse | protected function parse($str)
{
$count = preg_match_all($this->tags->regex(), $str, $matches);
// If we didn't find anything, return the string right back
if (!$count || !is_array($matches)) {
return $str;
}
// All we want is the array of actual strings matched
$matches = reset($matches);
return $this->parseTags($str, $matches);
} | php | protected function parse($str)
{
$count = preg_match_all($this->tags->regex(), $str, $matches);
// If we didn't find anything, return the string right back
if (!$count || !is_array($matches)) {
return $str;
}
// All we want is the array of actual strings matched
$matches = reset($matches);
return $this->parseTags($str, $matches);
} | [
"protected",
"function",
"parse",
"(",
"$",
"str",
")",
"{",
"$",
"count",
"=",
"preg_match_all",
"(",
"$",
"this",
"->",
"tags",
"->",
"regex",
"(",
")",
",",
"$",
"str",
",",
"$",
"matches",
")",
";",
"// If we didn't find anything, return the string right... | Parse the string for tags and replace them with their codes
@param string $str
@return string | [
"Parse",
"the",
"string",
"for",
"tags",
"and",
"replace",
"them",
"with",
"their",
"codes"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/Decorator/Parser/Ansi.php#L77-L90 | train |
thephpleague/climate | src/Decorator/Parser/Ansi.php | Ansi.parseTags | protected function parseTags($str, $tags)
{
// Let's keep a history of styles applied
$history = ($this->currentCode()) ? [$this->currentCode()] : [];
foreach ($tags as $tag) {
$str = $this->replaceTag($str, $tag, $history);
}
return $str;
} | php | protected function parseTags($str, $tags)
{
// Let's keep a history of styles applied
$history = ($this->currentCode()) ? [$this->currentCode()] : [];
foreach ($tags as $tag) {
$str = $this->replaceTag($str, $tag, $history);
}
return $str;
} | [
"protected",
"function",
"parseTags",
"(",
"$",
"str",
",",
"$",
"tags",
")",
"{",
"// Let's keep a history of styles applied",
"$",
"history",
"=",
"(",
"$",
"this",
"->",
"currentCode",
"(",
")",
")",
"?",
"[",
"$",
"this",
"->",
"currentCode",
"(",
")",... | Parse the given string for the tags and replace them with the appropriate codes
@param string $str
@param array $tags
@return string | [
"Parse",
"the",
"given",
"string",
"for",
"the",
"tags",
"and",
"replace",
"them",
"with",
"the",
"appropriate",
"codes"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/Decorator/Parser/Ansi.php#L101-L111 | train |
thephpleague/climate | src/Decorator/Parser/Ansi.php | Ansi.replaceTag | protected function replaceTag($str, $tag, &$history)
{
// We will be replacing tags one at a time, can't pass this by reference
$replace_count = 1;
if (strpos($tag, '/')) {
// We are closing out the tag, pop off the last element and get the codes that are left
array_pop($history);
$replace = $this->end($history);
} else {
// We are starting a new tag, add it onto the history and replace with correct color code
$history[] = $this->tags->value($tag);
$replace = $this->start($this->tags->value($tag));
}
return str_replace($tag, $replace, $str, $replace_count);
} | php | protected function replaceTag($str, $tag, &$history)
{
// We will be replacing tags one at a time, can't pass this by reference
$replace_count = 1;
if (strpos($tag, '/')) {
// We are closing out the tag, pop off the last element and get the codes that are left
array_pop($history);
$replace = $this->end($history);
} else {
// We are starting a new tag, add it onto the history and replace with correct color code
$history[] = $this->tags->value($tag);
$replace = $this->start($this->tags->value($tag));
}
return str_replace($tag, $replace, $str, $replace_count);
} | [
"protected",
"function",
"replaceTag",
"(",
"$",
"str",
",",
"$",
"tag",
",",
"&",
"$",
"history",
")",
"{",
"// We will be replacing tags one at a time, can't pass this by reference",
"$",
"replace_count",
"=",
"1",
";",
"if",
"(",
"strpos",
"(",
"$",
"tag",
",... | Replace the tag in the str
@param string $str
@param string $tag
@param array $history
@return string | [
"Replace",
"the",
"tag",
"in",
"the",
"str"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/Decorator/Parser/Ansi.php#L123-L139 | train |
thephpleague/climate | src/Decorator/Parser/Ansi.php | Ansi.codeStr | protected function codeStr($codes)
{
// If we get something that is already a code string, just pass it back
if (!is_array($codes) && strpos($codes, ';')) {
return $codes;
}
$codes = Helper::toArray($codes);
// Sort for the sake of consistency and testability
sort($codes);
return implode(';', $codes);
} | php | protected function codeStr($codes)
{
// If we get something that is already a code string, just pass it back
if (!is_array($codes) && strpos($codes, ';')) {
return $codes;
}
$codes = Helper::toArray($codes);
// Sort for the sake of consistency and testability
sort($codes);
return implode(';', $codes);
} | [
"protected",
"function",
"codeStr",
"(",
"$",
"codes",
")",
"{",
"// If we get something that is already a code string, just pass it back",
"if",
"(",
"!",
"is_array",
"(",
"$",
"codes",
")",
"&&",
"strpos",
"(",
"$",
"codes",
",",
"';'",
")",
")",
"{",
"return"... | Stringify the codes
@param mixed $codes
@return string | [
"Stringify",
"the",
"codes"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/Decorator/Parser/Ansi.php#L149-L162 | train |
thephpleague/climate | src/TerminalObject/Basic/Border.php | Border.result | public function result()
{
$length = $this->length ?: $this->util->width() ?: 100;
$str = str_repeat($this->char, $length);
$str = substr($str, 0, $length);
return $str;
} | php | public function result()
{
$length = $this->length ?: $this->util->width() ?: 100;
$str = str_repeat($this->char, $length);
$str = substr($str, 0, $length);
return $str;
} | [
"public",
"function",
"result",
"(",
")",
"{",
"$",
"length",
"=",
"$",
"this",
"->",
"length",
"?",
":",
"$",
"this",
"->",
"util",
"->",
"width",
"(",
")",
"?",
":",
"100",
";",
"$",
"str",
"=",
"str_repeat",
"(",
"$",
"this",
"->",
"char",
"... | Return the border
@return string | [
"Return",
"the",
"border"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/TerminalObject/Basic/Border.php#L59-L66 | train |
thephpleague/climate | src/TerminalObject/Helper/StringLength.php | StringLength.setIgnoreTags | protected function setIgnoreTags()
{
if (!count($this->ignore_tags)) {
$this->ignore_tags = array_keys($this->parser->tags->all());
}
} | php | protected function setIgnoreTags()
{
if (!count($this->ignore_tags)) {
$this->ignore_tags = array_keys($this->parser->tags->all());
}
} | [
"protected",
"function",
"setIgnoreTags",
"(",
")",
"{",
"if",
"(",
"!",
"count",
"(",
"$",
"this",
"->",
"ignore_tags",
")",
")",
"{",
"$",
"this",
"->",
"ignore_tags",
"=",
"array_keys",
"(",
"$",
"this",
"->",
"parser",
"->",
"tags",
"->",
"all",
... | Set the ignore tags property | [
"Set",
"the",
"ignore",
"tags",
"property"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/TerminalObject/Helper/StringLength.php#L18-L23 | train |
thephpleague/climate | src/TerminalObject/Helper/StringLength.php | StringLength.pad | protected function pad($str, $final_length, $padding_side = 'right')
{
$padding = $final_length - $this->lengthWithoutTags($str);
if ($padding_side == 'left') {
return str_repeat(' ', $padding) . $str;
}
return $str . str_repeat(' ', $padding);
} | php | protected function pad($str, $final_length, $padding_side = 'right')
{
$padding = $final_length - $this->lengthWithoutTags($str);
if ($padding_side == 'left') {
return str_repeat(' ', $padding) . $str;
}
return $str . str_repeat(' ', $padding);
} | [
"protected",
"function",
"pad",
"(",
"$",
"str",
",",
"$",
"final_length",
",",
"$",
"padding_side",
"=",
"'right'",
")",
"{",
"$",
"padding",
"=",
"$",
"final_length",
"-",
"$",
"this",
"->",
"lengthWithoutTags",
"(",
"$",
"str",
")",
";",
"if",
"(",
... | Apply padding to a string
@param string $str
@param string $final_length
@param string $padding_side
@return string | [
"Apply",
"padding",
"to",
"a",
"string"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/TerminalObject/Helper/StringLength.php#L62-L71 | train |
thephpleague/climate | src/TerminalObject/Helper/StringLength.php | StringLength.padArray | protected function padArray($arr, $final_length, $padding_side = 'right')
{
foreach ($arr as $key => $value) {
$arr[$key] = $this->pad($value, $final_length, $padding_side);
}
return $arr;
} | php | protected function padArray($arr, $final_length, $padding_side = 'right')
{
foreach ($arr as $key => $value) {
$arr[$key] = $this->pad($value, $final_length, $padding_side);
}
return $arr;
} | [
"protected",
"function",
"padArray",
"(",
"$",
"arr",
",",
"$",
"final_length",
",",
"$",
"padding_side",
"=",
"'right'",
")",
"{",
"foreach",
"(",
"$",
"arr",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"arr",
"[",
"$",
"key",
"]",
"=",
... | Apply padding to an array of strings
@param array $arr
@param integer $final_length
@param string $padding_side
@return array | [
"Apply",
"padding",
"to",
"an",
"array",
"of",
"strings"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/TerminalObject/Helper/StringLength.php#L82-L89 | train |
thephpleague/climate | src/TerminalObject/Dynamic/Checkboxes.php | Checkboxes.writeCheckboxes | protected function writeCheckboxes()
{
$this->updateCheckboxView();
$this->util->system->exec('stty -icanon');
$this->output->sameLine()->write($this->util->cursor->hide());
$this->listenForInput();
} | php | protected function writeCheckboxes()
{
$this->updateCheckboxView();
$this->util->system->exec('stty -icanon');
$this->output->sameLine()->write($this->util->cursor->hide());
$this->listenForInput();
} | [
"protected",
"function",
"writeCheckboxes",
"(",
")",
"{",
"$",
"this",
"->",
"updateCheckboxView",
"(",
")",
";",
"$",
"this",
"->",
"util",
"->",
"system",
"->",
"exec",
"(",
"'stty -icanon'",
")",
";",
"$",
"this",
"->",
"output",
"->",
"sameLine",
"(... | Output the checkboxes and listen for any keystrokes | [
"Output",
"the",
"checkboxes",
"and",
"listen",
"for",
"any",
"keystrokes"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/TerminalObject/Dynamic/Checkboxes.php#L66-L74 | train |
thephpleague/climate | src/TerminalObject/Dynamic/Checkboxes.php | Checkboxes.listenForInput | protected function listenForInput()
{
while ($char = $this->reader->char(1)) {
if ($this->handleCharacter($char)) {
break;
}
$this->moveCursorToTop();
$this->updateCheckboxView();
}
} | php | protected function listenForInput()
{
while ($char = $this->reader->char(1)) {
if ($this->handleCharacter($char)) {
break;
}
$this->moveCursorToTop();
$this->updateCheckboxView();
}
} | [
"protected",
"function",
"listenForInput",
"(",
")",
"{",
"while",
"(",
"$",
"char",
"=",
"$",
"this",
"->",
"reader",
"->",
"char",
"(",
"1",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"handleCharacter",
"(",
"$",
"char",
")",
")",
"{",
"break",... | Listen for input and act on it | [
"Listen",
"for",
"input",
"and",
"act",
"on",
"it"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/TerminalObject/Dynamic/Checkboxes.php#L79-L89 | train |
thephpleague/climate | src/TerminalObject/Dynamic/Checkboxes.php | Checkboxes.moveCursorToTop | protected function moveCursorToTop()
{
$output = $this->util->cursor->up($this->checkboxes->count() - 1);
$output .= $this->util->cursor->startOfCurrentLine();
$this->output->sameLine()->write($output);
} | php | protected function moveCursorToTop()
{
$output = $this->util->cursor->up($this->checkboxes->count() - 1);
$output .= $this->util->cursor->startOfCurrentLine();
$this->output->sameLine()->write($output);
} | [
"protected",
"function",
"moveCursorToTop",
"(",
")",
"{",
"$",
"output",
"=",
"$",
"this",
"->",
"util",
"->",
"cursor",
"->",
"up",
"(",
"$",
"this",
"->",
"checkboxes",
"->",
"count",
"(",
")",
"-",
"1",
")",
";",
"$",
"output",
".=",
"$",
"this... | Move the cursor to the top of the option list | [
"Move",
"the",
"cursor",
"to",
"the",
"top",
"of",
"the",
"option",
"list"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/TerminalObject/Dynamic/Checkboxes.php#L122-L128 | train |
thephpleague/climate | src/TerminalObject/Dynamic/Checkboxes.php | Checkboxes.handleAnsi | protected function handleAnsi()
{
switch ($this->reader->char(2)) {
// Up arrow
case '[A':
$this->checkboxes->setCurrent('previous');
break;
// Down arrow
case '[B':
$this->checkboxes->setCurrent('next');
break;
}
} | php | protected function handleAnsi()
{
switch ($this->reader->char(2)) {
// Up arrow
case '[A':
$this->checkboxes->setCurrent('previous');
break;
// Down arrow
case '[B':
$this->checkboxes->setCurrent('next');
break;
}
} | [
"protected",
"function",
"handleAnsi",
"(",
")",
"{",
"switch",
"(",
"$",
"this",
"->",
"reader",
"->",
"char",
"(",
"2",
")",
")",
"{",
"// Up arrow",
"case",
"'[A'",
":",
"$",
"this",
"->",
"checkboxes",
"->",
"setCurrent",
"(",
"'previous'",
")",
";... | Handle any ANSI characters | [
"Handle",
"any",
"ANSI",
"characters"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/TerminalObject/Dynamic/Checkboxes.php#L133-L146 | train |
thephpleague/climate | src/TerminalObject/Dynamic/Checkboxes.php | Checkboxes.updateCheckboxView | protected function updateCheckboxView()
{
$this->checkboxes->util($this->util);
$this->checkboxes->output($this->output);
$this->checkboxes->parser($this->parser);
$this->checkboxes->write();
} | php | protected function updateCheckboxView()
{
$this->checkboxes->util($this->util);
$this->checkboxes->output($this->output);
$this->checkboxes->parser($this->parser);
$this->checkboxes->write();
} | [
"protected",
"function",
"updateCheckboxView",
"(",
")",
"{",
"$",
"this",
"->",
"checkboxes",
"->",
"util",
"(",
"$",
"this",
"->",
"util",
")",
";",
"$",
"this",
"->",
"checkboxes",
"->",
"output",
"(",
"$",
"this",
"->",
"output",
")",
";",
"$",
"... | Re-write the checkboxes based on the current objects | [
"Re",
"-",
"write",
"the",
"checkboxes",
"based",
"on",
"the",
"current",
"objects"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/TerminalObject/Dynamic/Checkboxes.php#L151-L158 | train |
thephpleague/climate | src/Util/Output.php | Output.add | public function add($key, $writer)
{
$this->writers[$key] = $this->resolve(Helper::toArray($writer));
return $this;
} | php | public function add($key, $writer)
{
$this->writers[$key] = $this->resolve(Helper::toArray($writer));
return $this;
} | [
"public",
"function",
"add",
"(",
"$",
"key",
",",
"$",
"writer",
")",
"{",
"$",
"this",
"->",
"writers",
"[",
"$",
"key",
"]",
"=",
"$",
"this",
"->",
"resolve",
"(",
"Helper",
"::",
"toArray",
"(",
"$",
"writer",
")",
")",
";",
"return",
"$",
... | Add a writer to the available writers
@param string $key
@param WriterInterface|array $writer
@return \League\CLImate\Util\Output | [
"Add",
"a",
"writer",
"to",
"the",
"available",
"writers"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/Util/Output.php#L75-L80 | train |
thephpleague/climate | src/Util/Output.php | Output.get | public function get($writer)
{
if (!array_key_exists($writer, $this->writers)) {
throw new UnexpectedValueException('Unknown writer [' . $writer . ']');
}
if (count($this->writers[$writer]) == 1) {
return reset($this->writers[$writer]);
}
return $this->writers[$writer];
} | php | public function get($writer)
{
if (!array_key_exists($writer, $this->writers)) {
throw new UnexpectedValueException('Unknown writer [' . $writer . ']');
}
if (count($this->writers[$writer]) == 1) {
return reset($this->writers[$writer]);
}
return $this->writers[$writer];
} | [
"public",
"function",
"get",
"(",
"$",
"writer",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"writer",
",",
"$",
"this",
"->",
"writers",
")",
")",
"{",
"throw",
"new",
"UnexpectedValueException",
"(",
"'Unknown writer ['",
".",
"$",
"writer",
... | Get a specific writer
@param string $writer
@return WriterInterface|array
@throws UnexpectedValueException if writer key doesn't exist | [
"Get",
"a",
"specific",
"writer"
] | 88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075 | https://github.com/thephpleague/climate/blob/88b6e09dca7a5c3ac6a00143eb928f8c0c6f3075/src/Util/Output.php#L142-L153 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.