Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Commit

Permalink
Merge branch 'master' of https://github.com/zendframework/zf2 into ad…
Browse files Browse the repository at this point in the history
…d_maxlength_to_param_container
  • Loading branch information
postalservice14 committed Nov 13, 2014
156 parents 6d3ab5a + 5b7a64f + 7591112 + 7610b9a + f91c471 + acef74d + d753e94 + 7a829bf + 3b93376 + 6c2eca4 + 48bc01e + 3c88cd5 + fbfc750 + 441b9de + b57e2b9 + 2beef92 + 3ae4add + 994832b + 6db3cde + e0f83ee + 712223d + 3b4ec35 + e53a267 + 51bf3c7 + 10a1e95 + 30ee303 + 96417b9 + 50ea13f + 24d1c0c + b09295e + 13758aa + 99316f8 + 40b8ac3 + e284e0b + 8ff51b4 + 4b5ea1e + 5b24371 + ed932b6 + 357852d + 262e5d6 + 9057a3f + 0e1e846 + 5d11876 + 0ae0984 + 6ff135c + 0b45aba + 1778b0c + a574713 + ba3f132 + 56365a6 + 019f89a + b09b3ba + 2af32d0 + cb39fc7 + 3f8a6fd + 8999753 + a7cd86b + da1c469 + 5371cdb + fd9f625 + 99d3fcd + 1e3ed17 + a360459 + 1a1e9aa + 4c8955c + 94f2feb + 5b450ef + e64e5b0 + e9d19a6 + a5a9b6e + 5e59c3a + a47f2db + 3cf915a + a2a5c91 + 1cd3439 + ef9c643 + 298a619 + 001ae99 + c37ab8e + 017f6f1 + 0711f77 + 38af804 + 23120b4 + 5f96f53 + a257169 + 8085bc4 + 3110cd4 + f270d41 + 9536f09 + 4ec1292 + adcdd78 + e80fff6 + 99fc5ce + 1d23e94 + fa167cb + a93e92f + 13a2df8 + 06689fb + 2d601eb + 72a3295 + a59f42c + 0f4489d + b3f7029 + 3c492ce + 259bcdc + a811ae5 + f66f985 + 173e949 + b93077e + f11a10d + 5ac4be0 + cb31aff + d34bdbb + 725b978 + 27b423e + 624ac5e + a3340ac + 80ab2e3 + 3429053 + 998a6d7 + 8b9ab71 + d4dffb0 + 5456435 + 97180fa + 126be7f + c16eb72 + 8ccb096 + 50481b9 + 411738a + 50b5c0b + 0721376 + ca3399f + 5abf474 + 7783b57 + a53deb5 + c8885be + 1adf3e3 + 5a45e41 + 3370b44 + b4caa32 + df35d8a + c0d4707 + fb9dce0 + c45b896 + 739e942 + 29a4517 + 3179585 + ae205d0 + 2a7fc79 + 755e064 + fde42e0 + fb9bce8 + 3ff447c + 7cbed25 + 61aff3c + a27b9cd commit 7bfc680
Show file tree
Hide file tree
Showing 45 changed files with 2,614 additions and 176 deletions.
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
}
},
"require": {
"php": ">=5.3.3",
"php": ">=5.3.23",
"zendframework/zend-stdlib": "self.version"
},
"suggest": {
Expand All @@ -22,8 +22,8 @@
},
"extra": {
"branch-alias": {
"dev-master": "2.2-dev",
"dev-develop": "2.3-dev"
"dev-master": "2.3-dev",
"dev-develop": "2.4-dev"
}
},
"autoload-dev": {
Expand Down
77 changes: 70 additions & 7 deletions src/Adapter/AbstractAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

Expand Down Expand Up @@ -53,6 +53,9 @@ abstract class AbstractAdapter implements AdapterInterface
*/
public function write($text, $color = null, $bgColor = null)
{
//Encode text to match console encoding
$text = $this->encodeText($text);

if ($color !== null || $bgColor !== null) {
echo $this->colorize($text, $color, $bgColor);
} else {
Expand Down Expand Up @@ -241,7 +244,6 @@ public function writeBox(
}
}


// Draw corners
if ($lineStyle !== static::LINE_NONE) {
if ($color !== null) {
Expand Down Expand Up @@ -285,6 +287,7 @@ public function writeBox(
* @param int $y Block Y coordinate (row)
* @param null|int $color (optional) Text color
* @param null|int $bgColor (optional) Text background color
* @throws Exception\InvalidArgumentException
*/
public function writeTextBlock(
$text,
Expand All @@ -295,6 +298,43 @@ public function writeTextBlock(
$color = null,
$bgColor = null
) {
if ($x < 0 || $y < 0) {
throw new Exception\InvalidArgumentException('Supplied X,Y coordinates are invalid.');
}

if ($width < 1) {
throw new Exception\InvalidArgumentException('Invalid width supplied.');
}

if (null !== $height && $height < 1) {
throw new Exception\InvalidArgumentException('Invalid height supplied.');
}

// ensure the text is not wider than the width
if (strlen($text) <= $width) {
// just write the line at the spec'd position
$this->setPos($x, $y);
$this->write($text, $color, $bgColor);
return;
}

$text = wordwrap($text, $width, PHP_EOL, true);

// convert to array of lines
$lines = explode(PHP_EOL, $text);

// truncate if height was specified
if (null !== $height && count($lines) > $height) {
$lines = array_slice($lines, 0, $height);
}

// write each line
$curY = $y;
foreach ($lines as $line) {
$this->setPos($x, $curY);
$this->write($line, $color, $bgColor);
$curY++;//next line
}
}

/**
Expand All @@ -320,7 +360,7 @@ public function getHeight()
/**
* Determine and return current console width and height.
*
* @return array array($width, $height)
* @return int[] array($width, $height)
*/
public function getSize()
{
Expand Down Expand Up @@ -476,10 +516,10 @@ public function clearScreen()
*/
public function readLine($maxLength = 2048)
{
$f = fopen('php://stdin','r');
$f = fopen('php://stdin', 'r');
$line = stream_get_line($f, $maxLength, PHP_EOL);
fclose($f);
return rtrim($line,"\n\r");
return rtrim($line, "\n\r");
}

/**
Expand All @@ -490,11 +530,34 @@ public function readLine($maxLength = 2048)
*/
public function readChar($mask = null)
{
$f = fopen('php://stdin','r');
$f = fopen('php://stdin', 'r');
do {
$char = fread($f,1);
$char = fread($f, 1);
} while ("" === $char || ($mask !== null && false === strstr($mask, $char)));
fclose($f);
return $char;
}

/**
* Encode a text to match console encoding
*
* @param string $text
* @return string the encoding text
*/
public function encodeText($text)
{
if ($this->isUtf8()) {
if (StringUtils::isValidUtf8($text)) {
return $text;
}

return utf8_encode($text);
}

if (StringUtils::isValidUtf8($text)) {
return utf8_decode($text);
}

return $text;
}
}
21 changes: 18 additions & 3 deletions src/Adapter/AdapterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

Expand All @@ -29,6 +29,7 @@ interface AdapterInterface
* @param string $text
* @param null|int $color
* @param null|int $bgColor
* @return void
*/
public function write($text, $color = null, $bgColor = null);

Expand All @@ -38,6 +39,7 @@ public function write($text, $color = null, $bgColor = null);
* @param string $text
* @param null|int $color
* @param null|int $bgColor
* @return void
*/
public function writeText($text, $color = null, $bgColor = null);

Expand All @@ -48,6 +50,7 @@ public function writeText($text, $color = null, $bgColor = null);
* @param string $text
* @param null|int $color
* @param null|int $bgColor
* @return void
*/
public function writeLine($text = "", $color = null, $bgColor = null);

Expand All @@ -59,6 +62,7 @@ public function writeLine($text = "", $color = null, $bgColor = null);
* @param int $y Console Y coordinate (row)
* @param null|int $color
* @param null|int $bgColor
* @return void
*/
public function writeAt($text, $x, $y, $color = null, $bgColor = null);

Expand All @@ -77,6 +81,7 @@ public function writeAt($text, $x, $y, $color = null, $bgColor = null);
* @param int $bgColor (optional) Background color
* @param null|int $fillColor (optional) Foreground color of box fill
* @param null|int $fillBgColor (optional) Background color of box fill
* @return void
*/
public function writeBox(
$x1,
Expand All @@ -103,6 +108,7 @@ public function writeBox(
* @param int $y Block Y coordinate (row)
* @param null|int $color (optional) Text color
* @param null|int $bgColor (optional) Text background color
* @return void
*/
public function writeTextBlock(
$text,
Expand All @@ -114,7 +120,6 @@ public function writeTextBlock(
$bgColor = null
);


/**
* Determine and return current console width.
*
Expand Down Expand Up @@ -148,16 +153,19 @@ public function isUtf8();
*
* @param int $x
* @param int $y
* @return void
*/
public function setPos($x, $y);

/**
* Hide console cursor
* @return void
*/
public function hideCursor();

/**
* Show console cursor
* @return void
*/
public function showCursor();

Expand All @@ -174,33 +182,37 @@ public function getTitle();
* @param string $string
* @param null|int $color Foreground color
* @param null|int $bgColor Background color
* @return string
*/
public function colorize($string, $color = null, $bgColor = null);

/**
* Change current drawing color.
*
* @param int $color
* @return void
*/
public function setColor($color);

/**
* Change current drawing background color
*
* @param int $color
* @return void
*/
public function setBgColor($color);

/**
* Reset color to console default.
* @return void
*/
public function resetColor();


/**
* Set Console charset to use.
*
* @param CharsetInterface $charset
* @return void
*/
public function setCharset(CharsetInterface $charset);

Expand All @@ -218,16 +230,19 @@ public function getDefaultCharset();

/**
* Clear console screen
* @return void
*/
public function clear();

/**
* Clear line at cursor position
* @return void
*/
public function clearLine();

/**
* Clear console screen
* @return void
*/
public function clearScreen();

Expand Down
10 changes: 6 additions & 4 deletions src/Adapter/Posix.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

Expand Down Expand Up @@ -358,7 +358,7 @@ protected function restoreTTYMode()
* Change TTY (Console) mode
*
* @link http://en.wikipedia.org/wiki/Stty
* @param $mode
* @param string $mode
*/
protected function setTTYMode($mode)
{
Expand All @@ -373,6 +373,7 @@ protected function setTTYMode($mode)
* Get the final color code and throw exception on error
*
* @param null|int|Xterm256 $color
* @param string $type (optional) Foreground 'fg' or background 'bg'.
* @throws Exception\BadMethodCallException
* @return string
*/
Expand All @@ -392,8 +393,9 @@ protected function getColorCode($color, $type = 'fg')
if ($color !== null) {
if (!isset(static::$ansiColorMap[$type][$color])) {
throw new Exception\BadMethodCallException(sprintf(
'Unknown color "%s". Please use one of the Zend\Console\ColorInterface constants or use Zend\Console\Color\Xterm256::calculate',
$color
'Unknown color "%s". Please use one of the Zend\Console\ColorInterface constants '
. 'or use Zend\Console\Color\Xterm256::calculate',
$color
));
}

Expand Down
2 changes: 1 addition & 1 deletion src/Adapter/Virtual.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

Expand Down
Loading

0 comments on commit 7bfc680

Please sign in to comment.