This repository has been archived by the owner on Nov 24, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add 'fs' CLI command for generate a whole module. example: php fs g MyModule
- Loading branch information
Showing
11 changed files
with
951 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
/** | ||
* The FuelStart Fs cli was copied from FuelPhp Oil. | ||
*/ | ||
|
||
/** | ||
* Refuse to run oil when called from php-cgi ! | ||
*/ | ||
if (substr(php_sapi_name(), 0, 3) == 'cgi') | ||
{ | ||
die("The use of cli is not supported when running php-cgi. CLI needs php-cli to function!\n\n"); | ||
} | ||
|
||
/** | ||
* Set error reporting and display errors settings. You will want to change these when in production. | ||
*/ | ||
error_reporting(-1); | ||
ini_set('display_errors', 1); | ||
|
||
/** | ||
* Website document root | ||
*/ | ||
define('DOCROOT', __DIR__.DIRECTORY_SEPARATOR); | ||
|
||
/** | ||
* Path to the application directory. | ||
*/ | ||
define('APPPATH', realpath(__DIR__.'/fuel/app/').DIRECTORY_SEPARATOR); | ||
|
||
/** | ||
* Path to the default packages directory. | ||
*/ | ||
define('PKGPATH', realpath(__DIR__.'/fuel/packages/').DIRECTORY_SEPARATOR); | ||
|
||
/** | ||
* The path to the framework core. | ||
*/ | ||
define('COREPATH', realpath(__DIR__.'/fuel/core/').DIRECTORY_SEPARATOR); | ||
|
||
// Get the start time and memory for use later | ||
defined('FUEL_START_TIME') or define('FUEL_START_TIME', microtime(true)); | ||
defined('FUEL_START_MEM') or define('FUEL_START_MEM', memory_get_usage()); | ||
|
||
// Load in the Fuel autoloader | ||
require COREPATH.'classes'.DIRECTORY_SEPARATOR.'autoloader.php'; | ||
class_alias('Fuel\\Core\\Autoloader', 'Autoloader'); | ||
|
||
// Boot the app | ||
require APPPATH.'bootstrap.php'; | ||
|
||
Package::load('fs'); | ||
|
||
// Fire up the command line interfact | ||
Fs\Command::init($_SERVER['argv']); | ||
|
||
/* End of file oil */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
<?php | ||
/** | ||
* Extend theme class | ||
* | ||
* @author Vee W. | ||
*/ | ||
|
||
class Theme extends \Fuel\Core\Theme | ||
{ | ||
|
||
|
||
public function __construct(array $config = array()) { | ||
parent::__construct($config); | ||
}// __construct | ||
|
||
|
||
/** | ||
* find view file<br> | ||
* this method that extends fuelphp core theme is for re-arrange priority of theme and views. | ||
* | ||
* @param string $view | ||
* @param string $themes | ||
* @return string | ||
*/ | ||
protected function find_file($view, $themes = null) | ||
{ | ||
if ($themes === null) { | ||
$themes = array($this->active, $this->fallback); | ||
} | ||
|
||
// determine the path prefix and optionally the module path | ||
$path_prefix = ''; | ||
$module_path = null; | ||
if ($this->config['use_modules'] and class_exists('Request', false) and $request = \Request::active() and $module = $request->module) { | ||
// we're using module name prefixing | ||
$path_prefix = $module.DS; | ||
|
||
// and modules are in a separate path | ||
is_string($this->config['use_modules']) and $path_prefix = trim($this->config['use_modules'], '\\/').DS.$path_prefix; | ||
|
||
// do we need to check the module too? | ||
$this->config['use_modules'] === true and $module_path = \Module::exists($module).'themes'.DS; | ||
} | ||
|
||
foreach ($themes as $theme) { | ||
$ext = pathinfo($view, PATHINFO_EXTENSION) ? | ||
'.'.pathinfo($view, PATHINFO_EXTENSION) : $this->config['view_ext']; | ||
$file = (pathinfo($view, PATHINFO_DIRNAME) ? | ||
str_replace(array('/', DS), DS, pathinfo($view, PATHINFO_DIRNAME)).DS : ''). | ||
pathinfo($view, PATHINFO_FILENAME); | ||
|
||
if (empty($theme['find_file'])) { | ||
if ($module_path and ! empty($theme['name']) and is_file($path = $module_path.$theme['name'].DS.$file.$ext)) { | ||
// if use_modules is true then this $path will be /www/root/modules/<module name>/themes/<theme name>/<$view>.php | ||
return $path; | ||
} elseif (is_file($path = $theme['path'].$path_prefix.$file.$ext)) { | ||
// if use_modules is true then $path will be /www/root/<theme path>/<theme name>/<module name>/<$view>.php | ||
// if use_modules is 'modules' then $path will be /www/root/<theme path>/<theme name>/modules/<module name>/<$view>.php | ||
return $path; | ||
} elseif (is_file($path = \Module::exists($module) . 'views' . DS . $file . $ext)) { | ||
/** | ||
* this condition was added by Vee W. | ||
* look directly in modules/module_name/views. this $path will be /www/root/<modules path>/<module name>/views/<$view>.php | ||
* | ||
* @author Vee W. | ||
*/ | ||
return $path; | ||
} elseif (is_file($path = $theme['path'].$file.$ext)) { | ||
// this will not look into module name anymore. $path will be /www/root/<theme path>/<theme name>/<$view>.php | ||
return $path; | ||
} | ||
} else { | ||
if ($path = \Finder::search($theme['path'].$path_prefix, $file, $ext)) { | ||
return $path; | ||
} | ||
} | ||
} | ||
|
||
// not found, return the viewname to fall back to the standard View processing | ||
return $view; | ||
}// find_file | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
Autoloader::add_classes(array( | ||
'Fs\\Command' => __DIR__.'/classes/command.php', | ||
'Fs\\Exception' => __DIR__.'/classes/exception.php', | ||
'Fs\\Generate' => __DIR__.'/classes/generate.php', | ||
)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
<?php | ||
|
||
namespace Fs; | ||
|
||
/** | ||
* FuelStart CLI command | ||
* | ||
* @author Vee W. | ||
* | ||
* The FuelStart Fs cli was copied from FuelPhp Oil. | ||
*/ | ||
class Command | ||
{ | ||
|
||
|
||
protected static function _clear_args($actions = array()) | ||
{ | ||
foreach ($actions as $key => $action) | ||
{ | ||
if (substr($action, 0, 1) === '-') | ||
{ | ||
unset($actions[$key]); | ||
} | ||
|
||
// get rid of any junk added by Powershell on Windows... | ||
isset($actions[$key]) and $actions[$key] = trim($actions[$key]); | ||
} | ||
|
||
return $actions; | ||
}// _clear_args | ||
|
||
|
||
public static function help() | ||
{ | ||
echo <<<HELP | ||
Usage: | ||
php fs [g|generate] [module_name] | ||
[generate] is generete the module. | ||
[module_name] is the module name. It should be StudlyCaps as PSR-1 specified. | ||
Description: | ||
The 'fs' is FuelStart command, It will be use for generate module that is ready to code. | ||
HELP; | ||
}// help | ||
|
||
|
||
public static function init($args) | ||
{ | ||
// Remove flag options from the main argument list | ||
$args = self::_clear_args($args); | ||
|
||
try { | ||
if (!isset($args[1])) { | ||
static::help(); | ||
return false; | ||
} | ||
|
||
switch ($args[1]) { | ||
case 'g': | ||
case 'generate': | ||
if (!isset($args[2])) { | ||
\Cli::error('Please enter module name.'); | ||
\Cli::beep(); | ||
return false; | ||
} | ||
|
||
call_user_func('Fs\Generate::module', array_slice($args, 2)); | ||
break; | ||
default: | ||
static::help(); | ||
} | ||
} catch (\Exception $e) { | ||
static::print_exception($e); | ||
exit(1); | ||
}// end try catch | ||
}// init | ||
|
||
|
||
protected static function print_exception(\Exception $ex) | ||
{ | ||
\Cli::error('Uncaught exception '.get_class($ex).': '.$ex->getMessage()); | ||
if (\Fuel::$env != \Fuel::PRODUCTION) | ||
{ | ||
\Cli::error('Callstack: '); | ||
\Cli::error($ex->getTraceAsString()); | ||
} | ||
\Cli::beep(); | ||
\Cli::option('speak') and `say --voice="Trinoids" "{$ex->getMessage()}"`; | ||
|
||
if (($previous = $ex->getPrevious()) != null) | ||
{ | ||
\Cli::error(''); | ||
\Cli::error('Previous exception: '); | ||
static::print_exception($previous); | ||
} | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
namespace Fs; | ||
|
||
class Exception extends \Exception | ||
{ | ||
|
||
// public function __toString() | ||
// { | ||
// \Cli::write('Error: ' . $this->message); | ||
// } | ||
|
||
} |
Oops, something went wrong.