protected function dumpNotifications(\PhpConsole\Handler $console, $notifications)
 {
     if ($notifications instanceof $notifications) {
         $notifications->each(function (MessageInterface $message) use($console) {
             $console->debug((string) $message, $message->getType());
         });
     } else {
         $console->debug('Notifications should be ' . Stack::class . 'instances', 'console.error');
     }
 }
Пример #2
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');
 }
Пример #3
0
 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;
 }
Пример #4
0
 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
 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());
 }
Пример #6
0
 /**
  * Processes log messages and sends them to specific destination.   *
  * @param array $logs List of messages.  Each array elements represents one message
  * with the following structure:
  * array(
  *   [0] => message (string)
  *   [1] => level (string)
  *   [2] => category (string)
  *   [3] => timestamp (float, obtained by microtime(true));
  * @return bool
  */
 protected function processLogs($logs)
 {
     if ($this->handler) {
         foreach ($logs as $log) {
             if (is_scalar($log[0])) {
                 if ($log[1] == 'info') {
                     $this->handler->debug($log[0], $log[2], 9);
                 }
             }
         }
     }
     return true;
 }
Пример #7
0
 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;
 }
Пример #8
0
 public function init()
 {
     if (!class_exists('PhpConsole\\Connector')) {
         /** @noinspection PhpIncludeInspection */
         require_once Yii::getAlias($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;
     $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();
     }
 }
Пример #9
0
 /**
  * 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();
 }
 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 () {
     }));
 }
 /**
  * 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();
     }
 }
Пример #12
0
 /**
  * @return Handler
  */
 public function getHandler()
 {
     return Handler::getInstance();
 }
Пример #13
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']);
 }
Пример #14
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()));
 }
 function debug($message, $tags = 'debug')
 {
     \PhpConsole\Handler::getInstance()->debug($message, $tags, 1);
 }
Пример #16
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();
     }
 }
 /**
  * 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);
     }
 }
 /**
  * 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);
     }
 }