Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Vaseem ishak committed Jan 3, 2019
0 parents commit 779c435
Show file tree
Hide file tree
Showing 9 changed files with 150 additions and 0 deletions.
20 changes: 20 additions & 0 deletions Model/Config/Source/Editors.php
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'],
];
}
}
55 changes: 55 additions & 0 deletions Plugin/ErrorHandler.php
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);
}
}
}
11 changes: 11 additions & 0 deletions README.md
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
20 changes: 20 additions & 0 deletions composer.json
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"
]
}
}
13 changes: 13 additions & 0 deletions etc/adminhtml/system.xml
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>
11 changes: 11 additions & 0 deletions etc/config.xml
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>
6 changes: 6 additions & 0 deletions etc/di.xml
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>
5 changes: 5 additions & 0 deletions etc/module.xml
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>
9 changes: 9 additions & 0 deletions registration.php
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__
);

0 comments on commit 779c435

Please sign in to comment.