コード例 #1
0
 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;
             }
         }
     });
 }
コード例 #2
0
ファイル: LoggerTrait.php プロジェクト: skvn/laraext
 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;
 }
コード例 #3
0
 protected function setUp()
 {
     parent::setUp();
     $this->handler = \PhpConsole\Handler::getInstance();
     $this->connector = $this->getMockBuilder('\\PhpConsole\\Connector')->disableOriginalConstructor()->setMethods(array('sendMessage', 'onShutDown', 'isActiveClient'))->getMock();
     $this->connector->expects($this->any())->method('isActiveClient')->will($this->returnValue(true));
     $this->setProtectedProperty($this->handler, 'connector', $this->connector);
 }
コード例 #4
0
ファイル: Driver.php プロジェクト: vitre/php-console-bundle
 protected function initHandler()
 {
     $this->handler = Handler::getInstance();
     // disable exceptions handling
     $this->handler->setHandleExceptions($this->console->getContainer()->getParameter('vitre_php_console.handle.exceptions'));
     // disable errors handling
     $this->handler->setHandleErrors($this->console->getContainer()->getParameter('vitre_php_console.handle.errors'));
     // disable passing errors & exceptions to prviously defined handlers
     $this->handler->setCallOldHandlers($this->console->getContainer()->getParameter('vitre_php_console.handle.forward'));
     $this->handler->start();
 }
コード例 #5
0
 /**
  * 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();
     }
 }
コード例 #6
0
ファイル: PHPConsoleHandler.php プロジェクト: earncef/monolog
 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;
 }
コード例 #7
0
 /**
  * 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);
     }
 }
コード例 #8
0
ファイル: JiscDbModel.php プロジェクト: pdiveris/api_ht
 /**
  * Construct a suitable SQL statement and pass it to our manager
  * Note that we don't do any pagination or anything here
  * PD
  *
  * @param bool $raw
  * @throws \Exception
  * @internal param $raw
  * @return mixed
  * @todo inject SQLManager dependency
  */
 public function get($raw = false)
 {
     // reset criteria for next query
     $instance = self::getInstance();
     if (!$instance) {
         // some horror here....
         throw new \Exception("No valid instance of a model given");
     }
     $sql = 'WHERE true ';
     // AND WHERE
     foreach (self::getWhere() as $key => $values) {
         $sql .= ' AND ' . $values['column'] . ' ' . $values['operand'] . ' ' . $values['value'];
     }
     $sql .= "\n";
     // OR WHERE
     foreach (self::getOrWhere() as $key => $values) {
         $sql .= ' OR ' . $values['column'] . ' ' . $values['operand'] . ' ' . $values['value'];
     }
     $sql .= "\n";
     // ORDER BY
     if (count(self::getOrderBy()) > 0) {
         $sql .= " ORDER BY ";
         $i = 0;
         foreach (self::getOrderBy() as $j => $orderBy) {
             $sql .= $i > 0 ? " , {$orderBy['column']} {$orderBy['direction']}" : "  {$orderBy['column']} {$orderBy['direction']}";
         }
     }
     $sql .= "\n";
     if (count(self::getGroupBy()) > 0) {
         $sql .= " GROUP BY ";
         $i = 0;
         foreach (self::getGroupBy() as $j => $groupBy) {
             $sql .= $i > 0 ? " , {$groupBy}" : "  {$groupBy}";
         }
         $sql .= "\n";
     }
     if (self::getLimit() > 0) {
         $sql .= ' limit ' . self::getOffset() . ',' . self::getLimit();
     }
     if (isset(static::$table)) {
         $table = static::$table;
     } else {
         $table = strtolower(self::$class);
     }
     $columns = self::$select;
     // store the query string
     self::setQuery("select {$columns} from {$table} {$sql} ");
     // store the query time
     self::setQueryDateTime(date('c'));
     if (false) {
         \PhpConsole\Handler::getInstance()->debug('SQL', self::getQuery());
     }
     // @todo: move into SQLManager Interface
     $result = \DB::select(self::getQuery());
     self::resetQueries();
     // return raw stuff
     if ($raw) {
         return $result;
     }
     if (count($result) > 0) {
         $instance = self::getInstance()->itemCollection();
         $instance->items = array();
         foreach ($result as $i => $data) {
             $instance->items[] = new self::$class($data);
         }
     }
     return self::getInstance();
 }
