Skip to content

Commit b96368f

Browse files
author
Samuel Akopyan
committed
Adding cache-clear command, preparing make:controller command
1 parent 98ad58e commit b96368f

File tree

4 files changed

+63
-42
lines changed

4 files changed

+63
-42
lines changed

framework/Apphp.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ public function run()
292292
{
293293
if ( ! in_array(APPHP_MODE, array('hidden', 'console')) ) {
294294
// Specify error settings
295-
if (APPHP_MODE == 'debug' || APPHP_MODE == 'test') {
295+
if (in_array(APPHP_MODE, ['debug', 'test'])) {
296296
error_reporting(E_ALL);
297297
ini_set('display_errors', 'On');
298298
} else {

framework/components/CLogger.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,14 @@ class CLogger extends CComponent
4545
function __construct()
4646
{
4747
$this->_enabled = CConfig::get('log.enable') !== '' ? CConfig::get('log.enable') : false;
48-
$this->_logPath = APPHP_PATH.DS.(CConfig::get('log.path') !== '' ? CConfig::get('log.path')
49-
: 'protected/tmp/logs/');
50-
$this->_fileExtension = CConfig::exists('log.fileExtension') && CConfig::get('log.fileExtension') !== ''
51-
? ltrim(CConfig::get('log.fileExtension'), '.') : 'php';
48+
$this->_logPath = APPHP_PATH.DS.(CConfig::get('log.path') !== '' ? CConfig::get('log.path') : 'protected/tmp/logs/');
49+
$this->_fileExtension = CConfig::exists('log.fileExtension') && CConfig::get('log.fileExtension') !== '' ? ltrim(CConfig::get('log.fileExtension'), '.') : 'php';
5250
$this->_dateFormat = CConfig::get('log.dateFormat') !== '' ? CConfig::get('log.dateFormat') : '';
5351
$this->_lifetime = CConfig::get('log.lifetime') !== '' ? CConfig::get('log.lifetime') : '';
5452
$logThreshold = CConfig::get('log.threshold') !== '' ? CConfig::get('log.threshold') : '';
5553
$logFilePermissions = CConfig::get('log.filePermissions') !== '' ? CConfig::get('log.filePermissions') : '';
5654

57-
if ( ! file_exists($this->_logPath)) {
55+
if ( APPHP_MODE !== 'console' && ! file_exists($this->_logPath)) {
5856
mkdir($this->_logPath, 0755, true);
5957
}
6058

framework/console/CCacheClearCommand.php

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -28,43 +28,44 @@ public static function handle($param = '')
2828
{
2929
$output = '';
3030

31-
//var_dump($argv);
32-
//var_dump($argc);
33-
3431
if (empty($param)) {
35-
$output .= CConsole::redbg("No cache type for deleting is defined. Type cache:clear -help").PHP_EOL;
36-
// } elseif ($param === '-h' || $param === '-help') {
37-
// $output .= CConsole::yellow("Usage:") . PHP_EOL;
38-
// $output .= " cache:clear-all\tFlush all application cache". PHP_EOL;
39-
// $output .= " cache:clear [type]\tFlush specific application cache". PHP_EOL;
40-
// $output .= " \t\t\t[type] - the type of cache to be removed: 'db', 'css', 'js' or 'all'". PHP_EOL;
41-
// } elseif (in_array($param, ['db', 'css', 'js', 'all'])) {
42-
// if($param == 'db' || $param == 'all'){
43-
// if (CConfig::get('cache.db.path') == '') {
44-
// $output .= CConsole::redbg("Config value 'cache.db.path' is not defined. Check your configuration file.") . PHP_EOL;
45-
// }else{
46-
// $result = CFile::emptyDirectory(CConfig::get('cache.db.path'), array('index.html'));
47-
// $output .= 'DB cache ' . ($result ? 'successfully cleaned' : 'error');
48-
// }
49-
// }
50-
// if($param == 'css' || $param == 'all'){
51-
// if (CConfig::get('compression.css.path') == '') {
52-
// $output .= CConsole::redbg("Config value 'compression.css.path' is not defined. Check your configuration file.") . PHP_EOL;
53-
// }else{
54-
// $result = CFile::emptyDirectory(CConfig::get('compression.css.path'), array('index.html'));
55-
// $output .= 'CSS cache ' . ($result ? 'successfully cleaned' : 'error');
56-
// }
57-
// }
58-
// if($param == 'js' || $param == 'all'){
59-
// if (CConfig::get('compression.js.path') == '') {
60-
// $output .= CConsole::redbg("Config value 'compression.js.path' is not defined. Check your configuration file.") . PHP_EOL;
61-
// }else{
62-
// $result = CFile::emptyDirectory(CConfig::get('compression.js.path'), array('index.html'));
63-
// $output .= 'JS cache ' . ($result ? 'successfully cleaned' : 'error');
64-
// }
65-
// }
32+
$output .= CConsole::redbg("No cache type for deleting is defined. Type cache:clear -h or --help").PHP_EOL;
33+
}
34+
elseif ($param === '-h' || $param === '--help') {
35+
$output .= CConsole::yellow("Usage:") . PHP_EOL;
36+
$output .= " cache:clear-all\tFlush all application cache". PHP_EOL;
37+
$output .= " cache:clear [type]\tFlush specific application cache". PHP_EOL;
38+
$output .= " \t\t\t[type] - the type of cache to be removed: 'db', 'css', 'js' or 'all'". PHP_EOL;
39+
}
40+
elseif (in_array($param, ['db', 'css', 'js', 'all'])) {
41+
if($param == 'db' || $param == 'all'){
42+
if (CConfig::get('cache.db.path') == '') {
43+
$output .= CConsole::redbg("Config value 'cache.db.path' is not defined. Check your configuration file.") . PHP_EOL;
44+
}else{
45+
$result = CFile::emptyDirectory(CConfig::get('cache.db.path'), array('index.html'));
46+
$output .= 'DB cache ' . ($result ? 'successfully cleaned' : 'error');
47+
}
48+
}
49+
if($param == 'css' || $param == 'all'){
50+
if (CConfig::get('compression.css.path') == '') {
51+
$output .= CConsole::redbg("Config value 'compression.css.path' is not defined. Check your configuration file.") . PHP_EOL;
52+
}else{
53+
$result = CFile::emptyDirectory(CConfig::get('compression.css.path'), array('index.html'));
54+
$output .= 'CSS cache ' . ($result ? 'successfully cleaned' : 'error');
55+
}
56+
}
57+
if($param == 'js' || $param == 'all'){
58+
if (CConfig::get('compression.js.path') == '') {
59+
$output .= CConsole::redbg("Config value 'compression.js.path' is not defined. Check your configuration file.") . PHP_EOL;
60+
}else{
61+
$result = CFile::emptyDirectory(CConfig::get('compression.js.path'), array('index.html'));
62+
$output .= 'JS cache ' . ($result ? 'successfully cleaned' : 'error');
63+
}
64+
}
65+
}
66+
else {
67+
$output .= CConsole::redbg("No cache type for deleting is defined or wrong parameters. Type cache:clear -h or --help").PHP_EOL;
6668
}
67-
6869

6970
return $output;
7071
}

framework/console/CMakeControllerCommand.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,29 @@ class CMakeControllerCommand implements IConsoleCommand
2626
*/
2727
public static function handle($param = '')
2828
{
29-
$output = 'Controller created: '.$param;
29+
$output = '';
30+
31+
if (empty($param)) {
32+
$output .= CConsole::redbg("No model name is defined. Type make:controller -h or --help").PHP_EOL;
33+
}
34+
elseif ($param === '-h' || $param === '--help') {
35+
$output .= CConsole::yellow("Usage:") . PHP_EOL;
36+
$output .= " make:controller [model]\t Create a new controller class". PHP_EOL;
37+
$output .= " \t\t\t\t[model] - Generate a resource controller for the given model.". PHP_EOL;
38+
}
39+
elseif (CValidator::isVariable($param)) {
40+
// TODO: create controller
41+
}
42+
else {
43+
if (!CValidator::isVariable($param)){
44+
$output .= CConsole::redbg("The model name must be a valid controller name (alphanumeric, starts with letter and can contain an underscore)! Please re-enter.").PHP_EOL;
45+
} else {
46+
$output .= CConsole::redbg("No model name is defined or wrong parameters. Type make:controller -h or --help").PHP_EOL;
47+
}
48+
}
49+
50+
//echo $param;
51+
//$output = 'Controller created: '.$param;
3052

3153
return $output;
3254
}

0 commit comments

Comments
 (0)