8000 Simple CLI utility by mohitjawanjal · Pull Request #8 · feat7/Surface · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Simple CLI utility #8

New issue

Have a question about this proje 8000 ct? 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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions app/console/Welcome.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace app\console;

class Welcome{

/**
* Default method. This method will be called if no args are given
*/
public function run($args){
echo "Hello World!";
}

/**
* Custom method. Has to be specified in command as "./surface welcome another"
*/

public function another($args){
echo "Another Method";
}
}
48 changes: 48 additions & 0 deletions console
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/env php
<?php

use \app\config\Config;

require_once 'env.config.php';
use Illuminate\Database\Capsule\Manager as Capsule;

/**
* @Implementing Autoloader with two base namespaces.
*/

$loader = require 'vendor/autoload.php';
$loader->add('system', __DIR__);
$loader->add('app', __DIR__);

/**
* @Let us eat a capsule to use eloquent
*/

$capsule = new Capsule;

$capsule->addConnection([
'driver' => 'mysql',
'host' => DB_HOST,
'database' => DB_NAME,
'username' => DB_USER,
'password' => DB_PASS,
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
]);

// Set the event dispatcher used by Eloquent models... (optional)
use Illuminate\Events\Dispatcher;
use Illuminate\Container\Container;
$capsule->setEventDispatcher(new Dispatcher(new Container));

// Make this Capsule instance available globally via static methods... (optional)
$capsule->setAsGlobal();

// Setup the Eloquent ORM... (optional; unless you've used setEventDispatcher())
$capsule->bootEloquent(); //eloquent boot done

// Run the command
use system\console\Command;

$command = new Command($argv);
42 changes: 42 additions & 0 deletions system/console/Command.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace system\console;

use app\console;

class Command{

public function __construct($argv) {
array_shift($argv);
$className = ucwords($argv[0]);
array_shift($argv);
if(empty($argv)){
$methodName = "run";
}
else{
$methodName = $argv[0];
array_shift($argv);
}

try{
$this->run($className,$methodName, $argv);
}catch(Exception $e){

}
}

public function run($className, $methodName, $args){

$objectName = '\app\console\\'.$className;

if(method_exists($objectName, $methodName)) {

$object = new $objectName;
$object->{$methodName}($args);

4757 }
else{
echo "Method not found";
}
}
}
0