/**
  * {@inheritDoc}
  */
 public function createServiceWithName(ServiceLocatorInterface $formElements, $name, $requestedName)
 {
     if (!$this->canCreateServiceWithName($formElements, $name, $requestedName)) {
         throw new \BadMethodCallException(sprintf('This abstract factory can\'t create form for %s', $requestedName));
     }
     $services = $formElements->getServiceLocator();
     $builder = $this->getAnnotationBuilder($services);
     $formSpec = ArrayUtils::iteratorToArray($builder->getFormSpecification($requestedName));
     $config = $this->getConfig($services);
     foreach ($config as $name => $spec) {
         if (interface_exists($name) && $requestedName instanceof $name) {
             $formSpec = array_replace_recursive($formSpec, $spec);
         }
     }
     if (!empty($config[$requestedName])) {
         $formSpec = array_replace_recursive($formSpec, (array) $config[$requestedName]);
     }
     if (isset($formSpec['options'])) {
         $formSpec['options'] = array_replace_recursive($formSpec['options'], $this->creationOptions);
     } else {
         $formSpec['options'] = $this->creationOptions;
     }
     // Setting up some defaults
     if (!isset($formSpec['options']['merge_input_filter'])) {
         $formSpec['options']['merge_input_filter'] = true;
     }
     if (!isset($formSpec['options']['prefer_form_input_filter'])) {
         $formSpec['options']['prefer_form_input_filter'] = true;
     }
     if (!isset($formSpec['options']['use_input_filter_defaults'])) {
         $formSpec['options']['use_input_filter_defaults'] = true;
     }
     $this->config[$requestedName] = $formSpec;
     return parent::createServiceWithName($services, $name, $requestedName);
 }
Beispiel #2
0
 /**
  * {@inheritDoc}
  */
 protected function format($value, $glue = null)
 {
     if ($value instanceof Traversable) {
         $value = ArrayUtils::iteratorToArray($iterator, false);
     }
     $value = array_map('strval', $value);
     return implode($glue ?: $this->glue, $value);
 }
Beispiel #3
0
 /**
  * {@inheritDoc}
  */
 public function setOptions($options)
 {
     parent::setOptions($options);
     if ($options instanceof Traversable) {
         $options = ArrayUtils::iteratorToArray($options);
     }
     if (isset($options['locale'])) {
         $this->setLocale($options['locale']);
     }
 }
Beispiel #4
0
 /**
  * {@inheritDoc}
  */
 public function setOptions($options)
 {
     parent::setOptions($options);
     if ($options instanceof Traversable) {
         $options = ArrayUtils::iteratorToArray($options);
     }
     if (isset($options['max_date'])) {
         $this->setMaxDate($options['max_date']);
     }
     if (isset($options['min_date'])) {
         $this->setMinDate($options['min_date']);
     }
     return $this;
 }
Beispiel #5
0
 /**
  * @param MapInterface $map
  * @param array $attribs
  * @return string
  */
 public function render(MapInterface $map, array $attribs = [])
 {
     $imageHelper = $this->getImageHelper();
     $mapHelper = $this->getMapHelper();
     $image = $map->getImage();
     $attribs = array_merge_recursive($image->getAttribs(), $attribs);
     $id = $name = 'cms-image-map-' . $map->getId();
     $attribs['usemap'] = '#' . $name;
     $attribs = array_merge_recursive($attribs, ['class' => 'cms-image-map']);
     if ($map->hasAreas()) {
         $areas = ArrayUtils::iteratorToArray($map->getAreas(), false);
     } else {
         $areas = [];
     }
     return $imageHelper($image, $attribs) . PHP_EOL . $mapHelper($areas, compact('id', 'name'));
 }
 /**
  * @param ServiceLocatorInterface $services
  * @return array
  */
 protected function getCreationOptions(ServiceLocatorInterface $services)
 {
     if ($this->optionsClass && $services->has($this->optionsClass)) {
         $options = $services->get($this->optionsClass);
         if ($options instanceof AbstractOptions) {
             if ($options instanceof JQueryPluginOptionsInterface) {
                 return $options->setFromArray($this->creationOptions)->toArray();
             }
             $options = $options->toArray();
         }
         $options = ArrayUtils::iteratorToArray($options);
         if (is_array($options)) {
             return array_merge($options, $this->creationOptions);
         }
     }
     return $this->creationOptions;
 }
