connection) && !empty($this->params['connection'])) { $this->connection = $this->params['connection']; } } /** * Gets the path for output. Checks the plugin property * and returns the correct path. * * @return string Path to output. */ public function getPath() { $path = APP . $this->pathFragment; if (isset($this->plugin)) { $path = $this->_pluginPath($this->plugin) . 'src/' . $this->pathFragment; } return str_replace('/', DS, $path); } /** * Base execute method parses some parameters and sets some properties on the bake tasks. * call when overriding execute() * * @return void */ public function main() { if (isset($this->params['plugin'])) { $this->plugin = $this->params['plugin']; } if (isset($this->params['connection'])) { $this->connection = $this->params['connection']; } } /** * Executes an external shell command and pipes its output to the stdout * * @param string $command the command to execute * @return void * @throws \RuntimeException if any errors occurred during the execution */ public function callProcess($command) { $descriptorSpec = [ 0 => ['pipe', 'r'], 1 => ['pipe', 'w'], 2 => ['pipe', 'w'] ]; $this->_io->verbose('Running ' . $command); $process = proc_open( $command, $descriptorSpec, $pipes ); if (!is_resource($process)) { $this->error('Could not start subprocess.'); return false; } $output = $error = ''; fclose($pipes[0]); $output = stream_get_contents($pipes[1]); fclose($pipes[1]); $error = stream_get_contents($pipes[2]); fclose($pipes[2]); proc_close($process); if ($error) { throw new \RuntimeException($error); } $this->out($output); } /** * Handles splitting up the plugin prefix and classname. * * Sets the plugin parameter and plugin property. * * @param string $name The name to possibly split. * @return string The name without the plugin prefix. */ protected function _getName($name) { if (strpos($name, '.')) { list($plugin, $name) = pluginSplit($name); $this->plugin = $this->params['plugin'] = $plugin; } return $name; } /** * Get the option parser for this task. * * This base class method sets up some commonly used options. * * @return \Cake\Console\ConsoleOptionParser */ public function getOptionParser() { $parser = parent::getOptionParser(); $parser->addOption('plugin', [ 'short' => 'p', 'help' => 'Plugin to bake into.' ])->addOption('force', [ 'short' => 'f', 'boolean' => true, 'help' => 'Force overwriting existing files without prompting.' ])->addOption('connection', [ 'short' => 'c', 'default' => 'default', 'help' => 'The datasource connection to get data from.' ])->addOption('template', [ 'short' => 't', 'default' => 'default', 'help' => 'Template to use when baking code.' ]); return $parser; } }