PK GP
LICENSE.mdnu W+A Copyright (c) 2019-2020, Laminas Foundation
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- Neither the name of Laminas Foundation nor the names of its contributors may
be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
PK GP%'\ \ COPYRIGHT.mdnu W+A Copyright (c) 2019-2020, Laminas Foundation.
All rights reserved. (https://getlaminas.org/)
PK GPAé .travis.ymlnu W+A language: php
cache:
directories:
- $HOME/.composer/cache
env:
global:
- COMPOSER_ARGS="--no-interaction"
- COVERAGE_DEPS="php-coveralls/php-coveralls"
matrix:
fast_finish: true
include:
- php: 5.6
env:
- DEPS=lowest
- php: 5.6
env:
- DEPS=latest
- php: 7
env:
- DEPS=lowest
- php: 7
env:
- DEPS=latest
- php: 7.1
env:
- DEPS=lowest
- php: 7.1
env:
- DEPS=latest
- CS_CHECK=true
- TEST_COVERAGE=true
- php: 7.2
env:
- DEPS=lowest
- php: 7.2
env:
- DEPS=latest
- php: 7.3
env:
- DEPS=lowest
- php: 7.3
env:
- DEPS=latest
before_install:
- if [[ $TEST_COVERAGE != 'true' ]]; then phpenv config-rm xdebug.ini || return 0 ; fi
install:
- travis_retry composer install $COMPOSER_ARGS --ignore-platform-reqs
- if [[ $LEGACY_DEPS != '' ]]; then travis_retry composer update $COMPOSER_ARGS --with-dependencies $LEGACY_DEPS ; fi
- if [[ $DEPS == 'latest' ]]; then travis_retry composer update $COMPOSER_ARGS ; fi
- if [[ $DEPS == 'lowest' ]]; then travis_retry composer update --prefer-lowest --prefer-stable $COMPOSER_ARGS ; fi
- if [[ $TEST_COVERAGE == 'true' ]]; then travis_retry composer require --dev $COMPOSER_ARGS $COVERAGE_DEPS ; fi
- stty cols 120 && composer show
script:
- if [[ $TEST_COVERAGE == 'true' ]]; then composer test-coverage ; else composer test ; fi
- if [[ $CS_CHECK == 'true' ]]; then composer cs-check ; fi
after_script:
- if [[ $TEST_COVERAGE == 'true' ]]; then travis_retry php vendor/bin/php-coveralls -v ; fi
notifications:
email: false
PK GPx= = .coveralls.ymlnu W+A coverage_clover: clover.xml
json_path: coveralls-upload.json
PK GP}CC phpcs.xmlnu W+A
src
test
PK GP\yj README.mdnu W+A # laminas-text
[![Build Status](https://travis-ci.com/laminas/laminas-text.svg?branch=master)](https://travis-ci.com/laminas/laminas-text)
[![Coverage Status](https://coveralls.io/repos/github/laminas/laminas-text/badge.svg?branch=master)](https://coveralls.io/github/laminas/laminas-text?branch=master)
`Laminas\Text` is a component to work on text strings. It contains the subcomponents:
- `Laminas\Text\Figlet` that enables developers to create a so called FIGlet text.
A FIGlet text is a string, which is represented as ASCII art. FIGlets use a
special font format, called FLT (FigLet Font). By default, one standard font is
shipped with `Laminas\Text\Figlet`, but you can download additional fonts [here](http://www.figlet.org)
- `Laminas\Text\Table` to create text based tables on the fly with different
decorators. This can be helpful, if you either want to send structured data in
text emails, which are used to have mono-spaced fonts, or to display table
information in a CLI application. `Laminas\Text\Table` supports multi-line
columns, colspan and align as well.
## Installation
Run the following to install this library:
```bash
$ composer require laminas/laminas-text
```
## Documentation
Browse the documentation online at https://docs.laminas.dev/laminas-text/
## Support
* [Issues](https://github.com/laminas/laminas-text/issues/)
* [Chat](https://laminas.dev/chat/)
* [Forum](https://discourse.laminas.dev/)
PK GP@ݫ
.gitignorenu W+A /clover.xml
/composer.lock
/coveralls-upload.json
/docs/html/
/laminas-mkdoc-theme.tgz
/laminas-mkdoc-theme/
/phpunit.xml
/vendor/
PK GPn src/MultiByte.phpnu W+A )->wordWrap'
), E_USER_DEPRECATED);
try {
return StringUtils::getWrapper($charset)->wordWrap($string, $width, $break, $cut);
} catch (\Laminas\Stdlib\Exception\InvalidArgumentException $e) {
throw new Exception\InvalidArgumentException($e->getMessage(), $e->getCode(), $e);
}
}
/**
* String padding
*
* @param string $input
* @param int $padLength
* @param string $padString
* @param int $padType
* @param string $charset
* @return string
* @deprecated Please use Laminas\Stdlib\StringUtils instead
*/
public static function strPad($input, $padLength, $padString = ' ', $padType = STR_PAD_RIGHT, $charset = 'utf-8')
{
trigger_error(sprintf(
"This method is deprecated, please use '%s' instead",
'Laminas\Stdlib\StringUtils::getWrapper()->strPad'
), E_USER_DEPRECATED);
return StringUtils::getWrapper($charset)->strPad($input, $padLength, $padString, $padType);
}
}
PK GP " src/Exception/RuntimeException.phpnu W+A setContent($content, $charset);
}
if ($align !== null) {
$this->setAlign($align);
}
if ($colSpan !== null) {
$this->setColSpan($colSpan);
}
}
/**
* Set the content.
*
* If $charset is not defined, it is assumed that $content is encoded in
* the charset defined via Laminas\Text\Table::setInputCharset() (defaults
* to utf-8).
*
* @param string $content Content of the column
* @param string $charset The charset of the content
* @throws Exception\InvalidArgumentException When $content is not a string
* @return Column
*/
public function setContent($content, $charset = null)
{
if (is_string($content) === false) {
throw new Exception\InvalidArgumentException('$content must be a string');
}
if ($charset === null) {
$inputCharset = Table::getInputCharset();
} else {
$inputCharset = strtolower($charset);
}
$outputCharset = Table::getOutputCharset();
if ($inputCharset !== $outputCharset) {
if (PHP_OS !== 'AIX') {
// AIX does not understand these character sets
$strWrapper = StringUtils::getWrapper($inputCharset, $outputCharset);
$content = $strWrapper->convert($content);
}
}
$this->content = $content;
return $this;
}
/**
* Set the align
*
* @param string $align Align of the column
* @throws Exception\OutOfBoundsException When supplied align is invalid
* @return Column
*/
public function setAlign($align)
{
if (in_array($align, $this->allowedAligns) === false) {
throw new Exception\OutOfBoundsException('Invalid align supplied');
}
$this->align = $align;
return $this;
}
/**
* Set the colspan
*
* @param int $colSpan
* @throws Exception\InvalidArgumentException When $colSpan is smaller than 1
* @return Column
*/
public function setColSpan($colSpan)
{
if (is_int($colSpan) === false or $colSpan < 1) {
throw new Exception\InvalidArgumentException('$colSpan must be an integer and greater than 0');
}
$this->colSpan = $colSpan;
return $this;
}
/**
* Get the colspan
*
* @return int
*/
public function getColSpan()
{
return $this->colSpan;
}
/**
* Render the column width the given column width
*
* @param int $columnWidth The width of the column
* @param int $padding The padding for the column
* @throws Exception\InvalidArgumentException When $columnWidth is lower than 1
* @throws Exception\OutOfBoundsException When padding is greater than columnWidth
* @return string
*/
public function render($columnWidth, $padding = 0)
{
if (is_int($columnWidth) === false or $columnWidth < 1) {
throw new Exception\InvalidArgumentException('$columnWidth must be an integer and greater than 0');
}
$columnWidth -= ($padding * 2);
if ($columnWidth < 1) {
throw new Exception\OutOfBoundsException('Padding (' . $padding . ') is greater than column width');
}
switch ($this->align) {
case self::ALIGN_LEFT:
$padMode = STR_PAD_RIGHT;
break;
case self::ALIGN_CENTER:
$padMode = STR_PAD_BOTH;
break;
case self::ALIGN_RIGHT:
$padMode = STR_PAD_LEFT;
break;
default:
// This can never happen, but the CS tells I have to have it ...
break;
}
$outputCharset = Table::getOutputCharset();
$strWrapper = StringUtils::getWrapper($outputCharset);
$lines = explode("\n", $strWrapper->wordWrap($this->content, $columnWidth, "\n", true));
$paddedLines = [];
foreach ($lines as $line) {
$paddedLines[] = str_repeat(' ', $padding)
. $strWrapper->strPad($line, $columnWidth, ' ', $padMode)
. str_repeat(' ', $padding);
}
$result = implode("\n", $paddedLines);
return $result;
}
}
PK GPI99 9 src/Table/Table.phpnu W+A setOptions($options);
}
// If no decorator was given, use default unicode decorator
if ($this->decorator === null) {
if (static::getOutputCharset() === 'utf-8') {
$this->setDecorator('unicode');
} else {
$this->setDecorator('ascii');
}
}
}
/**
* Set options from array
*
* @param array $options Configuration for Table
* @return Table
*/
public function setOptions(array $options)
{
foreach ($options as $key => $value) {
if (in_array(strtolower($key), $this->skipOptions)) {
continue;
}
$method = 'set' . ucfirst($key);
if (method_exists($this, $method)) {
$this->$method($value);
}
}
return $this;
}
/**
* Set column widths
*
* @param array $columnWidths Widths of all columns
* @throws Exception\InvalidArgumentException When no columns were supplied
* @throws Exception\InvalidArgumentException When a column has an invalid width
* @return Table
*/
public function setColumnWidths(array $columnWidths)
{
if (! $columnWidths) {
throw new Exception\InvalidArgumentException('You must supply at least one column');
}
foreach ($columnWidths as $columnNum => $columnWidth) {
if (is_int($columnWidth) === false or $columnWidth < 1) {
throw new Exception\InvalidArgumentException('Column ' . $columnNum . ' has an invalid column width');
}
}
$this->columnWidths = $columnWidths;
return $this;
}
/**
* Set auto separation mode
*
* @param int $autoSeparate Auto separation mode
* @return Table
*/
public function setAutoSeparate($autoSeparate)
{
$this->autoSeparate = (int) $autoSeparate;
return $this;
}
/**
* Set decorator
*
* @param Decorator|string $decorator Decorator to use
* @return Table
*/
public function setDecorator($decorator)
{
if (! $decorator instanceof Decorator) {
$decorator = $this->getDecoratorManager()->get($decorator);
}
$this->decorator = $decorator;
return $this;
}
/**
* Set the column padding
*
* @param int $padding The padding for the columns
* @return Table
*/
public function setPadding($padding)
{
$this->padding = max(0, (int) $padding);
return $this;
}
/**
* Get the plugin manager for decorators
*
* @return DecoratorManager
*/
public function getDecoratorManager()
{
if ($this->decoratorManager instanceof DecoratorManager) {
return $this->decoratorManager;
}
$this->setDecoratorManager(new DecoratorManager(new ServiceManager()));
return $this->decoratorManager;
}
/**
* Set the plugin manager instance for decorators
*
* @param DecoratorManager $decoratorManager
* @return Table
*/
public function setDecoratorManager(DecoratorManager $decoratorManager)
{
$this->decoratorManager = $decoratorManager;
return $this;
}
/**
* Set default column align for rows created by appendRow(array $data)
*
* @param int $columnNum
* @param string $align
* @return Table
*/
public function setDefaultColumnAlign($columnNum, $align)
{
$this->defaultColumnAligns[$columnNum] = $align;
return $this;
}
/**
* Set the input charset for column contents
*
* @param string $charset
*/
public static function setInputCharset($charset)
{
static::$inputCharset = strtolower($charset);
}
/**
* Get the input charset for column contents
*
* @return string
*/
public static function getInputCharset()
{
return static::$inputCharset;
}
/**
* Set the output charset for column contents
*
* @param string $charset
*/
public static function setOutputCharset($charset)
{
static::$outputCharset = strtolower($charset);
}
/**
* Get the output charset for column contents
*
* @return string
*/
public static function getOutputCharset()
{
return static::$outputCharset;
}
/**
* Append a row to the table
*
* @param array|Row $row The row to append to the table
* @throws Exception\InvalidArgumentException When $row is neither an array nor Laminas\Text\Table\Row
* @throws Exception\OverflowException When a row contains too many columns
* @return Table
*/
public function appendRow($row)
{
if (! is_array($row) && ! ($row instanceof Row)) {
throw new Exception\InvalidArgumentException('$row must be an array or instance of Laminas\Text\Table\Row');
}
if (is_array($row)) {
if (count($row) > count($this->columnWidths)) {
throw new Exception\OverflowException('Row contains too many columns');
}
$data = $row;
$row = new Row();
$colNum = 0;
foreach ($data as $columnData) {
if (isset($this->defaultColumnAligns[$colNum])) {
$align = $this->defaultColumnAligns[$colNum];
} else {
$align = null;
}
$row->appendColumn(new Column($columnData, $align));
$colNum++;
}
}
$this->rows[] = $row;
return $this;
}
/**
* Render the table
*
* @throws Exception\UnexpectedValueException When no rows were added to the table
* @return string
*/
public function render()
{
// There should be at least one row
if (! $this->rows) {
throw new Exception\UnexpectedValueException('No rows were added to the table yet');
}
// Initiate the result variable
$result = '';
// Count total columns
$totalNumColumns = count($this->columnWidths);
// Check if we have a horizontal character defined
$hasHorizontal = $this->decorator->getHorizontal() !== '';
// Now render all rows, starting from the first one
$numRows = count($this->rows);
foreach ($this->rows as $rowNum => $row) {
// Get all column widths
if (isset($columnWidths) === true) {
$lastColumnWidths = $columnWidths;
}
$renderedRow = $row->render($this->columnWidths, $this->decorator, $this->padding);
$columnWidths = $row->getColumnWidths();
$numColumns = count($columnWidths);
// Check what we have to draw
if ($rowNum === 0 && $hasHorizontal) {
// If this is the first row, draw the table top
$result .= $this->decorator->getTopLeft();
foreach ($columnWidths as $columnNum => $columnWidth) {
$result .= str_repeat($this->decorator->getHorizontal(), $columnWidth);
if (($columnNum + 1) === $numColumns) {
$result .= $this->decorator->getTopRight();
} else {
$result .= $this->decorator->getHorizontalDown();
}
}
$result .= "\n";
} else {
// Else check if we have to draw the row separator
if (! $hasHorizontal) {
$drawSeparator = false; // there is no horizontal character;
} elseif ($this->autoSeparate & self::AUTO_SEPARATE_ALL) {
$drawSeparator = true;
} elseif ($rowNum === 1 && $this->autoSeparate & self::AUTO_SEPARATE_HEADER) {
$drawSeparator = true;
} elseif ($rowNum === ($numRows - 1) && $this->autoSeparate & self::AUTO_SEPARATE_FOOTER) {
$drawSeparator = true;
} else {
$drawSeparator = false;
}
if ($drawSeparator) {
$result .= $this->decorator->getVerticalRight();
$currentUpperColumn = 0;
$currentLowerColumn = 0;
$currentUpperWidth = 0;
$currentLowerWidth = 0;
// Add horizontal lines
// Loop through all column widths
foreach ($this->columnWidths as $columnNum => $columnWidth) {
// Add the horizontal line
$result .= str_repeat($this->decorator->getHorizontal(), $columnWidth);
// If this is the last line, break out
if (($columnNum + 1) === $totalNumColumns) {
break;
}
// Else check, which connector style has to be used
$connector = 0x0;
$currentUpperWidth += $columnWidth;
$currentLowerWidth += $columnWidth;
if ($lastColumnWidths[$currentUpperColumn] === $currentUpperWidth) {
$connector |= 0x1;
$currentUpperColumn += 1;
$currentUpperWidth = 0;
} else {
$currentUpperWidth += 1;
}
if ($columnWidths[$currentLowerColumn] === $currentLowerWidth) {
$connector |= 0x2;
$currentLowerColumn += 1;
$currentLowerWidth = 0;
} else {
$currentLowerWidth += 1;
}
switch ($connector) {
case 0x0:
$result .= $this->decorator->getHorizontal();
break;
case 0x1:
$result .= $this->decorator->getHorizontalUp();
break;
case 0x2:
$result .= $this->decorator->getHorizontalDown();
break;
case 0x3:
$result .= $this->decorator->getCross();
break;
default:
// This can never happen, but the CS tells I have to have it ...
break;
}
}
$result .= $this->decorator->getVerticalLeft() . "\n";
}
}
// Add the rendered row to the result
$result .= $renderedRow;
// If this is the last row, draw the table bottom
if (($rowNum + 1) === $numRows && $hasHorizontal) {
$result .= $this->decorator->getBottomLeft();
foreach ($columnWidths as $columnNum => $columnWidth) {
$result .= str_repeat($this->decorator->getHorizontal(), $columnWidth);
if (($columnNum + 1) === $numColumns) {
$result .= $this->decorator->getBottomRight();
} else {
$result .= $this->decorator->getHorizontalUp();
}
}
$result .= "\n";
}
}
return $result;
}
/**
* Magic method which returns the rendered table
*
* @return string
*/
public function __toString()
{
try {
return $this->render();
} catch (\Exception $e) {
trigger_error($e->getMessage(), E_USER_ERROR);
}
}
}
PK GP|)yK K src/Table/DecoratorManager.phpnu W+A Decorator\Ascii::class,
'Ascii' => Decorator\Ascii::class,
'blank' => Decorator\Blank::class,
'Blank' => Decorator\Blank::class,
'unicode' => Decorator\Unicode::class,
'Unicode' => Decorator\Unicode::class,
// Legacy Zend Framework aliases
\Zend\Text\Table\Decorator\Ascii::class => Decorator\Ascii::class,
\Zend\Text\Table\Decorator\Unicode::class => Decorator\Unicode::class,
\Zend\Text\Table\Decorator\Blank::class => Decorator\Blank::class,
// v2 normalized FQCNs
'zendtexttabledecoratorascii' => Decorator\Ascii::class,
'zendtexttabledecoratorblank' => Decorator\Blank::class,
'zendtexttabledecoratorunicode' => Decorator\Unicode::class,
];
protected $factories = [
Decorator\Ascii::class => InvokableFactory::class,
Decorator\Unicode::class => InvokableFactory::class,
Decorator\Blank::class => InvokableFactory::class,
'laminastexttabledecoratorascii' => InvokableFactory::class,
'laminastexttabledecoratorblank' => InvokableFactory::class,
'laminastexttabledecoratorunicode' => InvokableFactory::class,
];
protected $instanceOf = Decorator\DecoratorInterface::class;
/**
* {@inheritdoc} (v3)
*/
public function validate($instance)
{
if ($instance instanceof $this->instanceOf) {
// we're okay
return;
}
throw new InvalidServiceException(sprintf(
'Plugin of type %s is invalid; must implement %s\Decorator\DecoratorInterface',
(is_object($instance) ? get_class($instance) : gettype($instance)),
__NAMESPACE__
));
}
/**
* Validate the plugin (v2)
*
* Checks that the decorator loaded is an instance of Decorator\DecoratorInterface.
*
* @param mixed $plugin
* @return void
* @throws Exception\InvalidDecoratorException if invalid
*/
public function validatePlugin($plugin)
{
try {
$this->validate($plugin);
} catch (InvalidServiceException $e) {
throw new Exception\InvalidDecoratorException($e->getMessage(), $e->getCode(), $e);
}
}
}
PK GPuY * src/Table/Decorator/DecoratorInterface.phpnu W+A _uniChar(0x250C);
}
/**
* Defined by Laminas\Text\Table\Decorator\DecoratorInterface
*
* @return string
*/
public function getTopRight()
{
return $this->_uniChar(0x2510);
}
/**
* Defined by Laminas\Text\Table\Decorator\DecoratorInterface
*
* @return string
*/
public function getBottomLeft()
{
return $this->_uniChar(0x2514);
}
/**
* Defined by Laminas\Text\Table\Decorator\DecoratorInterface
*
* @return string
*/
public function getBottomRight()
{
return $this->_uniChar(0x2518);
}
/**
* Defined by Laminas\Text\Table\Decorator\DecoratorInterface
*
* @return string
*/
public function getVertical()
{
return $this->_uniChar(0x2502);
}
/**
* Defined by Laminas\Text\Table\Decorator\DecoratorInterface
*
* @return string
*/
public function getHorizontal()
{
return $this->_uniChar(0x2500);
}
/**
* Defined by Laminas\Text\Table\Decorator\DecoratorInterface
*
* @return string
*/
public function getCross()
{
return $this->_uniChar(0x253C);
}
/**
* Defined by Laminas\Text\Table\Decorator\DecoratorInterface
*
* @return string
*/
public function getVerticalRight()
{
return $this->_uniChar(0x251C);
}
/**
* Defined by Laminas\Text\Table\Decorator\DecoratorInterface
*
* @return string
*/
public function getVerticalLeft()
{
return $this->_uniChar(0x2524);
}
/**
* Defined by Laminas\Text\Table\Decorator\DecoratorInterface
*
* @return string
*/
public function getHorizontalDown()
{
return $this->_uniChar(0x252C);
}
/**
* Defined by Laminas\Text\Table\Decorator\DecoratorInterface
*
* @return string
*/
public function getHorizontalUp()
{
return $this->_uniChar(0x2534);
}
/**
* Convert am unicode character code to a character
*
* @param int $code
* @return string|false
*/
// @codingStandardsIgnoreStart
protected function _uniChar($code)
{
// @codingStandardsIgnoreEnd
if ($code <= 0x7F) {
$char = chr($code);
} elseif ($code <= 0x7FF) {
$char = chr(0xC0 | $code >> 6)
. chr(0x80 | $code & 0x3F);
} elseif ($code <= 0xFFFF) {
$char = chr(0xE0 | $code >> 12)
. chr(0x80 | $code >> 6 & 0x3F)
. chr(0x80 | $code & 0x3F);
} elseif ($code <= 0x10FFFF) {
$char = chr(0xF0 | $code >> 18)
. chr(0x80 | $code >> 12 & 0x3F)
. chr(0x80 | $code >> 6 & 0x3F)
. chr(0x80 | $code & 0x3F);
} else {
return false;
}
return $char;
}
}
PK GPs-o o src/Table/Row.phpnu W+A appendColumn($column);
return $this;
}
/**
* Append a column to the row
*
* @param \Laminas\Text\Table\Column $column The column to append to the row
* @return Row
*/
public function appendColumn(Column $column)
{
$this->columns[] = $column;
return $this;
}
/**
* Get a column by it's index
*
* Returns null, when the index is out of range
*
* @param int $index
* @return Column|null
*/
public function getColumn($index)
{
if (! isset($this->columns[$index])) {
return;
}
return $this->columns[$index];
}
/**
* Get all columns of the row
*
* @return array
*/
public function getColumns()
{
return $this->columns;
}
/**
* Get the widths of all columns, which were rendered last
*
* @throws Exception\UnexpectedValueException When no columns were rendered yet
* @return int
*/
public function getColumnWidths()
{
if ($this->columnWidths === null) {
throw new Exception\UnexpectedValueException(
'render() must be called before columnWidths can be populated'
);
}
return $this->columnWidths;
}
/**
* Render the row
*
* @param array $columnWidths Width of all columns
* @param Decorator $decorator Decorator for the row borders
* @param int $padding Padding for the columns
* @throws Exception\OverflowException When there are too many columns
* @return string
*/
public function render(array $columnWidths, Decorator $decorator, $padding = 0)
{
// Prepare an array to store all column widths
$this->columnWidths = [];
// If there is no single column, create a column which spans over the
// entire row
if (! $this->columns) {
$this->appendColumn(new Column(null, null, count($columnWidths)));
}
// First we have to render all columns, to get the maximum height
$renderedColumns = [];
$maxHeight = 0;
$colNum = 0;
foreach ($this->columns as $column) {
// Get the colspan of the column
$colSpan = $column->getColSpan();
// Verify if there are enough column widths defined
if (($colNum + $colSpan) > count($columnWidths)) {
throw new Exception\OverflowException('Too many columns');
}
// Calculate the column width
$columnWidth = ($colSpan - 1 + array_sum(array_slice($columnWidths, $colNum, $colSpan)));
// Render the column and split it's lines into an array
$result = explode("\n", $column->render($columnWidth, $padding));
// Store the width of the rendered column
$this->columnWidths[] = $columnWidth;
// Store the rendered column and calculate the new max height
$renderedColumns[] = $result;
$maxHeight = max($maxHeight, count($result));
// Set up the internal column number
$colNum += $colSpan;
}
// If the row doesnt contain enough columns to fill the entire row, fill
// it with an empty column
if ($colNum < count($columnWidths)) {
$remainingWidth = (count($columnWidths) - $colNum - 1) +
array_sum(array_slice($columnWidths, $colNum));
$renderedColumns[] = [str_repeat(' ', $remainingWidth)];
$this->columnWidths[] = $remainingWidth;
}
// Add each single column line to the result
$result = '';
for ($line = 0; $line < $maxHeight; $line++) {
$result .= $decorator->getVertical();
foreach ($renderedColumns as $index => $renderedColumn) {
if (isset($renderedColumn[$line]) === true) {
$result .= $renderedColumn[$line];
} else {
$result .= str_repeat(' ', $this->columnWidths[$index]);
}
$result .= $decorator->getVertical();
}
$result .= "\n";
}
return $result;
}
}
PK GP(&| | src/Figlet/Figlet.phpnu W+A setOptions($options);
}
// If no font was defined, load default font
if (! $this->fontLoaded) {
$this->_loadFont(__DIR__ . '/laminas-project.flf');
}
}
/**
* Set options from array
*
* @param array $options Configuration for Figlet
* @return Figlet
*/
public function setOptions(array $options)
{
foreach ($options as $key => $value) {
if (in_array(strtolower($key), $this->skipOptions)) {
continue;
}
$method = 'set' . ucfirst($key);
if (method_exists($this, $method)) {
$this->$method($value);
}
}
return $this;
}
/**
* Set a font to use
*
* @param string $font Path to the font
* @return Figlet
*/
public function setFont($font)
{
$this->_loadFont($font);
return $this;
}
/**
* Set handling of paragraphs
*
* @param bool $handleParagraphs Whether to handle paragraphs or not
* @return Figlet
*/
public function setHandleParagraphs($handleParagraphs)
{
$this->handleParagraphs = (bool) $handleParagraphs;
return $this;
}
/**
* Set the justification. 0 stands for left aligned, 1 for centered and 2
* for right aligned.
*
* @param int $justification Justification of the output text
* @return Figlet
*/
public function setJustification($justification)
{
$this->justification = min(3, max(0, (int) $justification));
return $this;
}
/**
* Set the output width
*
* @param int $outputWidth Output with which should be used for word
* wrapping and justification
* @return Figlet
*/
public function setOutputWidth($outputWidth)
{
$this->outputWidth = max(1, (int) $outputWidth);
return $this;
}
/**
* Set right to left mode. For writing from left to right, use
* Laminas\Text\Figlet::DIRECTION_LEFT_TO_RIGHT. For writing from right to left,
* use Laminas\Text\Figlet::DIRECTION_RIGHT_TO_LEFT.
*
* @param int $rightToLeft Right-to-left mode
* @return Figlet
*/
public function setRightToLeft($rightToLeft)
{
$this->rightToLeft = min(1, max(0, (int) $rightToLeft));
return $this;
}
/**
* Set the smush mode.
*
* Use one of the constants of Laminas\Text\Figlet::SM_*, you may combine them.
*
* @param int $smushMode Smush mode to use for generating text
* @return Figlet
*/
public function setSmushMode($smushMode)
{
$smushMode = (int) $smushMode;
if ($smushMode < -1) {
$this->smushOverride = self::SMO_NO;
} else {
if ($smushMode === 0) {
$this->userSmush = self::SM_KERN;
} elseif ($smushMode === -1) {
$this->userSmush = 0;
} else {
$this->userSmush = (($smushMode & 63) | self::SM_SMUSH);
}
$this->smushOverride = self::SMO_YES;
}
$this->_setUsedSmush();
return $this;
}
/**
* Render a FIGlet text
*
* @param string $text Text to convert to a figlet text
* @param string $encoding Encoding of the input string
* @throws Exception\InvalidArgumentException When $text is not a string
* @throws Exception\UnexpectedValueException When $text it not properly encoded
* @return string
*/
public function render($text, $encoding = 'UTF-8')
{
if (! is_string($text)) {
throw new Exception\InvalidArgumentException('$text must be a string');
}
// Get the string wrapper supporting UTF-8 character encoding and the input encoding
$strWrapper = StringUtils::getWrapper($encoding, 'UTF-8');
// Convert $text to UTF-8 and check encoding
$text = $strWrapper->convert($text);
if (! StringUtils::isValidUtf8($text)) {
throw new Exception\UnexpectedValueException('$text is not encoded with ' . $encoding);
}
$strWrapper = StringUtils::getWrapper('UTF-8');
$this->output = '';
$this->outputLine = [];
$this->_clearLine();
$this->outlineLengthLimit = ($this->outputWidth - 1);
$this->inCharLineLengthLimit = ($this->outputWidth * 4 + 100);
$wordBreakMode = 0;
$lastCharWasEol = false;
$textLength = $strWrapper->strlen($text);
for ($charNum = 0; $charNum < $textLength; $charNum++) {
// Handle paragraphs
$char = $strWrapper->substr($text, $charNum, 1);
if ($char === "\n" && $this->handleParagraphs && ! $lastCharWasEol) {
$nextChar = $strWrapper->substr($text, ($charNum + 1), 1);
if (! $nextChar) {
$nextChar = null;
}
$char = (ctype_space($nextChar)) ? "\n" : ' ';
}
$lastCharWasEol = (ctype_space($char) && $char !== "\t" && $char !== ' ');
if (ctype_space($char)) {
$char = ($char === "\t" || $char === ' ') ? ' ' : "\n";
}
// Skip unprintable characters
$ordChar = $this->_uniOrd($char);
if (($ordChar > 0 && $ordChar < 32 && $char !== "\n") || $ordChar === 127) {
continue;
}
// Build the character
// Note: The following code is complex and thoroughly tested.
// Be careful when modifying!
do {
$charNotAdded = false;
if ($wordBreakMode === -1) {
if ($char === ' ') {
break;
} elseif ($char === "\n") {
$wordBreakMode = 0;
break;
}
$wordBreakMode = 0;
}
if ($char === "\n") {
$this->_appendLine();
$wordBreakMode = false;
} elseif ($this->_addChar($char)) {
if ($char !== ' ') {
$wordBreakMode = ($wordBreakMode >= 2) ? 3 : 1;
} else {
$wordBreakMode = ($wordBreakMode > 0) ? 2 : 0;
}
} elseif ($this->outlineLength === 0) {
for ($i = 0; $i < $this->charHeight; $i++) {
if ($this->rightToLeft === 1 && $this->outputWidth > 1) {
$offset = (strlen($this->currentChar[$i]) - $this->outlineLengthLimit);
$this->_putString(substr($this->currentChar[$i], $offset));
} else {
$this->_putString($this->currentChar[$i]);
}
}
$wordBreakMode = -1;
} elseif ($char === ' ') {
if ($wordBreakMode === 2) {
$this->_splitLine();
} else {
$this->_appendLine();
}
$wordBreakMode = -1;
} else {
if ($wordBreakMode >= 2) {
$this->_splitLine();
} else {
$this->_appendLine();
}
$wordBreakMode = ($wordBreakMode === 3) ? 1 : 0;
$charNotAdded = true;
}
} while ($charNotAdded);
}
if ($this->outlineLength !== 0) {
$this->_appendLine();
}
return $this->output;
}
/**
* Puts the given string, substituting blanks for hardblanks. If outputWidth
* is 1, puts the entire string; otherwise puts at most outputWidth - 1
* characters. Puts a newline at the end of the string. The string is left-
* justified, centered or right-justified (taking outputWidth as the screen
* width) if justification is 0, 1 or 2 respectively.
*
* @param string $string The string to add to the output
* @return void
*/
// @codingStandardsIgnoreStart
protected function _putString($string)
{
// @codingStandardsIgnoreEnd
$length = strlen($string);
if ($this->outputWidth > 1) {
if ($length > ($this->outputWidth - 1)) {
$length = ($this->outputWidth - 1);
}
if ($this->justification > 0) {
for ($i = 1;
((3 - $this->justification) * $i + $length + $this->justification - 2) < $this->outputWidth;
$i++) {
$this->output .= ' ';
}
}
}
$this->output .= str_replace($this->hardBlank, ' ', $string) . "\n";
}
/**
* Appends the current line to the output
*
* @return void
*/
// @codingStandardsIgnoreStart
protected function _appendLine()
{
// @codingStandardsIgnoreEnd
for ($i = 0; $i < $this->charHeight; $i++) {
$this->_putString($this->outputLine[$i]);
}
$this->_clearLine();
}
/**
* Splits inCharLine at the last word break (bunch of consecutive blanks).
* Makes a new line out of the first part and appends it using appendLine().
* Makes a new line out of the second part and returns.
*
* @return void
*/
// @codingStandardsIgnoreStart
protected function _splitLine()
{
// @codingStandardsIgnoreEnd
$gotSpace = false;
for ($i = ($this->inCharLineLength - 1); $i >= 0; $i--) {
if (! $gotSpace && $this->inCharLine[$i] === ' ') {
$gotSpace = true;
$lastSpace = $i;
}
if ($gotSpace && $this->inCharLine[$i] !== ' ') {
break;
}
}
$firstLength = ($i + 1);
$lastLength = ($this->inCharLineLength - $lastSpace - 1);
$firstPart = '';
for ($i = 0; $i < $firstLength; $i++) {
$firstPart[$i] = $this->inCharLine[$i];
}
$lastPart = '';
for ($i = 0; $i < $lastLength; $i++) {
$lastPart[$i] = $this->inCharLine[($lastSpace + 1 + $i)];
}
$this->_clearLine();
for ($i = 0; $i < $firstLength; $i++) {
$this->_addChar($firstPart[$i]);
}
$this->_appendLine();
for ($i = 0; $i < $lastLength; $i++) {
$this->_addChar($lastPart[$i]);
}
}
/**
* Clears the current line
*
* @return void
*/
// @codingStandardsIgnoreStart
protected function _clearLine()
{
// @codingStandardsIgnoreEnd
for ($i = 0; $i < $this->charHeight; $i++) {
$this->outputLine[$i] = '';
}
$this->outlineLength = 0;
$this->inCharLineLength = 0;
}
/**
* Attempts to add the given character onto the end of the current line.
* Returns true if this can be done, false otherwise.
*
* @param string $char Character which to add to the output
* @return bool
*/
// @codingStandardsIgnoreStart
protected function _addChar($char)
{
// @codingStandardsIgnoreEnd
$this->_getLetter($char);
if ($this->currentChar === null) {
return true;
}
$smushAmount = $this->_smushAmount();
if (($this->outlineLength + $this->currentCharWidth - $smushAmount) > $this->outlineLengthLimit
|| ($this->inCharLineLength + 1) > $this->inCharLineLengthLimit) {
return false;
}
for ($row = 0; $row < $this->charHeight; $row++) {
if ($this->rightToLeft === 1) {
$tempLine = $this->currentChar[$row];
for ($k = 0; $k < $smushAmount; $k++) {
$position = ($this->currentCharWidth - $smushAmount + $k);
$tempLine[$position] = $this->_smushem($tempLine[$position], $this->outputLine[$row][$k]);
}
$this->outputLine[$row] = $tempLine . substr($this->outputLine[$row], $smushAmount);
} else {
for ($k = 0; $k < $smushAmount; $k++) {
if (($this->outlineLength - $smushAmount + $k) < 0) {
continue;
}
$position = ($this->outlineLength - $smushAmount + $k);
if (isset($this->outputLine[$row][$position])) {
$leftChar = $this->outputLine[$row][$position];
} else {
$leftChar = null;
}
$this->outputLine[$row][$position] = $this->_smushem($leftChar, $this->currentChar[$row][$k]);
}
$this->outputLine[$row] .= substr($this->currentChar[$row], $smushAmount);
}
}
$this->outlineLength = strlen($this->outputLine[0]);
$this->inCharLine[$this->inCharLineLength++] = $char;
return true;
}
/**
* Gets the requested character and sets current and previous char width.
*
* @param string $char The character from which to get the letter of
* @return void
*/
// @codingStandardsIgnoreStart
protected function _getLetter($char)
{
// @codingStandardsIgnoreEnd
if (array_key_exists($this->_uniOrd($char), $this->charList)) {
$this->currentChar = $this->charList[$this->_uniOrd($char)];
$this->previousCharWidth = $this->currentCharWidth;
$this->currentCharWidth = strlen($this->currentChar[0]);
} else {
$this->currentChar = null;
}
}
/**
* Returns the maximum amount that the current character can be smushed into
* the current line.
*
* @return int
*/
// @codingStandardsIgnoreStart
protected function _smushAmount()
{
// @codingStandardsIgnoreEnd
if (($this->smushMode & (self::SM_SMUSH | self::SM_KERN)) === 0) {
return 0;
}
$maxSmush = $this->currentCharWidth;
for ($row = 0; $row < $this->charHeight; $row++) {
if ($this->rightToLeft === 1) {
$charbd = strlen($this->currentChar[$row]);
while (true) {
if (! isset($this->currentChar[$row][$charbd])) {
$leftChar = null;
} else {
$leftChar = $this->currentChar[$row][$charbd];
}
if ($charbd > 0 && ($leftChar === null || $leftChar == ' ')) {
$charbd--;
} else {
break;
}
}
$linebd = 0;
while (true) {
if (! isset($this->outputLine[$row][$linebd])) {
$rightChar = null;
} else {
$rightChar = $this->outputLine[$row][$linebd];
}
if ($rightChar === ' ') {
$linebd++;
} else {
break;
}
}
$amount = ($linebd + $this->currentCharWidth - 1 - $charbd);
} else {
$linebd = strlen($this->outputLine[$row]);
while (true) {
if (! isset($this->outputLine[$row][$linebd])) {
$leftChar = null;
} else {
$leftChar = $this->outputLine[$row][$linebd];
}
if ($linebd > 0 && ($leftChar === null || $leftChar == ' ')) {
$linebd--;
} else {
break;
}
}
$charbd = 0;
while (true) {
if (! isset($this->currentChar[$row][$charbd])) {
$rightChar = null;
} else {
$rightChar = $this->currentChar[$row][$charbd];
}
if ($rightChar === ' ') {
$charbd++;
} else {
break;
}
}
$amount = ($charbd + $this->outlineLength - 1 - $linebd);
}
if (empty($leftChar) || $leftChar === ' ') {
$amount++;
} elseif (! empty($rightChar)) {
if ($this->_smushem($leftChar, $rightChar) !== null) {
$amount++;
}
}
$maxSmush = min($amount, $maxSmush);
}
return $maxSmush;
}
/**
* Given two characters, attempts to smush them into one, according to the
* current smushmode. Returns smushed character or false if no smushing can
* be done.
*
* Smushmode values are sum of following (all values smush blanks):
*
* 1: Smush equal chars (not hardblanks)
* 2: Smush '_' with any char in hierarchy below
* 4: hierarchy: "|", "/\", "[]", "{}", "()", "<>"
* Each class in hier. can be replaced by later class.
* 8: [ + ] -> |, { + } -> |, ( + ) -> |
* 16: / + \ -> X, > + < -> X (only in that order)
* 32: hardblank + hardblank -> hardblank
*
* @param string $leftChar Left character to smush
* @param string $rightChar Right character to smush
* @return string
*/
// @codingStandardsIgnoreStart
protected function _smushem($leftChar, $rightChar)
{
// @codingStandardsIgnoreEnd
if ($leftChar === ' ') {
return $rightChar;
}
if ($rightChar === ' ') {
return $leftChar;
}
if ($this->previousCharWidth < 2 || $this->currentCharWidth < 2) {
// Disallows overlapping if the previous character or the current
// character has a width of one or zero.
return;
}
if (($this->smushMode & self::SM_SMUSH) === 0) {
// Kerning
return;
}
if (($this->smushMode & 63) === 0) {
// This is smushing by universal overlapping
if ($leftChar === ' ') {
return $rightChar;
} elseif ($rightChar === ' ') {
return $leftChar;
} elseif ($leftChar === $this->hardBlank) {
return $rightChar;
} elseif ($rightChar === $this->hardBlank) {
return $rightChar;
} elseif ($this->rightToLeft === 1) {
return $leftChar;
} else {
// Occurs in the absence of above exceptions
return $rightChar;
}
}
if (($this->smushMode & self::SM_HARDBLANK) > 0) {
if ($leftChar === $this->hardBlank && $rightChar === $this->hardBlank) {
return $leftChar;
}
}
if ($leftChar === $this->hardBlank && $rightChar === $this->hardBlank) {
return;
}
if (($this->smushMode & self::SM_EQUAL) > 0) {
if ($leftChar === $rightChar) {
return $leftChar;
}
}
if (($this->smushMode & self::SM_LOWLINE) > 0) {
if ($leftChar === '_' && strchr('|/\\[]{}()<>', $rightChar) !== false) {
return $rightChar;
} elseif ($rightChar === '_' && strchr('|/\\[]{}()<>', $leftChar) !== false) {
return $leftChar;
}
}
if (($this->smushMode & self::SM_HIERARCHY) > 0) {
if ($leftChar === '|' && strchr('/\\[]{}()<>', $rightChar) !== false) {
return $rightChar;
} elseif ($rightChar === '|' && strchr('/\\[]{}()<>', $leftChar) !== false) {
return $leftChar;
} elseif (strchr('/\\', $leftChar) && strchr('[]{}()<>', $rightChar) !== false) {
return $rightChar;
} elseif (strchr('/\\', $rightChar) && strchr('[]{}()<>', $leftChar) !== false) {
return $leftChar;
} elseif (strchr('[]', $leftChar) && strchr('{}()<>', $rightChar) !== false) {
return $rightChar;
} elseif (strchr('[]', $rightChar) && strchr('{}()<>', $leftChar) !== false) {
return $leftChar;
} elseif (strchr('{}', $leftChar) && strchr('()<>', $rightChar) !== false) {
return $rightChar;
} elseif (strchr('{}', $rightChar) && strchr('()<>', $leftChar) !== false) {
return $leftChar;
} elseif (strchr('()', $leftChar) && strchr('<>', $rightChar) !== false) {
return $rightChar;
} elseif (strchr('()', $rightChar) && strchr('<>', $leftChar) !== false) {
return $leftChar;
}
}
if (($this->smushMode & self::SM_PAIR) > 0) {
if ($leftChar === '[' && $rightChar === ']') {
return '|';
} elseif ($rightChar === '[' && $leftChar === ']') {
return '|';
} elseif ($leftChar === '{' && $rightChar === '}') {
return '|';
} elseif ($rightChar === '{' && $leftChar === '}') {
return '|';
} elseif ($leftChar === '(' && $rightChar === ')') {
return '|';
} elseif ($rightChar === '(' && $leftChar === ')') {
return '|';
}
}
if (($this->smushMode & self::SM_BIGX) > 0) {
if ($leftChar === '/' && $rightChar === '\\') {
return '|';
} elseif ($rightChar === '/' && $leftChar === '\\') {
return 'Y';
} elseif ($leftChar === '>' && $rightChar === '<') {
return 'X';
}
}
return;
}
/**
* Load the specified font
*
* @param string $fontFile Font file to load
* @throws Exception\RuntimeException When font file was not found
* @throws Exception\RuntimeException When GZIP library is required but not found
* @throws Exception\RuntimeException When font file is not readable
* @throws Exception\UnexpectedValueException When font file is not a FIGlet 2 font file
* @return void
*/
// @codingStandardsIgnoreStart
protected function _loadFont($fontFile)
{
// @codingStandardsIgnoreEnd
// Check if the font file exists
if (! file_exists($fontFile)) {
throw new Exception\RuntimeException($fontFile . ': Font file not found');
}
// Check if gzip support is required
if (substr($fontFile, -3) === '.gz') {
if (! function_exists('gzcompress')) {
throw new Exception\RuntimeException('GZIP library is required for gzip compressed font files');
}
$fontFile = 'compress.zlib://' . $fontFile;
$compressed = true;
} else {
$compressed = false;
}
// Try to open the file
$fp = fopen($fontFile, 'rb');
if ($fp === false) {
throw new Exception\RuntimeException($fontFile . ': Could not open file');
}
// If the file is not compressed, lock the stream
if (! $compressed) {
flock($fp, LOCK_SH);
}
// Get magic
$magic = $this->_readMagic($fp);
// Get the header
$line = fgets($fp, 1000) ?: '';
$numsRead = sscanf(
$line,
'%*c%c %d %*d %d %d %d %d %d',
$this->hardBlank,
$this->charHeight,
$this->maxLength,
$smush,
$cmtLines,
$rightToLeft,
$this->fontSmush
);
if ($magic !== self::FONTFILE_MAGIC_NUMBER || $numsRead < 5) {
throw new Exception\UnexpectedValueException($fontFile . ': Not a FIGlet 2 font file');
}
// Set default right to left
if ($numsRead < 6) {
$rightToLeft = 0;
}
// If no smush2, decode smush into smush2
if ($numsRead < 7) {
if ($smush === 2) {
$this->fontSmush = self::SM_KERN;
} elseif ($smush < 0) {
$this->fontSmush = 0;
} else {
$this->fontSmush = (($smush & 31) | self::SM_SMUSH);
}
}
// Correct char height && maxlength
$this->charHeight = max(1, $this->charHeight);
$this->maxLength = max(1, $this->maxLength);
// Give ourselves some extra room
$this->maxLength += 100;
// See if we have to override smush settings
$this->_setUsedSmush();
// Get left to right value
if ($this->rightToLeft === null) {
$this->rightToLeft = $rightToLeft;
}
// Get justification value
if ($this->justification === null) {
$this->justification = (2 * $this->rightToLeft);
}
// Skip all comment lines
for ($line = 1; $line <= $cmtLines; $line++) {
$this->_skipToEol($fp);
}
// Fetch all ASCII characters
for ($asciiCode = 32; $asciiCode < 127; $asciiCode++) {
$this->charList[$asciiCode] = $this->_loadChar($fp);
}
// Fetch all german characters
foreach ($this->germanChars as $uniCode) {
$char = $this->_loadChar($fp);
if ($char === false) {
fclose($fp);
return;
}
if (trim(implode('', $char)) !== '') {
$this->charList[$uniCode] = $char;
}
}
// At the end fetch all extended characters
while (! feof($fp)) {
// Get the Unicode
$uniCode = fgets($fp, 2048);
if (false === $uniCode) {
continue;
}
list($uniCode) = explode(' ', $uniCode);
if (empty($uniCode)) {
continue;
}
// Convert it if required
if (0 === strpos($uniCode, '0x')) {
$uniCode = hexdec(substr($uniCode, 2));
} elseif (0 === strpos($uniCode, '0') &&
$uniCode !== '0' or
0 === strpos($uniCode, '-0')) {
$uniCode = octdec($uniCode);
} else {
$uniCode = (int) $uniCode;
}
// Now fetch the character
$char = $this->_loadChar($fp);
if ($char === false) {
fclose($fp);
return;
}
$this->charList[$uniCode] = $char;
}
fclose($fp);
$this->fontLoaded = true;
}
/**
* Set the used smush mode, according to smush override, user smush and
* font smush.
*
* @return void
*/
// @codingStandardsIgnoreStart
protected function _setUsedSmush()
{
// @codingStandardsIgnoreEnd
if ($this->smushOverride === self::SMO_NO) {
$this->smushMode = $this->fontSmush;
} elseif ($this->smushOverride === self::SMO_YES) {
$this->smushMode = $this->userSmush;
} elseif ($this->smushOverride === self::SMO_FORCE) {
$this->smushMode = ($this->fontSmush | $this->userSmush);
}
}
/**
* Reads a four-character magic string from a stream
*
* @param resource $fp File pointer to the font file
* @return string
*/
// @codingStandardsIgnoreStart
protected function _readMagic($fp)
{
// @codingStandardsIgnoreEnd
$magic = '';
for ($i = 0; $i < 4; $i++) {
$magic .= fgetc($fp);
}
return $magic;
}
/**
* Skip a stream to the end of line
*
* @param resource $fp File pointer to the font file
* @return void
*/
// @codingStandardsIgnoreStart
protected function _skipToEol($fp)
{
// @codingStandardsIgnoreEnd
$dummy = fgetc($fp);
while ($dummy !== false && ! feof($fp)) {
if ($dummy === "\n") {
return;
}
if ($dummy === "\r") {
$dummy = fgetc($fp);
if (! feof($fp) && $dummy !== "\n") {
fseek($fp, -1, SEEK_SET);
}
return;
}
$dummy = fgetc($fp);
}
}
/**
* Load a single character from the font file
*
* @param resource $fp File pointer to the font file
* @return array
*/
// @codingStandardsIgnoreStart
protected function _loadChar($fp)
{
// @codingStandardsIgnoreEnd
$char = [];
for ($i = 0; $i < $this->charHeight; $i++) {
if (feof($fp)) {
return false;
}
$line = rtrim(fgets($fp, 2048), "\r\n");
if (preg_match('#(.)\\1?$#', $line, $result) === 1) {
$line = str_replace($result[1], '', $line);
}
$char[] = $line;
}
return $char;
}
/**
* Unicode compatible ord() method
*
* @param string $c The char to get the value from
* @return int
*/
// @codingStandardsIgnoreStart
protected function _uniOrd($c)
{
// @codingStandardsIgnoreEnd
$h = ord($c[0]);
if ($h <= 0x7F) {
$ord = $h;
} elseif ($h < 0xC2) {
$ord = 0;
} elseif ($h <= 0xDF) {
$ord = (($h & 0x1F) << 6 | (ord($c[1]) & 0x3F));
} elseif ($h <= 0xEF) {
$ord = (($h & 0x0F) << 12 | (ord($c[1]) & 0x3F) << 6 | (ord($c[2]) & 0x3F));
} elseif ($h <= 0xF4) {
$ord = (($h & 0x0F) << 18 | (ord($c[1]) & 0x3F) << 12 |
(ord($c[2]) & 0x3F) << 6 | (ord($c[3]) & 0x3F));
} else {
$ord = 0;
}
return $ord;
}
}
PK GPc1 ) src/Figlet/Exception/RuntimeException.phpnu W+A #
#
#
#
#
#
##
?#
#
#
#
#
#
##
@#
#
#
#
#
#
##
___ #
/ _ \\ #
/ //\ \\ #
| ___ ||#
|_|| |_||#
`-` `-` #
##
______ #
| \\ #
| --$ // #
| -- \\ #
|______// #
`------` #
##
_____ #
/ ____|| #
/ //---`' #
\ \\___ #
\_____|| #
`----` #
##
_____ #
| __ \\ #
| |$ \ || #
| |__/ || #
|_____// #
-----` #
##
_____ #
| ___|| #
| ||__ #
| ||__ #
|_____|| #
`-----` #
##
______ #
/_____// #
`____ ` #
/___// #
`__ ` #
/_// #
`-` ##
_____ #
/ ___|| #
| //$__ #
| \\_\ || #
\____// #
`---` #
##
__ _ #
| || | || #
| '--' || #
| .--. || #
|_|| |_|| #
`-` `-` #
##
______ #
/_ _// #
-| ||- #
_| ||_ #
/_____// #
`-----` #
##
______ #
/_ _// #
| || #
_| || #
/__// #
`--` #
##
_ __ #
| |/ // #
| ' // #
| . \\ #
|_|\_\\ #
`-` --` #
##
__ #
| || #
| || #
| ||__ #
|____// #
`----` #
##
_ _ #
| \ / || #
| \/ || #
| . . || #
|_|\/|_|| #
`-` `-` #
##
_ _ #
| \| || #
| ' || #
| . || #
|_|\_|| #
`-` -` #
##
___ #
/ _ \\ #
| /$\ || #
| \_/ || #
\___// #
`---` #
##
____ #
| _ \\ #
| |_| || #
| .__// #
|_|--` #
`-` #
##
___ #
/ _ \\ #
| /$\ || #
| \_/ || #
\___ \\ #
`---` #
##
____ #
| _ \\ #
| |_| || #
| . // #
|_|\_\\ #
`-` --` #
##
_____ #
/ ___// #
\___ \\ #
/ $ // #
/____// #
`-----` #
##
______ #
/_ _// #
`-| |,- #
| || #
|_|| #
`-`' #
##
_ _ #
| || | || #
| || | || #
| \\_/ || #
\____// #
`---` #
##
__ __ #
\ \\ / // #
\ \/ // #
\ // #
\// #
` #
##
_ _ #
| | | || #
| |/\| || #
| /\ || #
|_// \_|| #
`-` `-` #
##
__ __ #
\ \\/ // #
\ $ // #
/ . \\ #
/_//\_\\ #
`-` --` #
##
__ __ #
\ \\/ // #
\ ` // #
| || #
|_|| #
`-`' #
##
______ #
|____ // #
/ // #
/ // #
/ //__ #
/______|| #
`------` ##
[#
#
#
#
#
#
##
\#
#
#
#
#
#
##
]#
#
#
#
#
#
##
^#
#
#
#
#
#
##
_#
#
#
#
#
#
##
`#
#
#
#
#
#
##
___ #
/ _ \\ #
/ //\ \\ #
| ___ ||#
|_|| |_||#
`-` `-` #
##
______ #
| \\ #
| --$ // #
| -- \\ #
|______// #
`------` #
##
_____ #
/ ____|| #
/ //---`' #
\ \\___ #
\_____|| #
`----` #
##
_____ #
| __ \\ #
| |$ \ || #
| |__/ || #
|_____// #
-----` #
##
_____ #
| ___|| #
| ||__ #
| ||__ #
|_____|| #
`-----` #
##
______ #
/_____// #
`____ ` #
/___// #
`__ ` #
/_// #
`-` ##
_____ #
/ ___|| #
| //$__ #
| \\_\ || #
\____// #
`---` #
##
__ _ #
| || | || #
| '--' || #
| .--. || #
|_|| |_|| #
`-` `-` #
##
______ #
/_ _// #
-| ||- #
_| ||_ #
/_____// #
`-----` #
##
______ #
/_ _// #
| || #
_| || #
/__// #
`--` #
##
_ __ #
| |/ // #
| ' // #
| . \\ #
|_|\_\\ #
`-` --` #
##
__ #
| || #
| || #
| ||__ #
|____// #
`----` #
##
_ _ #
| \ / || #
| \/ || #
| . . || #
|_|\/|_|| #
`-` `-` #
##
_ _ #
| \| || #
| ' || #
| . || #
|_|\_|| #
`-` -` #
##
___ #
/ _ \\ #
| /$\ || #
| \_/ || #
\___// #
`---` #
##
#
____ #
| \\ #
| [] || #
| __// #
|_|`-` #
`-` ##
#
___ #
/ || #
| [] || #
\__ || #
-|_|| #
`-` ##
____ #
| _ \\ #
| |_| || #
| . // #
|_|\_\\ #
`-` --` #
##
_____ #
/ ___// #
\___ \\ #
/ $ // #
/____// #
`-----` #
##
______ #
/_ _// #
`-| |,- #
| || #
|_|| #
`-`' #
##
_ _ #
| || | || #
| || | || #
| \\_/ || #
\____// #
`---` #
##
__ __ #
\ \\ / // #
\ \/ // #
\ // #
\// #
` #
##
_ _ #
| | | || #
| |/\| || #
| /\ || #
|_// \_|| #
`-` `-` #
##
__ __ #
\ \\/ // #
\ $ // #
/ . \\ #
/_//\_\\ #
`-` --` #
##
__ __ #
\ \\/ // #
\ ` // #
| || #
|_|| #
`-`' #
##
_____ #
|__ // #
/ // #
/ //__ #
/_____|| #
`-----` #
##
{#
#
#
#
#
#
##
|#
#
#
#
#
#
##
}#
#
#
#
#
#
##
~#
#
#
#
#
#
##
[]|_[]| #
/ _ \\ #
/ //\ \\ #
| $___$ ||#
|_||$ |_||#
`-` `-` #
##
[]|_[]| #
/ _ \\ #
| /$\ || #
| \_/ || #
\___// #
---` #
##
[]| []| #
| ||$| || #
| ||$| || #
| \\_/ || #
\____// #
`---` #
##
[]|_[]| #
/ _ \\ #
/ //\ \\ #
| $___$ ||#
|_||$ |_||#
`-` `-` #
##
[]|_[]| #
/ _ \\ #
| /$\ || #
| \_/ || #
\___// #
---` #
##
[]| []| #
| ||$| || #
| ||$| || #
| \\_/ || #
\____// #
`---` #
##
,--. #
| _$ \\ #
| // #
| |\ \\ #
|$ ___\\ #
|_|----` #
- ##
162 CENT SIGN
_ #
| || #
/ __// #
| (__` #
\ \\ #
|_|` #
`-` ##
215 MULTIPLICATION SIGN
#
#
\\// #
\\ #
//\\ #
#
##
PK GPTk^
mkdocs.ymlnu W+A docs_dir: docs/book
site_dir: docs/html
nav:
- Home: index.md
- Figlets: figlet.md
- Tables: table.md
site_name: laminas-text
site_description: "Create FIGlets and text-based tables"
repo_url: 'https://github.com/laminas/laminas-text'
extra:
project: Components
PK GP"y4 4 .github/workflows/docs-build.ymlnu W+A name: docs-build
on:
push:
branches:
- master
repository_dispatch:
jobs:
build-deploy:
runs-on: ubuntu-latest
steps:
- name: Build Docs
uses: laminas/documentation-theme/github-actions/docs@master
env:
DOCS_DEPLOY_KEY: ${{ secrets.DOCS_DEPLOY_KEY }}
PK GPtl .gitattributesnu W+A /.coveralls.yml export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/.travis.yml export-ignore
/docs/ export-ignore
/mkdocs.yml export-ignore
/phpcs.xml export-ignore
/phpunit.xml.dist export-ignore
/test/ export-ignore
PK GPRS60 0 test/FigletTest.phpnu W+A _equalAgainstFile($figlet->render('Dummy'), 'StandardAlignLeft.figlet');
}
public function testStandardAlignCenter()
{
$figlet = new Figlet\Figlet(['justification' => Figlet\Figlet::JUSTIFICATION_CENTER]);
$this->_equalAgainstFile($figlet->render('Dummy'), 'StandardAlignCenter.figlet');
}
public function testStandardAlignRight()
{
$figlet = new Figlet\Figlet(['justification' => Figlet\Figlet::JUSTIFICATION_RIGHT]);
$this->_equalAgainstFile($figlet->render('Dummy'), 'StandardAlignRight.figlet');
}
public function testStandardRightToLeftAlignLeft()
{
$figlet = new Figlet\Figlet(['justification' => Figlet\Figlet::JUSTIFICATION_LEFT,
'rightToLeft' => Figlet\Figlet::DIRECTION_RIGHT_TO_LEFT]);
$this->_equalAgainstFile($figlet->render('Dummy'), 'StandardRightToLeftAlignLeft.figlet');
}
public function testStandardRightToLeftAlignCenter()
{
$figlet = new Figlet\Figlet(['justification' => Figlet\Figlet::JUSTIFICATION_CENTER,
'rightToLeft' => Figlet\Figlet::DIRECTION_RIGHT_TO_LEFT]);
$this->_equalAgainstFile($figlet->render('Dummy'), 'StandardRightToLeftAlignCenter.figlet');
}
public function testStandardRightToLeftAlignRight()
{
$figlet = new Figlet\Figlet(['rightToLeft' => Figlet\Figlet::DIRECTION_RIGHT_TO_LEFT]);
$this->_equalAgainstFile($figlet->render('Dummy'), 'StandardRightToLeftAlignRight.figlet');
}
public function testWrongParameter()
{
$figlet = new Figlet\Figlet();
$this->expectException('Laminas\Text\Figlet\Exception\InvalidArgumentException');
$this->expectExceptionMessage('must be a string');
$figlet->render(1);
}
public function testCorrectEncodingUTF8()
{
$figlet = new Figlet\Figlet();
$this->_equalAgainstFile($figlet->render('Ömläüt'), 'CorrectEncoding.figlet');
}
public function testCorrectEncodingISO885915()
{
if (PHP_OS == 'AIX') {
$this->markTestSkipped('Test case cannot run on AIX');
}
$figlet = new Figlet\Figlet();
$isoText = iconv('UTF-8', 'ISO-8859-15', 'Ömläüt');
$this->_equalAgainstFile($figlet->render($isoText, 'ISO-8859-15'), 'CorrectEncoding.figlet');
}
public function testIncorrectEncoding()
{
$this->expectException('Laminas\Text\Figlet\Exception\UnexpectedValueException');
$this->expectExceptionMessage('text is not encoded with UTF-8');
$isoText = iconv('UTF-8', 'ISO-8859-15', 'Ömläüt');
$figlet = new Figlet\Figlet();
$figlet->render($isoText);
}
public function testNonExistentFont()
{
$this->expectException('Laminas\Text\Figlet\Exception\RuntimeException');
$this->expectExceptionMessage('not found');
$figlet = new Figlet\Figlet(['font' => __DIR__ . '/Figlet/NonExistentFont.flf']);
}
public function testInvalidFont()
{
$this->expectException('Laminas\Text\Figlet\Exception\UnexpectedValueException');
$this->expectExceptionMessage('Not a FIGlet');
$figlet = new Figlet\Figlet(['font' => __DIR__ . '/Figlet/InvalidFont.flf']);
}
public function testGzippedFont()
{
$figlet = new Figlet\Figlet(['font' => __DIR__ . '/Figlet/GzippedFont.gz']);
$this->_equalAgainstFile($figlet->render('Dummy'), 'StandardAlignLeft.figlet');
}
public function testConfig()
{
$config = new \Laminas\Config\Config(['justification' => Figlet\Figlet::JUSTIFICATION_RIGHT]);
$figlet = new Figlet\Figlet($config);
$this->_equalAgainstFile($figlet->render('Dummy'), 'StandardAlignRight.figlet');
}
public function testOutputWidth()
{
$figlet = new Figlet\Figlet(['outputWidth' => 50,
'justification' => Figlet\Figlet::JUSTIFICATION_RIGHT]);
$this->_equalAgainstFile($figlet->render('Dummy'), 'OutputWidth50AlignRight.figlet');
}
public function testSmushModeRemoved()
{
$figlet = new Figlet\Figlet(['smushMode' => -1]);
$this->_equalAgainstFile($figlet->render('Dummy'), 'NoSmush.figlet');
}
public function testSmushModeRemovedRightToLeft()
{
$figlet = new Figlet\Figlet(['smushMode' => -1,
'rightToLeft' => Figlet\Figlet::DIRECTION_RIGHT_TO_LEFT]);
$this->_equalAgainstFile($figlet->render('Dummy'), 'NoSmushRightToLeft.figlet');
}
public function testSmushModeInvalid()
{
$figlet = new Figlet\Figlet(['smushMode' => -5]);
$this->_equalAgainstFile($figlet->render('Dummy'), 'StandardAlignLeft.figlet');
}
public function testSmushModeTooSmall()
{
$figlet = new Figlet\Figlet(['smushMode' => -2]);
$this->_equalAgainstFile($figlet->render('Dummy'), 'StandardAlignLeft.figlet');
}
public function testSmushModeDefault()
{
$figlet = new Figlet\Figlet(['smushMode' => 0]);
$this->_equalAgainstFile($figlet->render('Dummy'), 'SmushDefault.figlet');
}
public function testSmushModeForced()
{
$figlet = new Figlet\Figlet(['smushMode' => 5]);
$this->_equalAgainstFile($figlet->render('Dummy'), 'SmushForced.figlet');
}
public function testWordWrapLeftToRight()
{
$figlet = new Figlet\Figlet();
$this->_equalAgainstFile($figlet->render('Dummy Dummy Dummy'), 'WordWrapLeftToRight.figlet');
}
public function testWordWrapRightToLeft()
{
$figlet = new Figlet\Figlet(['rightToLeft' => Figlet\Figlet::DIRECTION_RIGHT_TO_LEFT]);
$this->_equalAgainstFile($figlet->render('Dummy Dummy Dummy'), 'WordWrapRightToLeft.figlet');
}
public function testCharWrapLeftToRight()
{
$figlet = new Figlet\Figlet();
$this->_equalAgainstFile($figlet->render('DummyDumDummy'), 'CharWrapLeftToRight.figlet');
}
public function testCharWrapRightToLeft()
{
$figlet = new Figlet\Figlet(['rightToLeft' => Figlet\Figlet::DIRECTION_RIGHT_TO_LEFT]);
$this->_equalAgainstFile($figlet->render('DummyDumDummy'), 'CharWrapRightToLeft.figlet');
}
public function testParagraphOff()
{
$figlet = new Figlet\Figlet();
$this->_equalAgainstFile($figlet->render("Dum\nDum\n\nDum\n"), 'ParagraphOff.figlet');
}
public function testParagraphOn()
{
$figlet = new Figlet\Figlet(['handleParagraphs' => true]);
$this->_equalAgainstFile($figlet->render("Dum\nDum\n\nDum\n"), 'ParagraphOn.figlet');
}
public function testEmptyString()
{
$figlet = new Figlet\Figlet();
$this->assertEquals('', $figlet->render(''));
}
// @codingStandardsIgnoreStart
protected function _equalAgainstFile($output, $file)
{
// @codingStandardsIgnoreEnd
$compareString = file_get_contents(__DIR__ . '/Figlet/' . $file);
$this->assertEquals($compareString, $output);
}
}
PK GPSK; ; test/TableTest.phpnu W+A assertEquals($column->render(10), "foobar \nfoo ");
}
public function testColumnPadding()
{
$column = new Table\Column("foobar\nfoo");
$this->assertEquals($column->render(10, 1), " foobar \n foo ");
}
public function testColumnWordwrap()
{
$column = new Table\Column("foobar");
$this->assertEquals($column->render(3), "foo\nbar");
}
public function testColumnUnicodeWordwrap()
{
$column = new Table\Column("Ömläüt");
$this->assertEquals($column->render(3), "Öml\näüt");
}
public function testColumnAlignCenter()
{
$column = new Table\Column("foobar\nfoo", Table\Column::ALIGN_CENTER);
$this->assertEquals($column->render(10), " foobar \n foo ");
}
public function testColumnAlignRight()
{
$column = new Table\Column("foobar\nfoo", Table\Column::ALIGN_RIGHT);
$this->assertEquals($column->render(10), " foobar\n foo");
}
public function testColumnForcedEncoding()
{
if (PHP_OS == 'AIX') {
// AIX cannot handle these charsets
$this->markTestSkipped('Test case cannot run on AIX');
}
$iso885915 = iconv('utf-8', 'iso-8859-15', 'Ömläüt');
$column = new Table\Column($iso885915, null, null, 'iso-8859-15');
$this->assertEquals($column->render(6), 'Ömläüt');
}
public function testColumnDefaultInputEncoding()
{
if (PHP_OS == 'AIX') {
// AIX cannot handle these charsets
$this->markTestSkipped('Test case cannot run on AIX');
}
$iso885915 = iconv('utf-8', 'iso-8859-15', 'Ömläüt');
Table\Table::setInputCharset('iso-8859-15');
$column = new Table\Column($iso885915);
$this->assertEquals($column->render(6), 'Ömläüt');
}
public function testColumnDefaultOutputEncoding()
{
if (PHP_OS == 'AIX') {
// AIX cannot handle these charsets
$this->markTestSkipped('Test case cannot run on AIX');
}
$iso885915 = iconv('utf-8', 'iso-8859-15', 'Ömläüt');
Table\Table::setOutputCharset('iso-8859-15');
$column = new Table\Column('Ömläüt');
$this->assertEquals($column->render(6), $iso885915);
}
public function testColumnSetContentInvalidArgument()
{
$this->expectException('Laminas\Text\Table\Exception\InvalidArgumentException');
$this->expectExceptionMessage('must be a string');
$column = new Table\Column(1);
}
public function testColumnSetAlignInvalidArgument()
{
$this->expectException('Laminas\Text\Table\Exception\OutOfBoundsException');
$this->expectExceptionMessage('Invalid align supplied');
$column = new Table\Column(null, false);
}
public function testColumnSetColSpanInvalidArgument()
{
$this->expectException('Laminas\Text\Table\Exception\InvalidArgumentException');
$this->expectExceptionMessage('must be an integer and greater than 0');
$column = new Table\Column(null, null, 0);
}
public function testColumnRenderInvalidArgument()
{
$column = new Table\Column();
$this->expectException('Laminas\Text\Table\Exception\InvalidArgumentException');
$this->expectExceptionMessage('must be an integer and greater than 0');
$column->render(0);
}
public function testUnicodeStringPadding()
{
$decorator = new Decorator\Unicode();
$row = new Table\Row();
$row->appendColumn(new Table\Column('Eté'));
$row->appendColumn(new Table\Column('Ete'));
$this->assertEquals($row->render([10, 10], $decorator), "│Eté │Ete │\n");
}
public function testRowColumnsWithColSpan()
{
$decorator = new Decorator\Unicode();
$row = new Table\Row();
$row->appendColumn(new Table\Column('foobar'));
$row->appendColumn(new Table\Column('foobar', null, 2));
$this->assertEquals($row->render([10, 10, 10], $decorator), "│foobar │foobar │\n");
}
public function testRowWithNoColumns()
{
$decorator = new Decorator\Unicode();
$row = new Table\Row();
$this->assertEquals($row->render([10, 10, 10], $decorator), "│ │\n");
}
public function testRowNotEnoughColumnWidths()
{
$decorator = new Decorator\Unicode();
$row = new Table\Row();
$row->appendColumn(new Table\Column());
$row->appendColumn(new Table\Column());
$this->expectException('Laminas\Text\Table\Exception\OverflowException');
$this->expectExceptionMessage('Too many columns');
$row->render([10], $decorator);
}
public function testRowGetColumnWidthsBeforeRendering()
{
$row = new Table\Row();
$this->expectException('Laminas\Text\Table\Exception\UnexpectedValueException');
$this->expectExceptionMessage('render() must be called');
$row->getColumnWidths();
}
public function testRowAutoInsertColumns()
{
$decorator = new Decorator\Unicode();
$row = new Table\Row();
$row->appendColumn(new Table\Column('foobar'));
$this->assertEquals($row->render([10, 10, 10], $decorator), "│foobar │ │\n");
}
public function testRowMultiLine()
{
$decorator = new Decorator\Unicode();
$row = new Table\Row();
$row->appendColumn(new Table\Column("foo\nbar"));
$row->appendColumn(new Table\Column("foobar"));
$this->assertEquals(
$row->render([10, 10], $decorator),
"│foo │foobar │\n│bar │ │\n"
);
}
public function testUnicodeRowMultiLine()
{
$decorator = new Decorator\Unicode();
$row = new Table\Row();
$row->appendColumn(new Table\Column("föö\nbär"));
$row->appendColumn(new Table\Column("fööbär"));
$this->assertEquals(
$row->render([3, 10], $decorator),
"│föö│fööbär │\n│bär│ │\n"
);
}
public function testTableConstructInvalidColumnWidthsItem()
{
$this->expectException('Laminas\Text\Table\Exception\InvalidArgumentException');
$this->expectExceptionMessage('invalid column width');
$table = new Table\Table(['columnWidths' => ['foo']]);
}
public function testTableDecoratorLoaderSimple()
{
$table = new Table\Table(['columnWidths' => [10], 'decorator' => 'ascii']);
$row = new Table\Row();
$row->createColumn('foobar');
$table->appendRow($row);
$this->assertEquals($table->render(), "+----------+\n|foobar |\n+----------+\n");
}
public function testTableDecoratorEncodingDefault()
{
Table\Table::setOutputCharset('iso-8859-15');
$table = new Table\Table(['columnWidths' => [10]]);
$row = new Table\Row();
$row->createColumn('foobar');
$table->appendRow($row);
$this->assertEquals($table->render(), "+----------+\n|foobar |\n+----------+\n");
}
public function testTableDecoratorLoaderAdvanced()
{
$table = new Table\Table(['columnWidths' => [10], 'decorator' => new Decorator\Ascii()]);
$row = new Table\Row();
$row->createColumn('foobar');
$table->appendRow($row);
$this->assertEquals($table->render(), "+----------+\n|foobar |\n+----------+\n");
}
public function testTableSimpleRow()
{
$table = new Table\Table(['columnWidths' => [10]]);
$row = new Table\Row();
$row->createColumn('foobar');
$table->appendRow($row);
$this->assertEquals(
$table->render(),
"┌──────────┐\n│foobar │\n└──────────┘\n"
);
}
public function testDefaultColumnAlign()
{
$table = new Table\Table(['columnWidths' => [10]]);
$table->setDefaultColumnAlign(0, Table\Column::ALIGN_CENTER);
$table->appendRow(['foobar']);
$this->assertEquals(
$table->render(),
"┌──────────┐\n│ foobar │\n└──────────┘\n"
);
}
public function testRowGetColumns()
{
$row = new Table\Row();
$row->createColumn('foo')
->createColumn('bar');
$this->assertEquals(2, count($row->getColumns()));
}
public function testRowGetColumn()
{
$row = new Table\Row();
$row->createColumn('foo');
$this->assertInstanceOf('Laminas\Text\Table\Column', $row->getColumn(0));
}
public function testRowGetInvalidColumn()
{
$row = new Table\Row();
$row->createColumn('foo');
$this->assertEquals(null, $row->getColumn(1));
}
public function testTableWithoutRows()
{
$table = new Table\Table(['columnWidths' => [10]]);
$this->expectException('Laminas\Text\Table\Exception\UnexpectedValueException');
$this->expectExceptionMessage('No rows were added');
$table->render();
}
public function testTableColSpanWithMultipleRows()
{
$table = new Table\Table(['columnWidths' => [10, 10]]);
$row = new Table\Row();
$row->appendColumn(new Table\Column('foobar'));
$row->appendColumn(new Table\Column('foobar'));
$table->appendRow($row);
$row = new Table\Row();
$row->appendColumn(new Table\Column('foobar', null, 2));
$table->appendRow($row);
$this->assertEquals(
$table->render(),
"┌──────────┬──────────┐\n"
. "│foobar │foobar │\n"
. "├──────────┴──────────┤\n"
. "│foobar │\n"
. "└─────────────────────┘\n"
);
}
public function testTableComplex()
{
$table = new Table\Table(['columnWidths' => [10, 10, 10]]);
$row = new Table\Row();
$row->appendColumn(new Table\Column('foobar'));
$row->appendColumn(new Table\Column('foobar', null, 2));
$table->appendRow($row);
$row = new Table\Row();
$row->appendColumn(new Table\Column('foobar'));
$row->appendColumn(new Table\Column('foobar', null, 2));
$table->appendRow($row);
$row = new Table\Row();
$row->appendColumn(new Table\Column('foobar', null, 3));
$table->appendRow($row);
$row = new Table\Row();
$row->appendColumn(new Table\Column('foobar'));
$row->appendColumn(new Table\Column('foobar'));
$row->appendColumn(new Table\Column('foobar'));
$table->appendRow($row);
$this->assertEquals(
$table->render(),
"┌──────────┬─────────────────────┐\n"
. "│foobar │foobar │\n"
. "├──────────┼─────────────────────┤\n"
. "│foobar │foobar │\n"
. "├──────────┴─────────────────────┤\n"
. "│foobar │\n"
. "├──────────┬──────────┬──────────┤\n"
. "│foobar │foobar │foobar │\n"
. "└──────────┴──────────┴──────────┘\n"
);
}
public function testTableMagicToString()
{
$table = new Table\Table(['columnWidths' => [10]]);
$row = new Table\Row();
$row->appendColumn(new Table\Column('foobar'));
$table->appendRow($row);
$this->assertEquals(
(string) $table,
"┌──────────┐\n│foobar │\n└──────────┘\n"
);
}
public function testDecoratorUnicode()
{
$decorator = new Decorator\Unicode();
$chars = $decorator->getBottomLeft()
. $decorator->getBottomRight()
. $decorator->getCross()
. $decorator->getHorizontal()
. $decorator->getHorizontalDown()
. $decorator->getHorizontalUp()
. $decorator->getTopLeft()
. $decorator->getTopRight()
. $decorator->getVertical()
. $decorator->getVerticalLeft()
. $decorator->getVerticalRight();
$this->assertEquals($chars, '└┘┼─┬┴┌┐│┤├');
}
public function testDecoratorAscii()
{
$decorator = new Decorator\Ascii();
$chars = $decorator->getBottomLeft()
. $decorator->getBottomRight()
. $decorator->getCross()
. $decorator->getHorizontal()
. $decorator->getHorizontalDown()
. $decorator->getHorizontalUp()
. $decorator->getTopLeft()
. $decorator->getTopRight()
. $decorator->getVertical()
. $decorator->getVerticalLeft()
. $decorator->getVerticalRight();
$this->assertEquals($chars, '+++-++++|++');
}
public function testDecoratorBlank()
{
$decoratorManager = new Table\DecoratorManager(new ServiceManager());
$decorator = $decoratorManager->get('blank');
$chars = $decorator->getBottomLeft()
. $decorator->getBottomRight()
. $decorator->getCross()
. $decorator->getHorizontal()
. $decorator->getHorizontalDown()
. $decorator->getHorizontalUp()
. $decorator->getTopLeft()
. $decorator->getTopRight()
. $decorator->getVertical()
. $decorator->getVerticalLeft()
. $decorator->getVerticalRight();
$this->assertEquals($chars, '');
}
}
PK GP2QS # test/Table/DecoratorManagerTest.phpnu W+A StandardAlignLeft.figlet
figlet -f $UTFLF -c Dummy > StandardAlignCenter.figlet
figlet -f $UTFLF -r Dummy > StandardAlignRight.figlet
figlet -f $UTFLF -R Dummy > StandardRightToLeftAlignRight.figlet
figlet -f $UTFLF -Rc Dummy > StandardRightToLeftAlignCenter.figlet
figlet -f $UTFLF -Rl Dummy > StandardRightToLeftAlignLeft.figlet
figlet -f $UTFLF -w50 -r Dummy > OutputWidth50AlignRight.figlet
figlet -f $UTFLF -m-1 Dummy > NoSmush.figlet
figlet -f $UTFLF -m-1 -R Dummy > NoSmushRightToLeft.figlet
figlet -f $UTFLF -m0 Dummy > SmushDefault.figlet
figlet -f $UTFLF -m5 Dummy > SmushForced.figlet
echo 'Ömläüt' | iconv -f UTF-8 -t ISO-8859-15 | figlet -f $UTFLF > CorrectEncoding.figlet
figlet -f $UTFLF Dummy Dummy Dummy > WordWrapLeftToRight.figlet
figlet -f $UTFLF -R Dummy Dummy Dummy > WordWrapRightToLeft.figlet
figlet -f $UTFLF DummyDumDummy > CharWrapLeftToRight.figlet
figlet -f $UTFLF -R DummyDumDummy > CharWrapRightToLeft.figlet
echo -e "Dum\nDum\n\nDum" | figlet -f $UTFLF -p > ParagraphOn.figlet
echo -e "Dum\nDum\n\nDum" | figlet -f $UTFLF > ParagraphOff.figlet
PK GP@8 1 test/Figlet/StandardRightToLeftAlignCenter.figletnu W+A __ __ _ _ _ _ _ _ _____
\ \\/ // | \ / || | \ / || | || | || | __ \\
\ ` // | \/ || | \/ || | || | || | | \ ||
| || | . . || | . . || | \\_/ || | |__/ ||
|_|| |_|\/|_|| |_|\/|_|| \____// |_____//
`-`' `-` `-` `-` `-` `---` -----`
PK GP0 0 % test/Figlet/NoSmushRightToLeft.figletnu W+A __ __ _ _ _ _ _ _ _____
\ \\/ // | \ / || | \ / || | || | || | __ \\
\ ` // | \/ || | \/ || | || | || | | \ ||
| || | . . || | . . || | \\_/ || | |__/ ||
|_|| |_|\/|_|| |_|\/|_|| \____// |_____//
`-`' `-` `-` `-` `-` `---` -----`
PK GP@s` ` &