setEditor() public method

Set the editor to use to open referenced files, by a string identifier, or a callable that will be executed for every file reference, with a $file and $line argument, and should return a string.
public setEditor ( string | callable $editor )
$editor string | callable
 /**
  * Instantiate Whoops with the correct handlers.
  */
 public function init()
 {
     parent::init();
     require 'YiiWhoopsRunner.php';
     $this->whoops = new YiiWhoopsRunner();
     if (Yii::app()->request->isAjaxRequest) {
         $this->whoops->pushHandler(new JsonResponseHandler());
     } else {
         $page_handler = new PrettyPageHandler();
         if (isset($this->pageTitle)) {
             $page_handler->setPageTitle($this->pageTitle);
         }
         if (isset($this->editor)) {
             $editor = $this->editor;
             switch ($editor) {
                 case 'sublime':
                 case 'emacs':
                 case 'textmate':
                 case 'macvim':
                 case 'xdebug':
                     $page_handler->setEditor($editor);
                     break;
                 default:
                     $page_handler->setEditor(function ($file, $line) use($editor) {
                         return strtr($editor, array('{file}' => $file, '{line}' => $line));
                     });
                     break;
             }
         }
         $this->whoops->pushHandler($page_handler);
     }
 }
Example #2
0
 /**
  * {@inheritDoc}
  */
 public function onBootstrap(EventInterface $e)
 {
     $config = $e->getTarget()->getServiceManager()->get('Config');
     $config = isset($config['view_manager']) ? $config['view_manager'] : array();
     if ($e->getRequest() instanceof ConsoleRequest || empty($config['display_exceptions'])) {
         return;
     }
     $this->run = new Run();
     $this->run->register();
     // set up whoops config
     $prettyPageHandler = new PrettyPageHandler();
     if (isset($config['editor'])) {
         if ($config['editor'] == 'phpStorm') {
             $localPath = null;
             if (isset($config['local_path'])) {
                 $localPath = $config['local_path'];
             }
             $prettyPageHandler->setEditor(function ($file, $line) use($localPath) {
                 if ($localPath) {
                     // if your development server is not local it's good to map remote files to local
                     $translations = array('^' . __DIR__ => $config['editor_path']);
                     // change to your path
                     foreach ($translations as $from => $to) {
                         $file = preg_replace('#' . $from . '#', $to, $file, 1);
                     }
                 }
                 return "pstorm://{$file}:{$line}";
             });
         } else {
             $prettyPageHandler->setEditor($config['editor']);
         }
     }
     if (!empty($config['json_exceptions']['display'])) {
         $jsonHandler = new JsonResponseHandler();
         if (!empty($config['json_exceptions']['show_trace'])) {
             $jsonHandler->addTraceToOutput(true);
         }
         if (!empty($config['json_exceptions']['ajax_only'])) {
             $jsonHandler->onlyForAjaxRequests(true);
         }
         $this->run->pushHandler($jsonHandler);
     }
     if (!empty($config['whoops_no_catch'])) {
         $this->noCatchExceptions = $config['whoops_no_catch'];
     }
     $this->run->pushHandler($prettyPageHandler);
     $eventManager = $e->getTarget()->getEventManager();
     $eventManager->attach(MvcEvent::EVENT_RENDER_ERROR, array($this, 'prepareException'));
     $eventManager->attach(MvcEvent::EVENT_DISPATCH_ERROR, array($this, 'prepareException'));
 }
