/** * Restore the value from storage format. * * @param $value * @return null|FileInterface */ public function restore($value) { if (!$this->needsRestoring($value)) { return $value; } if ($value && ($file = $this->files->find($value))) { return $file; } return null; }
/** * Modify the value for database storage. * * @param $value * @return int */ public function modify($value) { if ($value instanceof FileInterface) { return $value->getId(); } if ($value && ($file = $this->files->find($value))) { return $file->getId(); } return null; }
/** * Restore the value from storage format. * * @param $value * @return null|FileInterface */ public function restore($value) { if ($value instanceof FileInterface) { return $value; } if ($value && ($file = $this->files->find($value))) { return $file; } return null; }
/** * Handle the command. * * @param DiskRepositoryInterface $disks * @param FileRepositoryInterface $files * @param FileFieldTypeParser $parser * @param Request $request * @param MountManager $manager * @return null|bool|FileInterface */ public function handle(DiskRepositoryInterface $disks, FileRepositoryInterface $files, FileFieldTypeParser $parser, Request $request, MountManager $manager) { $path = trim(array_get($this->fieldType->getConfig(), 'path'), './'); $entry = $this->fieldType->getEntry(); $file = $request->file($this->fieldType->getInputName()); $value = $request->get($this->fieldType->getInputName() . '_id'); /** * Make sure we have at least * some kind of input. */ if ($file === null) { if (!$value) { return null; } return $files->find($value); } // Make sure we have a valid upload disk. if (!($disk = $disks->find($id = array_get($this->fieldType->getConfig(), 'disk')))) { throw new \Exception("The configured disk [{$id}] for [{$this->fieldType->getInputName()}] could not be found."); } // Make the path. $path = $parser->parse($path, $this->fieldType); $path = (!empty($path) ? $path . '/' : null) . $file->getClientOriginalName(); return $manager->putStream($disk->path($path), fopen($file->getRealPath(), 'r+')); }
/** * Handle the command. * * @param DiskRepositoryInterface $disks * @param FileRepositoryInterface $files * @param FileFieldTypeParser $parser * @param Request $request * @param MountManager $manager * * @return null|bool|FileInterface */ public function handle(DiskRepositoryInterface $disks, FileRepositoryInterface $files, FileFieldTypeParser $parser, Request $request, MountManager $manager) { $path = trim(array_get($this->fieldType->getConfig(), 'path'), './'); $file = $request->file($this->fieldType->getInputName()); $value = $request->get($this->fieldType->getInputName() . '_id'); /** * Make sure we have at least * some kind of input. */ if ($file === null) { if (!$value) { return null; } return $files->find($value); } // Make sure we have a valid upload disk. First by slug. if (!($disk = $disks->findBySlug($slug = array_get($this->fieldType->getConfig(), 'disk')))) { // If that fails look up by id. if (!($disk = $disks->find($id = array_get($this->fieldType->getConfig(), 'disk')))) { return null; } } // Make the path. $path = $parser->parse($path, $this->fieldType); $path = (!empty($path) ? $path . '/' : null) . $file->getClientOriginalName(); return $manager->putStream($disk->path($path), fopen($file->getRealPath(), 'r+')); }
/** * Handle the command. * * @param FileRepositoryInterface $files * @param FolderRepositoryInterface $folders * @param Decorator $decorator * @return \Anomaly\FilesModule\File\Contract\FileInterface|\Anomaly\Streams\Platform\Model\EloquentModel|null */ public function handle(FileRepositoryInterface $files, FolderRepositoryInterface $folders) { if (is_numeric($this->identifier)) { return $files->find($this->identifier); } if (!is_numeric($this->identifier)) { list($folder, $name) = explode('/', $this->identifier); if (!($folder = $folders->findBySlug($folder))) { return null; } return $files->findByNameAndFolder($name, $folder); } return null; }
/** * Redirect to a file's URL. * * @param FileRepositoryInterface $files * @param $id * @return \Illuminate\Http\RedirectResponse */ public function view(FileRepositoryInterface $files, $id) { /* @var FileInterface $file */ $file = $files->find($id); return $this->redirect->to('files/' . $file->getFolder()->getSlug() . '/' . $file->getName()); }
/** * Redirect to a file's public URL.s * * @param FileRepositoryInterface $files * @param Redirector $redirector * @param $id * @return \Illuminate\Http\RedirectResponse */ public function view(FileRepositoryInterface $files, Redirector $redirector, $id) { $file = $files->find($id); return $redirector->to($file->publicPath()); }