New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add editor opening. #13

Closed
wants to merge 3 commits into
base: master
from
Jump to file or symbol
Failed to load files and symbols.
+74 −10
Diff settings

Always

Just for now

Next

Add editor opening.

  • Loading branch information...
dereuromark committed Feb 3, 2017
commit ad8ea7e1a12898f3fb7bbb9d965df783b8703a1e
Copy path View file
@@ -28,6 +28,24 @@ with the Whoops handler:
That's it!
## Editor
Opening the file via click in the editor is supported for most major IDEs.
Set your config as
```php
'Whoops' => [
'editor' => true,
],
```
To enable it.
If you are using a VM, e.g. CakeBox, you will also need the path mapping:
```php
'userBasePath' => 'C:\wamp\www\cakebox\Apps\my-app.local',
'serverBasePath' => '/home/vagrant/Apps/my-app.local',
```
## License
Copyright (c)2015, Jad Bitar and licensed under [The MIT License][mit].
Copy path View file
@@ -9,8 +9,15 @@
class WhoopsHandler extends ErrorHandler
{
/**
* @var \Whoops\Run
*/
protected $_whoops;
/**
* @return \Whoops\Run
*/
public function getWhoopsInstance()
{
if (empty($this->_whoops)) {
@@ -19,25 +26,64 @@ public function getWhoopsInstance()
return $this->_whoops;
}
/**
* @param array $error
* @param bool $debug
* @return void
*/
protected function _displayError($error, $debug)
{
if ($debug) {
$whoops = $this->getWhoopsInstance();
$whoops->pushHandler(new PrettyPageHandler());
$whoops->handleError($error['level'], $error['description'], $error['file'], $error['line']);
} else {
if (!$debug) {
parent::_displayError($error, $debug);
return;
}
$whoops = $this->getWhoopsInstance();
$whoops->pushHandler($this->getHandler());
$whoops->handleError($error['level'], $error['description'], $error['file'], $error['line']);
}
/**
* @param \Exception $exception
* @return void
*/
protected function _displayException($exception)
{
if (Configure::read('debug')) {
$whoops = $this->getWhoopsInstance();
$whoops->pushHandler(new PrettyPageHandler());
$whoops->handleException($exception);
} else {
if (!Configure::read('debug')) {
parent::_displayException($exception);
}
$whoops = $this->getWhoopsInstance();
$whoops->pushHandler($this->getHandler());
$whoops->handleException($exception);
}
/**
* @return \Whoops\Handler\PrettyPageHandler
*/
protected function getHandler()
{
$handler = new PrettyPageHandler();
if (!Configure::read('Whoops.editor')) {
return $handler;
}
$handler->setEditor(function ($file, $line) {
$userPath = Configure::read('Whoops.userBasePath');
$serverPath = Configure::read('Whoops.serverBasePath');
if ($userPath && $serverPath) {
$file = str_replace($serverPath, $userPath, $file);
}
$url = sprintf('phpstorm://open?file=%s&line=%s', $file, $line);
if (!Configure::read('Whoops.asAjax', false)) {
return $url;
}
return [
'url' => $url,
'ajax' => true,
];
});
return $handler;
}
}
ProTip! Use n and p to navigate between commits in a pull request.