/** * Creates a new generator instance. * * @param string $skeleton_name name of the skeleton * @param string $target_path full path to the target location (defaults to %core.module_dir%) * @param array $data variables to use as context for rendering via twig */ public function __construct($skeleton_name, $target_path = null, array $data = []) { $required_data_keys = ['vendor', 'package']; foreach ($required_data_keys as $required_data_key) { if (!array_key_exists($required_data_key, $data)) { throw new RuntimeError(sprintf('A "%s" parameter must be provided', $required_data_key)); } } $vendor = $data['vendor']; $package = $data['package']; $module_name = sprintf('%s_%s', $vendor, $package); if (null === $target_path) { $target_path = AgaviConfig::get('core.module_dir') . DIRECTORY_SEPARATOR . $module_name; } else { $target_path .= DIRECTORY_SEPARATOR . $module_name; } $data['target_path'] = $target_path; $data['db_prefix'] = AgaviConfig::get('core.db_prefix'); $data['vendor_prefix'] = StringToolkit::asSnakeCase($vendor); $data['package_prefix'] = StringToolkit::asSnakeCase($package); $data['timestamp'] = date('YmdHis'); parent::__construct($skeleton_name, $target_path, $data); $this->overwrite_enabled = isset($data['override_files']) ? $data['override_files'] : false; $this->reporting_enabled = isset($data['reporting_enabled']) ? $data['reporting_enabled'] : false; }
/** * Creates a new generator instance. * * @param string $skeleton_name name of the skeleton * @param string $target_path full path to the target location (defaults to %core.skeleton_dir% * @param array $data variables to use as context for rendering via twig */ public function __construct($skeleton_name, $target_path = null, array $data = []) { if (!array_key_exists('new_skeleton_name', $data)) { throw new RuntimeError('A "new_skeleton_name" parameter must be provided'); } if (null === $target_path) { $target_path = AgaviConfig::get('core.skeleton_dir') . DIRECTORY_SEPARATOR . $data['new_skeleton_name']; } else { $target_path .= DIRECTORY_SEPARATOR . $data['new_skeleton_name']; } $data['target_path'] = $target_path; parent::__construct($skeleton_name, $target_path, $data); }
public function generate() { parent::generate(); // Build projection variant trellis files $this->executeTrellis($this->data['variant_prefix']); // Copy Trellis ES mapping file to correction location $trellis_config_path = $this->getTargetPath($this->data['variant_prefix']) . $this->data['variant_prefix'] . '.ini'; $trellis_config = parse_ini_file($trellis_config_path); $mapping_source_path = sprintf('%s%s%s', dirname($trellis_config_path), DIRECTORY_SEPARATOR, $trellis_config['deploy_path']); if (!is_readable($mapping_source_path)) { throw new RuntimeError(sprintf('Could not find mapping source file at %s', $mapping_source_path)); } $mapping_target_path = sprintf('%1$s%2$smigration%2$selasticsearch%2$s%3$s_create_%4$s_%5$s%2$s%6$s', $this->data['target_path'], DIRECTORY_SEPARATOR, $this->data['timestamp'], $this->data['resource_prefix'], $this->data['variant_prefix'], str_replace('{{ timestamp }}', $this->data['timestamp'], basename($trellis_config['deploy_path']))); if (!is_writable(dirname($mapping_target_path))) { throw new RuntimeError(sprintf('Mapping target path is not writable for %s', $mapping_target_path)); } rename($mapping_source_path, $mapping_target_path); }