/** * {@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); }
/** * {@inheritDoc} */ public function setOptions($options) { parent::setOptions($options); if ($options instanceof Traversable) { $options = ArrayUtils::iteratorToArray($options); } if (isset($options['locale'])) { $this->setLocale($options['locale']); } }
/** * {@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; }
/** * @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; }
/** * {@inheritDoc} */ public function renderOptions(array $options, array $selectedOptions = []) { $template = '<option %s>%s</option>'; $optionStrings = []; $escapeHtml = $this->getEscapeHtmlHelper(); foreach ($options as $key => $optionSpec) { $value = ''; $label = ''; $selected = false; $disabled = false; if (is_scalar($optionSpec)) { $optionSpec = ['label' => $optionSpec, 'value' => $key]; } if (isset($optionSpec['options']) && is_array($optionSpec['options'])) { $optionStrings[] = $this->renderOptgroup($optionSpec, $selectedOptions); continue; } if (isset($optionSpec['value'])) { $value = $optionSpec['value']; } if (isset($optionSpec['label'])) { $label = $optionSpec['label']; } if (isset($optionSpec['selected'])) { $selected = $optionSpec['selected']; } if (isset($optionSpec['disabled'])) { $disabled = $optionSpec['disabled']; } if (ArrayUtils::inArray($value, $selectedOptions)) { $selected = true; } if (empty($optionSpec['translator_disabled']) && null !== ($translator = $this->getTranslator())) { $label = $translator->translate($label, $this->getTranslatorTextDomain()); } $attributes = compact('value', 'selected', 'disabled'); if (isset($optionSpec['attributes']) && is_array($optionSpec['attributes'])) { $attributes = array_merge($attributes, $optionSpec['attributes']); } $this->validTagAttributes = $this->validOptionAttributes; $optionStrings[] = sprintf($template, $this->createAttributesString($attributes), $escapeHtml($label)); } return implode("\n", $optionStrings); }
/** * @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); }
/** * @param mixed $comparison * @return bool */ public function isComparison($comparison) { if (!is_array($comparison)) { return false; } if (ArrayUtils::hasStringKeys($comparison) || count($comparison) < 2) { return false; } if (!is_string($comparison[0]) || !is_string($comparison[1])) { return false; } if (!$this->isOperator($comparison[1])) { return false; } $comparison[1] = $this->normalizeOperator($comparison[1]); return in_array($comparison[1], $this->comparisonOperators); }
/** * {@inheritDoc} */ public function setCreationOptions(array $options) { $this->creationOptions = ArrayUtils::filterRecursive($options, null, true); return $this; }
/** * @param AdapterInterface $ea * @param array $config * @param object $object * @throws \RuntimeException * @return array */ protected function processFileUploads(AdapterInterface $ea, array &$config, $meta, $object) { $files = []; if (empty($config['uploadable'])) { return $files; } $uploads = $this->getPropertyValueFromObject($meta, $config['fileInfoField'], $object); if (!is_array($uploads) || !ArrayUtils::filterRecursive($uploads, null, true)) { // No uploaded files return $files; } if (ArrayUtils::hasStringKeys($uploads)) { $uploads = [$uploads]; } $pathGenerator = null; if (!empty($config['pathGenerator'])) { $pathGenerator = $config['pathGenerator']; } if (empty($config['fileField']) || !$meta->hasAssociation($config['fileField'])) { $fileClass = $this->getFileClass(); } else { $fileClass = $meta->getAssociationTargetClass($config['fileField']); } if (!$fileClass) { throw new \RuntimeException('Target file class cannot be found.'); } $uploadableSubscriber = $this->getUploadableSubscriber(); $fileInfoClass = $uploadableSubscriber->getDefaultFileInfoClass(); foreach ($uploads as $fileInfoArray) { $file = $this->createFile($fileClass, $fileInfoArray, $pathGenerator); $fileInfo = $this->createFileInfo($fileInfoClass, $fileInfoArray); $uploadableSubscriber->addEntityFileInfo($file, $fileInfo); $files[] = $file; } $om = $ea->getObjectManager(); if ($meta->hasAssociation($config['fileField'])) { $uow = $om->getUnitOfWork(); $value = $meta->isCollectionValuedAssociation($config['fileField']) ? $files : $file; $this->updateField($object, $uow, $ea, $meta, $config['fileField'], $value); if ($meta->isCollectionValuedAssociation($config['fileField'])) { $uow->computeChangeSet($meta, $object); } else { $ea->recomputeSingleObjectChangeSet($uow, $meta, $object); } } $this->getEventManager()->trigger(__FUNCTION__, $this, $files); foreach ($files as $file) { $om->persist($file); } return $files; }
/** * @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; }
/** * {@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; }
/** * {@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); }
/** * @param HttpRequest $files * @return bool */ public static function hasUploadedFiles(HttpRequest $request) { $files = $request->getFiles()->toArray(); return (bool) ArrayUtils::filterRecursive($files, function ($value) { return $value && $value !== UPLOAD_ERR_NO_FILE; }, true); }