Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
joecwallace committed Jan 16, 2013
0 parents commit 8b054c3
Show file tree
Hide file tree
Showing 10 changed files with 282 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/vendor
composer.phar
composer.lock
.DS_Store
11 changes: 11 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
language: php

php:
- 5.3
- 5.4

before_script:
- curl -s http://getcomposer.org/installer | php
- php composer.phar install --dev

script: phpunit
27 changes: 27 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "joecwallace/artisan",
"description": "A web interface for the Laravel Artisan CLI",
"keywords": [ "laravel", "artisan" ],
"license": "MIT",
"authors": [
{
"name": "Joe Wallace",
"email": "[email protected]"
}
],
"require": {
"php": ">=5.3.0",
"illuminate/support": "4.0.x"
},
"autoload": {
"psr-0": {
"Joecwallace\\Artisan": "src/"
}
},
"minimum-stability": "dev",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
}
}
18 changes: 18 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
>
<testsuites>
<testsuite name="Package Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>
</phpunit>
28 changes: 28 additions & 0 deletions src/Joecwallace/Artisan/ArtisanRunner.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php namespace Joecwallace\Artisan;

use Illuminate\Console\Application;
use Illuminate\Support\Facades\Config;

class ArtisanRunner
{
public static function run(array $args = array())
{
array_unshift($args, 'artisan');

$app = app();
$providers = $app->getLoadedProviders();

foreach (Config::get('app.providers') as $provider)
{
if ( ! isset($providers[$provider]))
{
$app->register(new $provider($app));
}
}

$_SERVER['argv'] = $args;
$output = new HtmlOutput;

Application::start($app)->run(null, $output);
}
}
46 changes: 46 additions & 0 deletions src/Joecwallace/Artisan/ArtisanWebServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php namespace Joecwallace\Artisan;

use Illuminate\Support\ServiceProvider;

class ArtisanWebServiceProvider 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('joecwallace/artisan');

include __DIR__.'/routes.php';
}

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

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

}
126 changes: 126 additions & 0 deletions src/Joecwallace/Artisan/HtmlOutput.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
<?php namespace Joecwallace\Artisan;

use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Formatter\OutputFormatterInterface;

class HtmlOutput implements OutputInterface
{

protected $verbosity = OutputInterface::VERBOSITY_VERBOSE;
protected $decorated = true;
protected $formatter = null;

protected function formatOutput($message)
{
return str_replace(PHP_EOL, '<br>', $message);
}

/**
* Writes a message to the output.
*
* @param string|array $messages The message as an array of lines of a single string
* @param Boolean $newline Whether to add a newline or not
* @param integer $type The type of output (0: normal, 1: raw, 2: plain)
*
* @throws \InvalidArgumentException When unknown output type is given
*
* @api
*/
public function write($messages, $newline = false, $type = 0)
{
$messages = (array)$messages;

foreach ($messages as $message)
{
echo $this->formatOutput($message);
}

if ($newline) echo '<br>';
}

/**
* Writes a message to the output and adds a newline at the end.
*
* @param string|array $messages The message as an array of lines of a single string
* @param integer $type The type of output (0: normal, 1: raw, 2: plain)
*
* @api
*/
public function writeln($messages, $type = 0)
{
$this->write($messages, true, $type);
}

/**
* Sets the verbosity of the output.
*
* @param integer $level The level of verbosity
*
* @api
*/
public function setVerbosity($level)
{
$this->verbosity = $level;
}

/**
* Gets the current verbosity of the output.
*
* @return integer The current level of verbosity
*
* @api
*/
public function getVerbosity()
{
return $this->verbosity;
}

/**
* Sets the decorated flag.
*
* @param Boolean $decorated Whether to decorate the messages or not
*
* @api
*/
public function setDecorated($decorated)
{
$this->decorated = $decorated;
}

/**
* Gets the decorated flag.
*
* @return Boolean true if the output will decorate messages, false otherwise
*
* @api
*/
public function isDecorated()
{
return $this->decorated;
}

/**
* Sets output formatter.
*
* @param OutputFormatterInterface $formatter
*
* @api
*/
public function setFormatter(OutputFormatterInterface $formatter)
{
$this->formatter = $formatter;
}

/**
* Returns current output formatter instance.
*
* @return OutputFormatterInterface
*
* @api
*/
public function getFormatter()
{
return $this->formatter;
}

}
15 changes: 15 additions & 0 deletions src/Joecwallace/Artisan/routes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

use Joecwallace\Artisan\ArtisanRunner as Runner;
use Joecwallace\Artisan\HtmlOutput;

Route::get(Config::get('artisan::handles').'{uri}', function($uri = '')
{
$args = array();

if ( ! empty($uri)) {
$args = explode('+', trim($uri, '/'));
}

Runner::run($args);
})->where('uri', '^($|\/.*)');
7 changes: 7 additions & 0 deletions src/config/config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

return array(

'handles' => 'artisan',

);
Empty file added tests/.gitkeep
Empty file.

0 comments on commit 8b054c3

Please sign in to comment.