本文整理汇总了PHP中Cli::breakLines方法的典型用法代码示例。如果您正苦于以下问题:PHP Cli::breakLines方法的具体用法?PHP Cli::breakLines怎么用?PHP Cli::breakLines使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cli
的用法示例。
在下文中一共展示了Cli::breakLines方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: writeHelp
/**
* Writes the help for a given schema.
*
* @param array $schema A command line scheme returned from {@see Cli::getSchema()}.
*/
protected function writeHelp($schema)
{
// Write the command description.
$meta = Cli::val(Cli::META, $schema, []);
$description = Cli::val('description', $meta);
if ($description) {
echo implode("\n", Cli::breakLines($description, 80, false)) . PHP_EOL . PHP_EOL;
}
unset($schema[Cli::META]);
// Add the help.
$schema['help'] = ['description' => 'Display this help.', 'type' => 'boolean', 'short' => '?'];
echo Cli::bold('OPTIONS') . PHP_EOL;
ksort($schema);
$table = new Table();
$table->format = $this->format;
foreach ($schema as $key => $definition) {
$table->row();
// Write the keys.
$keys = "--{$key}";
if ($shortKey = Cli::val('short', $definition, false)) {
$keys .= ", -{$shortKey}";
}
if (Cli::val('required', $definition)) {
$table->bold($keys);
} else {
$table->cell($keys);
}
// Write the description.
$table->cell(Cli::val('description', $definition, ''));
}
$table->write();
echo PHP_EOL;
$args = Cli::val(Cli::ARGS, $meta, []);
if (!empty($args)) {
echo Cli::bold('ARGUMENTS') . PHP_EOL;
$table = new Table();
$table->format = $this->format;
foreach ($args as $aname => $arg) {
$table->row();
if (Cli::val('required', $definition)) {
$table->bold($aname);
} else {
$table->cell($aname);
}
$table->cell(Cli::val('description', $arg, ''));
}
$table->write();
echo PHP_EOL;
}
}
示例2: write
/**
* Writes the final table.
*/
public function write()
{
// Determine the width of the last column.
$columnWidths = array_sum($this->columnWidths);
$totalWidth = $this->indent + $columnWidths + $this->padding * (count($this->columnWidths) - 1);
$lastWidth = end($this->columnWidths) + $this->maxWidth - $totalWidth;
$lastWidth = max($lastWidth, 10);
// min width of 10
$this->columnWidths[count($this->columnWidths) - 1] = $lastWidth;
// Loop through each row and write it.
foreach ($this->rows as $row) {
$rowLines = [];
$lineCount = 0;
// Split the cells into lines.
foreach ($row as $i => $cell) {
list($text, ) = $cell;
$width = $this->columnWidths[$i];
$lines = Cli::breakLines($text, $width, $i < count($this->columnWidths) - 1);
$rowLines[] = $lines;
$lineCount = max($lineCount, count($lines));
}
// Write all of the lines.
for ($i = 0; $i < $lineCount; $i++) {
foreach ($rowLines as $j => $lines) {
$padding = $j === 0 ? $this->indent : $this->padding;
if (isset($lines[$i])) {
if ($this->formatOutput) {
if (isset($row[$j])) {
$wrap = $row[$j][1];
} else {
// if we're out of array, use the latest wraps
$wrap = $row[count($row) - 1][1];
}
echo str_repeat(' ', $padding) . $wrap[0] . $lines[$i] . $wrap[1];
} else {
echo str_repeat(' ', $padding) . $lines[$i];
}
} elseif ($j < count($this->columnWidths) - 1) {
// This is an empty line. Write the spaces.
echo str_repeat(' ', $padding + $this->columnWidths[$j]);
}
}
echo PHP_EOL;
}
}
}