/** * Overrides the original method from phinx in order to return a tailored * Config object containing the connection details for the database. * * @param bool $forceRefresh * @return \Phinx\Config\Config */ public function getConfig($forceRefresh = false) { if ($this->configuration && $forceRefresh === false) { return $this->configuration; } $folder = 'Migrations'; if ($this->input->getOption('source')) { $folder = $this->input->getOption('source'); } $dir = ROOT . DS . 'config' . DS . $folder; $plugin = null; if ($this->input->getOption('plugin')) { $plugin = $this->input->getOption('plugin'); $dir = Plugin::path($plugin) . 'config' . DS . $folder; } if (!is_dir($dir)) { mkdir($dir, 0777, true); } $plugin = $plugin ? Inflector::underscore($plugin) . '_' : ''; $plugin = str_replace(['\\', '/', '.'], '_', $plugin); $connection = $this->getConnectionName($this->input); $connectionConfig = ConnectionManager::config($connection); $adapterName = $this->getAdapterName($connectionConfig['driver']); $config = ['paths' => ['migrations' => $dir], 'environments' => ['default_migration_table' => $plugin . 'phinxlog', 'default_database' => 'default', 'default' => ['adapter' => $adapterName, 'host' => isset($connectionConfig['host']) ? $connectionConfig['host'] : null, 'user' => isset($connectionConfig['username']) ? $connectionConfig['username'] : null, 'pass' => isset($connectionConfig['password']) ? $connectionConfig['password'] : null, 'port' => isset($connectionConfig['port']) ? $connectionConfig['port'] : null, 'name' => $connectionConfig['database'], 'charset' => isset($connectionConfig['encoding']) ? $connectionConfig['encoding'] : null, 'unix_socket' => isset($connectionConfig['unix_socket']) ? $connectionConfig['unix_socket'] : null]]]; if ($adapterName === 'mysql') { if (!empty($connectionConfig['ssl_key']) && !empty($connectionConfig['ssl_cert'])) { $config['environments']['default']['mysql_attr_ssl_key'] = $connectionConfig['ssl_key']; $config['environments']['default']['mysql_attr_ssl_cert'] = $connectionConfig['ssl_cert']; } if (!empty($connectionConfig['ssl_ca'])) { $config['environments']['default']['mysql_attr_ssl_ca'] = $connectionConfig['ssl_ca']; } } return $this->configuration = new Config($config); }
/** * @param Input $input */ public function __invoke(Input $input) { $this->climate->br(); $name = $input->getArgument('name'); if (FALSE === strstr($name, '/')) { $name = 'middleout/arhitect-' . $name; } $ownerName = explode('/', $name); $packageName = $ownerName[1]; $ownerName = $ownerName[0]; $this->climate->yellow('Installing Arhitect Package ' . $ownerName . '/' . $packageName); $version = ''; $inputVersion = $input->getArgument('version'); if ($inputVersion) { $version = ':' . $inputVersion; } $preferDev = ' require '; $inputVersion = $input->getOption('dev'); if ($inputVersion) { $preferDev = ' require --dev '; } $this->climate->darkGray("composer" . $preferDev . $name . $version . ' --prefer-dist'); $result = shell_exec("composer" . $preferDev . $name . $version . ' --prefer-dist'); $this->climate->yellow($result); $configOwnerName = $ownerName; $configPackageName = $packageName; if ($configOwnerName == 'middleout') { $configOwnerName = 'arhitect'; $configPackageName = str_replace('arhitect-', '', $configPackageName); } $path = getcwd() . '/vendor/' . $ownerName . '/' . $packageName . '/app/config'; $path = str_replace('config/middleout/arhitect-', 'config/arhitect/', $path); if (is_dir($path)) { $this->copy($path, $this->configuration->getApplicationPath() . '/config/' . $configOwnerName); } $readme = getcwd() . '/vendor/' . $ownerName . '/' . $packageName . '/post-install.md'; if (is_file($readme)) { $postInstallMessage = file_get_contents($readme); } $this->climate->br(2); if (!$postInstallMessage) { $this->climate->green(<<<ART ______________________________________ ________| |_______ \\ | MODULE INSTALLED | / \\ | Let the coding session begin ! | / / |______________________________________| \\ /__________) (_________\\ ART ); } else { $this->climate->green('Module installed. The developer would like to tell you the following:'); $this->climate->br(2); $this->climate->yellow($postInstallMessage); } $this->climate->br(2); }
/** * Renders a template $template into $outputFile with the given templates directory $templates and input $data. * * @param Input $input * @param string $outputFile * @param string $template * @param string $templates * @param array $data */ protected function renderTemplate($input, $outputFile, $template, $templates, $data = []) { $paths = [$templates]; if ($templates = $input->getOption('templates')) { $paths[] = $templates; } $paths = array_filter($paths); $loader = new Twig_Loader_Filesystem($paths); $twig = new Twig_Environment($loader); $template = $twig->loadTemplate($template); $dataOption = $input->getOption('data'); if (file_exists($dataOption)) { $dataOption = file_get_contents($dataOption); } $dataOption = json_decode(stripcslashes($dataOption), true); if (!is_array($dataOption)) { $dataOption = []; } $data = array_merge($data, $dataOption); @mkdir(dirname($outputFile), 0755, true); file_put_contents($outputFile, $template->render($data)); }
/** * @param Input $input */ public function __invoke(Input $input) { $this->climate->br(); $name = $input->getArgument('name'); if (FALSE === strstr($name, '/')) { $name = 'middleout/arhitect-' . $name; } $ownerName = explode('/', $name); $packageName = $ownerName[1]; $ownerName = $ownerName[0]; $this->climate->yellow('Updating Arhitect Package ' . $ownerName . '/' . $packageName); $version = ''; $inputVersion = $input->getArgument('version'); if ($inputVersion) { $version = ':' . $inputVersion; } $preferDev = ' require '; $inputVersion = $input->getOption('dev'); if ($inputVersion) { $preferDev = ' require --dev '; } $this->climate->darkGray("composer" . $preferDev . $name . $version . ' --prefer-dist'); $result = shell_exec("composer" . $preferDev . $name . $version . ' --prefer-dist'); $this->climate->yellow($result); $configOwnerName = $ownerName; $configPackageName = $packageName; if ($configOwnerName == 'middleout') { $configOwnerName = 'arhitect'; $configPackageName = str_replace('arhitect-', '', $configPackageName); } $path = getcwd() . '/vendor/' . $ownerName . '/' . $packageName . '/app/config/' . $configOwnerName . '/' . $configPackageName; $path = str_replace('config/middleout/arhitect-', 'config/arhitect/', $path); if (is_dir($path)) { $this->copy($path, $this->configuration->getApplicationPath() . '/config/' . $configOwnerName . '/' . $configPackageName); } $this->climate->br(2); $this->climate->green(<<<ART ______________________________________ ________| |_______ \\ | MODULE UPDATED | / \\ | Let the coding session continue :) | / / |______________________________________| \\ /__________) (_________\\ ART ); $this->climate->br(2); }
public static function getVariable(Input $input = null, $default = '', $optionName = false, $envName = false) { $value = null; if ($optionName && $input && $input->hasOption($optionName)) { $value = $input->getOption($optionName); } if ($value === null) { if ($envName) { $value = getenv($envName); } if (!$value) { $value = $default; } } return $value === null ? '' : $value; }