コード例 #1
0
 public function __construct()
 {
     $that = $this;
     $this['config.path'] = function ($c) {
         $filename = 'cliframework.ini';
         $configAtCurrentDirectory = getcwd() . DIRECTORY_SEPARATOR . $filename;
         $configAtHomeDirectory = getenv('HOME') . DIRECTORY_SEPARATOR . $filename;
         if (file_exists($configAtCurrentDirectory)) {
             return $configAtCurrentDirectory;
         }
         if (file_exists($configAtHomeDirectory)) {
             return $configAtHomeDirectory;
         }
         return null;
     };
     $this['event'] = function () {
         return new PhpEvent();
     };
     $this['config'] = function ($c) {
         if (empty($c['config.path']) || !$c['config.path']) {
             return new GlobalConfig(array());
         }
         return new GlobalConfig(parse_ini_file($c['config.path'], true));
     };
     $this['writer'] = function ($c) {
         // return new StreamWriter(STDOUT);
         $output = fopen("php://output", "w");
         return new StreamWriter($output);
     };
     $this['logger'] = function ($c) use($that) {
         return new Logger($that);
     };
     $this['formatter'] = function ($c) {
         return new Formatter();
     };
     $this['console.stty'] = function ($c) use($that) {
         if ($that->isWindows()) {
             // TODO support Windows
             return new NullStty();
         }
         return new UnixStty();
     };
     $this['console'] = function ($c) {
         if (ReadlineConsole::isAvailable()) {
             return new ReadlineConsole($c['console.stty']);
         }
         return new StandardConsole($c['console.stty']);
     };
     $this['command_loader'] = function ($c) {
         return CommandLoader::getInstance();
     };
     parent::__construct();
 }
コード例 #2
0
ファイル: CommandBase.php プロジェクト: arunahk/CLIFramework
 /**
  * Returns command loader object.
  */
 public function getLoader()
 {
     return CommandLoader::getInstance();
 }