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

Commit

Permalink
Fix fatal errors after recent changes, fix handling of space and 0 in…
Browse files Browse the repository at this point in the history
… Posix adapter.
  • Loading branch information
Thinkscape committed Aug 2, 2012
1 parent 4ec1292 commit 9536f09
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/Adapter/AbstractAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ protected function stringTrim($string, $length)
public function readLine($maxLength = 2048)
{
$f = fopen('php://stdin','r');
$line = stream_get_line($f, 2048, PHP_EOL);
$line = stream_get_line($f, $maxLength, PHP_EOL);
fclose($f);
return rtrim($line,"\n\r");
}
Expand Down
3 changes: 2 additions & 1 deletion src/Adapter/Posix.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

use Zend\Console\Charset;
use Zend\Console\Exception;
use Zend\Console\ColorInterface as Color;

/**
* @todo Add GNU readline support
Expand Down Expand Up @@ -354,7 +355,7 @@ public function readChar($mask = null)
$stream = fopen('php://stdin', 'rb');
do {
$char = fgetc($stream);
} while (!$char || ($mask !== null && !stristr($mask, $char)));
} while (strlen($char) !== 1 || ($mask !== null && stristr($mask, $char) === false));
fclose($stream);

$this->restoreTTYMode();
Expand Down
13 changes: 10 additions & 3 deletions src/Console.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
namespace Zend\Console;

/**
* An static, utility class for interacting with Console enviromen.
* An static, utility class for interacting with Console enviroment.
* Declared abstract to prevent from instantiating.
*
* @category Zend
Expand All @@ -25,9 +25,15 @@ abstract class Console
protected static $instance;

/**
* Instantiate (if needed) and retrieve Adapter\AdapterInterface instance.
* Create and return Adapter\AdapterInterface instance.
*
* @param null $forceAdapter Adapter\AdapterInterface class name (can be absolute namespace or relative to Adapter\)
* @param null|string $forceAdapter Optional adapter class name. Ccan be absolute namespace or class name
* relative to Zend\Console\Adapter\. If not provided, a best matching
* adapter will be automatically selected.
* @param null|string $forceCharset optional charset name can be absolute namespace or class name relative to
* Zend\Console\Charset\. If not provided, charset will be detected
* automatically.
* @throws Exception\InvalidArgumentException
* @return Adapter\AdapterInterface
*/
public static function getInstance($forceAdapter = null, $forceCharset = null)
Expand Down Expand Up @@ -117,6 +123,7 @@ public static function isConsole()
}

/**
* Try to detect best matching adapter
* @return string|null
*/
public static function detectBestAdapter()
Expand Down
1 change: 1 addition & 0 deletions src/Prompt/AbstractPrompt.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
namespace Zend\Console\Prompt;

use ReflectionClass;
use Zend\Console\Console;
use Zend\Console\Adapter\AdapterInterface as ConsoleAdapter;
use Zend\Console\Exception;

Expand Down
2 changes: 1 addition & 1 deletion src/Prompt/Char.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public function show()
/**
* Check if it is an allowed char
*/
if (stristr($this->allowedChars,$char)) {
if (stristr($this->allowedChars,$char) !== false) {
if ($this->echo) {
echo trim($char)."\n";
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/Prompt/Select.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function show()
/**
* Set allowed options
*
* @param array|Traversable $options
* @param array|\Traversable $options
*/
public function setOptions($options)
{
Expand Down

0 comments on commit 9536f09

Please sign in to comment.