Beispiel #7
0
 /**
  * @param array|Traversable $weekdays
  * @param string $separator
  * @param string $format
  * @param string $locale
  * @param string|int $firstDayOfWeek
  * @return string
  */
 public static function implodeWeekdays($weekdays, $separator = ', ', $format = 'ccc', $locale = null, $firstDayOfWeek = null)
 {
     if ($weekdays instanceof Traversable) {
         $weekdays = ArrayUtils::iteratorToArray($weekdays);
     }
     if (!$weekdays) {
         return;
     }
     if (!is_array($weekdays)) {
         throw new \InvalidArgumentException('Argument 1 must be type of an array or ' . 'an instance of Traversable');
     }
     if (is_numeric($firstDayOfWeek)) {
         $firstDayOfWeek = static::$dowMap[$firstDayOfWeek];
     }
     $startDate = (new DateTime('now'))->modify($firstDayOfWeek ?: static::getFirstDayOfWeek($locale));
     $endDate = clone $startDate;
     $endDate = $endDate->modify('7 days');
     $weekdayFormat = new IntlDateFormatter($locale ?: Locale::getDefault(), IntlDateFormatter::NONE, IntlDateFormatter::NONE, $startDate->getTimezone()->getName(), IntlDateFormatter::GREGORIAN, $format);
     $formatted = [];
     while ($startDate <= $endDate) {
         $dow = $startDate->format('w');
         // 0 = Sunday, 6 = Saturday
         if (in_array($dow, $weekdays) && !isset($formatted[$dow])) {
             $formatted[$dow] = $weekdayFormat->format($startDate);
         }
         $startDate->modify('+1 day');
         // add one day to time
     }
     return implode($separator, $formatted);
 }
Beispiel #8
0
 /**
  * @param array|Traversable|AbsractOptions $options
  * @return self
  */
 public function setOptions($options)
 {
     if (!is_array($options)) {
         if ($options instanceof AbstractOptions) {
             $options = $options->toArray();
         } else {
             $options = ArrayUtils::iteratorToArray($options);
         }
     }
     foreach ($options as $name => $value) {
         $setter = $this->normalizeMethodName("set_{$name}");
         if (method_exists($this, $setter)) {
             $this->{$setter}($value);
         } else {
             $this->options[$name] = $value;
         }
     }
     return $this;
 }
Beispiel #9
0
 /**
  * {@inheritDoc}
  */
 public function setValue($value)
 {
     if ($value instanceof RangeableInterface) {
         $this->get('startDate')->setValue($value->getStartDate());
         $this->get('endDate')->setValue($value->getEndDate());
         return $this;
     }
     if ($value instanceof \Traversable) {
         $value = ArrayUtils::iteratorToArray($value, false);
     }
     if (is_array($value)) {
         foreach ($value as $name => $val) {
             if ($this->has($name)) {
                 $this->get($name)->setValue($val);
             }
         }
     }
     return $this;
 }
Beispiel #10
0
 /**
  * {@inheritDoc}
  */
 public function populateValues($data)
 {
     if ($data instanceof Traversable) {
         $data = ArrayUtils::iteratorToArray($data, true);
     }
     if (!is_array($data)) {
         throw new Exception\InvalidArgumentException(sprintf('%s expects an array or Traversable set of data; received "%s"', __METHOD__, is_object($data) ? get_class($data) : gettype($data)));
     }
     if (!isset($data['amount']) || !isset($data['currency'])) {
         throw new Exception\InvalidArgumentException(sprintf('%s expects an array with money amount and currency specified; received "%s"', __METHOD__, print_r($data, true)));
     }
     $money = new MoneyObject($data['amount'], $data['currency']);
     if (null === ($precision = $this->getOption('precision'))) {
         $precision = MoneyObject::PRECISION_CURRENCY;
     }
     $data['amount'] = $money->setPrecision($precision)->toUnits();
     return parent::populateValues($data);
 }