Skip to content

Commit eee16e9

Browse files
committed
Merge branch 'release/0.4.0'
2 parents 2ce0e8f + d931f6b commit eee16e9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1785
-229
lines changed

README.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ chmod +x psysh
3636

3737
## PsySH configuration
3838

39-
While PsySH strives to detect the right settings automatically, you might want to configure it yourself. Just add a file to `~/.config/psysh/config.php`:
39+
While PsySH strives to detect the right settings automatically, you might want to configure it yourself. Just add a file to `~/.config/psysh/config.php` (or `C:\Users\{USER}\AppData\Roaming\PsySH` on Windows):
4040

4141
```php
4242
<?php
@@ -98,12 +98,22 @@ return array(
9898
'presenters' => array(
9999
new \Psy\Presenter\MongoCursorPresenter,
100100
),
101+
102+
// You can disable tab completion if you want to. Not sure why you'd want to.
103+
'tabCompletion' => false,
104+
105+
// You can write your own autocomplete matchers, too! Here's one that enables
106+
// autocompletion for MongoDB collection names:
107+
'tabCompletionMatchers' => array(
108+
new \Psy\TabCompletion\Matcher\MongoClientMatcher,
109+
new \Psy\TabCompletion\Matcher\MongoDatabaseMatcher,
110+
),
101111
);
102112
```
103113

104114
## Downloading the manual
105115

106-
The PsySH `doc` command is great for documenting source code, but you'll need a little something extra for PHP core documentation. Download one of the following PHP Manual files and drop it in `~/.local/share/psysh/`:
116+
The PsySH `doc` command is great for documenting source code, but you'll need a little something extra for PHP core documentation. Download one of the following PHP Manual files and drop it in `~/.local/share/psysh/` (or `C:\Users\{USER}\AppData\Roaming\PsySH` on Windows):
107117

108118
* **[English](http://psysh.org/manual/en/php_manual.sqlite)**
109119
* [Brazilian Portuguese](http://psysh.org/manual/pt_BR/php_manual.sqlite)

bin/psysh

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,16 @@ EOL;
9595
// Pass additional arguments to Shell as 'includes'
9696
$shell->setIncludes($input->getArgument('include'));
9797

98-
// And go!
99-
$shell->run();
98+
try {
99+
// And go!
100+
$shell->run();
101+
} catch (Exception $e) {
102+
echo $e->getMessage() . PHP_EOL;
103+
104+
// TODO: this triggers the "exited unexpectedly" logic in the
105+
// ForkingLoop, so we can't exit(1) after starting the shell...
106+
// fix this :)
107+
108+
// exit(1);
109+
}
100110
});

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
"suggest": {
2929
"ext-pcntl": "Enabling the PCNTL extension makes PsySH a lot happier :)",
3030
"ext-posix": "If you have PCNTL, you'll want the POSIX extension as well.",
31-
"ext-readline": "Enables support for arrow-key history navigation, and showing and manipulating command history."
31+
"ext-readline": "Enables support for arrow-key history navigation, and showing and manipulating command history.",
32+
"ext-pdo-sqlite": "The doc command requires SQLite to work."
3233
},
3334
"autoload": {
3435
"files": ["src/Psy/functions.php"],

src/Psy/CodeCleaner/ValidClassNamePass.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ protected function validateClassStatement(ClassStmt $stmt)
8181
}
8282

8383
/**
84-
* Validate an interface definition statment.
84+
* Validate an interface definition statement.
8585
*
8686
* @param InterfaceStmt $stmt
8787
*/
@@ -92,7 +92,7 @@ protected function validateInterfaceStatement(InterfaceStmt $stmt)
9292
}
9393

