/** * @inheritdoc */ protected function normaliseRenderOptions() { return ArrayUtilities::combine(parent::normaliseRenderOptions(), array(self::RENDER_OPTION_KEY_ATTRIBUTES => array('type' => $this->getField()->getType() ?: 'text'))); }
/** * @inheritdoc */ protected function normaliseRenderOptions() { return ArrayUtilities::combine(array(self::RENDER_OPTION_KEY_OUTER_WRAPPER_ELEMENT_NAME => 'div', self::RENDER_OPTION_KEY_OUTER_WRAPPER_ATTRIBUTES => array('id' => sprintf('%s-container', $this->getField()->getName()), 'class' => sprintf('multiple-input-container %s-container', $this->getField()->getType())), self::RENDER_OPTION_KEY_INNER_WRAPPER_ELEMENT_NAME => 'div', self::RENDER_OPTION_KEY_INNER_WRAPPER_ATTRIBUTES => array(), self::RENDER_OPTION_KEY_INNER_WRAPPER_ID_PREFIX => 'value', self::RENDER_OPTION_KEY_LABELS_FIRST => false), parent::normaliseRenderOptions()); }
protected function normaliseRenderOptions() { return ArrayUtilities::combine(array(self::RENDER_OPTION_KEY_ERROR_WRAPPER_ELEMENT_NAME => 'div', self::RENDER_OPTION_KEY_ERROR_WRAPPER_ATTRIBUTES => array()), parent::normaliseRenderOptions()); }
/** * @inheritdoc */ public function activateDecorators() { foreach (func_get_args() as $arg) { if (is_array($arg) && ArrayUtilities::isIndexed($arg)) { // An indexed array, recurse with each element of the array as a separate argument. call_user_func_array(array($this, 'activateDecorators'), $arg); } elseif (is_array($arg)) { // An associative array, ensure it has an 'arguments' key. $this->activeDecorators[] = array_merge(array('arguments' => array()), $arg); } elseif (is_string($arg)) { // A string, use the parseFunctionCall() utility method. $this->activeDecorators[] = PhpSourceUtilities::parseFunctionCall($arg); } else { // Unhandled type. throw new \InvalidArgumentException(sprintf('Cannot use [%s] as decorator specification', TypeUtilities::describe($arg))); } } return $this; }
/** * @inheritdoc */ protected function normaliseRenderOptions() { return ArrayUtilities::combine(array(self::RENDER_OPTION_KEY_CAPTCHA_IMAGE_ATTRIBUTES => array('class' => 'sitegear-captcha-image')), ArrayUtilities::combine(parent::normaliseRenderOptions(), array(self::RENDER_OPTION_KEY_ATTRIBUTES => array('type' => $this->getField()->getType() ?: 'text')))); }
/** * @inheritdoc */ protected function normaliseRenderOptions() { return ArrayUtilities::combine(array(self::RENDER_OPTION_KEY_ATTRIBUTES => array('id' => $this->getField()->getName())), ArrayUtilities::combine(parent::normaliseRenderOptions(), array(self::RENDER_OPTION_KEY_ATTRIBUTES => array('name' => $this->getFieldNameAttribute())))); }
public function testCombineDeepNesting() { $array1 = array(); $array2 = array(); $nest1 = $array1; $nest2 = $array2; foreach (range(0, 99) as $i) { $nest1['simple-' . $i] = 'array1-' . $i; $nest2['simple-' . $i] = 'array2-' . $i; $nest1 = $nest1['nested-' . $i] = array(); $nest2 = $nest2['nested-' . $i] = array(); } $this->assertEquals($nest2, ArrayUtilities::combine($array1, $array2)); }
/** * @inheritdoc */ protected function normaliseRenderOptions() { return ArrayUtilities::combine(array(self::RENDER_OPTION_KEY_MARKER_SEPARATOR => ''), parent::normaliseRenderOptions()); }
/** * This method should be overridden by subclasses wishing to extend the normalising behaviour (e.g. ensure the * existence of additional keys, etc). Overriding implementations should be sure to call this implementation to * provide a baseline. * * @return array */ protected function normaliseRenderOptions() { $class = new \ReflectionClass($this); return ArrayUtilities::combine(array(self::RENDER_OPTION_KEY_ELEMENT_NAME => 'div', self::RENDER_OPTION_KEY_ATTRIBUTES => array()), $this->getFactory()->getRenderOptionDefaults($class->getName())); }
/** * @inheritdoc */ protected function normaliseRenderOptions() { $options = parent::normaliseRenderOptions(); $options['attributes'] = ArrayUtilities::mergeHtmlAttributes(array('id' => $this->getField()->getName() . '-field'), $options['attributes']); return $options; }
/** * Loa the data from the given location, according to any available loaders. * * If the given argument is a filename, also load the relevant environment-specific override file. * * @param array|string|\ArrayObject|\Sitegear\Config\Configuration $config Configuration data, filename or * configuration object. * * @return array Loaded data. * * @throws \InvalidArgumentException If the given argument is not a string or an array. */ public function load($config) { LoggerRegistry::debug('ConfigLoader::load({config})', array('config' => TypeUtilities::describe($config))); $result = $this->normalise($config); if (is_string($config) && !is_null($this->environmentInfo) && !is_null($this->environmentInfo->getEnvironment())) { $pathinfo = pathinfo($config); $dirname = array_key_exists('dirname', $pathinfo) ? strval($pathinfo['dirname']) : ''; $filename = array_key_exists('filename', $pathinfo) ? strval($pathinfo['filename']) : ''; $extension = array_key_exists('extension', $pathinfo) ? strval($pathinfo['extension']) : ''; $envFilename = sprintf('%s/%s.%s.%s', $dirname, $filename, $this->environmentInfo->getEnvironment(), $extension); $envConfig = $this->loadFile($envFilename); $result = ArrayUtilities::combine($result, $envConfig); } return $result; }
/** * Display a form. * * @param \Sitegear\View\ViewInterface $view * @param \Symfony\Component\HttpFoundation\Request $request * @param string $formKey Unique key of the form, used for session storage and also is the key used to retrieve the * form data, if it is not supplied directly. * @param array|null $values Values to set manually into the form before displaying it. Note this is used for * rendering the form only, these values are not set into the session. These values are merged into the values * currently stored in the session (these values take precedence). * @param array[]|null $errors Errors to set manually into the form before displaying it. These errors are merged * into the errors currently stored in the session (these errors take precedence). */ public function formComponent(ViewInterface $view, Request $request, $formKey, array $values = null, array $errors = null) { LoggerRegistry::debug('FormsModule::formComponent()'); // Retrieve the form object. $form = $this->registry()->getForm($formKey, $request); // Disable the back button if the previous step is not available. $currentStep = $this->registry()->getCurrentStep($formKey); $availableSteps = $this->registry()->getAvailableSteps($formKey); if (!in_array($currentStep - 1, $availableSteps) && is_array($form->getBackButtonAttributes())) { $form->setBackButtonAttributes(array_merge($form->getBackButtonAttributes(), array('disabled' => 'disabled'))); } // Setup the view. $view['form-renderer'] = $this->createRendererFactory()->createFormRenderer($form, $currentStep); // TODO Something better here $view['form-renderer']->setRenderOption('attributes', ArrayUtilities::mergeHtmlAttributes(array('id' => $formKey . '-form'), $view['form-renderer']->getRenderOption('attributes'))); $view['values'] = array_merge($this->registry()->getValues($formKey), $values ?: array()); $view['errors'] = array_merge($this->registry()->getErrors($formKey), $errors ?: array()); // Remove errors as they are about to be displayed (they are already set in the view), and we don't want to // show the same errors again. $this->registry()->clearErrors($formKey); }
/** * @inheritdoc */ protected function normaliseRenderOptions() { return ArrayUtilities::combine(parent::normaliseRenderOptions(), array(self::RENDER_OPTION_KEY_ATTRIBUTES => array('rows' => $this->getField()->getRows(), 'cols' => $this->getField()->getCols()))); }
/** * @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()))))); }
/** * Load the given configuration file, and its relative environment-specific file (see class docs), and merge the * contents with the existing configuration. * * @param string|array $config The base filename to load, or an array of values to merge in directly. * @param null|string|array $rootKey The root key to merge the values to, will be created if it does not exist. If * omitted, the values will be merged to the root of the existing config. * @param boolean $preferExisting Whether to prefer values from the passed-in config over the existing values (the * default) or to prefer existing values over passed-in values (if this argument is true). * * @return self * * @throws \InvalidArgumentException */ public function merge($config, $rootKey = null, $preferExisting = false) { LoggerRegistry::debug('Configuration::merge({config}, {rootKey}, {preferExisting})', array('config' => TypeUtilities::describe($config), 'rootKey' => TypeUtilities::describe($rootKey), 'preferExisting' => TypeUtilities::describe($preferExisting))); // Load using the container's ConfigLoader. $data = $this->loader->load($config); // Push the data down the hierarchy to the specified root key. $rootKey = $this->normaliseKey($rootKey); while (!empty($rootKey)) { $k = array_pop($rootKey); $data = array($k => $data); } // Combine the arrays depending on the $preferExisting flag. $this->data = $preferExisting ? ArrayUtilities::combine($data, $this->data) : ArrayUtilities::combine($this->data, $data); return $this; }
/** * @inheritdoc */ protected function normaliseRenderOptions() { return ArrayUtilities::combine(parent::normaliseRenderOptions(), array(self::RENDER_OPTION_KEY_ELEMENT_NAME => 'form', self::RENDER_OPTION_KEY_ATTRIBUTES => array('action' => $this->form->getSubmitUrl(), 'method' => $this->form->getMethod()))); }