addArg() 공개 메소드

public addArg ( string $key, string | array | null $value = null, boolean | null $escape = null ) : static
$key string the argument key to add e.g. `--feature` or `--name=`. If the key does not end with and `=`, the $value will be separated by a space, if any. Keys are not escaped unless $value is null and $escape is `true`.
$value string | array | null the optional argument value which will get escaped if $escapeArgs is true. An array can be passed to add more than one value for a key, e.g. `addArg('--exclude', array('val1','val2'))` which will create the option `--exclude 'val1' 'val2'`.
$escape boolean | null if set, this overrides the $escapeArgs setting and enforces escaping/no escaping
리턴 static for method chaining
예제 #1
0
 public function up()
 {
     preg_match('/host=([^;]*)/', $this->db->dsn, $hostMatches);
     $hostName = $hostMatches[1];
     preg_match('/dbname=([^;]*)/', $this->db->dsn, $databaseMatches);
     $databaseName = $databaseMatches[1];
     preg_match('/port=([^;]*)/', $this->db->dsn, $portMatches);
     if (isset($portMatches[1])) {
         $port = $portMatches[1];
     } else {
         $port = "3306";
     }
     $command = new Command($this->mysqlExecutable);
     $command->addArg('-h', $hostName);
     $command->addArg('-P', $port);
     $command->addArg('-u', $this->db->username);
     $command->addArg('--password=', $this->db->password);
     $cmd = $command->getExecCommand() . " \"{$databaseName}\" < \"{$this->file}\"";
     #echo "    ".$cmd . "\n"; // TODO echo only with --verbose
     exec($cmd, $output, $return);
     if ($return !== 0) {
         //var_dump($output, $return);
         return false;
     } else {
         return true;
     }
 }
예제 #2
0
 /**
  * Format the command to execute
  *
  * @param string                $subcommand   The subcommand to pass to docker-compose command
  * @param ComposeFileCollection $composeFiles The compose files to precise in the command
  */
 private function formatCommand($subcommand, ComposeFileCollection $composeFiles)
 {
     $command = new Command("docker-compose");
     $project = '';
     # Add files names
     $preciseFiles = '';
     foreach ($composeFiles->getAll() as $composeFile) {
         $command->addArg('-f', $composeFile->getFileName());
         #$preciseFiles .= ' -f ' . $composeFile->getFileName();
     }
     # Add project name
     if ($composeFiles->getProjectName() != null) {
         $command->addArg('--project-name', $composeFiles->getProjectName());
         #$project = ' --project-name ' . $composeFiles->getProjectName();
     }
     $command->addArg($subcommand);
     return $command;
 }
예제 #3
0
 /**
  * EXPERIMENTAL: Schema and/or Data dumps
  *
  * @option: --includeTables
  * @option: --excludeTables
  * @option: --dataOnly [0|1]
  * @option: --truncateTables [0|1]
  */
 public function actionXDump()
 {
     $command = new Command('mysqldump');
     $fileNameSuffix = 'schema-data';
     $truncateTable = '';
     $command->addArg('-h', getenv('DB_PORT_3306_TCP_ADDR'));
     $command->addArg('-u', getenv('DB_ENV_MYSQL_USER'));
     $command->addArg('--password='******'DB_ENV_MYSQL_PASSWORD'));
     $command->addArg(getenv('DB_ENV_MYSQL_DATABASE'));
     // if only data
     if ($this->dataOnly == 1) {
         $fileNameSuffix = 'data';
         $command->addArg('--no-create-info');
     }
     // if include tables
     if (!empty($this->includeTables)) {
         foreach ($this->includeTables as $table) {
             $command->addArg($table);
         }
     }
     // if exclude tables
     if (!empty($this->excludeTables)) {
         foreach ($this->excludeTables as $table) {
             $command->addArg('--ignore-table', getenv('DB_ENV_MYSQL_DATABASE') . '.' . $table);
         }
     }
     $command->execute();
     $dump = $command->getOutput();
     // if truncate tables
     if ($this->truncateTables == 1) {
         $truncateTable = 'TRUNCATE TABLE $1;';
     }
     $dump = preg_replace('/LOCK TABLES (.+) WRITE;/', 'LOCK TABLES $1 WRITE; ' . $truncateTable, $dump);
     // generate file
     $dir = \Yii::getAlias('@runtime/mysql');
     FileHelper::createDirectory($dir);
     $fileName = $this->getFilePrefix() . '_' . $fileNameSuffix . '.sql';
     $file = $dir . '/' . $fileName;
     file_put_contents($file, $dump);
     $this->stdout("\nMySQL dump successfully written to '{$file}'\n", Console::FG_GREEN);
 }
예제 #4
0
 public function testCanCastToString()
 {
     $command = new Command('ls');
     $command->addArg('-l');
     $command->addArg('-n');
     $this->assertEquals("ls -l -n", (string) $command);
 }