/** * Retrieve a property from a legend or create a new one. * * @param string $name The legend name. * * @param LegendInterface $legend The legend instance. * * @return PropertyInterface */ protected function getProperty($name, $legend) { foreach ($legend->getProperties() as $property) { if ($property->getName() == $name) { return $property; } } $property = new Property($name); $legend->addProperty($property); return $property; }
/** * Fill a legend from a multidimensional array of properties. * * @param LegendInterface $legend The legend. * * @param array $properties The properties. * * @return void * * @throws DcGeneralInvalidArgumentException When an invalid property is encountered. */ public static function fillLegend(LegendInterface $legend, array $properties) { foreach ($properties as $property) { if ($property instanceof PropertyInterface) { $legend->addProperty($property); } elseif (is_array($property)) { static::fillLegend($legend, $property); } else { $type = is_object($property) ? get_class($property) : gettype($property); throw new DcGeneralInvalidArgumentException('Property [' . $type . '] does not implement PropertyInterface'); } } }