/** * @inheritdoc */ public function getController(Request $request) { $route = explode(':', $request->attributes->get('_route')); $module = $this->engine->getModule($route[0]); $method = sprintf(self::FORMAT_CONTROLLER_METHOD_NAME, NameUtilities::convertToCamelCase($route[1])); if (!method_exists($module, $method)) { $module = $this->engine->getModule($this->engine->config('engine.module-resolution.default-controller')); $method = sprintf(self::FORMAT_CONTROLLER_METHOD_NAME, $this->engine->config('engine.module-resolution.default-controller-method')); } return array($module, $method); }
/** * @inheritdoc */ public function render(array &$output) { $innerIdPrefix = sprintf('%s-%s', $this->getField()->getName(), $this->getRenderOption(self::RENDER_OPTION_KEY_INNER_WRAPPER_ID_PREFIX)); // Add the outer container element open tag. $output[] = sprintf('<%s%s>', $this->getRenderOption(self::RENDER_OPTION_KEY_OUTER_WRAPPER_ELEMENT_NAME), HtmlUtilities::attributes($this->getRenderOption(self::RENDER_OPTION_KEY_OUTER_WRAPPER_ATTRIBUTES))); // Add a hidden field (note: using the raw field name always without [] appended) to reset the value each post. $output[] = sprintf('<input type="hidden" name="%s" value="" />', $this->getField()->getName()); // Add the input elements and value labels, one for each available value. $value = $this->getFieldValue(); foreach ($this->getField()->getValues() as $option) { // Add the input element itself. $optionId = sprintf('%s-%s', $innerIdPrefix, NameUtilities::convertToDashedLower($option['value'])); $optionAttributes = array_merge($this->getRenderOption(self::RENDER_OPTION_KEY_ATTRIBUTES), array('id' => $optionId, 'value' => $option['value'], 'type' => $this->getField()->getType(), 'class' => $this->getField()->getType())); if (is_array($value) && in_array($option['value'], $value)) { $optionAttributes['checked'] = 'checked'; } $input = sprintf('<input%s />', HtmlUtilities::attributes($optionAttributes)); // Add the input label element. $inputLabelAttributes = array('for' => $optionId, 'class' => sprintf('multiple-input-label %s-label', $this->getField()->getType())); $inputLabel = sprintf('<label%s>%s</label>', HtmlUtilities::attributes($inputLabelAttributes), $option['label']); // Add the inner wrapper. $optionWrapperAttributes = $this->getRenderOption(self::RENDER_OPTION_KEY_INNER_WRAPPER_ATTRIBUTES); $optionWrapperAttributes['id'] = sprintf('%s-container', $innerIdPrefix); $output[] = sprintf('<%s%s>', $this->getRenderOption(self::RENDER_OPTION_KEY_INNER_WRAPPER_ELEMENT_NAME), HtmlUtilities::attributes($optionWrapperAttributes)); if ($this->getRenderOption(self::RENDER_OPTION_KEY_LABELS_FIRST)) { $output[] = $inputLabel; $output[] = $input; } else { $output[] = $input; $output[] = $inputLabel; } $output[] = sprintf('</%s>', $this->getRenderOption(self::RENDER_OPTION_KEY_INNER_WRAPPER_ELEMENT_NAME)); } // Add the outer container element end tag. $output[] = sprintf('</%s>', $this->getRenderOption(self::RENDER_OPTION_KEY_OUTER_WRAPPER_ELEMENT_NAME)); }
/** * @inheritdoc * * This implementation returns the target name (in camelCase) plus 'Component'. */ public function getTargetController() { return array($this->view()->getEngine()->getModule($this->getContextModule($this->request())), sprintf(self::FORMAT_COMPONENT_CONTROLLER_METHOD_NAME, NameUtilities::convertToCamelCase($this->view()->getTarget(\Sitegear\View\View::TARGET_LEVEL_METHOD)))); }
/** * @param \Sitegear\Module\ModuleInterface $module * @param string $methodName * @param array|null $argumentDefaults * @param string|null $exceptionAction */ public function __construct(ModuleInterface $module, $methodName, array $argumentDefaults = null, $exceptionAction = null) { parent::__construct($argumentDefaults, $exceptionAction); $this->module = $module; $this->methodName = NameUtilities::convertToCamelCase($methodName); }
/** * Initialise the routing for this Engine. */ protected function compileRouteCollection(Request $request) { // Setup the request context. $context = new RequestContext(); $context->fromRequest($request); // Compile the collection. $this->compiledRouteCollection = new RouteCollection(); foreach ($this->getRawRouteMap() as $urlMapEntry) { $module = $this->getModule($urlMapEntry['module']); /** @var \Sitegear\Module\MountableModuleInterface $module */ $module->mount('/' . trim($urlMapEntry['root'], '/'), $context); $routes = $module->getRoutes(); if (!empty($routes)) { $routeNamespace = NameUtilities::convertToDashedLower($urlMapEntry['module']); foreach ($routes as $routeName => $routeObject) { $this->compiledRouteCollection->add(sprintf('%s:%s', $routeNamespace, $routeName), $routeObject); } } } }
/** * @expectedException \InvalidArgumentException */ public function testInvalidForm() { NameUtilities::convert('Anything', 123); }
/** * @inheritdoc */ public function applyViewDefaults(ViewInterface $view, $viewType, $viewName) { LoggerRegistry::debug('{class}::applyViewDefaults([view], {viewType}, {viewName})', array('class' => (new \ReflectionClass($this))->getShortName(), 'viewType' => TypeUtilities::describe($viewType), 'viewName' => TypeUtilities::describe($viewName))); $this->applyConfigToView('common', $view); $this->applyConfigToView(sprintf('%s.%s', NameUtilities::convertToDashedLower($viewType), NameUtilities::convertToDashedLower($viewName)), $view); }
/** * @inheritdoc * * This implementation allows the use of a simple syntax in view scripts to render nested view scripts. * * $view->section()->[sectionName]() * $view->component()->[componentName]() * $view->[moduleName]()->[componentName]() * * These all follow the same pattern; the first call specifies the source of the content, and the second call * specifies the exact target. The special strings 'section', 'component' and 'template' can be used in the first * position. The 'section' special string maps to the controller module; the 'component' and 'template' special * strings map to the Content module. * * For every occurrence encountered of the above syntax patterns in a view script, a new View object is * created dynamically. If the syntax is incorrect, e.g. if there are more or less than 2 chained method calls, * then an error message is output. */ public function __call($name, $arguments) { if (!$this->rendering) { // We are not rendering yet, so push a target onto the stack. $this->pushTarget(NameUtilities::convertToDashedLower($name), $arguments); } else { // We are already rendering this view, and the view script is requesting a child view; create it and call // the requested method on it (which will set the new view's first target, because the child view is not // rendering). $childView = $this->getEngine()->getViewFactory()->buildView($this->getRequest(), $this); return call_user_func_array(array($childView, $name), $arguments); } return $this; }
/** * Convert the given input (string) selector into an associative array with the relevant keys for internal use. * * @param string $selector Selector as passed to a DiscreteDataModuleInterface method. * * @return array Array containing 'entity-alias', 'entity-name', 'match-field-name', 'match-field-value' and * 'value-field-name'. * * @throws \InvalidArgumentException If the selector has invalid syntax. */ protected function parseSelector($selector) { $result = null; $matches = array(); if (preg_match(self::REGEX_PARSE_SELECTOR, $selector, $matches) && sizeof($matches) > 3) { $entityMatches = array(); if (preg_match(self::REGEX_PARSE_ENTITY_NAME, $matches[1], $entityMatches) && sizeof($entityMatches) > 1) { $result = array('entity-alias' => sizeof($entityMatches) > 2 ? sprintf('%s:', NameUtilities::convertToStudlyCaps($entityMatches[1])) : '', 'entity-name' => NameUtilities::convertToStudlyCaps(sizeof($entityMatches) > 2 ? $entityMatches[2] : $entityMatches[1]), 'match-field-name' => is_numeric($matches[2]) ? 'id' : 'urlPath', 'match-field-value' => $matches[2], 'value-field-name' => $matches[3]); } else { throw new \InvalidArgumentException(sprintf('DoctrineModule got invalid entity name format; required format is "entity" or "alias:entity", got "%s"', $matches[1])); } } else { throw new \InvalidArgumentException(sprintf('DoctrineModule got invalid selector format; required format is "entity/identifier/field", got "%s"', $selector)); } return $result; }
/** * Create a single condition for a single processor. * * @param array $conditionDefinition * * @return ConditionInterface * * @throws \InvalidArgumentException */ public function buildCondition(array $conditionDefinition) { $conditionClass = TypeUtilities::firstExistingClass($this->getFormsModule()->registry()->getConditionNamespaces(), NameUtilities::convertToStudlyCaps($conditionDefinition['condition']) . 'Condition'); if (is_null($conditionClass)) { throw new \InvalidArgumentException(sprintf('FormBuilder could not find a condition class for the name "%s"', $conditionDefinition['condition'])); } return $conditionClass->newInstance($conditionDefinition['options']); }
/** * @inheritdoc */ protected function normaliseRenderOptions() { return ArrayUtilities::combine(parent::normaliseRenderOptions(), array(self::RENDER_OPTION_KEY_ELEMENT_NAME => 'fieldset', self::RENDER_OPTION_KEY_ATTRIBUTES => array('id' => sprintf('sitegear-fieldset-%s', NameUtilities::convertToDashedLower($this->getFieldset()->getHeading()))))); }
/** * @inheritdoc */ public function getSitePath($location, $resource, ModuleInterface $module = null) { // Ensure the passed-in resource has no leading slashes and no surrounding whitespace $resource = ltrim(trim($resource), '/'); switch ($location) { case ResourceLocations::RESOURCE_LOCATION_SITE: // For the site level, the module name must be inserted $root = $this->getSiteRoot(); $resource = sprintf('%s/%s', NameUtilities::convertToDashedLower($this->engine->getModuleName($module)), $resource); break; case ResourceLocations::RESOURCE_LOCATION_VENDOR: throw new \InvalidArgumentException('The "vendor" location identifier cannot be used for site paths'); case ResourceLocations::RESOURCE_LOCATION_MODULE: $root = sprintf('%s/%s', $module->getModuleRoot(), ResourceLocations::RESOURCES_DIRECTORY); break; case ResourceLocations::RESOURCE_LOCATION_ENGINE: $root = sprintf('%s/%s', $this->engine->getEngineRoot(), ResourceLocations::RESOURCES_DIRECTORY); break; default: throw new \InvalidArgumentException(sprintf('Cannot find site resource in unknown location "%s"', $location)); } return sprintf('%s/site/%s', $root, $resource); }
/** * @inheritdoc */ protected function createModule($name) { LoggerRegistry::debug('AbstractConfigurableEngine::createModule({name})', array('name' => TypeUtilities::describe($name))); $module = parent::createModule($name); if ($module instanceof ConfigurableInterface) { $moduleConfigKey = sprintf('%s.%s', $this->getRootModuleOverrideConfigKey(), NameUtilities::convertToDashedLower($name)); $moduleConfig = $this->config($moduleConfigKey, array()); $module->configure($moduleConfig); } return $module; }
/** * @inheritdoc * * This implementation allows resources to be rendered by calling a method named for the resource type. For example * "$view->resources()->css()" renders the resources of type 'css'. The method name will be converted to * dashed-lower form, so a call like "$view->resources()->someType()" will refer to the type "some-type". */ public function __call($name, $arguments) { return $this->render(NameUtilities::convertToDashedLower($name)); }
/** * @inheritdoc */ public function getModuleClassName($name) { $name = NameUtilities::convertToStudlyCaps($name); $classMap = $this->config('engine.modules.class-map', array()); if (isset($classMap[$name])) { return $classMap[$name]; } else { foreach ($this->config('engine.modules.namespaces', array()) as $namespace) { $prefix = $this->config('engine.modules.class-name-prefix'); $suffix = $this->config('engine.modules.class-name-suffix'); $className = sprintf('%s\\%s\\%s%s%s', $namespace, $name, $prefix, $name, $suffix); if (class_exists($className)) { return $className; } } } return null; }
/** * Send a simple plain-text notification email with the given data. This is useful for contact form submissions as * the notification sent to the site owner. * * @param string $subject * @param array[] $addresses * @param array $data * @param string $intro Text to display above the data list * @param string $outro Text to display below the data list * @param string|null $charset * * @return boolean */ public function sendTextNotification($subject, $addresses, $data, $intro = null, $outro = null, $charset = null) { LoggerRegistry::debug('SwiftMailerModule::sendTextNotification({subject}, {addresses}, {data}, intro[{introCount} characters], outro[{outroCount} characters], {charset})', array('subject' => TypeUtilities::describe($subject), 'addresses' => TypeUtilities::describe($addresses), 'data' => TypeUtilities::describe($data), 'introCount' => strlen($intro), 'outroCount' => strlen($outro), 'charset' => TypeUtilities::describe($charset))); $nl = "\r\n"; $body = sprintf('** %s **', $subject) . $nl . $nl; $body .= ($intro ?: 'The following data was submitted:') . $nl . $nl; foreach ($data as $key => $value) { $body .= sprintf(' * %s: %s', NameUtilities::convertToTitleCase($key), $value) . $nl; } $body .= $nl . ($outro ?: 'This message text was automatically generated.') . $nl . $nl; return $this->send($subject, $addresses, $body, 'text/plain', $charset); }