public function executeConsole(AgaviRequestDataHolder $request_data)
 {
     $migration_description = $request_data->getParameter('description');
     $migration_timestamp = date('YmdHis');
     $migration_slug = StringToolkit::asSnakeCase(trim($request_data->getParameter('name', 'default')));
     $migration_name = StringToolkit::asStudlyCaps($migration_slug);
     $migration_dir = $this->getAttribute('migration_dir');
     // Bit of a hack to build namespace
     if (!preg_match('#.+/app/(?:modules|migration)/(\\w+_?)(?:$|/.+)#', $migration_dir, $matches)) {
         throw new RuntimeError(sprintf('Could not find namespace info in path %s', $migration_dir));
     }
     $namespace_parts = explode('_', $matches[1]);
     if (count($namespace_parts) == 1) {
         // @todo app migration - introduce a project root namespace setting
         $namespace_parts = ['Your', 'Application'];
     }
     // And a hack to determine the technology namespace
     $target = $request_data->getParameter('target');
     if (strpos($target, 'event_source')) {
         $technology = 'CouchDb';
     } elseif (strpos($target, 'view_store')) {
         $technology = 'Elasticsearch';
     } else {
         $technology = 'RabbitMq';
     }
     $migration_filepath = sprintf('%1$s%2$s%3$s_%4$s%2$s%4$s.php', $migration_dir, DIRECTORY_SEPARATOR, $migration_timestamp, $migration_slug);
     $twig_renderer = TwigRenderer::create(['template_paths' => [__DIR__]]);
     $twig_renderer->renderToFile($technology . 'Migration.tpl.twig', $migration_filepath, ['name' => $migration_name, 'timestamp' => $migration_timestamp, 'description' => $migration_description, 'folder' => $migration_dir, 'filepath' => $migration_filepath, 'vendor_prefix' => $namespace_parts[0], 'package_prefix' => $namespace_parts[1], 'technology' => $technology, 'project_prefix' => AgaviConfig::get('core.project_prefix')]);
     return $this->cliMessage('-> migration template was created here:' . PHP_EOL . $migration_filepath . PHP_EOL);
 }
 public function generate($name, array $schema_files)
 {
     $entity_type_map = [];
     foreach ($schema_files as $schema_file) {
         $trellis_schema_file = new SplFileInfo($schema_file);
         $trellis_config = (new ConfigIniParser())->parse(sprintf('%s/%s.ini', $trellis_schema_file->getPath(), $trellis_schema_file->getBasename('.xml')));
         $type_schema = (new EntityTypeSchemaXmlParser())->parse($trellis_schema_file->getRealPath());
         $entity_type_definition = $type_schema->getEntityTypeDefinition();
         $vendor_opt = $entity_type_definition->getOptions()->filterByName('vendor');
         $package_opt = $entity_type_definition->getOptions()->filterByName('package');
         if (!$vendor_opt || !$package_opt) {
             throw new RuntimeError('Missing vendor- and/or package-option for entity-type: ' . $entity_type_definition->getName());
         }
         // resource prefix
         $entity_type_key = sprintf('%s.%s.%s', StringToolkit::asSnakeCase($vendor_opt->getValue()), StringToolkit::asSnakeCase($package_opt->getValue()), StringToolkit::asSnakeCase($entity_type_definition->getName()));
         // add projection suffix
         $implementor = ltrim($entity_type_definition->getImplementor(), '\\');
         if (is_subclass_of($implementor, ProjectionTypeInterface::CLASS)) {
             $variant_opt = $entity_type_definition->getOptions()->filterByName('variant');
             $variant = $variant_opt ? $variant_opt->getValue() : ProjectionTypeInterface::DEFAULT_VARIANT;
             $entity_type_key = sprintf('%s::projection.%s', $entity_type_key, StringToolkit::asSnakeCase($variant));
         }
         $entity_type_map[$entity_type_key] = ['implementor' => sprintf('%s\\%s%s', $type_schema->getNamespace(), $entity_type_definition->getName(), $trellis_config->getTypeSuffix('Type')), 'workflow' => $this->getWorkflowConfig($entity_type_definition)];
     }
     $twig_renderer = TwigRenderer::create(['twig_options' => ['autoescape' => false], 'template_paths' => [AgaviConfig::get('core.template_dir'), AgaviConfig::get('core.honeybee_template_dir'), __DIR__ . DIRECTORY_SEPARATOR . 'templates']]);
     $target_path = AgaviConfig::get('core.config_dir') . DIRECTORY_SEPARATOR;
     $target_path .= 'includes' . DIRECTORY_SEPARATOR . $this->getConfigFileName();
     $twig_renderer->renderToFile($this->getTemplateName(), $target_path, ['entity_type_map' => $entity_type_map]);
     return [];
 }
 public function generate($name, array $files_to_include)
 {
     $target_path = AgaviConfig::get('core.config_dir') . '/includes/workflow_configs.php';
     $template_paths = [AgaviConfig::get('core.template_dir'), AgaviConfig::get('core.honeybee_template_dir'), __DIR__ . DIRECTORY_SEPARATOR . 'templates'];
     $template = 'workflow_configs.php.twig';
     $twig_renderer = TwigRenderer::create(['twig_options' => ['autoescape' => false], 'template_paths' => $template_paths]);
     $files = array_map(function ($abs_config_file_path) {
         return str_replace(AgaviConfig::get('core.module_dir'), '', $abs_config_file_path);
     }, $files_to_include);
     $twig_renderer->renderToFile($template, $target_path, ['files' => $files]);
     return $files_to_include;
 }
 public function executeConsole(AgaviRequestDataHolder $request_data)
 {
     $fixture_timestamp = date('YmdHis');
     $fixture_slug = StringToolkit::asSnakeCase(trim($request_data->getParameter('name', 'default')));
     $fixture_name = StringToolkit::asStudlyCaps($fixture_slug);
     $fixture_dir = $this->getAttribute('fixture_dir');
     // Bit of a hack to build namespace
     if (!preg_match('#.+/app/modules/(\\w+?)/.+#', $fixture_dir, $matches)) {
         throw new RuntimeError(sprintf('Could not find namespace info in path %s', $fixture_dir));
     }
     $namespace_parts = explode('_', $matches[1]);
     $fixture_filepath = sprintf('%1$s%2$s%3$s_%4$s%2$s%4$s.php', $fixture_dir, DIRECTORY_SEPARATOR, $fixture_timestamp, $fixture_slug);
     $twig_renderer = TwigRenderer::create(['template_paths' => [__DIR__]]);
     $twig_renderer->renderToFile('Fixture.tpl.twig', $fixture_filepath, ['name' => $fixture_name, 'timestamp' => $fixture_timestamp, 'folder' => $fixture_dir, 'filepath' => $fixture_filepath, 'vendor_prefix' => $namespace_parts[0], 'package_prefix' => $namespace_parts[1]]);
     touch(sprintf('%1$s%2$s%3$s_%4$s%2$s%3$s-fixture-data.json', $fixture_dir, DIRECTORY_SEPARATOR, $fixture_timestamp, $fixture_slug));
     $fixture_files_dir = sprintf('%1$s%2$s%3$s_%4$s%2$s%5$s', $fixture_dir, DIRECTORY_SEPARATOR, $fixture_timestamp, $fixture_slug, 'files');
     mkdir($fixture_files_dir);
     return $this->cliMessage('-> fixture template was generated here:' . PHP_EOL . $fixture_filepath . PHP_EOL);
 }
 public function generate($name, array $package_map)
 {
     $relative_packages = [];
     $included_directories = [];
     foreach ($package_map as $package) {
         $relative_package = $package;
         $relative_package['directory'] = str_replace(AgaviConfig::get('core.app_dir'), "dirname(dirname(__DIR__)).'", $relative_package['directory']);
         $included_directories[] = $relative_package['directory'];
         $relative_package['namespace'] = var_export($relative_package['namespace'] . '\\', true);
         $relative_packages[] = $relative_package;
     }
     if (!empty($relative_packages)) {
         $autoload_path = AgaviConfig::get('core.config_dir') . DIRECTORY_SEPARATOR;
         $autoload_path .= 'includes' . DIRECTORY_SEPARATOR . 'autoload.php';
         $twig_renderer = TwigRenderer::create(['twig_options' => ['autoescape' => false], 'template_paths' => [__DIR__ . DIRECTORY_SEPARATOR . 'templates']]);
         $twig_renderer->renderToFile('autoload.php.twig', $autoload_path, ['packages' => $relative_packages]);
     }
     return $included_directories;
 }
 /**
  * Renders all files within the target location whose extension is
  * ".tmpl.twig" onto a file that has the same name without that extension.
  * After the rendering all the ".tmpl.twig" files will be deleted in the
  * target location.
  */
 protected function renderTemplates()
 {
     $finder = new Finder();
     $finder->files()->name('*' . self::TEMPLATE_FILENAME_EXTENSION)->sortByName()->in($this->target_path);
     $twig_renderer = TwigRenderer::create(['twig_options' => ['autoescape' => false, 'cache' => false, 'debug' => true, 'strict_variables' => true], 'template_paths' => [$this->target_path]]);
     foreach ($finder as $template) {
         $target_file_path = $template->getPath() . DIRECTORY_SEPARATOR . $template->getBasename(self::TEMPLATE_FILENAME_EXTENSION);
         if (!file_exists($target_file_path) || is_readable($target_file_path) && $this->overwrite_enabled) {
             $twig_renderer->renderToFile($template->getRelativePathname(), $target_file_path, $this->data);
         }
         $msg = '[render] ' . $template->getRelativePathname() . ' => ' . $target_file_path;
         if ($this->reporting_enabled) {
             $this->report[] = $msg;
         }
     }
     $this->fs->remove($finder);
 }
 public function __construct()
 {
     $this->target_path = AgaviConfig::get('core.config_dir') . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . SkeletonFinder::VALIDATION_FILE;
     $this->template_path = __DIR__ . DIRECTORY_SEPARATOR . 'templates';
     $this->twig_renderer = TwigRenderer::create(['twig_options' => ['autoescape' => false], 'template_paths' => [$this->template_path]]);
 }