-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Vaseem ishak
committed
Jan 3, 2019
0 parents
commit 779c435
Showing
9 changed files
with
150 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
namespace Mnm\Whoops\Model\Config\Source; | ||
|
||
class Editors implements \Magento\Framework\Option\ArrayInterface | ||
{ | ||
public function toOptionArray() | ||
{ | ||
return [ | ||
['label' => 'Select default editor', 'value' => ''], | ||
['label' => 'phpstorm', 'value' => 'phpstorm'], | ||
['label' => 'vscode', 'value' => 'vscode'], | ||
['label' => 'sublime', 'value' => 'sublime'], | ||
['label' => 'textmate', 'value' => 'textmate'], | ||
['label' => 'emacs', 'value' => 'emacs'], | ||
['label' => 'macvim', 'value' => 'macvim'], | ||
['label' => 'idea', 'value' => 'idea'], | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
/** | ||
* Whoops plugin for Magento 2 | ||
*/ | ||
|
||
namespace Mnm\Whoops\Plugin; | ||
|
||
class ErrorHandler | ||
{ | ||
private $appState; | ||
|
||
private $request; | ||
|
||
private $scopeConfig; | ||
|
||
private $run; | ||
|
||
public function __construct( | ||
\Magento\Framework\App\State $appState, | ||
\Magento\Framework\App\RequestInterface $request, | ||
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig | ||
) { | ||
$this->appState = $appState; | ||
$this->request = $request; | ||
$this->scopeConfig = $scopeConfig; | ||
$this->run = new \Whoops\Run; | ||
} | ||
|
||
public function beforelaunch() | ||
{ | ||
if ($this->appState->getMode() == \Magento\Framework\App\State::MODE_DEVELOPER) { | ||
if ($this->request->isXmlHttpRequest()) { | ||
$handler = new \Whoops\Handler\JsonResponseHandler; | ||
} else { | ||
$handler = new \Whoops\Handler\PrettyPageHandler; | ||
$editor = $this->scopeConfig->getValue('dev/debug/default_editor'); | ||
if ($editor) { | ||
$handler->setEditor($editor); | ||
} | ||
} | ||
$this->run->pushHandler($handler); | ||
$this->run->register(); | ||
} | ||
} | ||
|
||
public function beforeCatchException( | ||
\Magento\Framework\App\Http $subject, | ||
\Magento\Framework\App\Bootstrap $bootstrap, | ||
\Exception $exception | ||
) { | ||
if ($this->appState->getMode() == \Magento\Framework\App\State::MODE_DEVELOPER) { | ||
$this->run->handleException($exception); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# magento2 whoops error handler | ||
|
||
This is magento 2 module that adds Whoops error handling. | ||
|
||
composer require --dev vaseemishak/magento2-whoops | ||
|
||
./bin/magento module:enable Mnm_Whoops | ||
./bin/magento setup:upgrade | ||
|
||
You can set default editor to open file with error from Whoops error page. | ||
Magento admin page -> Stores -> Configuration -> Advanced -> Developer -> Debug -> Default editor for whoops |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"name": "vaseemishak/magento2-whoops", | ||
"type": "magento2-module", | ||
"license": "OSL-3.0", | ||
"description": "Magento 2 Whoops error handler", | ||
"require": { | ||
"magento/framework": "^100.1.0|^101.0.0|^102.0.0", | ||
"filp/whoops": "^2.1", | ||
"php": ">=7.0.0", | ||
"symfony/var-dumper": "3.2.*" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Mnm\\Whoops\\": "" | ||
}, | ||
"files": [ | ||
"registration.php" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0"?> | ||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd"> | ||
<system> | ||
<section id="dev"> | ||
<group id="debug"> | ||
<field id="default_editor" translate="label" type="select" sortOrder="1" showInDefault="1" showInWebsite="0" showInStore="0"> | ||
<label>Default editor for whoops</label> | ||
<source_model>Mnm\Whoops\Model\Config\Source\Editors</source_model> | ||
</field> | ||
</group> | ||
</section> | ||
</system> | ||
</config> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version="1.0"?> | ||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd"> | ||
<default> | ||
<dev> | ||
<debug> | ||
<default_editor></default_editor> | ||
</debug> | ||
</dev> | ||
</default> | ||
</config> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" ?> | ||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> | ||
<type name="Magento\Framework\App\Http"> | ||
<plugin name="Mnm_Whoops_Plugin" type="\Mnm\Whoops\Plugin\ErrorHandler" /> | ||
</type> | ||
</config> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0"?> | ||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd"> | ||
<module name="Mnm_Whoops" setup_version="1.0.0"> | ||
</module> | ||
</config> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
use Magento\Framework\Component\ComponentRegistrar; | ||
|
||
ComponentRegistrar::register( | ||
ComponentRegistrar::MODULE, | ||
'Mnm_Whoops', | ||
__DIR__ | ||
); |