protected function setUp() { $this->connector = \PhpConsole\Connector::getInstance(); $this->setProtectedProperty($this->connector, 'isActiveClient', true); $this->debugDispatcher = $this->getMockBuilder('\\PhpConsole\\Dispatcher\\Debug')->setConstructorArgs(array($this->connector, new \PhpConsole\Dumper()))->setMethods(array('dispatchDebug'))->getMock(); $this->connector->setDebugDispatcher($this->debugDispatcher); }
public function testContextDataIsDumped() { /** @var \PhpConsole\Dumper $dumper */ $dumper = $this->connector->getDumper(); $string = str_repeat('x', $dumper->itemSizeLimit + 1); $this->getLogger()->info('{var}', array('var' => $string)); $messagesData = $this->getLogs(); $this->assertEquals('info ' . $dumper->dump($string), $messagesData[0]); }
public function testSetErrorsHandlerLevel() { $this->handler->setErrorsHandlerLevel(E_ALL ^ E_USER_NOTICE); $this->handler->start(); trigger_error('hehe', E_USER_NOTICE); $this->connector->expects($this->never())->method('sendMessage'); }
public function run(ApplicationInterface $app) { $connector = Connector::getInstance(); $connector->setSourcesBasePath(getcwd()); $matcher = new Matcher(); // redirect errors to PhpConsole \PhpConsole\Handler::getInstance()->start(); $app->getEventsHandler()->bind('*', function (EventInterface $event) use($app, $connector, $matcher) { /** * @var $connector \PhpConsole\Connector */ if ($connector->isActiveClient()) { $console = \PhpConsole\Handler::getInstance(); $context = $event->getContext(); $origin = $event->getOrigin(); switch (true) { case $event->getName() == 'application.workflow.step.run': $console->debug(sprintf('Starting running step %s', $origin->getName()), 'workflow.step'); break; case $event->getName() == 'application.workflow.hook.run': $middleware = $origin->getMiddleware(); $console->debug(sprintf('Running Middleware %s (%s)', $middleware->getReference(), $middleware->getDescription()), 'workflow.hook'); $this->dumpNotifications($console, $middleware->getNotifications()); break; case $matcher->match(ServicesFactory::EVENT_INSTANCE_BUILT . '.*', $event->getName()): $console->debug(sprintf('Built service %s (%s)', $context['serviceSpecs']->getId(), is_object($context['instance']) ? get_class($context['instance']) : get_type($context['instance'])), 'services'); break; case $matcher->match($event->getName(), '*.notify.*'): $this->dumpNotifications($console, $event->getContext('notifications')); break; } } }); }
private function getLaraextConsole() { if (is_null($this->__laraext_console)) { $params = \Config::get("laraext.console"); if (!$params['enabled']) { return null; } if (empty($GLOBALS['laraext_console_storage_installed'])) { \PhpConsole\Connector::setPostponeStorage(new \PhpConsole\Storage\File(storage_path('laraext-php-console.dat'), true)); $GLOBALS['laraext_console_storage_installed'] = true; } $connector = \PhpConsole\Connector::getInstance(); if (!empty($params['password'])) { $connector->setPassword($params['password'], true); } if (!empty($params['ips'])) { $connector->setAllowedIpMasks(explode(",", $params['ips'])); } $this->__laraext_console = \PhpConsole\Handler::getInstance(); if (!$this->__laraext_console->isStarted()) { if (empty($params['catch_errors'])) { $this->__laraext_console->setHandleErrors(false); $this->__laraext_console->setHandleExceptions(false); $this->__laraext_console->setCallOldHandlers(false); } $this->__laraext_console->start(); } } return $this->__laraext_console; }
/** * Logs with an arbitrary level. * */ public function log($level, $message, array $context = array()) { if (is_object($message) && is_callable($message, '__toString')) { $message = (string) $message; } $message = $this->fetchMessageContext($message, $context); if (isset(static::$debugLevels[$level])) { $this->connector->getDebugDispatcher()->dispatchDebug($message, static::$debugLevels[$level], null); } elseif (isset(static::$errorsLevels[$level])) { if (isset($context['exception']) && $context['exception'] instanceof \Exception) { $this->connector->getErrorsDispatcher()->dispatchException($context['exception']); } else { $this->connector->getErrorsDispatcher()->dispatchError(static::$errorsLevels[$level], $message, null, null, null); } } else { throw new \Psr\Log\InvalidArgumentException('Unknown log level "' . $level . '"'); } }
public function testPostponeIfHeadersLimitExceeded() { $headersLimit = \PhpConsole\ClientEmulator\Connector::HEADERS_LIMIT; $messageSizeLimit = \PhpConsole\Connector::getInstance()->getDumper()->itemSizeLimit; for ($size = 0; $size < $headersLimit; $size += $messageSizeLimit) { $this->request->addScript('dispatch_debug', array('data' => str_repeat('x', $messageSizeLimit))); } $this->sendRequest(); $this->assertTrue($this->response->isPostponed); $this->assertMessageInResponse(array('data' => str_repeat('x', $messageSizeLimit)), false); }
public function testRecursiveExceptionsHandlingLimit() { $handler = $this->handler; set_exception_handler(function () use($handler) { $handler->handleException(new \Exception()); }); $this->connector->getErrorsDispatcher()->ignoreRepeatedSource = false; $this->connector->expects($this->exactly(\PhpConsole\Handler::ERRORS_RECURSION_LIMIT))->method('sendMessage'); $this->handler->start(); $this->handler->handleException(new \Exception()); }
/** * 打印数据到chrome控制台 * * @param mixed $var 要打印的变量 * @param string $tag 标签 * * @return void */ function dumpUsePHPConsole($var, $tag = 'debug') { if (!Config::get('dump_use_php_console')) { throwException(Lang::get('_NOT_OPEN_', 'dump_use_php_console')); } static $connector = false; if ($connector === false) { $connector = PhpConsoleConnector::getInstance(); $connector->setPassword(Config::get('php_console_password')); } $connector->getDebugDispatcher()->dispatchDebug($var, $tag); }
/** * Initializes the route. * This method is invoked after the route is created by the route manager. */ public function init() { /** @noinspection PhpIncludeInspection */ require_once Yii::getPathOfAlias($this->phpConsolePathAlias) . '/__autoload.php'; if ($this->registerHelper) { Helper::register(); } if (!$this->isEnabled || !Connector::getInstance()->isActiveClient()) { return; } $handler = Handler::getInstance(); $handler->setHandleErrors($this->handleErrors); $handler->setHandleErrors($this->handleExceptions); $handler->start(); $this->handler = $handler; // required for correct PhpConsoleExtension work /** @noinspection PhpUndefinedMethodInspection */ Yii::app()->getErrorHandler()->discardOutput = false; Yii::getLogger()->autoFlush = 1; $connector = Connector::getInstance(); if ($this->sourcesBasePath) { $connector->setSourcesBasePath($this->sourcesBasePath); } if ($this->serverEncoding) { $connector->setServerEncoding($this->serverEncoding); } if ($this->password) { $connector->setPassword($this->password); } if ($this->enableSslOnlyMode) { $connector->enableSslOnlyMode(); } if ($this->ipMasks) { $connector->setAllowedIpMasks($this->ipMasks); } if ($this->headersLimit) { $connector->setHeadersLimit($this->headersLimit); } if ($this->detectDumpTraceAndSource) { $connector->getDebugDispatcher()->detectTraceAndSource = true; } $dumper = $connector->getDumper(); $dumper->levelLimit = $this->dumperLevelLimit; $dumper->itemsCountLimit = $this->dumperItemsCountLimit; $dumper->itemSizeLimit = $this->dumperItemSizeLimit; $dumper->dumpSizeLimit = $this->dumperDumpSizeLimit; $dumper->detectCallbacks = $this->dumperDetectCallbacks; if ($this->isEvalEnabled) { $connector->startEvalRequestsListener(); } }
public function testGetEvalDispatcher() { $this->assertInstanceOf('\\PhpConsole\\Dispatcher\\Evaluate', $this->connector->getEvalDispatcher()); }
/** * Initialize PHP Console. * * @since 1.0.0 */ public function init() { // Get PHP Console extension password. $password = $this->options['password']; if (!$password) { // Display admin notice and abort if no password has been set. add_action('admin_notices', array($this, 'password_notice')); return; } // Selectively remove slashes added by WordPress as expected by PhpConsole. if (array_key_exists(PhpConsole\Connector::POST_VAR_NAME, $_POST)) { $_POST[PhpConsole\Connector::POST_VAR_NAME] = stripslashes_deep($_POST[PhpConsole\Connector::POST_VAR_NAME]); } // Get PHP Console instance if wasn't set yet. if (!$this->connector instanceof PhpConsole\Connector) { $this->connector = PhpConsole\Connector::getInstance(); } // Set PHP Console password. try { $this->connector->setPassword($password); } catch (\Exception $e) { $this->print_notice_exception($e); } // Get PHP Console handler instance. $handler = PhpConsole\Handler::getInstance(); if (true !== PhpConsole\Handler::getInstance()->isStarted()) { try { $handler->start(); } catch (\Exception $e) { $this->print_notice_exception($e); } } // Enable SSL-only mode. if (true === $this->options['ssl']) { $this->connector->enableSslOnlyMode(); } // Restrict IP addresses. $allowedIpMasks = !empty($this->options['ip']) ? explode(',', $this->options['ip']) : ''; if (is_array($allowedIpMasks) && count($allowedIpMasks) > 0) { $this->connector->setAllowedIpMasks($allowedIpMasks); } $evalProvider = $this->connector->getEvalDispatcher()->getEvalProvider(); try { $evalProvider->addSharedVar('uri', $_SERVER['REQUEST_URI']); } catch (\Exception $e) { $this->print_notice_exception($e); } try { $evalProvider->addSharedVarReference('post', $_POST); } catch (\Exception $e) { $this->print_notice_exception($e); } $openBaseDirs = array(ABSPATH, get_template_directory()); try { $evalProvider->addSharedVarReference('dirs', $openBaseDirs); } catch (\Exception $e) { $this->print_notice_exception($e); } $evalProvider->setOpenBaseDirs($openBaseDirs); try { $this->connector->startEvalRequestsListener(); } catch (\Exception $e) { $this->print_notice_exception($e); } }
protected function initPhpConsole() { if (!$this->dataStorage) { $this->dataStorage = new PhpConsole\Storage\File(storage_path('php-console.dat'), true); } if ($this->dataStorage instanceof \PhpConsole\Storage\Session) { throw new \Exception('Unable to use PhpConsole\\Storage\\Session as PhpConsole storage interface because of problems with overridden $_SESSION handler in Laravel'); } Connector::setPostponeStorage($this->dataStorage); $connector = Connector::getInstance(); if ($this->registerHelper) { Helper::register(); } $isActiveClient = $connector->isActiveClient(); if (!$this->isEnabled || !$isActiveClient) { if ($isActiveClient) { $connector->disable(); } return; } $handler = Handler::getInstance(); $handler->setHandleErrors($this->handleErrors); $handler->setHandleErrors($this->handleExceptions); $handler->start(); if ($this->sourcesBasePath) { $connector->setSourcesBasePath($this->sourcesBasePath); } if ($this->serverEncoding) { $connector->setServerEncoding($this->serverEncoding); } if ($this->password) { $connector->setPassword($this->password); } if ($this->enableSslOnlyMode) { $connector->enableSslOnlyMode(); } if ($this->ipMasks) { $connector->setAllowedIpMasks($this->ipMasks); } if ($this->headersLimit) { $connector->setHeadersLimit($this->headersLimit); } if ($this->detectDumpTraceAndSource) { $connector->getDebugDispatcher()->detectTraceAndSource = true; } $dumper = $connector->getDumper(); $dumper->levelLimit = $this->dumperLevelLimit; $dumper->itemsCountLimit = $this->dumperItemsCountLimit; $dumper->itemSizeLimit = $this->dumperItemSizeLimit; $dumper->dumpSizeLimit = $this->dumperDumpSizeLimit; $dumper->detectCallbacks = $this->dumperDetectCallbacks; if ($this->isEvalEnabled) { $connector->startEvalRequestsListener(); } }
private function handleErrorRecord(array $record) { $context = $record['context']; $this->connector->getErrorsDispatcher()->dispatchError(isset($context['code']) ? $context['code'] : null, isset($context['message']) ? $context['message'] : $record['message'], isset($context['file']) ? $context['file'] : null, isset($context['line']) ? $context['line'] : null, $this->options['classesPartialsTraceIgnore']); }
<?php require_once __DIR__ . '/../../src/PhpConsole/__autoload.php'; \PhpConsole\OldVersionAdapter::register(); // register PhpConsole class emulator // Call old PhpConsole v1 methods as is PhpConsole::start(true, true, $_SERVER['DOCUMENT_ROOT']); PhpConsole::debug('Debug using old method PhpConsole::debug()', 'some,tags'); debug('Debug using old function debug()', 'some,tags'); echo $undefinedVar; PhpConsole::getInstance()->handleException(new Exception('test')); // Call new PhpConsole methods, if you need :) \PhpConsole\Connector::getInstance()->setServerEncoding('cp1251'); \PhpConsole\Helper::register(); PC::debug('Debug using new methods'); echo 'So there is an easy way to migrate from PhpConsole v1.x to v3.x without any code changes';
/** * @dataProvider provideDumperOptionsValues */ public function testDumperOptions($option, $dumperProperty, $value) { new PHPConsoleHandler(array($option => $value), $this->connector); $this->assertEquals($value, $this->connector->getDumper()->{$dumperProperty}); }
function pc($var, $tag = 'debug') { if (class_exists('PhpConsole\\Connector')) { \PhpConsole\Connector::getInstance()->getDebugDispatcher()->dispatchDebug($var, $tag, 1); } }
protected function initErrorDispatcherMock(Connector $connector) { return $this->getMockBuilder('PhpConsole\\Dispatcher\\Errors')->disableOriginalConstructor()->setMethods(array('dispatchError', 'dispatchException'))->setConstructorArgs(array($connector, $connector->getDumper()))->getMock(); }
protected function initPostponeStorage(Storage $storage = null) { if ($storage instanceof \PhpConsole\Storage\Session) { throw new \Exception('Unable to use PhpConsole\\Storage\\Session as PhpConsole storage interface because of problems with overridden $_SESSION handler in Silex'); } Connector::setPostponeStorage($storage); }
* @version 3.0 * @author Sergey Barbushin http://linkedin.com/in/barbushin * @license http://opensource.org/licenses/BSD-3-Clause "BSD 3-Clause License" * @copyright © Sergey Barbushin, 2013. Some rights reserved. */ // List of scripts from ./features directory $features = array('debug_vars' => 'Debug vars', 'handle_errors' => 'Handle errors and exceptions', 'handle_on_redirect' => 'Handle messages on redirect', 'handle_javascript_errors' => 'Handle JavaScript errors', 'protect_by_password' => 'Protect by password', 'eval_terminal' => 'PHP code remote execution', 'highload_optimization' => 'Highload optimization', 'complex_usage_example' => 'Complex usage example', 'old_version_adapter' => 'Old version adapter'); // List of scripts from ./utils directory $utils = array('build_phar' => 'Build PHAR', 'test_jump_to_file' => 'Test Jump to File', 'detect_headers_limit' => 'Detect server headers limit'); // Highlight & print feature script source code if (isset($_GET['highlight']) && isset($features[$_GET['highlight']])) { highlight_string(preg_replace('/(\\$password\\s*=\\s*).*?;/', '\\1*****;', file_get_contents(__DIR__ . '/features/' . $_GET['highlight'] . '.php'))); exit; } require_once __DIR__ . '/../src/PhpConsole/__autoload.php'; $isActiveClient = \PhpConsole\Connector::getInstance()->isActiveClient(); ?> <html lang="en"> <head> <meta charset="utf-8" /> <title>PHP Console usage examples</title> <link rel="stylesheet" href="//xpart.ru/_share/pure-nr-min.css" /> <link rel="stylesheet" href="styles.css" /> <script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script> <script> if(typeof jQuery == 'undefined') { alert('Internet connection required to load JQuery to use examples browser. You can run examples offline manually from ./features & ./utils'); } else { $(function() { function initMenuItems(items, group, showSource) {
/** * Initialize PHP Console. * * @since 1.0.0 */ public function init() { // Display admin notice and abort if no password has been set $password = isset($this->options['password']) ? $this->options['password'] : ''; if (!$password) { add_action('admin_notices', array($this, 'password_notice')); return; // abort } // Selectively remove slashes added by WordPress as expected by PhpConsole if (isset($_POST[PhpConsole\Connector::POST_VAR_NAME])) { $_POST[PhpConsole\Connector::POST_VAR_NAME] = stripslashes_deep($_POST[PhpConsole\Connector::POST_VAR_NAME]); } $connector = PhpConsole\Connector::getInstance(); try { $connector->setPassword($password); } catch (\Exception $e) { $this->print_notice_exception($e); } // PhpConsole instance $handler = PhpConsole\Handler::getInstance(); if (PhpConsole\Handler::getInstance()->isStarted() !== true) { try { $handler->start(); } catch (\Exception $e) { $this->print_notice_exception($e); } } // Enable SSL-only mode $enableSslOnlyMode = isset($this->options['ssl']) ? !empty($this->options['ssl']) ? $this->options['ssl'] : '' : ''; if ($enableSslOnlyMode) { $connector->enableSslOnlyMode(); } // Restrict IP addresses $allowedIpMasks = isset($this->options['ip']) ? !empty($this->options['ip']) ? explode(',', $this->options['ip']) : '' : ''; if (is_array($allowedIpMasks) && !empty($allowedIpMasks)) { $connector->setAllowedIpMasks((array) $allowedIpMasks); } $evalProvider = $connector->getEvalDispatcher()->getEvalProvider(); try { $evalProvider->addSharedVar('uri', $_SERVER['REQUEST_URI']); } catch (\Exception $e) { $this->print_notice_exception($e); } try { $evalProvider->addSharedVarReference('post', $_POST); } catch (\Exception $e) { $this->print_notice_exception($e); } $openBaseDirs = array(ABSPATH, get_template_directory()); try { $evalProvider->addSharedVarReference('dirs', $openBaseDirs); } catch (\Exception $e) { $this->print_notice_exception($e); } $evalProvider->setOpenBaseDirs($openBaseDirs); try { $connector->startEvalRequestsListener(); } catch (\Exception $e) { $this->print_notice_exception($e); } }
protected function initSession() { $cacheDir = $this->console->getContainer()->get('kernel')->getCacheDir(); $file = $cacheDir . '/vitre_php_console.data'; Connector::setPostponeStorage(new \PhpConsole\Storage\File($file)); }