Overview

Namespaces

  • DcGeneral
    • Clipboard
    • Contao
      • Callback
      • Compatibility
      • DataDefinition
        • Definition
      • Dca
        • Builder
          • Legacy
        • Definition
        • Palette
        • Populator
      • Event
      • View
        • Contao2BackendView
          • Event
    • Controller
    • Data
    • DataDefinition
      • Builder
      • Definition
        • Properties
        • View
          • Panel
      • ModelRelationship
      • Palette
        • Builder
          • Event
        • Condition
          • Palette
          • Property
    • EnvironmentPopulator
    • Event
    • Exception
    • Factory
      • Event
    • Panel
    • View
      • Event

Classes

  • Legend
  • Palette
  • PaletteCollection
  • PaletteFactory
  • Property

Interfaces

  • LegendInterface
  • PaletteCollectionInterface
  • PaletteInterface
  • PropertyInterface
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Todo
  1: <?php
  2: /**
  3:  * PHP version 5
  4:  * @package    generalDriver
  5:  * @author     Christian Schiffler <c.schiffler@cyberspectrum.de>
  6:  * @author     Stefan Heimes <stefan_heimes@hotmail.com>
  7:  * @author     Tristan Lins <tristan.lins@bit3.de>
  8:  * @copyright  The MetaModels team.
  9:  * @license    LGPL.
 10:  * @filesource
 11:  */
 12: 
 13: namespace DcGeneral\DataDefinition\Palette;
 14: 
 15: use DcGeneral\Exception\DcGeneralInvalidArgumentException;
 16: 
 17: /**
 18:  * The palette factory.
 19:  *
 20:  * @deprecated This class is deprecated for the moment, use the PaletteBuilder instead.
 21:  */
 22: class PaletteFactory
 23: {
 24:     /**
 25:      * Create a new palette collection from a list of palettes.
 26:      *
 27:      * @param array|PaletteInterface $palettes A list of palettes. Can be multiple arrays and arrays of arrays.
 28:      *
 29:      *
 30:      * @param PaletteInterface       $_        A list of palettes. Can be multiple arrays and arrays of arrays.
 31:      *
 32:      * @return PaletteCollectionInterface
 33:      */
 34:     public static function createPaletteCollection($palettes, $_ = null)
 35:     {
 36:         $collection = new PaletteCollection();
 37: 
 38:         $args = func_get_args();
 39:         static::fillPaletteCollection($collection, $args);
 40:         return $collection;
 41:     }
 42: 
 43:     /**
 44:      * Fill a palette collection from a multidimensional array of palettes.
 45:      *
 46:      * @param PaletteCollection $collection The collection.
 47:      *
 48:      * @param array             $palettes   The palettes to fill.
 49:      *
 50:      * @return void
 51:      *
 52:      * @throws DcGeneralInvalidArgumentException When an invalid palette has been passed.
 53:      */
 54:     public static function fillPaletteCollection(PaletteCollection $collection, array $palettes)
 55:     {
 56:         foreach ($palettes as $palette)
 57:         {
 58:             if ($palette instanceof PaletteInterface)
 59:             {
 60:                 $collection->addPalette($palette);
 61:             }
 62:             elseif (is_array($palette))
 63:             {
 64:                 static::fillPaletteCollection($collection, $palette);
 65:             }
 66:             else
 67:             {
 68:                 $type = is_object($palette) ? get_class($palette) : gettype($palette);
 69:                 throw new DcGeneralInvalidArgumentException('Palette [' . $type . '] does not implement PaletteInterface');
 70:             }
 71:         }
 72:     }
 73: 
 74:     /**
 75:      * Create a new palette from a list of legends.
 76:      *
 77:      * @param string $name   The name of the palette, can be omitted (deprecated).
 78:      *
 79:      * @param array  $legend A list of legends. Can be multiple arrays and arrays of arrays.
 80:      *
 81:      * @param array  $_      A list of legends. Can be multiple arrays and arrays of arrays.
 82:      *
 83:      * @return PaletteInterface
 84:      */
 85:     public static function createPalette($name = null, $legend = null, $_ = null)
 86:     {
 87:         $palette = new Palette();
 88: 
 89:         $args = func_get_args();
 90: 
 91:         if (is_string($args[0]))
 92:         {
 93:             $name = array_shift($args);
 94:             $palette->setName($name);
 95:         }
 96: 
 97:         static::fillPalette($palette, $args);
 98: 
 99:         return $palette;
100:     }
101: 
102:     /**
103:      * Fill a palette from a multidimensional array of legends.
104:      *
105:      * @param PaletteInterface $palette The palette.
106:      *
107:      * @param array            $legends The legends.
108:      *
109:      * @return void
110:      *
111:      * @throws DcGeneralInvalidArgumentException When an invalid legend has been passed.
112:      */
113:     public static function fillPalette(PaletteInterface $palette, array $legends)
114:     {
115:         foreach ($legends as $legend)
116:         {
117:             if ($legend instanceof LegendInterface)
118:             {
119:                 $palette->addLegend($legend);
120:             }
121:             elseif (is_array($legend))
122:             {
123:                 static::fillPalette($palette, $legend);
124:             }
125:             else {
126:                 $type = is_object($legend) ? get_class($legend) : gettype($legend);
127:                 throw new DcGeneralInvalidArgumentException('Legend [' . $type . '] does not implement LegendInterface');
128:             }
129:         }
130:     }
131: 
132:     /**
133:      * Create a new legend from a list of properties.
134:      *
135:      * @param string                  $name     The name of the legend.
136:      *
137:      * @param array|PropertyInterface $property A list of properties. Can be multiple arrays and arrays of arrays.
138:      *
139:      * @param PropertyInterface       $_        A list of properties. Can be multiple arrays and arrays of arrays.
140:      *
141:      * @return LegendInterface
142:      */
143:     public static function createLegend($name, $property = null, $_ = null)
144:     {
145:         $legend = new Legend();
146:         $legend->setName($name);
147: 
148:         $args = func_get_args();
149:         // Drop the name from argument list.
150:         array_shift($args);
151: 
152:         static::fillLegend($legend, $args);
153: 
154:         return $legend;
155:     }
156: 
157:     /**
158:      * Fill a legend from a multidimensional array of properties.
159:      *
160:      * @param LegendInterface $legend     The legend.
161:      *
162:      * @param array           $properties The properties.
163:      *
164:      * @return void
165:      *
166:      * @throws DcGeneralInvalidArgumentException When an invalid property is encountered.
167:      */
168:     public static function fillLegend(LegendInterface $legend, array $properties)
169:     {
170:         foreach ($properties as $property)
171:         {
172:             if ($property instanceof PropertyInterface)
173:             {
174:                 $legend->addProperty($property);
175:             }
176:             elseif (is_array($property))
177:             {
178:                 static::fillLegend($legend, $property);
179:             }
180:             else
181:             {
182:                 $type = is_object($property) ? get_class($property) : gettype($property);
183:                 throw new DcGeneralInvalidArgumentException('Property [' . $type . '] does not implement PropertyInterface');
184:             }
185:         }
186:     }
187: }
188: 
contao-community-alliance/dc-general API documentation generated by ApiGen 2.8.0