Skip to content

Commit

Permalink
Merge branch 'release/0.1.8'
Browse files Browse the repository at this point in the history
  • Loading branch information
bobthecow committed Apr 13, 2014
2 parents 636ea9b + e3f4e1b commit 33db0d5
Show file tree
Hide file tree
Showing 9 changed files with 141 additions and 51 deletions.
8 changes: 7 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ php:
- 5.3
- 5.4
- 5.5
- 5.6
- hhvm

before_script:
- composer install
- composer install

matrix:
allow_failures:
- php: hhvm
46 changes: 36 additions & 10 deletions bin/psysh
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,50 @@ if (is_file(__DIR__ . '/../vendor/autoload.php')) {
}
/* >>> */

use Psy\Configuration;
use Psy\Shell;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputDefinition;
use Symfony\Component\Console\Input\InputOption;

// If the psysh binary was included directly, assume they just wanted an
// autoloader and bail early.
if (Shell::isIncluded(debug_backtrace())) {
return;
}

call_user_func(function(ArgvInput $input, Shell $shell) {
call_user_func(function() {
$usageException = null;

$input = new ArgvInput();
try {
$input->bind(new InputDefinition(array(
new InputOption('help', 'h', InputOption::VALUE_NONE),
new InputOption('config', 'c', InputOption::VALUE_REQUIRED),
new InputOption('version', 'v', InputOption::VALUE_NONE),

new InputArgument('include', InputArgument::IS_ARRAY),
)));
} catch (\RuntimeException $e) {
$usageException = $e;
}

$config = array();

// Handle --config
if ($configFile = $input->getOption('config')) {
$config['configFile'] = $configFile;
}

$shell = new Shell(new Configuration($config));

// Handle --help
if ($input->hasParameterOption(array('--help', '-h'))) {
if ($usageException !== null || $input->getOption('help')) {
if ($usageException !== null) {
echo $usageException->getMessage() . PHP_EOL . PHP_EOL;
}

$version = $shell->getVersion();
$name = reset($_SERVER['argv']);
echo <<<EOL
Expand All @@ -48,27 +78,23 @@ Usage:
Options:
--help -h Display this help message.
--config -c Use an alternate PsySH config file location.
--version -v Display the PsySH version.
EOL;
exit(0);
exit($usageException === null ? 0 : 1);
}


// Handle --version
if ($input->hasParameterOption(array('--version', '-v'))) {
if ($input->getOption('version')) {
echo $shell->getVersion() . PHP_EOL;
exit(0);
}


// Pass additional arguments to Shell as 'includes'
$input->bind(new InputDefinition(array(
new InputArgument('include', InputArgument::IS_ARRAY)
)));
$shell->setIncludes($input->getArgument('include'));


// And go!
$shell->run();
}, new ArgvInput, new Shell);
});
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"nikic/php-parser": "~0.9.3"
},
"require-dev": {
"phpunit/phpunit": "~3.7",
"phpunit/phpunit": ">=3.7, <4.1",
"symfony/finder": "~2.1"
},
"suggest": {
Expand Down
2 changes: 1 addition & 1 deletion src/Psy/Command/HelpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
));
}

