Esempio n. 1
0
 /**
  * Run the seeder.
  */
 public function run()
 {
     $disk = $this->disks->findBySlug('local');
     $this->folders->truncate();
     $this->folders->create(['en' => ['name' => 'Images', 'description' => 'A folder for images.'], 'slug' => 'images', 'disk' => $disk, 'allowed_types' => ['png', 'jpeg', 'jpg']]);
     $this->folders->create(['en' => ['name' => 'Documents', 'description' => 'A folder for documents.'], 'slug' => 'documents', 'disk' => $disk, 'allowed_types' => ['pdf', 'docx']]);
 }
 /**
  * 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+'));
 }
 /**
  * Create a new field assignment.
  *
  * @param AssignmentFormBuilder     $builder
  * @param DiskRepositoryInterface   $disks
  * @param FieldRepositoryInterface  $fields
  * @param StreamRepositoryInterface $streams
  * @param                           $id
  * @param                           $field
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function create(AssignmentFormBuilder $builder, DiskRepositoryInterface $disks, FieldRepositoryInterface $fields, StreamRepositoryInterface $streams, $id, $field)
 {
     /* @var DiskInterface $disk */
     $disk = $disks->find($id);
     $stream = $streams->findBySlugAndNamespace($disk->getSlug(), 'files');
     return $builder->setOption('redirect', 'admin/files/disks/assignments/' . $id)->setField($fields->find($field))->setStream($stream)->render();
 }
Esempio n. 4
0
 /**
  * Handle the event.
  */
 public function handle()
 {
     /* @var DiskInterface $disk */
     foreach ($this->disks->all() as $disk) {
         $this->manager->register($disk);
     }
 }
 /**
  * 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+'));
 }
Esempio n. 6
0
 /**
  * Return the form to edit an existing disk.
  *
  * @param DiskFormBuilder          $disk
  * @param AdapterFormBuilder       $form
  * @param DiskRepositoryInterface  $disks
  * @param ConfigurationFormBuilder $configuration
  * @param                          $id
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function edit(DiskFormBuilder $disk, AdapterFormBuilder $form, DiskRepositoryInterface $disks, ConfigurationFormBuilder $configuration, $id)
 {
     $entry = $disks->find($id);
     $adapter = $entry->getAdapter();
     $form->addForm('disk', $disk->setEntry($id)->setAdapter($adapter));
     $form->addForm('configuration', $configuration->setEntry($adapter->getNamespace())->setScope($entry->getSlug()));
     return $form->render();
 }
 /**
  * Return a form to create a new folder.
  *
  * @param FolderFormBuilder $form
  * @param                   $path
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function create(FolderFormBuilder $form, DiskRepositoryInterface $disks, FolderRepositoryInterface $folders, $disk, $path = null)
 {
     $form->setDisk($disk = $disks->findBySlug($disk));
     if ($path && ($parent = $folders->findByPath($path, $disk))) {
         $form->setParent($parent);
     }
     return $form->render();
 }
Esempio n. 8
0
 /**
  * Return the form to upload files.
  *
  * @param FolderRepositoryInterface $folders
  * @param DiskRepositoryInterface   $disks
  * @param FileFormBuilder           $form
  * @param                           $disk
  * @param null                      $path
  * @return Response
  */
 public function upload(FolderRepositoryInterface $folders, DiskRepositoryInterface $disks, FileFormBuilder $form, $disk, $path = null)
 {
     $form->setDisk($disk = $disks->findBySlug($disk));
     if ($path && ($folder = $folders->findByPath($path, $disk))) {
         $form->setFolder($folder);
     }
     return $form->render();
 }
Esempio n. 9
0
 /**
  * Handle the event.
  */
 public function handle()
 {
     /* @var DiskInterface $disk */
     foreach ($this->disks->all() as $disk) {
         /* @var AdapterInterface $adapter */
         $adapter = $disk->getAdapter();
         $adapter->load($disk);
     }
 }
Esempio n. 10
0
 /**
  * Locate a file by disk and path.
  *
  * @param $disk
  * @param $path
  * @return FileInterface|null
  */
 public function locate($disk, $path)
 {
     if (!($disk = $this->disks->findBySlug($disk))) {
         return null;
     }
     $folder = dirname($path) !== '.' ? $this->folders->findByPath(dirname($path), $disk) : null;
     if (!($file = $this->files->findByName(basename($path), $disk, $folder))) {
         return null;
     }
     return $file;
 }
Esempio n. 11
0
 /**
  * Handle the validation.
  *
  * @param FormBuilder             $builder
  * @param DiskRepositoryInterface $disks
  * @param                         $attribute
  * @return bool
  */
 public function handle(FormBuilder $builder, DiskRepositoryInterface $disks, $attribute)
 {
     $fieldType = $builder->getFormField($attribute);
     $disk = array_get($fieldType->getConfig(), 'disk');
     if (is_numeric($disk) && !$disks->find($disk)) {
         return false;
     }
     if (!is_numeric($disk) && !$disks->findBySlug($disk)) {
         return false;
     }
     return true;
 }
 /**
  * Handle the file upload.
  *
  * @param DiskRepositoryInterface $disks
  * @param ResponseFactory         $response
  * @param MountManager            $manager
  * @param Request                 $request
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function handle(DiskRepositoryInterface $disks, ResponseFactory $response, MountManager $manager, Request $request)
 {
     $path = trim($request->get('path'), '.');
     $file = $request->file('upload');
     $disk = $request->get('disk');
     if (is_numeric($disk)) {
         $disk = $disks->find($disk);
     } elseif (is_string($disk)) {
         $disk = $disks->findBySlug($disk);
     }
     $file = $manager->putStream($disk->path(ltrim(trim($path, '/') . '/' . $file->getClientOriginalName(), '/')), fopen($file->getRealPath(), 'r+'));
     /* @var FileInterface $file */
     return $response->json($file->getAttributes());
 }
Esempio n. 13
0
 /**
  * Return the details of a file or folder.
  *
  * @param $disk
  * @param $path
  * @return string
  */
 public function view($disk, $path)
 {
     $disk = $this->disks->findBySlug($disk);
     $folder = $this->folders->findByPath(dirname($path), $disk);
     $file = $this->files->findByName(basename($path), $disk, $folder);
     if (!$disk || !$folder && !$file) {
         abort(404);
     }
     if ($file) {
         return json_encode($file);
     }
     if ($folder) {
         return json_encode($folder);
     }
 }
Esempio n. 14
0
 /**
  * Run the seeder.
  */
 public function run()
 {
     $this->disks->truncate()->create(['en' => ['name' => 'Local', 'description' => 'A local (public) storage disk.'], 'slug' => 'local', 'adapter' => 'anomaly.extension.local_storage_adapter']);
 }