Example #3
0
 public function __invoke($request, $response, $next)
 {
     $app = $next;
     $container = $app->getContainer();
     $settings = $container['settings'];
     if (isset($settings['debug']) === true && $settings['debug'] === true) {
         // Enable PrettyPageHandler with editor options
         $prettyPageHandler = new PrettyPageHandler();
         if (empty($settings['whoops.editor']) === false) {
             $prettyPageHandler->setEditor($settings['whoops.editor']);
         }
         // Enable JsonResponseHandler when request is AJAX
         $jsonResponseHandler = new JsonResponseHandler();
         $jsonResponseHandler->onlyForAjaxRequests(true);
         // Add more information to the PrettyPageHandler
         $prettyPageHandler->addDataTable('Slim Application', ['Application Class' => get_class($app), 'Script Name' => $app->environment->get('SCRIPT_NAME'), 'Request URI' => $app->environment->get('PATH_INFO') ?: '<none>']);
         $prettyPageHandler->addDataTable('Slim Application (Request)', array('Accept Charset' => $app->request->getHeader('ACCEPT_CHARSET') ?: '<none>', 'Content Charset' => $app->request->getContentCharset() ?: '<none>', 'Path' => $app->request->getUri()->getPath(), 'Query String' => $app->request->getUri()->getQuery() ?: '<none>', 'HTTP Method' => $app->request->getMethod(), 'Base URL' => (string) $app->request->getUri(), 'Scheme' => $app->request->getUri()->getScheme(), 'Port' => $app->request->getUri()->getPort(), 'Host' => $app->request->getUri()->getHost()));
         // Set Whoops to default exception handler
         $whoops = new \Whoops\Run();
         $whoops->pushHandler($prettyPageHandler);
         $whoops->pushHandler($jsonResponseHandler);
         $whoops->register();
         $container['errorHandler'] = function ($c) use($whoops) {
             return new WhoopsErrorHandler($whoops);
         };
         //
         $container['whoops'] = $whoops;
     }
     return $app($request, $response);
 }
 public function register()
 {
     $error_page = new PrettyPageHandler();
     $error_page->setEditor('sublime');
     $this->whoops->pushHandler($error_page);
     $this->whoops->register();
 }
 public function __invoke($request, $response, $next)
 {
     $container = $this->app->getContainer();
     $settings = DotArray::newDotArray($container['settings']);
     if ($settings['app.debug'] === true) {
         // Enable PrettyPageHandler with editor options
         $prettyPageHandler = new PrettyPageHandler();
         if ($settings->has('whoops.editor')) {
             $prettyPageHandler->setEditor($settings['whoops.editor']);
         }
         // Enable JsonResponseHandler when request is AJAX
         $jsonResponseHandler = new JsonResponseHandler();
         $jsonResponseHandler->onlyForAjaxRequests(true);
         // Add more information to the PrettyPageHandler
         $prettyPageHandler->addDataTable('Slim Application', ['Application Class' => get_class($this->app), 'Script Name' => $this->app->environment->get('SCRIPT_NAME'), 'Request URI' => $this->app->environment->get('PATH_INFO') ?: '<none>']);
         $prettyPageHandler->addDataTable('Slim Application (Request)', ['Accept Charset' => $this->app->request->getHeader('ACCEPT_CHARSET') ?: '<none>', 'Content Charset' => $this->app->request->getContentCharset() ?: '<none>', 'Path' => $this->app->request->getUri()->getPath(), 'Query String' => $this->app->request->getUri()->getQuery() ?: '<none>', 'HTTP Method' => $this->app->request->getMethod(), 'Base URL' => (string) $this->app->request->getUri(), 'Scheme' => $this->app->request->getUri()->getScheme(), 'Port' => $this->app->request->getUri()->getPort(), 'Host' => $this->app->request->getUri()->getHost()]);
         $prettyPageHandler->addDataTable('SlimFastShake Settings', $settings->flatten());
         // Set Whoops to default exception handler
         $whoops = new \Whoops\Run();
         $whoops->pushHandler($prettyPageHandler);
         $whoops->pushHandler($jsonResponseHandler);
         if (isset($container['logger'])) {
             $logger = $container['logger'];
             $whoops->pushHandler(function ($exception, $inspector, $run) use($logger) {
                 $logger->critical('Whoops: ' . $exception->getMessage());
             });
         }
         $whoops->register();
         $container['errorHandler'] = function ($c) use($whoops) {
             return new WhoopsErrorHandler($whoops);
         };
         $container['whoops'] = $whoops;
     }
     return $next($request, $response);
 }