9494
/**
95-
* Validate a trait definition statment.
95+
* Validate a trait definition statement.
9696
*
9797
* @param TraitStmt $stmt
9898
*/
@@ -130,6 +130,8 @@ protected function validateClassConstFetchExpression(ClassConstFetch $stmt)
130130
/**
131131
* Ensure that no class, interface or trait name collides with a new definition.
132132
*
133+
* @throws FatalErrorException
134+
*
133135
* @param Stmt $stmt
134136
*/
135137
protected function ensureCanDefine(Stmt $stmt)
@@ -158,6 +160,8 @@ protected function ensureCanDefine(Stmt $stmt)
158160
/**
159161
* Ensure that a referenced class exists.
160162
*
163+
* @throws FatalErrorException
164+
*
161165
* @param string $name
162166
* @param Stmt $stmt
163167
*/
@@ -171,12 +175,15 @@ protected function ensureClassExists($name, $stmt)
171175
/**
172176
* Ensure that a referenced interface exists.
173177
*
174-
* @param string $name
175-
* @param Stmt $stmt
178+
* @throws FatalErrorException
179+
*
180+
* @param $interfaces
181+
* @param Stmt $stmt
176182
*/
177183
protected function ensureInterfacesExist($interfaces, $stmt)
178184
{
179185
foreach ($interfaces as $interface) {
186+
/** @var string $name */
180187
$name = $this->getFullyQualifiedName($interface);
181188
if (!$this->interfaceExists($name)) {
182189
throw $this->createError(sprintf('Interface \'%s\' not found', $name), $stmt);
@@ -243,7 +250,7 @@ protected function traitExists($name)
243250
*
244251
* @param string $name
245252
*
246-
* @return string
253+
* @return string|null
247254
*/
248255
protected function findInScope($name)
249256
{
@@ -254,7 +261,7 @@ protected function findInScope($name)
254261
}
255262

256263
/**
257-
* Error creation factory
264+
* Error creation factory.
258265
*
259266
* @param string $msg
260267
* @param Stmt $stmt

src/Psy/CodeCleaner/ValidFunctionNamePass.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ public function leaveNode(Node $node)
4949
if (!$name instanceof Expression && !$name instanceof Variable) {
5050
$shortName = implode('\\', $name->parts);
5151
$fullName = $this->getFullyQualifiedName($name);
52-
5352
$inScope = isset($this->currentScope[strtolower($fullName)]);
5453
if (!$inScope && !function_exists($shortName) && !function_exists($fullName)) {
5554
$message = sprintf('Call to undefined function %s()', $name);

src/Psy/Command/Command.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
use Psy\Shell;
1515
use Symfony\Component\Console\Application;
1616
use Symfony\Component\Console\Command\Command as BaseCommand;
17+
use Symfony\Component\Console\Helper\Table;
18+
use Symfony\Component\Console\Helper\TableHelper;
19+
use Symfony\Component\Console\Helper\TableStyle;
20+
use Symfony\Component\Console\Output\OutputInterface;
1721

1822
/**
1923
* The Psy Shell base command.
@@ -233,4 +237,46 @@ private function formatDefaultValue($default)
233237

234238
return str_replace("\n", '', var_export($default, true));
235239
}
240+
241+
/**
242+
* Get a Table instance.
243+
*
244+
* Falls back to legacy TableHelper.
245+
*
246+
* @return Table|TableHelper
247+
*/
248+
protected function getTable(OutputInterface $output)
249+
{
250+
if (!class_exists('Symfony\Component\Console\Helper\Table')) {
251+
return $this->getTableHelper();
252+
}
253+
254+
$style = new TableStyle();
255+
$style
256+
->setVerticalBorderChar(' ')
257+
->setHorizontalBorderChar('')
258+
->setCrossingChar('');
259+
260+
$table = new Table($output);
261+
262+
return $table
263+
->setRows(array())
264+
->setStyle($style);
265+
}
266+
267+
/**
268+
* Legacy fallback for getTable.
269+
*
270+
* @return TableHelper
271+
*/
272+
protected function getTableHelper()
273+
{
274+
$table = $this->getApplication()->getHelperSet()->get('table');
275+
276+
return $table
277+
->setRows(array())
278+
->setLayout(TableHelper::LAYOUT_BORDERLESS)
279+
->setHorizontalBorderChar('')
280+
->setCrossingChar('');
281+
}
236282
}

src/Psy/Command/HelpCommand.php

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
6666
// list available commands
6767
$commands = $this->getApplication()->all();
6868

69-
$table = $this->getTable();
69+
$table = $this->getTable($output);
7070

7171
foreach ($commands as $name => $command) {
7272
if ($name !== $command->getName()) {
@@ -86,28 +86,13 @@ protected function execute(InputInterface $input, OutputInterface $output)
8686
));
8787
}
8888

89-
$output->page(function ($output) use ($table) {
89+
$output->startPaging();
90+
if ($table instanceof TableHelper) {
9091
$table->render($output);
91-
});
92+
} else {
93+
$table->render();
94+
}
95+
$output->stopPaging();
9296
}
9397
}
94-
95-
/**
96-
* Get a TableHelper instance.
97-
*
98-
* @return TableHelper
99-
*/
100-
protected function getTable()
101-
{
102-
$old = error_reporting();
103-
error_reporting($old & ~E_USER_DEPRECATED);
104-
$table = $this->getApplication()->getHelperSet()->get('table');
105-
error_reporting($old);
106-
107-
return $table
108-
->setRows(array())
109-
->setLayout(TableHelper::LAYOUT_BORDERLESS)
110-
->setHorizontalBorderChar('')
111-
->setCrossingChar('');
112-
}
11398
}

