/** * @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 * * 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); }
public function testConvertToCamelCase() { $this->assertEquals('fromCamelCase', NameUtilities::convertToCamelCase('fromCamelCase')); $this->assertEquals('fromStudlyCaps', NameUtilities::convertToCamelCase('FromStudlyCaps')); $this->assertEquals('fromDashedLower', NameUtilities::convertToCamelCase('from-dashed-lower')); $this->assertEquals('fromUnderscoreLower', NameUtilities::convertToCamelCase('from-underscore-lower')); $this->assertEquals('fromUnderscoreCaps', NameUtilities::convertToCamelCase('From_Underscore_Caps')); $this->assertEquals('fromLowerCase', NameUtilities::convertToCamelCase('from lower case')); $this->assertEquals('fromTitleCase', NameUtilities::convertToCamelCase('From Title Case')); $this->assertEquals('thisOneIsntEasyATestCaseSitegearOrg', NameUtilities::convertToCamelCase('This One Isn\'t Easy - A Test Case @ sitegear.org')); }
/** * Create a single constraint on a field. * * @param array $constraintDefinition * * @return ConditionalConstraintInterface * * @throws \InvalidArgumentException */ public function buildConditionalConstraint(array $constraintDefinition) { LoggerRegistry::debug('FormBuilder::buildConstraint()'); /** @var Constraint $constraint */ if (isset($constraintDefinition['class'])) { // Constraint class is directly set in the definition. $constraint = new $constraintDefinition['class']($constraintDefinition['options']); } elseif (isset($constraintDefinition['callback'])) { // Callback constraint which calls a method in either the engine or a module. // Check the 'callback' value first, it should be either 'engine' or 'module'; in the latter case a // 'module' key is also expected. switch ($constraintDefinition['callback']) { case 'engine': $callbackObject = $this->getFormsModule()->getEngine(); break; case 'module': $callbackObject = $this->getFormsModule()->getEngine()->getModule($constraintDefinition['module']); break; default: throw new \InvalidArgumentException(sprintf('FormBuilder encountered invalid callback type "%s"', $constraintDefinition['callback'])); } // Setup the required options and return the Callback constraint object. if (!isset($constraintDefinition['options'])) { $constraintDefinition['options'] = array(); } if (!isset($constraintDefinition['options']['methods'])) { $constraintDefinition['options']['methods'] = array(); } $constraintDefinition['options']['methods'][] = array($callbackObject, NameUtilities::convertToCamelCase($constraintDefinition['method'])); $constraint = new Callback($constraintDefinition['options']); } else { // Use the registered constraint class mappings. $constraintClass = TypeUtilities::firstExistingClass($this->getFormsModule()->registry()->getConstraintNamespaces(), NameUtilities::convertToStudlyCaps($constraintDefinition['name'])); if (is_null($constraintClass)) { throw new \InvalidArgumentException(sprintf('FormBuilder could not find a constraint class for the name "%s"', $constraintDefinition['name'])); } $constraint = $constraintClass->newInstance(isset($constraintDefinition['options']) ? $constraintDefinition['options'] : null); } // Add conditions to the constraint if any are specified. $conditions = array(); if (isset($constraintDefinition['conditions'])) { foreach ($constraintDefinition['conditions'] as $conditionDefinition) { $conditions[] = $this->buildCondition($conditionDefinition); } } return new ConditionalConstraint($constraint, $conditions); }