Skip to content
This repository
  • 2 commits
  • 9 files changed
  • 0 comments
  • 1 contributor
5  config/environment.php
@@ -10,7 +10,10 @@
10 10
 $config['env'] = array(
11 11
     //  Choose from "live" or "local" 
12 12
     //  Live will turn off debugging and error displaying, local will do the opposite
13  
-    'mode' => 'local'
  13
+    'mode' => 'local',
  14
+    
  15
+    //  Enable or disable the CLI environment
  16
+    'cli' => true
14 17
 );
15 18
 
16 19
 
13  core/bootstrapper.php
@@ -63,13 +63,16 @@
63 63
     include_once $scaffoldPath;
64 64
     $scaffold = new Scaffold($config, $classes);
65 65
     
66  
-    //  Load the default controller
67  
-    include_once CORE_BASE . 'defaults/controller.php';
68  
-    $controller = new Controller;
  66
+    if($config['env']['cli'] === true and PHP_SAPI === 'cli') {
  67
+        include_once CORE_BASE . 'cli/bootstrapper.php';
  68
+    } else {
  69
+        //  Load the default controller
  70
+        include_once CORE_BASE . 'defaults/controller.php';
  71
+        $controller = new Controller;
  72
+    }
69 73
 } else {
70 74
     $badFiles[] = $scaffoldPath;
71  
-    Error::log('Scaffold class not loaded. Sky is falling.');
72  
-    exit;
  75
+    die('Scaffold class not loaded. Sky is falling.');
73 76
 }
74 77
 
75 78
 //  When any errors get thrown, call our error class
4  core/classes/request.php
@@ -22,6 +22,10 @@ public static function post($url, $vars = array()) {
22 22
 	}
23 23
 	
24 24
 	private static function doRequest($url) {
  25
+	    if(!self::$_curl) {
  26
+	        self::init();
  27
+	    }
  28
+		
25 29
 		self::set(CURLOPT_RETURNTRANSFER, true);
26 30
 		self::set(CURLOPT_URL, $url);
27 31
 	}
33  core/cli/bootstrapper.php
... ...
@@ -1,25 +1,18 @@
1 1
 <?php !defined('IN_APP') and header('location: /');
2 2
 
3  
-//  Scaffold v0.1 CLI
4  
-//  SUPERBETA
  3
+/**
  4
+ *  Scaffold CLI v0.1
  5
+ */
  6
+ 
  7
+//  We make the errors, not PHP
  8
+//error_reporting(0);
5 9
 
6  
-error_reporting(0);
  10
+//  Include the command-line base
  11
+require_once 'command.php';
7 12
 
8  
-include_once 'cli.php';
  13
+//  Set up the Command Center
  14
+$cmd = new Command($argv);
  15
+$cmd->run();
9 16
 
10  
-// put some spacing before
11  
-echo "\n";
12  
-
13  
-//  Load our methods
14  
-if(isset($argv[1])) {
15  
-    $methods = include_once 'methods.php';
16  
-   	
17  
-    // create a new Cli object
18  
-    $cli = new Cli($argv, $methods);
19  
-    
20  
-    // parse the inputs
21  
-    $cli->parse();
22  
-}
23  
-
24  
-//  Stupid CLI
25  
-echo "\n" . "\n";
  17
+//  And we're done!
  18
+echo PHP_EOL;
34  core/cli/command.php
... ...
@@ -0,0 +1,34 @@
  1
+<?php !defined('IN_APP') and header('location: /');
  2
+
  3
+class Command {
  4
+    public $args;
  5
+    
  6
+    public function __construct($args = array()) {
  7
+        foreach($args as $arg) {
  8
+            $this->args[] = preg_replace('/[^A-Za-z0-9\-_]+/', '', $arg);
  9
+        }
  10
+    }
  11
+    
  12
+    public function arg($index, $fallback = '') {
  13
+        if(isset($this->args[$index])) {
  14
+            return $this->args[$index];
  15
+        }
  16
+        
  17
+        return $fallback;
  18
+    }
  19
+    
  20
+    public function run() {
  21
+        $path = CORE_BASE . 'cli/tasks/' . $this->arg(1) . '.php';
  22
+        $c = ucfirst($this->arg(1));
  23
+        
  24
+        if(!file_exists($path)) {
  25
+            $path = str_replace($this->arg(1), '_error', $path);
  26
+            $c = 'Error';
  27
+        }
  28
+        
  29
+        include_once $path;
  30
+        $this->task = new $c;
  31
+        
  32
+        echo $this->task->run($this->arg(2), $this->arg(3), $this->arg(4));
  33
+    }
  34
+}
43  core/cli/methods.php
... ...
@@ -1,7 +1,14 @@
1 1
 <?php