src/Psy/Command/ListCommand.php

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@
2424
use Psy\Exception\RuntimeException;
2525
use Psy\Presenter\PresenterManager;
2626
use Psy\Presenter\PresenterManagerAware;
27+
use Symfony\Component\Console\Helper\TableHelper;
2728
use Symfony\Component\Console\Formatter\OutputFormatter;
2829
use Symfony\Component\Console\Input\InputArgument;
2930
use Symfony\Component\Console\Input\InputInterface;
3031
use Symfony\Component\Console\Input\InputOption;
3132
use Symfony\Component\Console\Output\OutputInterface;
32-
use Symfony\Component\Console\Helper\TableHelper;
3333

3434
/**
3535
* List available local variables, object properties, etc.
@@ -190,7 +190,7 @@ protected function writeLong(OutputInterface $output, array $result = null)
190190
return;
191191
}
192192

193-
$table = $this->getTable();
193+
$table = $this->getTable($output);
194194

195195
foreach ($result as $label => $items) {
196196
$output->writeln('');
@@ -201,7 +201,11 @@ protected function writeLong(OutputInterface $output, array $result = null)
201201
$table->addRow(array($this->formatItemName($item), $item['value']));
202202
}
203203

204-
$table->render($output);
204+
if ($table instanceof TableHelper) {
205+
$table->render($output);
206+
} else {
207+
$table->render();
208+
}
205209
}
206210
}
207211

@@ -271,22 +275,4 @@ private function validateInput(InputInterface $input)
271275
$input->setOption('methods', true);
272276
}
273277
}
274-
275-
/**
276-
* Get a TableHelper instance.
277-
*
278-
* @return TableHelper
279-
*/
280-
private function getTable()
281-
{
282-
$old = error_reporting();
283-
error_reporting($old & ~E_USER_DEPRECATED);
284-
$table = $this->getApplication()->getHelperSet()->get('table');
285-
error_reporting($old);
286-
287-
return $table
288-
->setLayout(TableHelper::LAYOUT_BORDERLESS)
289-
->setHorizontalBorderChar('')
290-
->setCrossingChar('');
291-
}
292278
}

src/Psy/Command/ReflectingCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ abstract class ReflectingCommand extends Command implements ContextAware
2929
const INSTANCE_STATIC = '/^\$(\w+)::\$(\w+)$/';
3030

3131
/**
32-
* Context instance (for ContextAware interface)
32+
* Context instance (for ContextAware interface).
3333
*
34-
* @type Context
34+
* @var Context
3535
*/
3636
protected $context;
3737

0 commit comments

Comments
 (0)