$output->page(function($output) use ($table) {
$output->page(function ($output) use ($table) {
$table->render($output);
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/Psy/Command/WtfCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$trace = $this->getBacktrace($exception, $count);

$shell = $this->getApplication();
$output->page(function($output) use ($exception, $trace, $shell) {
$output->page(function ($output) use ($exception, $trace, $shell) {
$shell->renderException($exception, $output);
$output->writeln('--');
$output->write($trace, true, ShellOutput::NUMBER_LINES);
Expand Down
53 changes: 36 additions & 17 deletions src/Psy/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@

namespace Psy;

use Psy\Exception\RuntimeException;
use Psy\ExecutionLoop\ForkingLoop;
use Psy\ExecutionLoop\Loop;
use Psy\Output\OutputPager;
use Psy\Output\ShellOutput;
use Psy\Presenter\PresenterManager;
use Psy\Readline\Readline;
use Psy\Readline\Libedit;
use Psy\Readline\GNUReadline;
use Psy\Readline\Libedit;
use Psy\Readline\Readline;
use Psy\Readline\Transient;

/**
Expand Down Expand Up @@ -366,25 +367,35 @@ public function setReadline(Readline $readline)
public function getReadline()
{
if (!isset($this->readline)) {
$className = $this->getReadlineClass();
$this->readline = new $className(
$this->getHistoryFile(),
$this->getHistorySize(),
$this->getEraseDuplicates()
);
}

$historyFile = $this->getHistoryFile();
$historySize = $this->getHistorySize();
$eraseDups = $this->getEraseDuplicates();

if ($this->useReadline()) {
if (GNUReadline::isSupported()) {
$this->readline = new GNUReadline($historyFile, $historySize, $eraseDups);
} elseif (Libedit::isSupported()) {
$this->readline = new Libedit($historyFile, $historySize, $eraseDups);
}
}
return $this->readline;
}

if (!isset($this->readline)) {
$this->readline = new Transient(null, $historySize, $eraseDups);
/**
* Get the appropriate Readline implementation class name.
*
* @see self::getReadline
*
* @return string
*/
private function getReadlineClass()
{
if ($this->useReadline()) {
if (GNUReadline::isSupported()) {
return 'Psy\Readline\GNUReadline';
} elseif (Libedit::isSupported()) {
return 'Psy\Readline\Libedit';
}
}

return $this->readline;
return 'Psy\Readline\Transient';
}

/**
Expand Down Expand Up @@ -621,7 +632,15 @@ public function getManualDb()
if (!isset($this->manualDb)) {
$dbFile = $this->getManualDbFile();
if (is_file($dbFile)) {
$this->manualDb = new \PDO('sqlite:'.$dbFile);
try {
$this->manualDb = new \PDO('sqlite:'.$dbFile);
} catch (\PDOException $e) {
if ($e->getMessage() === 'could not find driver') {
throw new RuntimeException('SQLite PDO driver not found', 0, $e);
} else {
throw $e;
}
}
}
}

Expand Down
76 changes: 58 additions & 18 deletions src/Psy/Presenter/MongoCursorPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,46 +41,86 @@ public function canPresent($value)
*/
protected function getProperties($value, \ReflectionClass $class)
{
$empty = new \StdClass;
$info = $value->info();
$info = $value->info();

if ($info['query'] == $empty) {
$info['query'] = array();
$this->normalizeQueryArray($info);
$this->normalizeFieldsArray($info);
$this->unsetBoringFields($info);
$this->unsetIgnoredFields($info);

if ($value->dead()) {
$info['dead'] = true;
}

return array_merge(
$info,
parent::getProperties($value, $class)
);
}

/**
* Normalize (empty) cursor query to always be an actual array.
*
* @param array $info Cursor info
*
* @return void
*/
private function normalizeQueryArray(array &$info)
{
if (isset($info['query'])) {
if (isset($info['query']['$query'])) {
if ($info['query']['$query'] == $empty) {
if ($info['query'] == new \StdClass) {
$info['query'] = array();
} elseif (is_array($info['query']) && isset($info['query']['$query'])) {
if ($info['query']['$query'] == new \StdClass) {
$info['query']['$query'] = array();
}
} elseif ($info['query'] == $empty) {
$info['query'] = array();
}
}
}

if (isset($info['fields']) && $info['fields'] == $empty) {
/**
* Normalize (empty) cursor fields to always be an actual array.
*
* @param array $info Cursor info
*
* @return void
*/
private function normalizeFieldsArray(array &$info)
{
if (isset($info['fields']) && $info['fields'] == new \StdClass) {
$info['fields'] = array();
}
}

/**
* Unset boring fields from the Cursor info array.
*
* @param array $info Cursor info
*
* @return void
*/
private function unsetBoringFields(array &$info)
{
foreach (self::$boringFields as $boring) {
if ($info[$boring] === 0) {
unset($info[$boring]);
}
}
}

/**
* Unset ignored fields from the Cursor info array.
*
* @param array $info Cursor info
*
* @return void
*/
private function unsetIgnoredFields(array &$info)
{
foreach (self::$ignoreFields as $ignore) {
if (isset($info[$ignore])) {
unset($info[$ignore]);
}
}

if ($value->dead()) {
$info['dead'] = true;
}

return array_merge(
$info,
parent::getProperties($value, $class)
);
}
}
2 changes: 1 addition & 1 deletion src/Psy/Shell.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
*/
class Shell extends Application
{
const VERSION = 'v0.1.7';
const VERSION = 'v0.1.8';

const PROMPT = '>>> ';
const BUFF_PROMPT = '... ';
Expand Down
1 change: 0 additions & 1 deletion test/Psy/Test/Presenter/ArrayPresenterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ private static function strip($text)
}
}


class FakeArrayObject extends \ArrayObject
{
// this space intentionally left blank.
Expand Down

0 comments on commit 33db0d5

Please sign in to comment.