Example #6
0
 public function register(Container $container)
 {
     // Setup Whoops-based error handler
     $errors = new Errors();
     $error_page = new PrettyPageHandler();
     $error_page->setPageTitle('Crikey! There was an error...');
     $error_page->setEditor('sublime');
     $error_page->addResourcePath(GRAV_ROOT . '/system/assets');
     $error_page->addCustomCss('whoops.css');
     $json_page = new JsonResponseHandler();
     $json_page->onlyForAjaxRequests(true);
     $errors->pushHandler($error_page, 'pretty');
     $errors->pushHandler(new PlainTextHandler(), 'text');
     $errors->pushHandler($json_page, 'json');
     $logger = $container['log'];
     $errors->pushHandler(function (\Exception $exception, $inspector, $run) use($logger) {
         try {
             $logger->addCritical($exception->getMessage() . ' - Trace: ' . $exception->getTraceAsString());
         } catch (\Exception $e) {
             echo $e;
         }
     }, 'log');
     $errors->register();
     $container['errors'] = $errors;
 }
 /**
  * Inject an editor into the whoops configuration.
  *
  * @see https://github.com/filp/whoops/blob/master/docs/Open%20Files%20In%20An%20Editor.md
  * @param PrettyPageHandler $handler
  * @param array|\ArrayAccess $config
  * @param ContainerInterface $container
  * @throws Exception\InvalidServiceException for an invalid editor definition.
  */
 private function injectEditor(PrettyPageHandler $handler, $config, ContainerInterface $container)
 {
     if (!isset($config['editor'])) {
         return;
     }
     $editor = $config['editor'];
     if (is_callable($editor)) {
         $handler->setEditor($editor);
         return;
     }
     if (!is_string($editor)) {
         throw new Exception\InvalidServiceException(sprintf('Whoops editor must be a string editor name, string service name, or callable; received "%s"', is_object($editor) ? get_class($editor) : gettype($editor)));
     }
     if ($container->has($editor)) {
         $editor = $container->get($editor);
     }
     $handler->setEditor($editor);
 }
 /**
  * Register the Whoops! Exception Handler
  *
  * @return \Whoops\Run $whoops
  */
 public function start()
 {
     $whoops = new Run();
     $handler = new PrettyPageHandler();
     $handler->addResourcePath(__DIR__ . '/Resources');
     $handler->setEditor('sublime');
     $whoops->pushHandler($handler);
     $whoops->register();
     $this->whoops = $whoops;
 }
Example #9
0
 public function onBootstrap(EventInterface $event)
 {
     $prettyPageHandler = new PrettyPageHandler();
     // Set editor
     $config = $event->getApplication()->getServiceManager()->get('Config');
     if (isset($config['view_manager']['editor'])) {
         $prettyPageHandler->setEditor($config['view_manager']['editor']);
     }
     $this->run = new Run();
     $this->run->register();
     $this->run->pushHandler($prettyPageHandler);
     $this->attachListeners($event);
 }
 public function register(Container $container)
 {
     /** @var $config Registry */
     $config = $container->resolve('config');
     if ($config->get('debug', false)) {
         $whoops = new Run();
         $handler = new PrettyPageHandler();
         $editor = $config->get('debugEditor');
         if ($editor == 'pstorm') {
             $handler->setEditor(function ($file, $line) {
                 return "pstorm://{$file}:{$line}";
             });
         } else {
             $handler->setEditor($editor);
         }
         $whoops->pushHandler($handler);
         $whoops->register();
         $container->bind('whoops', function () use($whoops) {
             return $whoops;
         });
     }
 }
Example #11
0
 private function boot()
 {
     if (ENVIRONMENT == 'development') {
         $run = new \Whoops\Run();
         $handler = new PrettyPageHandler();
         $handler->setPageTitle("We're all going to be fired!");
         $handler->setEditor('textmate');
         $run->pushHandler($handler);
         $handler = new JsonResponseHandler();
         $handler->onlyForAjaxRequests(true);
         $run->pushHandler($handler);
         $run->register();
     }
 }
Example #12
0
 public function __construct()
 {
     // Load in whoops on exception?
     $this->whoops = Configuration::get('app.env', 'production') === 'development' && Configuration::get('app.visualException', false);
     if ($this->whoops) {
         $this->whoops = new Run();
         $pretty = new PrettyPageHandler();
         $pretty->setPageTitle("Arvici - Exception is thrown!");
         if (Configuration::get('app.ide', 'none') === 'idea') {
             $pretty->setEditor(function ($file, $line) {
                 return array('url' => "http://localhost:63342/api/file/?file={$file}&line={$line}", 'ajax' => true);
             });
         }
         $this->whoops->pushHandler($pretty);
     }
 }
