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 gen($route, array $params = array(), $options = array()) { list($uri, $parameters, $options, $extras, $is_null_route) = parent::gen($route, $params, $options); $cli_params = ''; foreach ($parameters as $name => $value) { $cli_params .= sprintf(' %s %s', escapeshellarg('-' . $name), escapeshellarg(self::getAsString($value))); } $extra_params = ''; foreach ($extras as $name => $value) { $extra_params .= sprintf(' %s %s', escapeshellarg('-' . $name), escapeshellarg(self::getAsString($value))); } $cmd = AgaviConfig::get('config.cmd.honeybee', 'bin/cli'); if (array_key_exists('APPLICATION_DIR', $_SERVER)) { /* * on ubuntu/nginx the '_' was set to the relative "bin/cli" command that was used in CLI * on opensuse/nginx the '_' was set to the absolute path of the php executable * on windows the '_' is never available afaik */ if (array_key_exists('_', $_SERVER) && StringToolkit::endsWith($_SERVER['_'], 'cli')) { $cmd = $_SERVER['_']; } } // TODO parameters that are part of the route pattern should not be appended here; // anyone with a bit of time may have a look at the parent::gen() to fix this return $cmd . ' ' . $uri . $cli_params . $extra_params; }
/** * 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; }
/** * Gets executed when the route of this callback is about to be reverse * generated into an URL. * * @param array The default parameters stored in the route. * @param array The parameters the user supplied to AgaviRouting::gen(). * @param array The options the user supplied to AgaviRouting::gen(). * * @return bool false as this route part should not be generated. * * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function onGenerate(array $default_parameters, array &$user_parameters, array &$user_options) { $ro = $this->getContext()->getRouting(); if (array_key_exists('attribute', $user_parameters)) { $attribute = $user_parameters['attribute']->getValue(); if ($attribute instanceof AttributeInterface) { $user_parameters['module'] = $ro->createValue(sprintf('%s-%s-%s', StringToolkit::asSnakeCase($attribute->getRootType()->getVendor()), StringToolkit::asSnakeCase($attribute->getRootType()->getPackage()), StringToolkit::asSnakeCase($attribute->getRootType()->getName()))); return true; } } if (array_key_exists('resource', $user_parameters)) { $resource = $user_parameters['resource']->getValue(); if ($resource instanceof EntityInterface) { $root_entity = $resource->getRoot() ?: $resource; $ro = $this->getContext()->getRouting(); $user_parameters['module'] = $ro->createValue(sprintf('%s-%s-%s', StringToolkit::asSnakeCase($root_entity->getType()->getVendor()), StringToolkit::asSnakeCase($root_entity->getType()->getPackage()), StringToolkit::asSnakeCase($root_entity->getType()->getName()))); return true; } } if (array_key_exists('module', $user_parameters)) { $module = $user_parameters['module']->getValue(); if ($module instanceof EntityTypeInterface) { $root_type = $module->getRoot() ?: $module; $ro = $this->getContext()->getRouting(); $user_parameters['module'] = $ro->createValue(sprintf('%s-%s-%s', StringToolkit::asSnakeCase($root_type->getVendor()), StringToolkit::asSnakeCase($root_type->getPackage()), StringToolkit::asSnakeCase($root_type->getName()))); return true; } } // there might be a 'module' set as a string in the user parameters if (!array_key_exists('module', $user_parameters)) { throw new InvalidArgumentException('A "resource" or "module" or "attribute" user parameter instance implementing ' . 'EntityInterface, EntityTypeInterface or AttributeInterface is expected.'); } return true; }
public function executeWrite(AgaviRequestDataHolder $request_data) { $parameters = $request_data->getParameters(); $skeleton_name = $request_data->getParameter('skeleton'); $target_path = $request_data->getParameter('target_path'); $type_name = $request_data->getParameter('type'); // in case of missing custom skeleton validation and missing CLI option, we need to use a default generator $skeleton_generator = $request_data->getParameter('skeleton_generator', self::DEFAULT_SKELETON_GENERATOR); $parameters['skeleton_generator'] = $skeleton_generator; $parameters['reporting_enabled'] = !$request_data->getParameter('quiet'); try { $report = []; $report[] = 'Generating skeleton "' . $skeleton_name . '" using generator "' . $skeleton_generator . '".'; $report[] = 'Generator parameters used are: '; $report[] = StringToolkit::getAsString($parameters, true); $report[] = ''; $generator = new $skeleton_generator($skeleton_name, $target_path, $parameters); $generator->generate(); $this->setAttribute('report', array_merge($report, $generator->getReport())); } catch (Exception $e) { $this->setAttribute('errors', $e->getMessage() . PHP_EOL); return 'Error'; } return 'Success'; }
/** * @return MigrationList */ public function loadMigrations() { $migration_dir = $this->config->get('directory'); if (!is_dir($migration_dir)) { throw new RuntimeError(sprintf('Given migration path is not a directory: %s', $migration_dir)); } $migration_list = new MigrationList(); $glob_expression = sprintf('%1$s%2$s[0-9]*%2$s%3$s', $migration_dir, DIRECTORY_SEPARATOR, self::GLOB_EXPRESSION); foreach (glob($glob_expression) as $migration_file) { $class_parser = new PhpClassParser(); $migration_class_info = $class_parser->parse($migration_file); $migration_class = $migration_class_info->getFullyQualifiedClassName(); if (!class_exists($migration_class)) { require_once $migration_class_info->getFilePath(); } if (!class_exists($migration_class)) { throw new RuntimeError(sprintf("Unable to load migration class %s", $migration_class)); } $class_name_parts = explode('_', $migration_class_info->getClassName()); $name = $class_name_parts[2] . (isset($class_name_parts[3]) ? $class_name_parts[3] : ''); $version = $class_name_parts[1]; $migration = $this->injector->make($migration_class, [':state' => ['name' => StringToolkit::asSnakeCase($name), 'version' => $version]]); $migration_list->addItem($migration); } return $migration_list; }
protected function getDefaultTemplateIdentifier() { $view_scope = $this->getOption('view_scope', 'missing_view_scope.collection'); if (StringToolkit::endsWith($view_scope, 'collection')) { return $this->output_format->getName() . '/attribute/text-list/as_itemlist_item_cell.twig'; } return $this->output_format->getName() . '/attribute/choice/as_input_roles.twig'; }
protected function getWidgetImplementor() { $default = ''; $view_scope = $this->getOption('view_scope', 'missing_view_scope.collection'); if (StringToolkit::endsWith($view_scope, 'modify') || StringToolkit::endsWith($view_scope, 'create')) { $default = 'jsb_Honeybee_Core/ui/DatePicker'; } return $this->getOption('widget', $default); }
protected function getDefaultTemplateIdentifier() { $view_scope = $this->getOption('view_scope', 'missing_view_scope.collection'); $input_suffixes = $this->getInputViewTemplateNameSuffixes($this->output_format->getName()); if (StringToolkit::endsWith($view_scope, $input_suffixes)) { return $this->output_format->getName() . '/attribute/url-list/as_input.twig'; } return $this->output_format->getName() . '/attribute/url-list/as_itemlist_item_cell.twig'; }
protected function getWorkflowConfig(EntityTypeDefinition $entity_type_definition) { $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()); } return ['name' => sprintf(self::WORKFLOW_NAME_PATTERN, StringToolkit::asSnakeCase($vendor_opt->getValue()), StringToolkit::asSnakeCase($package_opt->getValue()), StringToolkit::asSnakeCase($entity_type_definition->getName())), 'file' => sprintf('/%s_%s/config/%s/workflows.xml', $vendor_opt->getValue(), $package_opt->getValue(), $entity_type_definition->getName())]; }
protected function getValidatedCommandValues(array $request_payload, AggregateRootInterface $aggregate_root) { $command_values = (array) parent::getValidatedCommandValues($request_payload, $aggregate_root); $expire_date = (new DateTimeImmutable())->add(new DateInterval('PT20M')); $command_values['auth_token'] = StringToolkit::generateRandomToken(); $command_values['token_expire_date'] = $expire_date; if (!isset($command_values['role'])) { $command_values['role'] = $this->getParameter('default_role', 'non-privileged'); } return $command_values; }
public static function getType() { $fqcn_parts = explode('\\', static::CLASS); if (count($fqcn_parts) < 4) { throw new RuntimeError(sprintf('A concrete command class must be made up of at least four namespace parts: ' . '(vendor, package, type, command), in order to support auto-type generation.' . ' The given command-class %s only has %d parts.', static::CLASS, count($fqcn_parts))); } $vendor = strtolower(array_shift($fqcn_parts)); $package = StringToolkit::asSnakeCase(array_shift($fqcn_parts)); $type = StringToolkit::asSnakeCase(array_shift($fqcn_parts)); $command = str_replace('_command', '', StringToolkit::asSnakeCase(array_pop($fqcn_parts))); return sprintf('%s.%s.%s.%s', $vendor, $package, $type, $command); }
public static function buildServiceKey(ObjectInterface $object, $service_type) { $reflection_class = new ReflectionClass($object); $namespace_parts = explode('\\', $reflection_class->getNamespaceName()); if (count($namespace_parts) < 3) { throw new RuntimeError('Missing min. namespace-depth of 3. Unable to build a valid service-key.'); } $vendor_name = array_shift($namespace_parts); $package_name = array_shift($namespace_parts); $entity_type = array_shift($namespace_parts); return sprintf('%s.%s.%s.%s', strtolower($vendor_name), StringToolkit::asSnakeCase($package_name), StringToolkit::asSnakeCase($entity_type), $service_type); }
/** * Gets executed when the route of this callback is about to be reverse * generated into an URL. It converts a given Honeybee EntityInterface * instance to an identifier that can be used in the generated URL. * * @param array $default_parameters default parameters stored in the route * @param array $user_parameters parameters the user supplied to AgaviRouting::gen() * @param array $user_options options the user supplied to AgaviRouting::gen() * * @return bool false when this route part should not be generated. True otherwise. * * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function onGenerate(array $default_parameters, array &$user_parameters, array &$user_options) { if (array_key_exists('resource', $user_parameters) && is_object($user_parameters['resource'])) { $resource = $user_parameters['resource']->getValue(); if ($resource instanceof EntityInterface) { $root_entity = $resource->getRoot() ?: $resource; $ro = $this->getContext()->getRouting(); $user_parameters['resource'] = $ro->createValue($root_entity->getIdentifier()); $user_parameters['module'] = $ro->createValue(sprintf('%s-%s-%s', StringToolkit::asSnakeCase($root_entity->getType()->getVendor()), StringToolkit::asSnakeCase($root_entity->getType()->getPackage()), StringToolkit::asSnakeCase($root_entity->getType()->getName()))); } else { $this->logDebug("Skipping invalid resource parameter. Expected instance of ", EntityInterface::CLASS); } } return true; }
public function executeHtml(AgaviRequestDataHolder $request_data) { $this->setupHtml($request_data); $resource = $this->getAttribute('resource'); $view_config_scope = $this->getAttribute('view_scope'); $entity_short_prefix = StringToolkit::asSnakeCase($resource->getType()->getName()); $data_ns = sprintf('create_%s', $entity_short_prefix); $default_settings = ['group_parts' => [$data_ns]]; $renderer_settings = $this->getResourceRendererSettings($default_settings); $rendered_resource = $this->renderSubject($resource, $renderer_settings); $this->setAttribute('rendered_resource', $rendered_resource); $this->setSubheaderActivities($request_data); $this->setPrimaryActivities($request_data); $this->setAttribute('create_url', $this->routing->gen(null)); if ($template = $this->getCustomTemplate($resource)) { $this->getLayer('content')->setTemplate($template); } }
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); }
/** * Gets executed when the route of this callback is about to be reverse * generated into an URL. It converts a given Honeybee EntityInterface * instance to an identifier that can be used in the generated URL. * * @param array $default_parameters default parameters stored in the route * @param array $user_parameters parameters the user supplied to AgaviRouting::gen() * @param array $user_options options the user supplied to AgaviRouting::gen() * * @return bool false when this route part should not be generated. True otherwise. * * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function onGenerate(array $default_parameters, array &$user_parameters, array &$user_options) { if (!array_key_exists('resource', $user_parameters)) { throw new InvalidArgumentException('A "resource" user parameter is expected for URL generation that implements: ' . EntityInterface::CLASS); } $resource = $user_parameters['resource']->getValue(); if ($resource instanceof EntityInterface) { $ro = $this->getContext()->getRouting(); $root_entity = $resource->getRoot() ?: $resource; $user_parameters['resource'] = $ro->createValue($root_entity->getIdentifier()); /* * @see ModuleRoutingCallback that runs later on and would get only * the resource identifier instead of the ProjectionInterface instance * * @todo check for EntityTypeInterface on the resource and if it has a type at all? */ $user_parameters['module'] = $ro->createValue(sprintf('%s-%s-%s', StringToolkit::asSnakeCase($root_entity->getType()->getVendor()), StringToolkit::asSnakeCase($root_entity->getType()->getPackage()), StringToolkit::asSnakeCase($root_entity->getType()->getName()))); } return true; }
protected function importFixture($type_name, array $fixture) { $aggregate_root_type = $this->aggregate_root_type_map->getItem($type_name); $type_class_name = get_class($aggregate_root_type); $command_namespace = array_slice(explode('\\', $type_class_name), 0, -2); $command_class = isset($fixture['@command']) ? $fixture['@command'] : sprintf('%1$s\\Task\\Create%2$s\\Create%2$sCommand', implode('\\', $command_namespace), $aggregate_root_type->getName()); $builder = new AggregateRootCommandBuilder($aggregate_root_type, $command_class); if (isset($fixture['@command'])) { unset($fixture['@command']); foreach ($fixture as $command_property => $command_data) { $builder->{'with' . StringToolkit::asCamelCase($command_property)}($command_data); } } else { $builder->withValues($fixture); } $result = $builder->build(); if (!$result instanceof Success) { $this->logger->error('Error importing fixtures:' . print_r($result->get(), true)); throw new RuntimeError(sprintf('Error importing fixtures. Incidents have been logged.')); } $this->command_bus->post($result->get()); }
/** * Creates a new generator instance. * * @param string $skeleton_name name of the skeleton * @param string $target_path full path to the target location * @param array $data variables to use as context for rendering via twig */ public function __construct($skeleton_name, $target_path, array $data = []) { $required_data_keys = ['vendor', 'package', 'resource', 'variant']; 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']; $resource = $data['resource']; $variant = $data['variant']; $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['resource_prefix'] = StringToolkit::asSnakeCase($resource); $data['variant_prefix'] = StringToolkit::asSnakeCase($variant); $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; }
/** * @return FixtureList */ public function loadFixtures() { $fixture_dir = $this->config->get('directory'); if (!is_dir($fixture_dir)) { throw new RuntimeError(sprintf('Given fixture path is not a directory: %s', $fixture_dir)); } $fixture_list = new FixtureList(); $glob_expression = sprintf('%1$s%2$s[0-9]*%2$s%3$s', $fixture_dir, DIRECTORY_SEPARATOR, self::GLOB_EXPRESSION); foreach (glob($glob_expression) as $fixture_file) { $class_parser = new PhpClassParser(); $fixture_class_info = $class_parser->parse($fixture_file); $fixture_class = $fixture_class_info->getFullyQualifiedClassName(); if (!class_exists($fixture_class)) { require_once $fixture_class_info->getFilePath(); } if (!class_exists($fixture_class)) { throw new RuntimeError(sprintf("Unable to load fixture class %s", $fixture_class)); } $class_name_parts = explode('_', $fixture_class_info->getClassName()); $fixture = $this->service_locator->createEntity($fixture_class, [':state' => ['name' => StringToolkit::asSnakeCase($class_name_parts[2]), 'version' => $class_name_parts[1]]]); $fixture_list->addItem($fixture); } return $fixture_list; }
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()))); }
protected function getSubjectName($subject) { $name = ''; if (is_null($subject)) { $name = 'null'; } elseif (is_string($subject)) { $name = $subject; } else { $subject_name = gettype($subject); if (is_object($subject)) { $subject_class = new ReflectionClass($subject); $subject_name = $subject_class->getShortName(); if ($subject instanceof ActivityInterface) { $subject_name = $subject->getName() . $subject_name; } } $name = StringToolkit::asSnakeCase($subject_name); } return $name; }
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 array with additional logging information as key => value */ public static function getExtraInformation() { $agavi_context = AgaviContext::getInstance(); $request_uri = ''; if (php_sapi_name() !== 'cli' && isset($_SERVER['REQUEST_URI'])) { $request_uri = $_SERVER['REQUEST_URI']; } else { $request_uri = $agavi_context->getRouting()->getInput(); } $matched_module_and_action = ''; $matched_routes = ''; $route_names_array = $agavi_context->getRequest()->getAttribute('matched_routes', 'org.agavi.routing'); if (!empty($route_names_array)) { $main_route = $agavi_context->getRouting()->getRoute(reset($route_names_array)); $matched_module_and_action = $main_route['opt']['module'] . '/' . $main_route['opt']['action']; $matched_routes = implode(', ', $route_names_array); } // the first container is the one returned from the \AgaviRouting::execute() call $first_container = @$agavi_context->getRouting()->getContainer(); if (!empty($first_container)) { $first_output_type = $first_container->getOutputType()->getName(); $first_module_action_and_view = $first_container->getModuleName() . '/' . $first_container->getActionName() . ' => ' . $first_container->getViewModuleName() . '/' . $first_container->getViewName(); } $server_name = isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : ''; $server_name .= isset($_SERVER['SERVER_PORT']) ? ':' . $_SERVER['SERVER_PORT'] : ''; $server_addr = isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : ''; $server_addr .= isset($_SERVER['SERVER_PORT']) ? ':' . $_SERVER['SERVER_PORT'] : ''; $remote_addr = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : ''; $remote_addr .= isset($_SERVER['REMOTE_PORT']) ? ':' . $_SERVER['REMOTE_PORT'] : ''; $extra = array('app_name' => AgaviConfig::get('core.app_name'), 'agavi_context' => $agavi_context->getName(), 'agavi_environment' => AgaviConfig::get('core.environment'), 'agavi_version' => AgaviConfig::get('agavi.version'), 'php_version' => phpversion(), 'system' => php_uname(), 'pid' => getmypid(), 'memory_usage' => StringToolkit::formatBytes(memory_get_usage(true)), 'memory_peak_usage' => StringToolkit::formatBytes(memory_get_peak_usage(true))); if (!empty($_SERVER['SERVER_SOFTWARE'])) { $extra['server_software'] = $_SERVER['SERVER_SOFTWARE']; } $extra['remote_addr'] = $remote_addr; if (!empty($_SERVER['X_FORWARDED_FOR'])) { $extra['x_forwarded_for'] = $_SERVER['X_FORWARDED_FOR']; } if (!empty($server_name)) { $extra['server_name'] = $server_name; } if (!empty($server_addr)) { $extra['server_addr'] = $server_addr; } /* * the following is only accessible validated or while initialization */ /* 'http_host' => isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '', 'http_accept' => isset($_SERVER['HTTP_ACCEPT']) ? $_SERVER['HTTP_ACCEPT'] : '', 'http_accept_language' => isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? $_SERVER['HTTP_ACCEPT_LANGUAGE'] : '', 'http_accept_encoding' => isset($_SERVER['HTTP_ACCEPT_ENCODING']) ? $_SERVER['HTTP_ACCEPT_ENCODING'] : '', 'http_cookie' => isset($_SERVER['HTTP_COOKIE']) ? $_SERVER['HTTP_COOKIE'] : '', 'http_connection' => isset($_SERVER['HTTP_CONNECTION']) ? $_SERVER['HTTP_CONNECTION'] : '', 'http_cache_control' => isset($_SERVER['HTTP_CACHE_CONTROL']) ? $_SERVER['HTTP_CACHE_CONTROL'] : '', */ $extra['request_uri'] = $request_uri; $extra['request_method'] = $agavi_context->getRequest()->getMethod(); $extra['matched_module_and_action'] = $matched_module_and_action; $extra['matched_routes'] = $matched_routes; if (!empty($first_container)) { $extra['first_container_output_type'] = $first_output_type; $extra['first_container_module_action_and_view'] = $first_module_action_and_view; } // see AclSecurityUser or user class defined in factories.xml $user = $agavi_context->getUser(); if (is_callable([$user, 'getRawUserAgent'])) { $extra['raw_user_agent'] = $agavi_context->getUser()->getRawUserAgent(); $extra['raw_referer'] = $agavi_context->getUser()->getRawReferer(); } $ssh_connection = getenv('SSH_CONNECTION'); if (!empty($ssh_connection)) { $extra['ssh_connection'] = $ssh_connection; } $user = getenv('USER'); if (!empty($user)) { $extra['CLI User'] = $user; $extra['CLI Home'] = getenv('HOME'); } return $extra; }
/** * 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; }
public function getByAggregateRootType(AggregateRootTypeInterface $aggregate_root_type, $variant = ProjectionTypeInterface::DEFAULT_VARIANT) { return $this->getItem(sprintf('%s::projection.%s', $aggregate_root_type->getPrefix(), StringToolkit::asSnakeCase($variant))); }
public function executeWrite(AgaviRequestDataHolder $request_data) { $aggregate_root_type = $request_data->getParameter('type'); $trellis_target = $request_data->getParameter('target'); $migration_name = $request_data->getParameter('migration_name'); // Should probably use a service for some of this $finder = new TrellisTargetFinder(); $location = HoneybeeAgaviToolkit::getTypeSchemaPath($aggregate_root_type); if ($trellis_target == TrellisTargetValidator::ALL_TARGETS) { $trellis_schema_paths = $finder->findAll((array) $location); } else { $trellis_schema_paths = $finder->findByName($trellis_target, (array) $location); } foreach ($trellis_schema_paths as $trellis_schema_path) { $current_target = pathinfo($trellis_schema_path, PATHINFO_FILENAME); $trellis_config_path = sprintf('%s%s%s.ini', dirname($trellis_schema_path), DIRECTORY_SEPARATOR, $current_target); $command = new GenerateCodeCommand(); $input = new ArrayInput(['action' => 'gen+dep', '--schema' => $trellis_schema_path, '--config' => $trellis_config_path]); $output = new BufferedOutput(); $report = array(); $report[] = 'Generating trellis target "' . $current_target . '" for type "' . $aggregate_root_type->getName() . '".'; $report[] = 'Trellis parameters used are: '; $report[] = StringToolkit::getAsString($input, true); $report[] = ''; $exit_code = $command->run($input, $output); if ($exit_code != 0) { $this->setAttribute('errors', explode(PHP_EOL, $output->fetch())); return 'Error'; } // Handle copying of generated mappings to selected migration folder if ($current_target != 'aggregate_root' && $migration_name != MigrationNameValidator::NONE_MIGRATION) { try { $target_name = $request_data->getParameter('type')->getPackagePrefix() . '::migration::view_store'; $migration_service = $this->getServiceLocator()->getMigrationService(); $migration_list = $migration_service->getMigrationList($target_name); $migrations = $migration_list->filter(function (MigrationInterface $migration) use($migration_name) { return $migration->getVersion() . ':' . $migration->getName() == $migration_name; }); if (count($migrations) !== 1) { throw new RuntimeError(sprintf('Unexpected number of migrations found for %s', $migration_name)); } // @todo more sophisticated ini parsing $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('%s%s%s', dirname((new ReflectionClass($migrations[0]))->getFileName()), DIRECTORY_SEPARATOR, 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)); } $timestamp = date('YmdHis'); $mapping_target_path = str_replace('{{ timestamp }}', $timestamp, $mapping_target_path); rename($mapping_source_path, $mapping_target_path); $this->setAttribute('mapping_target_path', $mapping_target_path); } catch (Exception $e) { $this->setAttribute('errors', [$e->getMessage()]); return 'Error'; } } $output = $output->fetch(); if (!empty($output)) { $report = array_merge($report, explode(PHP_EOL, $output)); } } $this->setAttribute('report', $report); return 'Success'; }
protected function getAsSnakeCase($string) { return StringToolkit::asSnakeCase($string); }
public function getVariantPrefix() { return sprintf('%s::projection.%s', $this->getPrefix(), StringToolkit::asSnakeCase($this->getVariant())); }
public function endsWith($haystack, $needle) { return StringToolkit::endsWith($haystack, $needle); }