$class) { $this->registerFileCollectionClass($class, $type); } } /** * Register a (new) FileCollection type * * @param string $className * @param string $type FileCollection type max length 30 chars (db field restriction) * @param bool $override existing FileCollection type * @return bool TRUE if registration succeeded * @throws \InvalidArgumentException */ public function registerFileCollectionClass($className, $type, $override = false) { if (strlen($type) > 30) { throw new \InvalidArgumentException('FileCollection type can have a max string length of 30 bytes', 1391295611); } if (!class_exists($className)) { throw new \InvalidArgumentException('Class ' . $className . ' does not exist.', 1391295613); } if (!in_array(AbstractFileCollection::class, class_parents($className) ?: [], true)) { throw new \InvalidArgumentException('FileCollection ' . $className . ' needs to extend the AbstractFileCollection.', 1391295633); } if (isset($this->types[$type])) { // Return immediately without changing configuration if ($this->types[$type] === $className) { return true; } if (!$override) { throw new \InvalidArgumentException('FileCollections ' . $type . ' is already registered.', 1391295643); } } $this->types[$type] = $className; return true; } /** * Returns a class name for a given type * * @param string $type * @return string The class name * @throws \InvalidArgumentException */ public function getFileCollectionClass($type) { if (!isset($this->types[$type])) { throw new \InvalidArgumentException('Desired FileCollection type "' . $type . '" is not in the list of available FileCollections.', 1391295644); } return $this->types[$type]; } /** * Checks if the given FileCollection type exists * * @param string $type Type of the FileCollection * @return bool TRUE if the FileCollection exists, FALSE otherwise */ public function fileCollectionTypeExists($type) { return isset($this->types[$type]); } }