Skip to content
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

support Laravel 5.x #38

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
41 changes: 15 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
# Laravel 4 Console
# Laravel 5 Console

In-browser console for Laravel 4 PHP framework.
In-browser console for Laravel 5 PHP framework.

This bundle executes your code within `ConsoleController@postExecute` context, and displays the produced output.
This package is a re-published, re-organised and maintained version of darsain/laravel-console, which isn't maintained anymore.

This package executes your code within `ConsoleController@postExecute` context, and displays the produced output.

The purpose is to easily test your stuff without creating garbage routes and controllers just to run something, ...
I'm sure you know what I'm talking about :)

This bundle is intended for a local testing, and **shouldn't get nowhere near your production servers!**
This package is intended for a local testing, and **shouldn't get nowhere near your production servers!**

## Screenshots

Expand All @@ -17,44 +19,31 @@ This bundle is intended for a local testing, and **shouldn't get nowhere near yo

## Installation

### Laravel 4

Add this into `require-dev` in your `composer.json` file:

```
"require-dev" : {
...
"darsain/laravel-console": "dev-master"
}
```
### Laravel 5

Run an update:
To install through composer, simply run the following command:

```
php composer.phar update
php cocomposer require teepluss/laravel-console
```

Register the console service provider in `app/config/app.php`:
Register the console service provider in `config/app.php`:

```php
'providers' => array(
'providers' => [
...
'Darsain\Console\ConsoleServiceProvider',
);
Darsain\Console\ConsoleServiceProvider::class,
];
```

Then publish the bundle assets:
Then publish the package assets:

```
php artisan asset:publish
php artisan vendor:publish --provider="Darsain\Console\ConsoleServiceProvider"
```

And you are done! Open the console in:

```
yourdomain.com/console
```

### Laravel 3

