Esempio n. 1
0
 /**
  * Fill a palette collection from a multidimensional array of palettes.
  *
  * @param PaletteCollection $collection The collection.
  *
  * @param array             $palettes   The palettes to fill.
  *
  * @return void
  *
  * @throws DcGeneralInvalidArgumentException When an invalid palette has been passed.
  */
 public static function fillPaletteCollection(PaletteCollection $collection, array $palettes)
 {
     foreach ($palettes as $palette) {
         if ($palette instanceof PaletteInterface) {
             $collection->addPalette($palette);
         } elseif (is_array($palette)) {
             static::fillPaletteCollection($collection, $palette);
         } else {
             $type = is_object($palette) ? get_class($palette) : gettype($palette);
             throw new DcGeneralInvalidArgumentException('Palette [' . $type . '] does not implement PaletteInterface');
         }
     }
 }
Esempio n. 2
0
 /**
  * Parse the given palettes.
  *
  * @param array(string => string)    $palettes             The array of palettes, e.g.
  *                                                         <code>array('default' => '{title_legend},title')</code>.
  *
  * @param array(string => string)    $subPaletteProperties Mapped array from subpalette [optional].
  *
  * @param array                      $selectorFieldNames   List of names of the properties to be used as selector
  *                                                         [optional].
  *
  * @param PaletteCollectionInterface $collection           The palette collection to populate [optional].
  *
  * @return PaletteCollectionInterface
  */
 public function parsePalettes(array $palettes, array $subPaletteProperties = array(), array $selectorFieldNames = array(), PaletteCollectionInterface $collection = null)
 {
     if (!$collection) {
         $collection = new PaletteCollection();
     }
     if (isset($palettes['__selector__'])) {
         $selectorFieldNames = array_merge($selectorFieldNames, $palettes['__selector__']);
         $selectorFieldNames = array_unique($selectorFieldNames);
         unset($palettes['__selector__']);
     }
     foreach ($palettes as $selector => $fields) {
         // Fields list must be a string.
         if (!is_string($fields)) {
             continue;
         }
         if ($collection->hasPaletteByName($selector)) {
             $palette = $collection->getPaletteByName($selector);
             $this->parsePalette($selector, $fields, $subPaletteProperties, $selectorFieldNames, $palette);
         } else {
             $palette = $this->parsePalette($selector, $fields, $subPaletteProperties, $selectorFieldNames);
             $collection->addPalette($palette);
         }
     }
     return $collection;
 }