/** * Load file with ID matching that submitted, and assign it to the bundle. * * @param Bundle $bundle * @param array $data * @throws Exception\BundleBuildException Throws exception if no file exists with submitted file ID * @throws Exception\BundleBuildException Throws exception if the file loaded is not an image */ private function _addImage(Bundle $bundle, array $data) { if (!empty($data[Form\BundleForm::IMAGE])) { $id = $data[Form\BundleForm::IMAGE]; $image = $this->_fileLoader->getByID($id); if (!$image) { throw new Exception\BundleBuildException('Could not load file with ID `' . $id . '`'); } if (!$image instanceof File\File || $image->typeID !== File\Type::IMAGE) { throw new Exception\BundleBuildException('File with ID `' . $id . '` is not a valid image'); } $bundle->setImage($image); } }