コード例 #1
0
ファイル: Database.php プロジェクト: javinc/Framework
 /**
  * Tries to gather what we need for this task to run
  *
  * @param array $args CLI arguments
  *
  * @return Eve\Framework\Cli\Database
  */
 public function setup($args)
 {
     if (count($args) < 2) {
         Index::error('Not enough arguments.', 'Usage: eve database <schema>');
     }
     $this->name = $args[1];
     $file = $this->cwd . '/schema/' . $this->name . '.php';
     if (!file_exists($file)) {
         Index::error('Cannot find schema/' . $this->name . '.php');
     }
     $this->schema = (include $this->cwd . '/schema/' . $this->name . '.php');
     if (!is_array($this->schema)) {
         Index::error('Schema is invalid.');
     }
     $file = $this->cwd . '/settings/databases.php';
     if (!file_exists($file)) {
         Index::error('Cannot find settings/databases.php');
     }
     $databases = (include $this->cwd . '/settings/databases.php');
     if (!is_array($databases)) {
         Index::error('Database is invalid.');
     }
     foreach ($databases as $config) {
         if ($config['type'] === 'mysql' && $config['default']) {
             $database = $config;
         }
     }
     if (!$database) {
         Index::error('No valid database found.', false);
         Index::error('Needs to be of mysql type and set to a default');
     }
     $this->database = $this('mysql', $database['host'], $database['name'], $database['user'], $database['pass']);
     return $this;
 }
コード例 #2
0
ファイル: Job.php プロジェクト: javinc/Framework
 /**
  * Runs the CLI process
  *
  * @param array $args CLI arguments
  *
  * @return mixed
  */
 public function run(array $args)
 {
     if (count($args) < 3) {
         Index::error('Not enough arguments.', 'Usage: eve job random-mail subject=hi&body=hello...');
     }
     $data = array();
     if (strpos($args[2], '?') === 0) {
         parse_str(substr($args[2], 1), $data);
     } else {
         $data = json_decode($args[2], true);
     }
     $namespace = 'Eve';
     if (file_exists($this->cwd . '/composer.json')) {
         $json = $this('file', $this->cwd . '/composer.json')->getContent();
         $json = json_decode($json, true);
         if (isset($json['autoload']['psr-4']) && is_array($json['autoload']['psr-4'])) {
             foreach ($json['autoload']['psr-4'] as $namespace => $path) {
                 if (strlen($path) === 0) {
                     $namespace = substr($namespace, 0, -1);
                     break;
                 }
             }
         }
     }
     \Eve\Framework\Index::i($this->cwd, $namespace)->defaultPaths()->defaultDatabases()->job($args[1])->setData($data)->run();
     Index::success('`' . $args[1] . '` job has been successfully executed.');
 }
コード例 #3
0
ファイル: Generate.php プロジェクト: javinc/Framework
 /**
  * Generates REST tests
  *
  * @return Eve\Framework\Cli\Generate
  */
 public function generateRestTests()
 {
     $sourceRoot = $this->source . '/test/Action/Rest';
     $destinationRoot = $this->cwd . '/test' . $this->schema['paths']['rest'] . '/' . ucwords($this->schema['name']);
     if (!is_dir($destinationRoot)) {
         mkdir($destinationRoot, 0777, true);
     }
     foreach ($this->schema['rest'] as $action) {
         $source = $sourceRoot . '/' . ucwords($action) . '.html';
         $destination = $destinationRoot . '/' . ucwords($action) . '.php';
         if (!file_exists($source)) {
             Index::error(sprintf(self::SKIP, 'test/Action/Rest', ucwords($action)), false);
             continue;
         }
         $this->copy($source, $destination);
     }
 }
コード例 #4
0
ファイル: Install.php プロジェクト: javinc/Framework
 /**
  * Runs the CLI Install process
  *
  * @param array $args CLI arguments
  *
  * @return void
  */
 public function run($args)
 {
     $this->setup($args);
     Index::info('Downloading files..');
     $this('curl')->setUrl('https://github.com/Eve-PHP/Shade/archive/master.zip')->setFile($this->file)->setFollowLocation(true)->setSslVerifyPeer(false)->send();
     fclose($this->file);
     Index::info('Extracting files..');
     try {
         $zip = new \ZipArchive();
         $resource = $zip->open($this->cwd . '/tmp/framework.zip');
         if (!$resource) {
             throw new \Exception('Cannot extract data. Aborting.');
         }
         $zip->extractTo($this->cwd . '/tmp');
         $zip->close();
         Index::info('Copying files..');
         $root = $this->cwd . '/tmp/Shade-master';
         $files = $this('folder', $root)->getFiles(null, true);
         foreach ($files as $file) {
             $destination = str_replace('/tmp/Shade-master', '', $file->get());
             $folder = $this('file', $destination)->getFolder();
             if (!is_dir($folder)) {
                 mkdir($folder, 0777, true);
             }
             copy($file->get(), $destination);
         }
     } catch (\Exception $e) {
         Index::error($e->getMessage(), false);
     }
     Index::info('Cleaning up ..');
     $tmp = $this('folder', $this->cwd . '/tmp');
     $files = $tmp->getFiles(null, true);
     $folders = $tmp->getFolders(null, true);
     $folders = array_reverse($folders);
     foreach ($files as $file) {
         $file->remove();
     }
     foreach ($folders as $folder) {
         $folder->remove();
     }
     $tmp->remove();
     Index::info('Copying settings..');
     $this('file', $this->cwd . '/settings/databases.php')->setData($this->databases);
     copy($this->cwd . '/settings/sample.config.php', $this->cwd . '/settings/config.php');
     copy($this->cwd . '/settings/sample.test.php', $this->cwd . '/settings/test.php');
     Index::info('Creating database..');
     $this->install();
     Index::success('Database created.');
     Index::warning('Please set the configs in the settings folder');
     Index::system('Control Login is: admin@openovate.com / admin');
     Index::success('Framework installation complete!');
     die(0);
 }