1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* RisolutoCli.php |
4
|
|
|
* |
5
|
|
|
* Risoluto Cliプログラムを実行する |
6
|
|
|
* |
7
|
|
|
* @package risoluto |
8
|
|
|
* @author Risoluto Developers |
9
|
|
|
* @license http://opensource.org/licenses/bsd-license.php new BSD license |
10
|
|
|
* @copyright (C) 2008-2015 Risoluto Developers / All Rights Reserved. |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
//------------------------------------------------------// |
14
|
|
|
// 名前空間の定義 |
15
|
|
|
//------------------------------------------------------// |
16
|
|
|
namespace RisolutoCli; |
17
|
|
|
|
18
|
|
|
//------------------------------------------------------// |
19
|
|
|
// 定数定義 |
20
|
|
|
//------------------------------------------------------// |
21
|
|
|
define( 'RISOLUTODIR', dirname( dirname( dirname( __FILE__ ) ) ) ); |
22
|
|
|
|
23
|
|
|
define( 'RISOLUTO_SYSROOT', RISOLUTODIR . '/risoluto/' ); |
24
|
|
|
|
25
|
|
|
define( 'RISOLUTO_APPS', RISOLUTO_SYSROOT . 'apps/' ); |
26
|
|
|
define( 'RISOLUTO_CLI', RISOLUTO_SYSROOT . 'cli/' ); |
27
|
|
|
define( 'RISOLUTO_CONF', RISOLUTO_SYSROOT . 'conf/' ); |
28
|
|
|
define( 'RISOLUTO_DATA', RISOLUTO_SYSROOT . 'data/' ); |
29
|
|
|
define( 'RISOLUTO_LIB', RISOLUTO_SYSROOT . 'lib/' ); |
30
|
|
|
|
31
|
|
|
define( 'RISOLUTO_CACHE', RISOLUTO_DATA . 'cache/' ); |
32
|
|
|
define( 'RISOLUTO_LOGS', RISOLUTO_DATA . 'logs/' ); |
33
|
|
|
define( 'RISOLUTO_SESS', RISOLUTO_DATA . 'sess/' ); |
34
|
|
|
define( 'RISOLUTO_UPLOAD', RISOLUTO_DATA . 'upload/' ); |
35
|
|
|
|
36
|
|
|
define( 'RISOLUTO_LIB_VENDOR', RISOLUTO_LIB . 'vendor/' ); |
37
|
|
|
|
38
|
|
|
define( 'DS', DIRECTORY_SEPARATOR ); |
39
|
|
|
|
40
|
|
|
//------------------------------------------------------// |
41
|
|
|
// 動作環境チェック |
42
|
|
|
//------------------------------------------------------// |
43
|
|
|
// PHPバージョンが指定された以前のものであれば強制終了 |
44
|
|
|
if (version_compare( PHP_VERSION, '5.5.0', '<' )) { |
45
|
|
|
exit( 'Risoluto requires PHP 5.5.0 or later...' ); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
if (PHP_SAPI !== 'cli') { |
49
|
|
|
exit( 'Cli environment required...' ); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
//------------------------------------------------------// |
53
|
|
|
// インクルードパスの変更 |
54
|
|
|
//------------------------------------------------------// |
55
|
|
|
set_include_path( RISOLUTO_LIB_VENDOR . PATH_SEPARATOR |
56
|
|
|
. RISOLUTO_APPS . PATH_SEPARATOR |
57
|
|
|
. get_include_path() ); |
58
|
|
|
|
59
|
|
|
//------------------------------------------------------// |
60
|
|
|
// オートローダ読み込みと設定 |
61
|
|
|
//------------------------------------------------------// |
62
|
|
|
$autoloader = RISOLUTO_LIB_VENDOR . 'autoload.php'; |
63
|
|
|
|
64
|
|
|
clearstatcache( true ); |
65
|
|
View Code Duplication |
if (file_exists( $autoloader ) and is_file( $autoloader ) and is_readable( $autoloader )) { |
|
|
|
|
66
|
|
|
// オートローダが存在すれば読み込む |
67
|
|
|
/** @noinspection PhpIncludeInspection */ |
68
|
|
|
require_once( $autoloader ); |
69
|
|
|
} else { |
70
|
|
|
// 存在しなければ強制終了 |
71
|
|
|
exit( "この必須ファイルが存在しないかロードできません: $autoloader" ); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
//------------------------------------------------------// |
75
|
|
|
// 引数のチェック |
76
|
|
|
//------------------------------------------------------// |
77
|
|
|
/** @noinspection PhpUndefinedVariableInspection */ |
78
|
|
|
if ($argc < 2) { |
79
|
|
|
/** @noinspection PhpUndefinedVariableInspection */ |
80
|
|
|
die( "Usage: php $argv[0] {your cli program} {options...}" . PHP_EOL ); |
81
|
|
|
} else { |
82
|
|
|
// 不要な情報を排除(配列の先頭はこのプログラムのため、ユーザサイドのCliプログラムには不要な情報である) |
83
|
|
|
/** @noinspection PhpUndefinedVariableInspection */ |
84
|
|
|
$options = $argv; |
85
|
|
|
|
86
|
|
|
define( 'RISOLUTOCLI_PGM', array_shift( $options ) ); |
87
|
|
|
define( 'RISOLUTOCLI_SELF', array_shift( $options ) ); |
88
|
|
|
$callable = '\\RisolutoCli\\' . RISOLUTOCLI_SELF; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
//------------------------------------------------------// |
92
|
|
|
// インスタンスの生成と実行 |
93
|
|
|
//------------------------------------------------------// |
94
|
|
|
/** @noinspection PhpUnnecessaryFullyQualifiedNameInspection */ |
95
|
|
|
$instance = new $callable; |
96
|
|
|
/** @noinspection PhpUndefinedMethodInspection */ |
97
|
|
|
$instance->run( $options ); |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.