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.
+78 −10
Diff settings

Always

Just for now

View
@@ -4,6 +4,9 @@
Built to seamlessly integrate [Whoops] with [CakePHP 3].
**DEPRECATED** Use **[dereuromark/cakephp-whoops](https://github.com/dereuromark/cakephp-whoops) package** instead.
## Install
Using [Composer]:
@@ -28,6 +31,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].
@@ -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,65 @@ 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);
}
$pattern = Configure::read('Whoops.ideLinkPattern') ?: 'phpstorm://open?file=%s&line=%s';
$url = sprintf($pattern, $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.