levacic/laravel-whoops-editor-link

Fixed the Sublime editor link path when running a project from a VM

1.0.3 2014-09-21 10:05 UTC

README

This tiny package rewrites the file link in Whoops's Pretty Page handler, when used within a Laravel project.

When running your project within a virtual machine, the links generated by Whoops will point to the file path within the virtual machine, which are inaccessible from your host environment. In order for these links to work, they must be rewritten so they would point to the correct file on the host machine. Using this package, it's easy to fix these links.

Installation

In your project root, do this:

composer require levacic/laravel-whoops-editor-link:~1

Alternatively, you may specify whichever package version is currently available when you install the package, e.g. ~1.0.3.

After that, publish the configuration file:

php artisan config:publish levacic/laravel-whoops-editor-link

This will copy the configuration file into app/config/packages/levacic/laravel-whoops-editor-link/path.php, and you should configure the appropriate paths for your environment.

For example, if your application on your host machine is located in /home/username/www/application, and within your virtual machine, the application root is in /var/www/sites/application, your configuration should look something like this:

<?php

return [

	/**
	 * The path to the application root on the host machine.
	 *
	 * Don't use a trailing slash!
	 */
	'host' => '/home/username/www/application',

	/**
	 * The path to the application root on the guest machine.
	 *
	 * Don't use a trailing slash!
	 */
	'guest' => '/var/www/sites/application',

];

However, if you do this, you'll have hardcoded application paths within your application repo, which is considered bad practice. The recommended way to configure this package is to configure the paths using Laravel's environment variables, naming the variables, for example, APP_ROOT_HOST and APP_ROOT_GUEST, and setting your configuration to use these:

<?php

return [

	/**
	 * The path to the application root on the host machine.
	 *
	 * Don't use a trailing slash!
	 */
	'host' => getenv('APP_ROOT_HOST'),

	/**
	 * The path to the application root on the guest machine.
	 *
	 * Don't use a trailing slash!
	 */
	'guest' => getenv('APP_ROOT_GUEST'),

];

Finally, you need to add the package's service provider to your app.providers array:

	'providers' => array(

		/** Various Illuminate service providers **/

		'Levacic\LaravelWhoopsEditorLink\LaravelWhoopsEditorLinkServiceProvider',

	),

Of course, for this to work, you need to also have the appropriate protocol handler configured on your system for subl:// links.

Compatibility

This package is written for Laravel 4.2, and at the time of this writing, Laravel 5.0 is not stable yet. When it's released, the package will also be updated (if needed) to work with it. Feel free to contact me if you need it, and I forgot about it!

Contributing

There's not really much to contribute here, due to the very specific scope of what this package does, but I guess we could add the same functionality for other editors - if anyone needs this, or wants to add the functionality, just open an issue or a pull request, and we'll fix it.

License

The package is licensed as open-source software under the MIT license.