Compare commits

..

No commits in common. "97a6b4b7cbcffd181f7517a9fedcb6efc4dd1c31" and "6aa41133109e5b94286f06cbf22968c3bb8c5f05" have entirely different histories.

4 changed files with 30 additions and 149 deletions

View file

@ -16,4 +16,4 @@ else
die("Fail to find composer vendor/autoload.php file\n");
App::init(null, null, __DIR__);
Cli :: handle_args(null, true);
Cli :: handle_args();

View file

@ -75,38 +75,6 @@ class Check {
return true;
}
public static function ip_address($ip, $allow_private_ip_address=true, $allow_reserved_ip_address=false,
$ipv4_only=false, $ipv6_only=false) {
$flag = null;
if ($ipv4_only)
$flag |= FILTER_FLAG_IPV4;
if ($ipv6_only)
$flag |= FILTER_FLAG_IPV6;
if (!isset($allow_private_ip_address) || !$allow_private_ip_address)
$flag |= FILTER_FLAG_NO_PRIV_RANGE;
if (!isset($allow_reserved_ip_address) || !$allow_reserved_ip_address)
$flag |= FILTER_FLAG_NO_RES_RANGE;
if (!is_null($flag))
return (bool)filter_var($ip, FILTER_VALIDATE_IP, $flag);
else
return (bool)filter_var($ip, FILTER_VALIDATE_IP);
}
public static function tcp_or_udp_port($value) {
if (!is_int($value)) {
if (!preg_match('/^[0-9]+$/', $value))
return false;
$value = intval($value);
}
if ($value <= 0) return false;
if ($value > 65635) return false;
return true;
}
public static function is_empty($val) {
switch(gettype($val)) {
case "boolean":

View file

@ -6,38 +6,13 @@ use Exception;
class Cli {
/**
* EesyPHP core mode
*/
private static $core_mode = false;
/**
* Initialize
* @return void
*/
public static function init() {
Hook :: register('cli_set_core_mode', array('\\EesyPHP\\Cli', 'on_cli_set_core_mode'));
}
/**
* Get/set core mode
* @return bool
*/
public static function core_mode($enable=null) {
if (!is_null($enable)) {
self :: $core_mode = boolval($enable);
Hook :: trigger('cli_set_core_mode', array('enabled' => self :: $core_mode));
}
return self :: $core_mode;
}
/**
* On CLI set core mode hook
* @param \EesyPHP\HookEvent $event
* @return void
*/
public static function on_cli_set_core_mode($event) {
if ($event->enabled) {
if (php_sapi_name() != 'cli')
return;
self :: add_command(
'new_project',
array('\\EesyPHP\\Cli', 'cli_new_project'),
@ -48,18 +23,6 @@ class Cli {
"EesyPHP framework.")
);
}
else {
self :: add_command(
'serve',
array('\\EesyPHP\\Cli', 'cli_serve'),
I18n :: ___("Start the PHP built-in HTTP server to serve the application"),
null,
I18n :: ___(
"This command could be used to start the PHP built-in HTTP server to serve the ".
"application.")
);
}
}
/**
* Registered commands
@ -164,12 +127,10 @@ class Cli {
/**
* Handle command line arguments
* @param array|null $args Command line argurment to handle (optional, default: $argv)
* @param bool|null $core_mode Force enable/disable EesyPHP core mode (optional, default: null)
* @return void
*/
public static function handle_args($args=null, $core_mode=null) {
public static function handle_args($args=null) {
global $argv;
self :: core_mode($core_mode);
$args = is_array($args)?$args:array_slice($argv, 1);
$log_level_set = false;
self :: $command = null;
@ -283,57 +244,4 @@ class Cli {
echo "done. Start coding!\n";
}
/**
* Command to start PHP built-in HTTP server to serve the EesyPHP project
*
* @param array $command_args The command arguments
* @return void
*/
public static function cli_serve($command_args) {
if (count($command_args) > 1) {
self :: usage(
_('This command only accept one argument (the listen address in formart host:port).')
);
return;
}
// Check listen address
$listen_address = ($command_args?$command_args[0]:'127.0.0.1:8000');
$parts = explode(':', $listen_address);
if (count($parts) != 2) {
self :: usage(
_('Invalid listen address specify. Must be in formart host:port.')
);
return;
}
if (empty($parts[0])) {
$parts[0] = '0.0.0.0';
}
else if (!Check::ip_address($parts[0])) {
self :: usage(
_('Invalid listen host specified. Must be an IPv4 or IPv6 address.')
);
return;
}
if (!Check::tcp_or_udp_port($parts[1])) {
self :: usage(
_('Invalid listen port specified. Must be a positive integer between 1 and 65535.')
);
return;
}
$listen_address = implode(':', $parts);
$public_html = App::get('root_directory_path')."/public_html";
chdir($public_html) or die(
sprintf(
'Fail to enter in the public_html directory of the application (%s).',
$public_html
)
);
passthru(PHP_BINARY." -S $listen_address index.php", $exit_code);
exit($exit_code);
}
}

View file

@ -319,12 +319,13 @@ class I18n {
* @return void
*/
public static function cli_extract_messages($command_args) {
$root_path = Cli::core_mode()?self::$core_root_path:self::$root_path;
$core_mode = in_array('--core', $command_args);
$root_path = $core_mode?self::$core_root_path:self::$root_path;
// Store list of generated POT files
$pot_files = array();
if (Cli::core_mode()) {
if ($core_mode) {
// List EesyPHP PHP files to parse
$eesyphp_php_files = run_external_command(
array(
@ -400,8 +401,8 @@ class I18n {
// Extract messages from JS files using xgettext in each registered static directories
foreach(Tpl::static_directories() as $idx => $static_directory) {
if (Cli::core_mode() && $static_directory != Tpl::$core_static_directory) continue;
if (!Cli::core_mode() && $static_directory == Tpl::$core_static_directory) continue;
if ($core_mode && $static_directory != Tpl::$core_static_directory) continue;
if (!$core_mode && $static_directory == Tpl::$core_static_directory) continue;
// List JS files to parse
$result = run_external_command(
array('find', escapeshellarg(basename($static_directory)), '-name', "'*.js'"),
@ -440,8 +441,8 @@ class I18n {
if (Tpl :: initialized()) {
foreach (Tpl :: templates_directories() as $idx => $templates_directory) {
if (Cli::core_mode() && $templates_directory != Tpl::$core_templates_directory) continue;
if (!Cli::core_mode() && $templates_directory == Tpl::$core_templates_directory) continue;
if ($core_mode && $templates_directory != Tpl::$core_templates_directory) continue;
if (!$core_mode && $templates_directory == Tpl::$core_templates_directory) continue;
// Extract messages from templates files using tsmarty2c.php
$result = run_external_command(
array(
@ -501,17 +502,20 @@ class I18n {
* @return bool
*/
public static function cli_update_messages($command_args) {
$core_mode = false;
$compendium_args = array();
foreach ($command_args as $arg) {
if (!file_exists($arg))
if ($arg == '--core')
$core_mode = true;
else if (!file_exists($arg))
Log :: fatal(self::_("Compendium file %s not found."), $arg);
else {
$compendium_args[] = '-C';
$compendium_args[] = $arg;
}
}
$domain = Cli::core_mode()?self::CORE_TEXT_DOMAIN:self::TEXT_DOMAIN;
$root_path = Cli::core_mode()?self::$core_root_path:self::$root_path;
$domain = $core_mode?self::CORE_TEXT_DOMAIN:self::TEXT_DOMAIN;
$root_path = $core_mode?self::$core_root_path:self::$root_path;
$pot_file = "$root_path/messages.pot";
if (!is_file($pot_file))
@ -591,8 +595,9 @@ class I18n {
* @return bool
*/
public static function cli_compile_messages($command_args) {
$domain = Cli::core_mode()?self::CORE_TEXT_DOMAIN:self::TEXT_DOMAIN;
$root_path = Cli::core_mode()?self::$core_root_path:self::$root_path;
$core_mode = in_array('--core', $command_args);
$domain = $core_mode?self::CORE_TEXT_DOMAIN:self::TEXT_DOMAIN;
$root_path = $core_mode?self::$core_root_path:self::$root_path;
if ($dh = opendir($root_path)) {
$error = False;
while (($file = readdir($dh)) !== false) {
@ -671,7 +676,7 @@ class I18n {
}
// Compile messages from PO file to JS catalog file
$js_catalog = self :: po2json($lang, $po_file, Cli::core_mode());
$js_catalog = self :: po2json($lang, $po_file, $core_mode);
$js_file = "$root_path/$lang.js";
if(!$fd = fopen($js_file, 'w')) {
Log :: error(self::_("Fail to open %s JS catalog file in write mode (%s)."),