本文整理汇总了PHP中Grav\Common\Utils::truncate方法的典型用法代码示例。如果您正苦于以下问题:PHP Utils::truncate方法的具体用法?PHP Utils::truncate怎么用?PHP Utils::truncate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Grav\Common\Utils
的用法示例。
在下文中一共展示了Utils::truncate方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: serve
/**
* @return int|null|void
*/
protected function serve()
{
$this->options = $this->input->getOptions();
$this->gpm = new GPM($this->options['force']);
$this->displayGPMRelease();
$this->data = $this->gpm->getRepository();
$data = $this->filter($this->data);
$climate = new CLImate();
$climate->extend('Grav\\Console\\TerminalObjects\\Table');
if (!$data) {
$this->output->writeln('No data was found in the GPM repository stored locally.');
$this->output->writeln('Please try clearing cache and running the <green>bin/gpm index -f</green> command again');
$this->output->writeln('If this doesn\'t work try tweaking your GPM system settings.');
$this->output->writeln('');
$this->output->writeln('For more help go to:');
$this->output->writeln(' -> <yellow>https://learn.getgrav.org/troubleshooting/common-problems#cannot-connect-to-the-gpm</yellow>');
die;
}
foreach ($data as $type => $packages) {
$this->output->writeln("<green>" . strtoupper($type) . "</green> [ " . count($packages) . " ]");
$packages = $this->sort($packages);
if (!empty($packages)) {
$table = [];
$index = 0;
foreach ($packages as $slug => $package) {
$row = ['Count' => $index++ + 1, 'Name' => "<cyan>" . Utils::truncate($package->name, 20, false, ' ', '...') . "</cyan> ", 'Slug' => $slug, 'Version' => $this->version($package), 'Installed' => $this->installed($package)];
$table[] = $row;
}
$climate->table($table);
}
$this->output->writeln('');
}
$this->output->writeln('You can either get more informations about a package by typing:');
$this->output->writeln(' <green>' . $this->argv . ' info <cyan><package></cyan></green>');
$this->output->writeln('');
$this->output->writeln('Or you can install a package by typing:');
$this->output->writeln(' <green>' . $this->argv . ' install <cyan><package></cyan></green>');
$this->output->writeln('');
}
示例2: testTruncate
public function testTruncate()
{
$this->assertEquals('engli' . '…', Utils::truncate('english', 5));
$this->assertEquals('english', Utils::truncate('english'));
$this->assertEquals('This is a string to truncate', Utils::truncate('This is a string to truncate'));
$this->assertEquals('Th' . '…', Utils::truncate('This is a string to truncate', 2));
$this->assertEquals('engli' . '...', Utils::truncate('english', 5, true, " ", "..."));
$this->assertEquals('english', Utils::truncate('english'));
$this->assertEquals('This is a string to truncate', Utils::truncate('This is a string to truncate'));
$this->assertEquals('This ', Utils::truncate('This is a string to truncate', 3, true));
$this->assertEquals('<input ', Utils::truncate('<input type="file" id="file" multiple />', 6, true));
}
示例3: testTruncate
public function testTruncate()
{
$this->assertEquals(Utils::truncate('english', 5), 'engli' . '…');
$this->assertEquals(Utils::truncate('english'), 'english');
$this->assertEquals(Utils::truncate('This is a string to truncate'), 'This is a string to truncate');
$this->assertEquals(Utils::truncate('This is a string to truncate', 2), 'Th' . '…');
$this->assertEquals(Utils::truncate('english', 5, true, " ", "..."), 'engli' . '...');
$this->assertEquals(Utils::truncate('english'), 'english');
$this->assertEquals(Utils::truncate('This is a string to truncate'), 'This is a string to truncate');
$this->assertEquals(Utils::truncate('This is a string to truncate', 3, true), 'This ');
}