Example #13
0
 public function __invoke($request, $response, $next)
 {
     $container = $this->app->getContainer();
     $settings = $container['settings'];
     if (isset($settings['debug']) === true && $settings['debug'] === true) {
         // Enable PrettyPageHandler with editor options
         $prettyPageHandler = new PrettyPageHandler();
         if (empty($settings['whoops.editor']) === false) {
             $prettyPageHandler->setEditor($settings['whoops.editor']);
         }
         // Enable JsonResponseHandler when request is AJAX
         $jsonResponseHandler = new JsonResponseHandler();
         $jsonResponseHandler->onlyForAjaxRequests(true);
         // Add more information to the PrettyPageHandler
         $prettyPageHandler->addDataTable('Slim Application', ['Application Class' => get_class($this->app), 'Script Name' => $container['environment']->get('SCRIPT_NAME'), 'Request URI' => $container['environment']->get('PATH_INFO') ?: '<none>']);
         $prettyPageHandler->addDataTable('Slim Application (Request)', array('Accept Charset' => $container['request']->getHeader('ACCEPT_CHARSET') ?: '<none>', 'Content Charset' => $container['request']->getContentCharset() ?: '<none>', 'Path' => $container['request']->getUri()->getPath(), 'Query String' => $container['request']->getUri()->getQuery() ?: '<none>', 'HTTP Method' => $container['request']->getMethod(), 'Base URL' => (string) $container['request']->getUri(), 'Scheme' => $container['request']->getUri()->getScheme(), 'Port' => $container['request']->getUri()->getPort(), 'Host' => $container['request']->getUri()->getHost()));
         // Set Whoops to default exception handler
         $whoops = new \Whoops\Run();
         $whoops->pushHandler($prettyPageHandler);
         $whoops->pushHandler($jsonResponseHandler);
         /*// Setup Monolog, for example:
           $logger = new \Monolog\Logger('Test');
           $logger->pushHandler(new \Monolog\Handler\StreamHandler("c:/xampp/php/logs/php_error_log"));*/
         // Place our custom handler in front of the others, capturing exceptions
         // and logging them, then passing the exception on to the other handlers:
         if (!empty($logger = $this->logger)) {
             $whoops->pushHandler(function ($exception, $inspector, $run) use($logger) {
                 $logger->error($exception->getMessage());
             });
         }
         $whoops->register();
         $container['errorHandler'] = function ($c) use($whoops) {
             return function ($request, $response, $exception) use($whoops) {
                 $handler = \Whoops\Run::EXCEPTION_HANDLER;
                 ob_start();
                 $whoops->{$handler}($exception);
                 $content = ob_get_clean();
                 $code = $exception instanceof HttpException ? $exception->getStatusCode() : 500;
                 return $response->withStatus($code)->withHeader('Content-type', 'text/html')->write($content);
             };
         };
         //
         $container['whoops'] = $whoops;
     }
     return $next($request, $response);
 }
Example #14
0
 static function reload()
 {
     $run = new Whoops\Run();
     $handler = new PrettyPageHandler();
     $CI =& get_instance();
     $handler->setEditor("sublime");
     // Set the editor used for the "Open" link
     $handler->addDataTable("Extra Info", array("Name" => 'Forhad Ahmed', "email" => "*****@*****.**"));
     // Set the title of the error page:
     $handler->setPageTitle("Whoops! There was a problem.");
     $run->pushHandler($handler);
     $CI =& load_class('Input');
     if ($CI->is_ajax_request() == true) {
         $run->pushHandler(new JsonResponseHandler());
     }
     // Register the handler with PHP, and you're set!
     $run->register();
 }
 public function register(Container $container)
 {
     /** @var UniformResourceLocator $locator */
     $locator = $container['locator'];
     /** @var Platform $platform */
     $platform = $container['platform'];
     // Setup Whoops-based error handler
     $errors = new Run();
     $errors->registerPaths($platform->errorHandlerPaths());
     $error_page = new PrettyPageHandler();
     $error_page->setPageTitle('Crikey! There was an error...');
     $error_page->setEditor('sublime');
     foreach ($locator->findResources('gantry-assets://css/whoops.css') as $path) {
         $error_page->addResourcePath(dirname($path));
     }
     $error_page->addCustomCss('whoops.css');
     $json_page = new JsonResponseHandler();
     $json_page->onlyForAjaxRequests(true);
     $errors->pushHandler($error_page, 'pretty');
     $errors->pushHandler(new PlainTextHandler(), 'text');
     $errors->pushHandler($json_page, 'json');
     $errors->register();
     $container['errors'] = $errors;
 }
Example #16
0
 protected function prettyPageInit(PrettyPageHandler $handler)
 {
     $options = $this->whoopsConfig['handler']['options'];
     $handler->setEditor($options['editor']);
 }
Example #17
0
 /**
  * @return Bootstrap
  */
 protected function registerExceptionHandler() : Bootstrap
 {
     // Better Exception Handling.
     /*
     $runner = new Runner();
     $runner->pushFormatter(new HtmlTableFormatter());
     $runner->setErrorPageFormatter(new HtmlTableFormatter());
     $runner->register();
     $this->container->share(Runner::class, $runner);
     */
     // Because leauge/booboo is not PHP7 compatible
     $whoopsFormatter = new PrettyPageHandler();
     $whoopsFormatter->setEditor('phpstorm');
     $whoops = new Run();
     $whoops->pushHandler($whoopsFormatter);
     $whoops->register();
     $this->container->share(Run::class, $whoops);
     $this->container->share(HandlerInterface::class, $whoopsFormatter);
     return $this;
 }