Laravel 3 version along with installation process can be found in the [L3 branch](https://github.com/Darsain/laravel-console/tree/L3).
17 changes: 13 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,17 @@
"console"
],
"license": "MIT",
"authors": [
{
"name": "Teepluss",
"email": "[email protected]",
"homepage": "https://github.com/teepluss",
"role": "Developer"
}
],
"require": {
"php": ">=5.3.0",
"illuminate/support": ">=4.0.0"
"php": ">=5.4.0",
"illuminate/support": ">=5.1.0"
},
"autoload": {
"classmap": [
Expand All @@ -19,5 +27,6 @@
"Darsain\\Console\\": "src/"
}
},
"minimum-stability": "dev"
}
"minimum-stability": "dev",
"prefer-stable": true
}
3 changes: 3 additions & 0 deletions public/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ jQuery(function ($) {
var $response = $('#response');
var $controlbar = $('#controlbar');
var $editor = $('#editor');


var action = $console.data('action');
var $execute = $('#execute');
var $controls = $('#controls');
Expand Down Expand Up @@ -106,6 +108,7 @@ jQuery(function ($) {
var execution = $.ajax(action, {
type: 'POST',
cache: false,
headers: { 'X-CSRF-TOKEN': Laravel.csrfToken },
data: {
code: editor.getValue()
},
Expand Down
21 changes: 17 additions & 4 deletions src/Darsain/Console/Console.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,23 @@ public static function query($sql, $bindings, $time)
*/
public static function attach()
{
Event::listen('illuminate.query', function ($sql, $bindings, $time)
{
Console::query($sql, $bindings, $time);
});
$db = app('db');
$db->listen(
function ($query, $bindings = null, $time = null, $connectionName = null) use ($db) {
// Laravel 5.2 changed the way some core events worked. We must account for
// the first argument being an "event object", where arguments are passed
// via object properties, instead of individual arguments.
if ($query instanceof \Illuminate\Database\Events\QueryExecuted) {
$bindings = $query->bindings;
$time = $query->time;
$connection = $query->connection;
$query = $query->sql;
} else {
$connection = $db->connection($connectionName);
}
Console::query((string) $query, $bindings, $time);
}
);
}

/**
Expand Down
112 changes: 66 additions & 46 deletions src/Darsain/Console/ConsoleServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,49 +4,69 @@

class ConsoleServiceProvider extends ServiceProvider {

/**
* Indicates if loading of the provider is deferred.
*
* @var bool
*/
protected $defer = false;

/**
* Bootstrap the application events.
*
* @return void
*/
public function boot()
{
$this->package('darsain/laravel-console');

$src_path = __DIR__ . '/../../';

// Routes
require $src_path . 'routes.php';

// Attach Console events
Console::attach();
}

/**
* Register the service provider.
*
* @return void
*/
public function register()
{
//
}

/**
* Get the services provided by the provider.
*
* @return array
*/
public function provides()
{
return array();
}

}
/**
* Indicates if loading of the provider is deferred.
*
* @var bool
*/
protected $defer = false;

/**
* Bootstrap the application events.
*
* @return void
*/
public function boot()
{
// Publish config.
$this->publishes([
__DIR__.'/../../config/config.php' => config_path('console.php'),
__DIR__.'/../../../public' => base_path('public/vendor/darsain/console'),
], 'public');
}

/**
* Register the service provider.
*
* @return void
*/
public function register()
{
if ($this->app['request']->is('console') and $this->app['request']->getMethod() == 'POST') {
$this->app->bind(
'Illuminate\Contracts\Debug\ExceptionHandler',
'Darsain\Console\Handler'
);
}

$this->mergeConfigFrom(
__DIR__.'/../../config/config.php', 'console'
);

$this->loadViewsFrom(
__DIR__.'/../../views', 'console'
);

$this->publishes([
__DIR__.'/../../views' => resource_path('views/vendor/console'),
], 'view');

if (! $this->app->routesAreCached()) {
require __DIR__ . '/../../routes.php';
}

// Attach Console events
Console::attach();
}

/**
* Get the services provided by the provider.
*
* @return array
*/
public function provides()
{
return array();
}

}
30 changes: 30 additions & 0 deletions src/Darsain/Console/Handler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php namespace Darsain\Console;

use Exception;
use Monolog\Handler\BrowserConsoleHandler;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;

use App, Request, Response;

class Handler extends ExceptionHandler {

/**
* Render an exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
* @param \Exception $e
* @return \Illuminate\Http\Response
*/
public function render($request, Exception $e)
{
Console::addProfile('error', array(
'type' => $e->getCode(),
'message' => $e->getMessage(),
'file' => $e->getFile(),
'line' => $e->getLine(),
));

return Response::json(Console::getProfile(), 200);
}

}
16 changes: 1 addition & 15 deletions src/config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,6 @@
|
*/

'filter' => 'console_whitelist',

/*
|--------------------------------------------------------------------------
| Enable console only for this locations
|--------------------------------------------------------------------------
|
| Addresses allowed to access the console. This array is used in
| 'console_whitelist' route filter. Nevertheless, this bundle should never
| get nowhere near your production servers, but who am I to tell you how
| to live your life :)
|
*/

'whitelist' => array('127.0.0.1', '::1'),
'middleware' => ['web'],

);
17 changes: 11 additions & 6 deletions src/controllers/ConsoleController.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
<?php namespace Darsain\Console;
<?php

use \Controller, \View, \Input, \Response;
namespace Darsain\Console;

class ConsoleController extends Controller {
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\View;
use Illuminate\Support\Facades\Input;
use Illuminate\Support\Facades\Session;
use Illuminate\Support\Facades\Response;

class ConsoleController extends Controller
{
public function getIndex()
{
return View::make('laravel-console::console');
return View::make('console::console');
}

public function postExecute()
Expand All @@ -24,5 +30,4 @@ public function postExecute()
// Response
return Response::json($profile);
}

}
}
Loading