2 2
 
3  
-return array(
  3
+$methods = array(
  4
+    //  Install a helper
4 5
     'install' => function($arg) {
  6
+    
  7
+        if(!$arg) {
  8
+            echo 'Wait, what did you want me to install?';
  9
+            return;
  10
+        }
  11
+    
5 12
         // $endpoint = 'http://helpers.scaffold.im';
6 13
         $endpoint = 'http://localhost:8000/' . $arg;
7 14
         $json = json_decode(file_get_contents($endpoint . '/about.json'));
@@ -25,6 +32,7 @@
25 32
         }
26 33
     },
27 34
     
  35
+    //  Uninstall/remove a helper
28 36
     'uninstall' => function($arg) {
29 37
     	$path = APP_BASE . 'helpers/' . $arg . '.php';
30 38
     	
@@ -36,9 +44,34 @@
36 44
     	}
37 45
     },
38 46
     
39  
-    //  Alias these 
  47
+    //  Give the current Scaffold version
40 48
     'version' => SCAFFOLD_VERSION,
41  
-    '-v' => SCAFFOLD_VERSION,
42 49
     
43  
-    'update' => function() {}
44  
-);
  50
+    //  Update to the latest version
  51
+    'update' => function() {},
  52
+    
  53
+    //  What's the date?
  54
+    'now' => function() {
  55
+        echo time();
  56
+    },
  57
+    
  58
+    'url' => function() {
  59
+        `echo 'test' | pbcopy`
  60
+    }
  61
+);
  62
+
  63
+
  64
+function list_methods() {
  65
+    global $methods;
  66
+    return $methods;
  67
+}
  68
+
  69
+//  List methods
  70
+$methods['help'] = $methods['list'] = function() {
  71
+    echo 'You can currently call any of these methods:
  72
+
  73
+';
  74
+    foreach(list_methods() as $key => $val) {
  75
+        echo $key . "\n";
  76
+    }
  77
+};
27  core/cli/tasks/_error.php
... ...
@@ -0,0 +1,27 @@
  1
+<?php !defined('IN_APP') and header('location: /');
  2
+
  3
+class Error extends Command {
  4
+    //  Let's go.
  5
+    public function __construct() {
  6
+        parent::__construct();
  7
+    }
  8
+    
  9
+    //  And handle the argument
  10
+    public function run($arg) {
  11
+        $fails = array(
  12
+            'Task * not found.',
  13
+            'I beg your pardon?',
  14
+            'I will not be talked to in that way!',
  15
+            'Are you sure you spelt that right? * sounds wrong.',
  16
+            '0mgz0r5, you spelt a command wrong.',
  17
+            'What in blazes is *?',
  18
+            '* ain\'t no method I ever heard of.',
  19
+            'That does not exist, and probably never will do.',
  20
+            'Negatory, big buddy.',
  21
+            'Made a typo? * doesn\'t sound right.',
  22
+            'Bleep bloop bleep KTHWAWK.'
  23
+        );
  24
+        
  25
+        return str_replace('*', '"' . $arg . '"', $fails[mt_rand(0, count($fails) -1)]);
  26
+    } 
  27
+}
27  core/cli/tasks/install.php
... ...
@@ -0,0 +1,27 @@
  1
+<?php !defined('IN_APP') and header('location: /');
  2
+
  3
+class Install extends Command {
  4
+    //  Set a description for `./scaffold help`
  5
+    public static $description = 'Install a helper from the Helper Centre.';
  6
+    public static $endpoint = 'http://localhost:8000/';
  7
+    
  8
+    //  Let's go.
  9
+    public function __construct() {
  10
+        parent::__construct();
  11
+    }
  12
+    
  13
+    //  And handle the argument
  14
+    public function run($arg) {
  15
+        if(!$arg) {
  16
+            return $this->error('Wait, what did you want me to install?');
  17
+        }
  18
+        
  19
+        $json = $this->_getJSON($arg);
  20
+        
  21
+        return 'Helper "' . $arg . '" installed successfully.';
  22
+    } 
  23
+    
  24
+    private function _getJSON($slug) {
  25
+        return json_decode(Request::get(self::$endpoint . $slug . '/about.json'));
  26
+    }
  27
+}
2  public/index.php
@@ -32,7 +32,7 @@
32 32
 require BASE . 'config/paths.php';
33 33
 
34 34
 //  Load the boostrapper
35  
-require CORE_BASE . (PHP_SAPI === 'cli' ? 'cli/' : '') . 'bootstrapper.php';
  35
+require CORE_BASE . 'bootstrapper.php';
36 36
 
37 37
 //  Buh-bye!
38 38
 exit;

No commit comments for this range

Something went wrong with that request. Please try again.