public function connect() { if ($this->connection === false) { $this->initSession(); $this->connection = Connector::getInstance(); $this->configure(); $this->initHandler(); PhpConsole\Helper::register(); } }
/** * Initializes the route. * This method is invoked after the route is created by the route manager. */ public function init() { if (!class_exists('PhpConsole\\Connector')) { /** @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(); } }
private function initConnector(Connector $connector = null) { if (!$connector) { if ($this->options['dataStorage']) { Connector::setPostponeStorage($this->options['dataStorage']); } $connector = Connector::getInstance(); } if ($this->options['registerHelper'] && !Helper::isRegistered()) { Helper::register(); } if ($this->options['enabled'] && $connector->isActiveClient()) { if ($this->options['useOwnErrorsHandler'] || $this->options['useOwnExceptionsHandler']) { $handler = VendorPhpConsoleHandler::getInstance(); $handler->setHandleErrors($this->options['useOwnErrorsHandler']); $handler->setHandleExceptions($this->options['useOwnExceptionsHandler']); $handler->start(); } if ($this->options['sourcesBasePath']) { $connector->setSourcesBasePath($this->options['sourcesBasePath']); } if ($this->options['serverEncoding']) { $connector->setServerEncoding($this->options['serverEncoding']); } if ($this->options['password']) { $connector->setPassword($this->options['password']); } if ($this->options['enableSslOnlyMode']) { $connector->enableSslOnlyMode(); } if ($this->options['ipMasks']) { $connector->setAllowedIpMasks($this->options['ipMasks']); } if ($this->options['headersLimit']) { $connector->setHeadersLimit($this->options['headersLimit']); } if ($this->options['detectDumpTraceAndSource']) { $connector->getDebugDispatcher()->detectTraceAndSource = true; } $dumper = $connector->getDumper(); $dumper->levelLimit = $this->options['dumperLevelLimit']; $dumper->itemsCountLimit = $this->options['dumperItemsCountLimit']; $dumper->itemSizeLimit = $this->options['dumperItemSizeLimit']; $dumper->dumpSizeLimit = $this->options['dumperDumpSizeLimit']; $dumper->detectCallbacks = $this->options['dumperDetectCallbacks']; if ($this->options['enableEvalListener']) { $connector->startEvalRequestsListener(); } } return $connector; }
/** * Apply options. * * @since 1.4.0 */ private function apply_options() { // Bail out if not connected yet to PHP Console. if (!$this->connector instanceof PhpConsole\Connector) { return; } // Apply 'register' option to PHP Console... if (true === $this->options['register'] && !class_exists('PC', false)) { // ...only if PC not registered yet. try { PhpConsole\Helper::register(); } catch (\Exception $e) { $this->print_notice_exception($e); } } // Apply 'stack' option to PHP Console. if (true === $this->options['stack']) { $this->connector->getDebugDispatcher()->detectTraceAndSource = true; } // Apply 'short' option to PHP Console. if (true === $this->options['short']) { try { $this->connector->setSourcesBasePath($_SERVER['DOCUMENT_ROOT']); } catch (\Exception $e) { $this->print_notice_exception($e); } } }
<?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';
<?php /* * This file is part of the Yare package. * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ //namespace Yare; if (defined('WP_DEBUG') and WP_DEBUG) { $password = Yare::config('theme.debug.password'); if (!$password) { return; } $connector = \PhpConsole\Helper::register(); if ($connector->isActiveClient()) { // Apply 'stack' option to PHP Console. //if ( true === $this->options['stack'] ) { //} // Init errors & exceptions handler $handler = \PC::getHandler(); /* You can override default Handler behavior: $handler->setHandleErrors(false); // disable errors handling $handler->setHandleExceptions(false); // disable exceptions handling $handler->setCallOldHandlers(false); // disable passing errors & exceptions to prviously defined handlers */ $handler->start(); // start handling PHP errors & exceptions if (Yare::config('theme.debug.stack')) { $connector->getDebugDispatcher()->detectTraceAndSource = true; $connector->setSourcesBasePath($_SERVER['DOCUMENT_ROOT']);
/** * Init. * * @since 1.0.0 */ public function __construct() { $this->plugin_name = 'WP PHP Console'; $this->plugin_slug = 'wp-php-console'; $this->version = '1.4.0'; $this->options = $this->get_options(); // Bail out if PHP Console can't be found if (!class_exists('PhpConsole\\Connector')) { return; } // By default PHP Console uses PhpConsole\Storage\Session for postponed responses, // so all temporary data will be stored in $_SESSION. // But there is some problem with frameworks like WordPress that override PHP session handler. // PHP Console has alternative storage drivers for this - we will write to a temporary file: $phpcdir = dirname(__FILE__) . '/tmp'; $make_dir = wp_mkdir_p($phpcdir); if ($make_dir === true) { try { $storage = new PhpConsole\Storage\File($phpcdir . '/' . md5(__FILE__) . '_pc.data'); PhpConsole\Connector::setPostponeStorage($storage); } catch (\Exception $e) { // TODO $storage is under DOCUMENT_ROOT - it's insecure but did not find another solution in WP // $this->print_notice_exception( $e ); } } // Perform PHP Console initialisation required asap for other code to be able to output to the JavaScript console $connector = PhpConsole\Connector::getInstance(); // Apply 'register' option to PHP Console if (!empty($this->options['register']) && !class_exists('PC', false)) { // Only if PC not registered yet try { PhpConsole\Helper::register(); } catch (\Exception $e) { $this->print_notice_exception($e); } } // Apply 'stack' option to PHP Console if (!empty($this->options['stack'])) { $connector->getDebugDispatcher()->detectTraceAndSource = true; } // Apply 'short' option to PHP Console if (!empty($this->options['short'])) { try { $connector->setSourcesBasePath($_SERVER['DOCUMENT_ROOT']); } catch (\Exception $e) { $this->print_notice_exception($e); } } // Translation add_action('plugins_loaded', array($this, 'set_locale')); // Admin menu add_action('admin_menu', array($this, 'register_settings_page')); // Delay further PHP Console initialisation to have more context during Remote PHP execution add_action('wp_loaded', array($this, 'init')); }
public function __construct() { \PhpConsole\Helper::register(); }
/** * Loads the debug interface and/or the console class if requested. See @ref dbg_getting_started * @param array $options array of options, see PtcDebug::$ _defaultOptions */ public static function load($options = null) { $now = microtime(true); if (defined('_PTCDEBUG_NAMESPACE_')) { $err = array('errno' => static::_msgType(E_USER_NOTICE), 'errstr' => 'Debug already loaded!', 'errfile' => 'trace'); static::_buildBuffer('log', '{errorHandler}', $err); return; } $called_class = get_called_class(); /* if error handler was called previously */ if (@isset(static::$_options['die_on_error'])) { static::$_defaultOptions['die_on_error'] = static::$_options['die_on_error']; } if (@isset(static::$_options['error_reporting'])) { static::$_defaultOptions['error_reporting'] = static::$_options['error_reporting']; } static::$_options = is_array($options) ? array_merge(static::$_defaultOptions, $options) : static::$_defaultOptions; if (!($has_access = static::_checkAccess())) { return; } // check access with ips $buffer = 'Debug Info:'; if (static::$_options['check_referer']) { static::checkReferer(); } // check if referer has debug vars if (static::$_options['session_start']) { if (session_id() === '') { session_start(); $buffer .= '<br>Initialized browser session with session_start( )'; } else { $buffer .= '<br>Session id is ' . session_id(); } } if (!@$_SESSION) { $_SESSION = array(); } if (!@$_SESSION['ptcdebug']) { $_SESSION['ptcdebug'] = array(); } if (@$_GET[static::$_options['url_key']] == static::$_options['url_pass']) { $_SESSION['ptcdebug'][static::$_options['url_key']] = true; $_SESSION['ptcdebug']['code_highlighter'] = true; $_SESSION['ptcdebug']['search_files'] = true; //$buffer .= '<br>PtcDebug turned on!'; } else { if (@$_GET[static::$_options['url_key'] . '_off'] == static::$_options['url_pass']) { $_SESSION['ptcdebug'][static::$_options['url_key']] = false; $_SESSION['ptcdebug']['code_highlighter'] = false; $_SESSION['ptcdebug']['search_files'] = false; } } if (static::_getSessionVars(static::$_options['url_key'])) { static::$_startTime = microtime(true); if (static::$_options['set_time_limit']) { set_time_limit(static::$_options['set_time_limit']); } if (static::$_options['memory_limit']) { ini_set('memory_limit', static::$_options['memory_limit']); } if (static::$_options['show_interface'] || static::$_options['debug_console']) { register_shutdown_function(array($called_class, 'processBuffer')); } if (static::$_options['replace_error_handler']) { static::setErrorHandler(static::$_options['die_on_error']); $buffer .= '<br>Error handler has been overridden!'; } if (static::$_options['catch_exceptions']) { set_exception_handler(array($called_class, 'exceptionHandler')); $buffer .= "<br>Exception Handler turned on!"; } if (static::$_options['debug_console']) { static::$_consoleStarted = false; $buffer .= '<br>Console debug turned on'; if (file_exists(dirname(__FILE__) . '/PhpConsole/__autoload.php')) { require_once dirname(__FILE__) . '/PhpConsole/__autoload.php'; static::$_consoleStarted = true; \PhpConsole\Helper::register(); $buffer .= ", phpConsole class started!"; } else { $buffer .= ', but could not find phpConsole class!'; } } if (static::$_options['enable_inspector'] || static::$_options['code_coverage'] || static::$_options['trace_functions']) { register_tick_function(array($called_class, 'tickHandler')); //if ( static::$_options[ 'declare_ticks' ] ) { declare( ticks = 1 ); } $buffer .= "<br>Variables inspector enabled!"; } if (static::$_options['code_coverage'] === 'full') { static::startCoverage(); $buffer .= "<br>Code coverage analysis for all scripts enabled!"; } if (static::$_options['trace_functions'] === 'full') { static::startTrace(); $buffer .= "<br>Function calls tracing for all scripts enabled!"; } if (!static::_getSessionVars('show_messages')) { static::_setSessionVars(); } if (@$_GET['hidepanels']) { static::_disablePanels(); } else { static::$_options['show_messages'] = static::_getSessionVars('show_messages'); static::$_options['show_globals'] = static::_getSessionVars('show_globals'); static::$_options['show_sql'] = static::_getSessionVars('show_sql'); static::$_options['show_w3c'] = static::_getSessionVars('show_w3c'); } @define('_PTCDEBUG_NAMESPACE_', $called_class); static::$_tickTime = microtime(true) - $now + static::$_tickTime; static::bufferLog('', '<span>' . $buffer . '<span>', 'Debug Loader'); } }
public function testShortHelperLoaded() { \PhpConsole\Helper::register($this->connector); $this->assertEquals('PhpConsole\\Helper', get_parent_class('PC')); }
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(); } }
/** * Registers services on the given app. * * This method should only be used to configure services and parameters. * It should not get services. * * @param Application $app An Application instance */ public function register(Application $app) { $connector = $this->getConnector(); $handler = $this->getHandler(); Helper::register($connector, $handler); $app['php-console.connector'] = $connector; $app['php-console.handler'] = $handler; $app->error(function (\Exception $exception) { }); }