コード例 #9
0
 public function testOptionUseOwnErrorsAndExceptionsHandler()
 {
     $this->initLogger(array('useOwnErrorsHandler' => true, 'useOwnExceptionsHandler' => true));
     $this->assertEquals(array(Handler::getInstance(), 'handleError'), set_error_handler(function () {
     }));
     $this->assertEquals(array(Handler::getInstance(), 'handleException'), set_exception_handler(function () {
     }));
 }
コード例 #10
0
 /**
  * Constructs the writer, optionally starts the handler
  * @param boolean $autostart set to true to autostart the handler
  * @return  void
  */
 public function __construct($autostart = true)
 {
     $this->handler = \PhpConsole\Handler::getInstance();
     $this->connector = $this->handler->getConnector();
     if ($autostart && !$this->handler->isStarted()) {
         $this->handler->start();
     }
 }
コード例 #11
0
 /**
  * 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);
     }
 }
コード例 #12
0
 /**
  * Sends the buffer to the PhpConsole class. See @ref ajax_env
  */
 protected static function _debugConsole()
 {
     $handler = \PhpConsole\Handler::getInstance();
     $handler->setHandleErrors(false);
     $handler->setHandleExceptions(false);
     $handler->start();
     foreach (static::$_buffer as $k => $arr) {
         if (@$arr['console_string'] || @$arr['console_statement']) {
             if (!@$arr) {
                 $php_trace = static::_debugTrace(1);
                 $arr = array('errline' => $php_trace['line'], 'errfile' => $php_trace['file']);
             }
             $statement = @$arr['console_statement'] ? strip_tags(preg_replace("=<br */?>=i", "\n", @$arr['console_statement'])) : null;
             $statement .= @$arr['console_time'] ? ' [time: ' . $arr['console_time'] . ']' : '';
             $console_type = '[' . @end(@explode('/', $arr['errfile'][0])) . ':';
             $console_type .= $arr['errline'][0] . ']';
             $key = @$arr['type'] == 'log' ? 'messages' : 'sql';
             if (static::$_options['show_' . $key]) {
                 if ('error' === $arr['console_statement']) {
                     $handler->handleError($arr['console_category'], $arr['errstr'], $arr['errfile'][0], $arr['errline'][0], null, 2);
                 } else {
                     \PC::debug($console_type, $arr['console_category'] . '.file');
                     if ($statement) {
                         \PC::debug($statement, $arr['console_category'] . '.message');
                     }
                     if (@$arr['console_string']) {
                         \PC::debug($arr['console_string'], $arr['console_category'] . '.result');
                     }
                     if (@$arr['errfile']) {
                         unset($arr['errfile'][0]);
                         if (!empty($arr['errfile'])) {
                             \PC::debug($arr['errfile'], $arr['console_category'] . '.trace');
                         }
                     }
                     //\PC::debug( $arr , $arr[ 'console_category' ] . '[full]' );
                 }
             }
         }
     }
     if (!static::$_options['show_interface']) {
         static::_buildCoverageData();
         static::_buildTraceData();
     }
     $time = static::$_endTime - static::$_startTime - static::$_tickTime;
     $console_final = 'Seconds: ' . round($time, 3) . ' | Milliseconds: ' . round($time * 1000, 3);
     \PC::debug(array(@get_included_files()), static::$_options['default_category'] . '.includedFiles');
     \PC::debug('Global Execution Time ' . $console_final, static::$_options['default_category']);
 }
コード例 #13
0
 public function testGetCustomHandler()
 {
     $handler = \PhpConsole\Handler::getInstance();
     \PhpConsole\Helper::register($this->connector, $handler);
     $this->assertEquals(spl_object_hash($handler), spl_object_hash(\PhpConsole\Helper::getHandler()));
 }
コード例 #14
0
 function debug($message, $tags = 'debug')
 {
     \PhpConsole\Handler::getInstance()->debug($message, $tags, 1);
 }
コード例 #15
0
 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();
     }
 }
コード例 #16
0
 /**
  * @return Handler
  */
 public function getHandler()
 {
     return Handler::getInstance();
 }