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 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 asStudlyCaps($value) { return StringToolkit::asStudlyCaps($value); }
protected function buildCommand(BulkMetaData $meta_data, array $payload) { $command_implementor = $meta_data->getCommand(); return new $command_implementor(array_merge($payload, array('aggregate_root_type' => StringToolkit::asStudlyCaps($meta_data->getType()), 'aggregate_root_identifier' => $meta_data->getIdentifier()))); }
/** * This method constructs a Message from the given twig mail template. * * A valid twig mail template is a file with a '.mail.twig' extension, * that has multiple blocks with content: * * - 'subject' - subject of the message * - 'from' - email address of creator * - 'sender' - email address of sender (if different from creator) * - 'to' - email address of main recipient * - 'cc' - email address of carbon-copy receiver * - 'bcc' - email address of blind-carbon-copy receiver * - 'reply_to' - default email address for replies * - 'return_path' - email address to be used for bounce handling * - 'body_html' - HTML body part * - 'body_text' - plain text body part * * Only blocks, that exist in the template will be rendered and set. * * @param mixed $identifier usually the name of the template * @param array $variables array of placeholders for the twig template * @param array $options array of additional options for the renderer * * @return Message mail message for further customization */ public function createMessageFromTemplate($identifier, array $variables = array(), array $options = array()) { if (!isset($options['template_extension'])) { $options['template_extension'] = '.mail.twig'; //$this->config->get('template_extension', '.mail.twig'); } if (!isset($options['add_agavi_assigns'])) { $options['add_agavi_assigns'] = $this->config->get('add_agavi_assigns', true); } if (!$options['add_agavi_assigns']) { $twig_template = $this->loadTemplate($identifier, $options); } else { // add all assigns from the renderer parameters to the variables $layer = $this->getLayer($identifier, $options); $renderer = $layer->getRenderer(); $context = AgaviContext::getInstance(); $assigns = []; foreach ($renderer->getParameter('assigns', []) as $item => $var) { $getter = 'get' . StringToolkit::asStudlyCaps($item); if (is_callable([$context, $getter])) { if (null === $var) { continue; } $assigns[$var] = call_user_func([$context, $getter]); } } $variables = array_merge($variables, $assigns); $twig_template = $renderer->loadTemplate($layer); } $message = new Message(); if ($twig_template->hasBlock('subject')) { $message->setSubject($twig_template->renderBlock('subject', $variables)); } if ($twig_template->hasBlock('body_html')) { $message->setBodyHtml($twig_template->renderBlock('body_html', $variables)); } if ($twig_template->hasBlock('body_text')) { $message->setBodyText($twig_template->renderBlock('body_text', $variables)); } if ($twig_template->hasBlock('from')) { $message->setFrom($twig_template->renderBlock('from', $variables)); } if ($twig_template->hasBlock('to')) { $message->setTo($twig_template->renderBlock('to', $variables)); } if ($twig_template->hasBlock('cc')) { $message->setCc($twig_template->renderBlock('cc', $variables)); } if ($twig_template->hasBlock('bcc')) { $message->setBcc($twig_template->renderBlock('bcc', $variables)); } if ($twig_template->hasBlock('return_path')) { $message->setReturnPath($twig_template->renderBlock('return_path', $variables)); } if ($twig_template->hasBlock('sender')) { $message->setSender($twig_template->renderBlock('sender', $variables)); } if ($twig_template->hasBlock('reply_to')) { $message->setReplyTo($twig_template->renderBlock('reply_to', $variables)); } return $message; }
protected function buildTypeString($namespaced_type) { $type_parts = explode('\\', $namespaced_type); $type_name = array_pop($type_parts); $type_parts[] = StringToolkit::asStudlyCaps($this->output_format_name) . $type_name; return implode('\\', $type_parts); }
/** * @return Result */ protected function adoptPropertyValue($prop_name, $prop_value) { $validation_method = 'validate' . StringToolkit::asStudlyCaps($prop_name); if (method_exists($this, $validation_method)) { return call_user_func([$this, $validation_method], $prop_value); } return Success::unit($prop_value); }