update v 1.0.7.5

This commit is contained in:
Sujit Prasad
2016-06-13 20:41:55 +05:30
parent aa9786d829
commit 283d97e3ea
5078 changed files with 339851 additions and 175995 deletions

View File

@@ -1,9 +1,9 @@
<?php
/*
* This file is part of Psy Shell
* This file is part of Psy Shell.
*
* (c) 2012-2014 Justin Hileman
* (c) 2012-2015 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@@ -36,7 +36,7 @@ class BufferCommand extends Command
))
->setDescription('Show (or clear) the contents of the code input buffer.')
->setHelp(
<<<HELP
<<<'HELP'
Show the contents of the code buffer for the current multi-line expression.
Optionally, clear the buffer by passing the <info>--clear</info> option.

View File

@@ -1,9 +1,9 @@
<?php
/*
* This file is part of Psy Shell
* This file is part of Psy Shell.
*
* (c) 2012-2014 Justin Hileman
* (c) 2012-2015 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@@ -31,7 +31,7 @@ class ClearCommand extends Command
->setDefinition(array())
->setDescription('Clear the Psy Shell screen.')
->setHelp(
<<<HELP
<<<'HELP'
Clear the Psy Shell screen.
Pro Tip: If your PHP has readline support, you should be able to use ctrl+l too!

View File

@@ -1,9 +1,9 @@
<?php
/*
* This file is part of Psy Shell
* This file is part of Psy Shell.
*
* (c) 2012-2014 Justin Hileman
* (c) 2012-2015 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.

View File

@@ -1,9 +1,9 @@
<?php
/*
* This file is part of Psy Shell
* This file is part of Psy Shell.
*
* (c) 2012-2014 Justin Hileman
* (c) 2012-2015 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.

View File

@@ -1,9 +1,9 @@
<?php
/*
* This file is part of Psy Shell
* This file is part of Psy Shell.
*
* (c) 2012-2014 Justin Hileman
* (c) 2012-2015 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@@ -12,9 +12,8 @@
namespace Psy\Command;
use Psy\Exception\RuntimeException;
use Psy\Presenter\Presenter;
use Psy\Presenter\PresenterManager;
use Psy\Presenter\PresenterManagerAware;
use Psy\VarDumper\Presenter;
use Psy\VarDumper\PresenterAware;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
@@ -25,18 +24,18 @@ use Symfony\Component\Console\Output\OutputInterface;
*
* This is like var_dump but *way* awesomer.
*/
class DumpCommand extends ReflectingCommand implements PresenterManagerAware
class DumpCommand extends ReflectingCommand implements PresenterAware
{
private $presenterManager;
private $presenter;
/**
* PresenterManagerAware interface.
* PresenterAware interface.
*
* @param PresenterManager $manager
* @param Presenter $presenter
*/
public function setPresenterManager(PresenterManager $manager)
public function setPresenter(Presenter $presenter)
{
$this->presenterManager = $manager;
$this->presenter = $presenter;
}
/**
@@ -53,14 +52,14 @@ class DumpCommand extends ReflectingCommand implements PresenterManagerAware
))
->setDescription('Dump an object or primitive.')
->setHelp(
<<<HELP
<<<'HELP'
Dump an object or primitive.
This is like var_dump but <strong>way</strong> awesomer.
e.g.
<return>>>> dump \$_</return>
<return>>>> dump \$someVar</return>
<return>>>> dump $_</return>
<return>>>> dump $someVar</return>
HELP
);
}
@@ -72,7 +71,7 @@ HELP
{
$depth = $input->getOption('depth');
$target = $this->resolveTarget($input->getArgument('target'));
$output->page($this->presenterManager->present($target, $depth, $input->getOption('all') ? Presenter::VERBOSE : 0));
$output->page($this->presenter->present($target, $depth, $input->getOption('all') ? Presenter::VERBOSE : 0));
}
/**

View File

@@ -1,9 +1,9 @@
<?php
/*
* This file is part of Psy Shell
* This file is part of Psy Shell.
*
* (c) 2012-2014 Justin Hileman
* (c) 2012-2015 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@@ -33,7 +33,7 @@ class ExitCommand extends Command
->setDefinition(array())
->setDescription('End the current session and return to caller.')
->setHelp(
<<<HELP
<<<'HELP'
End the current session and return to caller.
e.g.

View File

@@ -1,9 +1,9 @@
<?php
/*
* This file is part of Psy Shell
* This file is part of Psy Shell.
*
* (c) 2012-2014 Justin Hileman
* (c) 2012-2015 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.

View File

@@ -1,9 +1,9 @@
<?php
/*
* This file is part of Psy Shell
* This file is part of Psy Shell.
*
* (c) 2012-2014 Justin Hileman
* (c) 2012-2015 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@@ -60,7 +60,7 @@ class HistoryCommand extends Command
))
->setDescription('Show the Psy Shell history.')
->setHelp(
<<<HELP
<<<'HELP'
Show, search, save or replay the Psy Shell history.
e.g.
@@ -212,7 +212,7 @@ HELP
*
* @param string $pattern
*
* @return boolean
* @return bool
*/
private function validateRegex($pattern)
{

View File

@@ -1,9 +1,9 @@
<?php
/*
* This file is part of Psy Shell
* This file is part of Psy Shell.
*
* (c) 2012-2014 Justin Hileman
* (c) 2012-2015 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@@ -22,8 +22,8 @@ use Psy\Command\ListCommand\PropertyEnumerator;
use Psy\Command\ListCommand\TraitEnumerator;
use Psy\Command\ListCommand\VariableEnumerator;
use Psy\Exception\RuntimeException;
use Psy\Presenter\PresenterManager;
use Psy\Presenter\PresenterManagerAware;
use Psy\VarDumper\Presenter;
use Psy\VarDumper\PresenterAware;
use Symfony\Component\Console\Formatter\OutputFormatter;
use Symfony\Component\Console\Helper\TableHelper;
use Symfony\Component\Console\Input\InputArgument;
@@ -34,19 +34,19 @@ use Symfony\Component\Console\Output\OutputInterface;
/**
* List available local variables, object properties, etc.
*/
class ListCommand extends ReflectingCommand implements PresenterManagerAware
class ListCommand extends ReflectingCommand implements PresenterAware
{
protected $presenterManager;
protected $presenter;
protected $enumerators;
/**
* PresenterManagerAware interface.
* PresenterAware interface.
*
* @param PresenterManager $manager
* @param Presenter $manager
*/
public function setPresenterManager(PresenterManager $manager)
public function setPresenter(Presenter $presenter)
{
$this->presenterManager = $manager;
$this->presenter = $presenter;
}
/**
@@ -84,7 +84,7 @@ class ListCommand extends ReflectingCommand implements PresenterManagerAware
))
->setDescription('List local, instance or class variables, methods and constants.')
->setHelp(
<<<HELP
<<<'HELP'
List variables, constants, classes, interfaces, traits, functions, methods,
and properties.
@@ -96,7 +96,7 @@ and methods on that class.
e.g.
<return>>>> ls</return>
<return>>>> ls \$foo</return>
<return>>>> ls $foo</return>
<return>>>> ls -k --grep mongo -i</return>
<return>>>> ls -al ReflectionClass</return>
<return>>>> ls --constants --category date</return>
@@ -141,7 +141,7 @@ HELP
protected function initEnumerators()
{
if (!isset($this->enumerators)) {
$mgr = $this->presenterManager;
$mgr = $this->presenter;
$this->enumerators = array(
new ClassConstantEnumerator($mgr),

View File

@@ -1,9 +1,9 @@
<?php
/*
* This file is part of Psy Shell
* This file is part of Psy Shell.
*
* (c) 2012-2014 Justin Hileman
* (c) 2012-2015 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.

View File

@@ -1,9 +1,9 @@
<?php
/*
* This file is part of Psy Shell
* This file is part of Psy Shell.
*
* (c) 2012-2014 Justin Hileman
* (c) 2012-2015 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.

View File

@@ -1,9 +1,9 @@
<?php
/*
* This file is part of Psy Shell
* This file is part of Psy Shell.
*
* (c) 2012-2014 Justin Hileman
* (c) 2012-2015 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.

View File

@@ -1,9 +1,9 @@
<?php
/*
* This file is part of Psy Shell
* This file is part of Psy Shell.
*
* (c) 2012-2014 Justin Hileman
* (c) 2012-2015 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@@ -12,8 +12,8 @@
namespace Psy\Command\ListCommand;
use Psy\Formatter\SignatureFormatter;
use Psy\Presenter\PresenterManager;
use Psy\Util\Mirror;
use Psy\VarDumper\Presenter;
use Symfony\Component\Console\Input\InputInterface;
/**
@@ -30,7 +30,7 @@ abstract class Enumerator
const IS_CLASS = 'class';
const IS_FUNCTION = 'function';
private $presenterManager;
private $presenter;
private $filter = false;
private $invertFilter = false;
@@ -39,11 +39,11 @@ abstract class Enumerator
/**
* Enumerator constructor.
*
* @param PresenterManager $presenterManager
* @param Presenter $presenter
*/
public function __construct(PresenterManager $presenterManager)
public function __construct(Presenter $presenter)
{
$this->presenterManager = $presenterManager;
$this->presenter = $presenter;
}
/**
@@ -87,7 +87,7 @@ abstract class Enumerator
protected function presentRef($value)
{
return $this->presenterManager->presentRef($value);
return $this->presenter->presentRef($value);
}
protected function showItem($name)
@@ -121,7 +121,7 @@ abstract class Enumerator
*
* @param string $pattern
*
* @return boolean
* @return bool
*/
private function validateRegex($pattern)
{

View File

@@ -1,9 +1,9 @@
<?php
/*
* This file is part of Psy Shell
* This file is part of Psy Shell.
*
* (c) 2012-2014 Justin Hileman
* (c) 2012-2015 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.

View File

@@ -1,9 +1,9 @@
<?php
/*
* This file is part of Psy Shell
* This file is part of Psy Shell.
*
* (c) 2012-2014 Justin Hileman
* (c) 2012-2015 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.

View File

@@ -1,9 +1,9 @@
<?php
/*
* This file is part of Psy Shell
* This file is part of Psy Shell.
*
* (c) 2012-2014 Justin Hileman
* (c) 2012-2015 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.

View File

@@ -1,9 +1,9 @@
<?php
/*
* This file is part of Psy Shell
* This file is part of Psy Shell.
*
* (c) 2012-2014 Justin Hileman
* (c) 2012-2015 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@@ -55,7 +55,7 @@ class MethodEnumerator extends Enumerator
/**
* Get defined methods for the given class or object Reflector.
*
* @param boolean $showAll Include private and protected methods.
* @param bool $showAll Include private and protected methods.
* @param \Reflector $reflector
*
* @return array

View File

@@ -1,9 +1,9 @@
<?php
/*
* This file is part of Psy Shell
* This file is part of Psy Shell.
*
* (c) 2012-2014 Justin Hileman
* (c) 2012-2015 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@@ -55,7 +55,7 @@ class PropertyEnumerator extends Enumerator
/**
* Get defined properties for the given class or object Reflector.
*
* @param boolean $showAll Include private and protected properties.
* @param bool $showAll Include private and protected properties.
* @param \Reflector $reflector
*
* @return array

View File

@@ -1,9 +1,9 @@
<?php
/*
* This file is part of Psy Shell
* This file is part of Psy Shell.
*
* (c) 2012-2014 Justin Hileman
* (c) 2012-2015 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.

View File

@@ -1,9 +1,9 @@
<?php
/*
* This file is part of Psy Shell
* This file is part of Psy Shell.
*
* (c) 2012-2014 Justin Hileman
* (c) 2012-2015 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@@ -12,7 +12,7 @@
namespace Psy\Command\ListCommand;
use Psy\Context;
use Psy\Presenter\PresenterManager;
use Psy\VarDumper\Presenter;
use Symfony\Component\Console\Input\InputInterface;
/**
@@ -29,13 +29,13 @@ class VariableEnumerator extends Enumerator
* Unlike most other enumerators, the Variable Enumerator needs access to
* the current scope variables, so we need to pass it a Context instance.
*
* @param PresenterManager $presenterManager
* @param Context $context
* @param Presenter $presenter
* @param Context $context
*/
public function __construct(PresenterManager $presenterManager, Context $context)
public function __construct(Presenter $presenter, Context $context)
{
$this->context = $context;
parent::__construct($presenterManager);
parent::__construct($presenter);
}
/**
@@ -68,7 +68,7 @@ class VariableEnumerator extends Enumerator
/**
* Get scope variables.
*
* @param boolean $showAll Include special variables (e.g. $_).
* @param bool $showAll Include special variables (e.g. $_).
*
* @return array
*/

View File

@@ -1,9 +1,9 @@
<?php
/*
* This file is part of Psy Shell
* This file is part of Psy Shell.
*
* (c) 2012-2014 Justin Hileman
* (c) 2012-2015 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@@ -11,38 +11,59 @@
namespace Psy\Command;
use PhpParser\Lexer;
use PhpParser\Node;
use PhpParser\Parser;
use Psy\Presenter\PHPParserPresenter;
use Psy\Presenter\PresenterManager;
use Psy\Presenter\PresenterManagerAware;
use Psy\ParserFactory;
use Psy\VarDumper\Presenter;
use Psy\VarDumper\PresenterAware;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\VarDumper\Caster\Caster;
/**
* Parse PHP code and show the abstract syntax tree.
*/
class ParseCommand extends Command implements PresenterManagerAware
class ParseCommand extends Command implements PresenterAware
{
private $presenterManager;
private $parser;
private $presenter;
private $parserFactory;
private $parsers;
/**
* PresenterManagerAware interface.
*
* @param PresenterManager $manager
* {@inheritdoc}
*/
public function setPresenterManager(PresenterManager $manager)
public function __construct($name = null)
{
$this->presenterManager = new PresenterManager();
$this->parserFactory = new ParserFactory();
$this->parsers = array();
foreach ($manager as $presenter) {
$this->presenterManager->addPresenter($presenter);
}
parent::__construct($name);
}
$this->presenterManager->addPresenter(new PHPParserPresenter());
/**
* PresenterAware interface.
*
* @param Presenter $presenter
*/
public function setPresenter(Presenter $presenter)
{
$this->presenter = clone $presenter;
$this->presenter->addCasters(array(
'PhpParser\Node' => function (Node $node, array $a) {
$a = array(
Caster::PREFIX_VIRTUAL . 'type' => $node->getType(),
Caster::PREFIX_VIRTUAL . 'attributes' => $node->getAttributes(),
);
foreach ($node->getSubNodeNames() as $name) {
$a[Caster::PREFIX_VIRTUAL . $name] = $node->$name;
}
return $a;
},
));
}
/**
@@ -50,15 +71,26 @@ class ParseCommand extends Command implements PresenterManagerAware
*/
protected function configure()
{
$definition = array(
new InputArgument('code', InputArgument::REQUIRED, 'PHP code to parse.'),
new InputOption('depth', '', InputOption::VALUE_REQUIRED, 'Depth to parse', 10),
);
if ($this->parserFactory->hasKindsSupport()) {
$msg = 'One of PhpParser\\ParserFactory constants: '
. implode(', ', ParserFactory::getPossibleKinds())
. " (default is based on current interpreter's version)";
$defaultKind = $this->parserFactory->getDefaultKind();
$definition[] = new InputOption('kind', '', InputOption::VALUE_REQUIRED, $msg, $defaultKind);
}
$this
->setName('parse')
->setDefinition(array(
new InputArgument('code', InputArgument::REQUIRED, 'PHP code to parse.'),
new InputOption('depth', '', InputOption::VALUE_REQUIRED, 'Depth to parse', 10),
))
->setDefinition($definition)
->setDescription('Parse PHP code and show the abstract syntax tree.')
->setHelp(
<<<HELP
<<<'HELP'
Parse PHP code and show the abstract syntax tree.
This command is used in the development of PsySH. Given a string of PHP code,
@@ -81,22 +113,22 @@ HELP
$code = '<?php ' . $code;
}
$depth = $input->getOption('depth');
$nodes = $this->parse($code);
$output->page($this->presenterManager->present($nodes, $depth));
$parserKind = $input->getOption('kind');
$depth = $input->getOption('depth');
$nodes = $this->parse($this->getParser($parserKind), $code);
$output->page($this->presenter->present($nodes, $depth));
}
/**
* Lex and parse a string of code into statements.
*
* @param Parser $parser
* @param string $code
*
* @return array Statements
*/
private function parse($code)
private function parse(Parser $parser, $code)
{
$parser = $this->getParser();
try {
return $parser->parse($code);
} catch (\PhpParser\Error $e) {
@@ -112,14 +144,16 @@ HELP
/**
* Get (or create) the Parser instance.
*
* @param string|null $kind One of Psy\ParserFactory constants (only for PHP parser 2.0 and above).
*
* @return Parser
*/
private function getParser()
private function getParser($kind = null)
{
if (!isset($this->parser)) {
$this->parser = new Parser(new Lexer());
if (!array_key_exists($kind, $this->parsers)) {
$this->parsers[$kind] = $this->parserFactory->createParser($kind);
}
return $this->parser;
return $this->parsers[$kind];
}
}

View File

@@ -1,9 +1,9 @@
<?php
/*
* This file is part of Psy Shell
* This file is part of Psy Shell.
*
* (c) 2012-2014 Justin Hileman
* (c) 2012-2015 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.

View File

@@ -1,9 +1,9 @@
<?php
/*
* This file is part of Psy Shell
* This file is part of Psy Shell.
*
* (c) 2012-2014 Justin Hileman
* (c) 2012-2015 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@@ -50,8 +50,8 @@ abstract class ReflectingCommand extends Command implements ContextAware
*
* @throws \InvalidArgumentException when the value specified can't be resolved.
*
* @param string $valueName Function, class, variable, constant, method or property name.
* @param boolean $classOnly True if the name should only refer to a class, function or instance
* @param string $valueName Function, class, variable, constant, method or property name.
* @param bool $classOnly True if the name should only refer to a class, function or instance
*
* @return array (class or instance name, member name, kind)
*/
@@ -66,13 +66,13 @@ abstract class ReflectingCommand extends Command implements ContextAware
case preg_match(self::INSTANCE, $valueName, $matches):
return array($this->resolveInstance($matches[1]), null, 0);
case (!$classOnly && preg_match(self::CLASS_MEMBER, $valueName, $matches)):
case !$classOnly && preg_match(self::CLASS_MEMBER, $valueName, $matches):
return array($this->resolveName($matches[1]), $matches[2], Mirror::CONSTANT | Mirror::METHOD);
case (!$classOnly && preg_match(self::CLASS_STATIC, $valueName, $matches)):
case !$classOnly && preg_match(self::CLASS_STATIC, $valueName, $matches):
return array($this->resolveName($matches[1]), $matches[2], Mirror::STATIC_PROPERTY | Mirror::PROPERTY);
case (!$classOnly && preg_match(self::INSTANCE_MEMBER, $valueName, $matches)):
case !$classOnly && preg_match(self::INSTANCE_MEMBER, $valueName, $matches):
if ($matches[2] === '->') {
$kind = Mirror::METHOD | Mirror::PROPERTY;
} else {
@@ -81,7 +81,7 @@ abstract class ReflectingCommand extends Command implements ContextAware
return array($this->resolveInstance($matches[1]), $matches[3], $kind);
case (!$classOnly && preg_match(self::INSTANCE_STATIC, $valueName, $matches)):
case !$classOnly && preg_match(self::INSTANCE_STATIC, $valueName, $matches):
return array($this->resolveInstance($matches[1]), $matches[2], Mirror::STATIC_PROPERTY);
default:
@@ -117,8 +117,8 @@ abstract class ReflectingCommand extends Command implements ContextAware
/**
* Get a Reflector and documentation for a function, class or instance, constant, method or property.
*
* @param string $valueName Function, class, variable, constant, method or property name.
* @param boolean $classOnly True if the name should only refer to a class, function or instance
* @param string $valueName Function, class, variable, constant, method or property name.
* @param bool $classOnly True if the name should only refer to a class, function or instance
*
* @return array (value, Reflector)
*/

View File

@@ -1,9 +1,9 @@
<?php
/*
* This file is part of Psy Shell
* This file is part of Psy Shell.
*
* (c) 2012-2014 Justin Hileman
* (c) 2012-2015 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@@ -11,6 +11,7 @@
namespace Psy\Command;
use Psy\Configuration;
use Psy\Exception\RuntimeException;
use Psy\Formatter\CodeFormatter;
use Psy\Formatter\SignatureFormatter;
@@ -24,6 +25,18 @@ use Symfony\Component\Console\Output\OutputInterface;
*/
class ShowCommand extends ReflectingCommand
{
private $colorMode;
/**
* @param null|string $colorMode (default: null)
*/
public function __construct($colorMode = null)
{
$this->colorMode = $colorMode ?: Configuration::COLOR_MODE_AUTO;
return parent::__construct();
}
/**
* {@inheritdoc}
*/
@@ -54,7 +67,7 @@ HELP
list($value, $reflector) = $this->getTargetAndReflector($input->getArgument('value'));
try {
$output->page(CodeFormatter::format($reflector), ShellOutput::OUTPUT_RAW);
$output->page(CodeFormatter::format($reflector, $this->colorMode), ShellOutput::OUTPUT_RAW);
} catch (RuntimeException $e) {
$output->writeln(SignatureFormatter::format($reflector));
throw $e;

View File

@@ -1,9 +1,9 @@
<?php
/*
* This file is part of Psy Shell
* This file is part of Psy Shell.
*
* (c) 2012-2014 Justin Hileman
* (c) 2012-2015 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@@ -52,14 +52,14 @@ class ThrowUpCommand extends Command implements ContextAware
))
->setDescription('Throw an exception out of the Psy Shell.')
->setHelp(
<<<HELP
<<<'HELP'
Throws an exception out of the current the Psy Shell instance.
By default it throws the most recent exception.
e.g.
<return>>>> throw-up</return>
<return>>>> throw-up \$e</return>
<return>>>> throw-up $e</return>
HELP
);
}

View File

@@ -1,9 +1,9 @@
<?php
/*
* This file is part of Psy Shell
* This file is part of Psy Shell.
*
* (c) 2012-2014 Justin Hileman
* (c) 2012-2015 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@@ -35,7 +35,7 @@ class TraceCommand extends Command
))
->setDescription('Show the current call stack.')
->setHelp(
<<<HELP
<<<'HELP'
Show the current call stack.
Optionally, include PsySH in the call stack by passing the <info>--include-psy</info> option.
@@ -53,7 +53,7 @@ HELP
protected function execute(InputInterface $input, OutputInterface $output)
{
$trace = $this->getBacktrace(new \Exception(), $input->getOption('num'), $input->getOption('include-psy'));
$output->page($trace, ShellOutput::NUMBER_LINES | ShellOutput::OUTPUT_RAW);
$output->page($trace, ShellOutput::NUMBER_LINES);
}
/**
@@ -106,7 +106,7 @@ HELP
$line = isset($trace[$i]['line']) ? $trace[$i]['line'] : 'n/a';
$lines[] = sprintf(
' %s%s%s() at <info>%s:%s</info>',
' <class>%s</class>%s%s() at <info>%s:%s</info>',
OutputFormatter::escape($class),
OutputFormatter::escape($type),
OutputFormatter::escape($function),

View File

@@ -1,9 +1,9 @@
<?php
/*
* This file is part of Psy Shell
* This file is part of Psy Shell.
*
* (c) 2012-2014 Justin Hileman
* (c) 2012-2015 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@@ -11,8 +11,9 @@
namespace Psy\Command;
use JakubOnderka\PhpConsoleColor\ConsoleColor;
use JakubOnderka\PhpConsoleHighlighter\Highlighter;
use Psy\Configuration;
use Psy\ConsoleColorFactory;
use Psy\Output\ShellOutput;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
@@ -23,8 +24,15 @@ use Symfony\Component\Console\Output\OutputInterface;
*/
class WhereamiCommand extends Command
{
public function __construct()
private $colorMode;
/**
* @param null|string $colorMode (default: null)
*/
public function __construct($colorMode = null)
{
$this->colorMode = $colorMode ?: Configuration::COLOR_MODE_AUTO;
if (version_compare(PHP_VERSION, '5.3.6', '>=')) {
$this->backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
} else {
@@ -46,7 +54,7 @@ class WhereamiCommand extends Command
))
->setDescription('Show where you are in the code.')
->setHelp(
<<<HELP
<<<'HELP'
Show where you are in the code.
Optionally, include how many lines before and after you want to display.
@@ -106,8 +114,8 @@ HELP
{
$info = $this->fileInfo();
$num = $input->getOption('num');
$colors = new ConsoleColor();
$colors->addTheme('line_number', array('blue'));
$factory = new ConsoleColorFactory($this->colorMode);
$colors = $factory->getConsoleColor();
$highlighter = new Highlighter($colors);
$contents = file_get_contents($info['file']);
$output->page($highlighter->getCodeSnippet($contents, $info['line'], $num, $num), ShellOutput::OUTPUT_RAW);

View File

@@ -1,9 +1,9 @@
<?php
/*
* This file is part of Psy Shell
* This file is part of Psy Shell.
*
* (c) 2012-2014 Justin Hileman
* (c) 2012-2015 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@@ -55,7 +55,7 @@ class WtfCommand extends TraceCommand implements ContextAware
))
->setDescription('Show the backtrace of the most recent exception.')
->setHelp(
<<<HELP
<<<'HELP'
Shows a few lines of the backtrace of the most recent exception.
If you want to see more lines, add more question marks or exclamation marks: