├── CHANGELOG.md ├── LICENSE ├── README.md ├── composer.json ├── config └── whoops-editor.php └── src └── Providers └── WhoopsEditorServiceProvider.php /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to `laravel-whoops-editor` will be documented in this file. 4 | 5 | ## [3.0.0] - 2017-12-15 6 | 7 | ### Fixed 8 | 9 | - Use default config if `whoops-editor.editors` not found 10 | - PHP 7.0 support 11 | 12 | ### Changed 13 | 14 | - `resolveEditor` method in `WhoopsEditorServiceProvider` not require `$config` argument 15 | - `resolveFilePath` method `WhoopsEditorServiceProvider` not require `$config` argument 16 | 17 | ## [2.0.0] - 2017-12-15 18 | 19 | ### Added 20 | 21 | - `APP_EDITOR` environment variable 22 | 23 | ### Changed 24 | 25 | - `overwriteConfig` method renamed to `overwriteAppConfig` in `WhoopsEditorServiceProvider` 26 | 27 | ## 1.0.0 - 2017-12-15 28 | 29 | ### Added 30 | 31 | - Linux support for IntelliJ PHPStorm 32 | - Linux support for IntelliJ IDEA 33 | - Linux support for SublimeText 34 | 35 | [3.0.0]: https://github.com/cybercog/laravel-whoops-editor/compare/2.0.0...3.0.0 36 | [2.0.0]: https://github.com/cybercog/laravel-whoops-editor/compare/1.0.0...2.0.0 37 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020, Anton Komarev 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Laravel Whoops Editor 2 | 3 | ![cog-laravel-whoops-editor](https://user-images.githubusercontent.com/1849174/34025716-77df6958-e162-11e7-858a-f2196f4e2372.png) 4 | 5 |

6 | Build Status 7 | StyleCI 8 | Releases 9 | License 10 |

11 | 12 | ## Introduction 13 | 14 | Laravel Whoops Editor helps to open your code editor from exception stack trace. Go to code editor in a blink of an eye! 15 | 16 | This feature was introduced in Laravel 5.5.25, but unfortunately has issues on Linux machines. Laravel Whoops Editor fixes PHPStorm, IDEA and SublimeText Linux support. 17 | 18 | Additionally allows you to open editor when using Homestead. 19 | 20 | For Atom support you can use [Mike Bronner's](https://github.com/mikebronner) [laravel-whoops-atom](https://github.com/GeneaLabs/laravel-whoops-atom) package or publish config and specify launch path in editors config section. 21 | 22 | ## Contents 23 | 24 | - [Features](#features) 25 | - [Requirements](#requirements) 26 | - [Installation](#installation) 27 | - [Configuration](#configuration) 28 | - [Usage](#usage) 29 | - [Protocol Handlers](#protocol-handlers) 30 | - [Change log](#change-log) 31 | - [Contributing](#contributing) 32 | - [Testing](#testing) 33 | - [Security](#security) 34 | - [Contributors](#contributors) 35 | - [Alternatives](#alternatives) 36 | - [License](#license) 37 | - [About CyberCog](#about-cybercog) 38 | 39 | ## Features 40 | 41 | - PHPStorm cross-platform support. 42 | - IDEA cross-platform support. 43 | - Sublime cross-platform support. 44 | - Allow opening code editor when using Homestead. 45 | - Following PHP Standard Recommendations: 46 | - [PSR-1 (Basic Coding Standard)](http://www.php-fig.org/psr/psr-1/). 47 | - [PSR-2 (Coding Style Guide)](http://www.php-fig.org/psr/psr-2/). 48 | - [PSR-4 (Autoloading Standard)](http://www.php-fig.org/psr/psr-4/). 49 | - Covered with unit tests. 50 | 51 | ## Requirements 52 | 53 | - PHP >= 7.0.0 54 | - Laravel >= 5.5.25 55 | 56 | ## Installation 57 | 58 | First, pull in the package through Composer: 59 | 60 | ```shell script 61 | $ composer require cybercog/laravel-whoops-editor --dev 62 | ``` 63 | 64 | ## Configuration 65 | 66 | Package designed to work right out of the box, but you could publish configuration file to tweak settings: 67 | 68 | ```shell script 69 | $ php artisan vendor:publish --provider="Cog\Laravel\WhoopsEditor\Providers\WhoopsEditorServiceProvider" --tag="config" 70 | ``` 71 | 72 | ## Usage 73 | 74 | Specify your editor by adding `APP_EDITOR=phpstorm` in `.env` file. 75 | 76 | Optionally you can specify editor by adding `editor` key to the `./config/app.php` configuration file. 77 | 78 | ```php 79 | 'editor' => 'phpstorm', 80 | ``` 81 | 82 | This package provides extended Linux support for editors: `phpstorm`, `idea`, `sublime`. 83 | 84 | Complete list of supported editors could be found in [Whoops documentation](https://github.com/filp/whoops/blob/master/docs/Open%20Files%20In%20An%20Editor.md). 85 | 86 | ### Protocol Handlers 87 | 88 | If your OS trying to open file in web browser instead of code editor you should install Protocol Handler. 89 | 90 | | Editor | Protocol | Linux | MacOS | Windows | 91 | | ------ | -------- | ----- | ----- | ------- | 92 | | SublimeText | `subl://` | [thecotne/subl-protocol](https://github.com/thecotne/subl-protocol) | - | - | 93 | | Atom | `atm://` | [eclemens/atom-url-handler](https://github.com/eclemens/atom-url-handler) | [WizardOfOgz/atom-handler](https://github.com/WizardOfOgz/atom-handler) | - | 94 | 95 | ## Change log 96 | 97 | Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently. 98 | 99 | ## Contributing 100 | 101 | Please see [CONTRIBUTING](CONTRIBUTING.md) for details. 102 | 103 | ## Testing 104 | 105 | Run the tests with: 106 | 107 | ```shell script 108 | $ vendor/bin/phpunit 109 | ``` 110 | 111 | ## Security 112 | 113 | If you discover any security related issues, please email open@cybercog.su instead of using the issue tracker. 114 | 115 | ## Contributors 116 | 117 | | ![@antonkomarev](https://avatars.githubusercontent.com/u/1849174?s=110)
Anton Komarev
| 118 | | :---: | 119 | 120 | [Laravel Whoops Editor contributors list](../../contributors) 121 | 122 | ## Alternatives 123 | 124 | - [GeneaLabs/laravel-whoops-atom](https://github.com/GeneaLabs/laravel-whoops-atom) 125 | 126 | ## License 127 | 128 | - `Laravel Whoops Editor` package is open-sourced software licensed under the [MIT License](LICENSE) by [Anton Komarev](https://komarev.com). 129 | - `Error In Document` image licensed under [Creative Commons 3.0](https://creativecommons.org/licenses/by/3.0/us/) by Kid A. 130 | 131 | ## About CyberCog 132 | 133 | [CyberCog](https://cybercog.su) is a Social Unity of enthusiasts. Research best solutions in product & software development is our passion. 134 | 135 | - [Follow us on Twitter](https://twitter.com/cybercog) 136 | - [Read our articles on Medium](https://medium.com/cybercog) 137 | 138 | CyberCog 139 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "cybercog/laravel-whoops-editor", 3 | "description": "Laravel Whoops Editor helps to open your code editor from exception stack trace.", 4 | "type": "library", 5 | "license": "MIT", 6 | "keywords": [ 7 | "cybercog", 8 | "cog", 9 | "laravel", 10 | "whoops", 11 | "exception", 12 | "error", 13 | "ide", 14 | "editor", 15 | "stacktrace" 16 | ], 17 | "authors": [ 18 | { 19 | "name": "Anton Komarev", 20 | "email": "anton@komarev.com", 21 | "homepage": "https://komarev.com", 22 | "role": "Developer" 23 | } 24 | ], 25 | "homepage": "https://komarev.com/sources/laravel-whoops-editor", 26 | "support": { 27 | "email": "open@cybercog.su", 28 | "issues": "https://github.com/cybercog/laravel-whoops-editor/issues", 29 | "wiki": "https://github.com/cybercog/laravel-whoops-editor/wiki", 30 | "source": "https://github.com/cybercog/laravel-whoops-editor", 31 | "docs": "https://github.com/cybercog/laravel-whoops-editor/wiki" 32 | }, 33 | "require": { 34 | "php": "^7.0", 35 | "filp/whoops": "~2.0", 36 | "illuminate/support": ">=5.5.25" 37 | }, 38 | "require-dev": { 39 | "friendsofphp/php-cs-fixer": "^1.11", 40 | "orchestra/testbench": "~3.5.0", 41 | "phpunit/phpunit": "^6.0" 42 | }, 43 | "autoload": { 44 | "psr-4": { 45 | "Cog\\Laravel\\WhoopsEditor\\": "src/" 46 | } 47 | }, 48 | "autoload-dev": { 49 | "psr-4": { 50 | "Cog\\Tests\\Laravel\\WhoopsEditor\\": "tests/" 51 | } 52 | }, 53 | "scripts": { 54 | "test": "vendor/bin/phpunit" 55 | }, 56 | "config": { 57 | "sort-packages": true 58 | }, 59 | "extra": { 60 | "laravel": { 61 | "providers": [ 62 | "Cog\\Laravel\\WhoopsEditor\\Providers\\WhoopsEditorServiceProvider" 63 | ] 64 | } 65 | }, 66 | "minimum-stability": "dev", 67 | "prefer-stable" : true 68 | } 69 | -------------------------------------------------------------------------------- /config/whoops-editor.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | declare(strict_types=1); 13 | 14 | return [ 15 | 16 | /* 17 | |-------------------------------------------------------------------------- 18 | | Application Whoops Editor 19 | |-------------------------------------------------------------------------- 20 | | 21 | | When using the pretty error page feature, whoops comes with the ability 22 | | to open referenced files directly in your IDE or editor. This feature 23 | | only works in case your php-source files are locally accessible to 24 | | the machine on which the editor is installed. 25 | | 26 | | Supported: "emacs", "idea", "macvim", "phpstorm", "sublime", "textmate", "xdebug", "vscode" 27 | | See: https://github.com/filp/whoops/blob/master/docs/Open%20Files%20In%20An%20Editor.md 28 | | 29 | */ 30 | 'editor' => env('APP_EDITOR', null), 31 | 32 | /* 33 | |-------------------------------------------------------------------------- 34 | | Editors Configuration 35 | |-------------------------------------------------------------------------- 36 | | 37 | | Specify custom editors and configuration in this section. 38 | | 39 | */ 40 | 'editors' => [ 41 | 42 | 'idea' => [ 43 | 'url' => 'http://localhost:63342/api/file/?file=%file&line=%line', 44 | 'ajax' => true, 45 | ], 46 | 47 | 'phpstorm' => [ 48 | 'url' => 'http://localhost:63342/api/file/?file=%file&line=%line', 49 | 'ajax' => true, 50 | ], 51 | 52 | 'sublime' => 'subl://%file:%line', 53 | 54 | ], 55 | 56 | /* 57 | |-------------------------------------------------------------------------- 58 | | Local Sites Path 59 | |-------------------------------------------------------------------------- 60 | | 61 | | Specify the local development folder that is synchronized with Homestead. 62 | | If you are not using Homestead, set this to an empty string or null. 63 | | This corresponds to the `-map:` line under `folders` in your 64 | | `Homestead.yaml` file. 65 | | 66 | | Default: ~/projects (string|null) 67 | | 68 | */ 69 | 'local-projects-path' => '~/projects', 70 | 71 | /* 72 | |-------------------------------------------------------------------------- 73 | | Homestead Sites Path 74 | |-------------------------------------------------------------------------- 75 | | 76 | | Specify the base path where Homestead stores the synced folder with your 77 | | web sites. If you are not using Homestead, set this to an empty string 78 | | or null. This corresponds to the `to:` line under `folders` in 79 | | your Homestead.yaml file. 80 | | 81 | | Default: /home/vagrant/projects (string|null) 82 | | 83 | */ 84 | 'homestead-projects-path' => '/home/vagrant/projects', 85 | 86 | ]; 87 | -------------------------------------------------------------------------------- /src/Providers/WhoopsEditorServiceProvider.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | declare(strict_types=1); 13 | 14 | namespace Cog\Laravel\WhoopsEditor\Providers; 15 | 16 | use Illuminate\Support\ServiceProvider; 17 | 18 | /** 19 | * Class WhoopsEditorServiceProvider. 20 | * 21 | * @package Cog\Laravel\WhoopsEditor\Providers 22 | */ 23 | class WhoopsEditorServiceProvider extends ServiceProvider 24 | { 25 | /** 26 | * @var \Illuminate\Contracts\Config\Repository 27 | */ 28 | private $config; 29 | 30 | /** 31 | * Bootstrap the application services. 32 | * 33 | * @return void 34 | */ 35 | public function boot() 36 | { 37 | $this->registerPublishes(); 38 | $this->overwriteAppConfig(); 39 | } 40 | 41 | /** 42 | * Register the application services. 43 | * 44 | * @return void 45 | */ 46 | public function register() 47 | { 48 | $this->configure(); 49 | } 50 | 51 | /** 52 | * Setup the configuration for Whoops Editor. 53 | * 54 | * @return void 55 | */ 56 | protected function configure() 57 | { 58 | $this->mergeConfigFrom( 59 | __DIR__ . '/../../config/whoops-editor.php', 'whoops-editor' 60 | ); 61 | } 62 | 63 | /** 64 | * Setup the resource publishing groups for Whoops Editor. 65 | * 66 | * @return void 67 | */ 68 | protected function registerPublishes() 69 | { 70 | $this->publishes([ 71 | __DIR__ . '/../../config/whoops-editor.php' => config_path('whoops-editor.php'), 72 | ], 'config'); 73 | } 74 | 75 | /** 76 | * Build URI for editor based on file path and line. 77 | * 78 | * @param string $uri 79 | * @param string $filePath 80 | * @param int $line 81 | * @return string 82 | */ 83 | protected function buildUri(string $uri, string $filePath, int $line): string 84 | { 85 | $uri = str_replace('%file', $filePath, $uri); 86 | $uri = str_replace('%line', $line, $uri); 87 | 88 | return $uri; 89 | } 90 | 91 | /** 92 | * Overwrite application editor config with Whoops Editor. 93 | * 94 | * @return void 95 | */ 96 | protected function overwriteAppConfig() 97 | { 98 | $this->config = $this->app->make('config'); 99 | $editor = $this->resolveEditor(); 100 | $editorConfig = $this->config->get('whoops-editor.editors.' . $editor); 101 | if (!$editorConfig) { 102 | $this->overwriteAppEditor($editor); 103 | 104 | return; 105 | } 106 | 107 | $this->overwriteAppEditor(function ($filePath, $line) use ($editorConfig) { 108 | $filePath = $this->resolveFilePath($filePath); 109 | 110 | if (is_string($editorConfig)) { 111 | return $this->buildUri($editorConfig, $filePath, $line); 112 | } 113 | 114 | $editorConfig['url'] = $this->buildUri($editorConfig['url'], $filePath, $line); 115 | 116 | return $editorConfig; 117 | }); 118 | } 119 | 120 | /** 121 | * Overwrite application editor configuration value. 122 | * 123 | * @param string|\Closure $editor 124 | */ 125 | protected function overwriteAppEditor($editor) 126 | { 127 | $this->config->set('app.editor', $editor); 128 | } 129 | 130 | /** 131 | * Resolve code editor. 132 | * 133 | * @return mixed 134 | */ 135 | protected function resolveEditor() 136 | { 137 | return $this->config->get('app.editor', $this->config->get('whoops-editor.editor')); 138 | } 139 | 140 | /** 141 | * Resolve file path when using Homestead. 142 | * 143 | * @param string $filePath 144 | * @return string 145 | */ 146 | protected function resolveFilePath(string $filePath): string 147 | { 148 | $localPath = $this->config->get('whoops-editor.local-projects-path'); 149 | $homesteadPath = $this->config->get('whoops-editor.homestead-projects-path'); 150 | 151 | if (!$localPath || !$homesteadPath) { 152 | return $filePath; 153 | } 154 | 155 | $local = rtrim($localPath, '/'); 156 | $homestead = rtrim($homesteadPath, '/'); 157 | 158 | return str_replace("{$homestead}/", "{$local}/", $filePath); 159 | } 160 | } 161 | --------------------------------------------------------------------------------