/** * Private constructor * * @param HydratorInterface|array|string $hydrator File hydrator * @param ReaderInterface $reader Reader instance */ protected function __construct($hydrator, ReaderInterface $reader = null) { // If the hydrator needs to be instantiated from a string or array if (!$hydrator instanceof HydratorInterface) { $hydrator = HydratorFactory::build((array) $hydrator); } // Register the hydrator $this->hydrator = $hydrator; // Register the reader if available if ($reader instanceof ReaderInterface) { $this->load($reader); } }
/** * Multipart hydrator constructor * * @param array $subhydrators Subpart hydrators * @param int $minOccurrences Minimum occurrences * @param int $maxOccurrences Maximum occurrences */ public function __construct(array $subhydrators, $minOccurrences = 1, $maxOccurrences = 1) { parent::__construct(HydratorInterface::STANDARD); // Run through all subhydrators foreach ($subhydrators as $part => $subhydrator) { // Validate the hydrator name AbstractPart::validatePartIdentifier($part); // If the subhydrator needs to be instantiated from a string or array if (!$subhydrator instanceof HydratorInterface) { $subhydrator = HydratorFactory::build(is_array($subhydrator) ? $subhydrator : [[$part => $subhydrator]]); } $this->subhydrators[$part] = $subhydrator; } // Validate the occurrence numbers self::validateParameters($minOccurrences, $maxOccurrences); $this->minimumOccurrences = intval($minOccurrences); $this->maximumOccurrences = intval($maxOccurrences); }