示例#1
0
 /**
  * Generates an MD5 hash of the file attributes and options.
  *
  * @param File $file
  * @param array $options
  * @return string
  */
 protected function generateHash(File $file, array $options = [])
 {
     $fileSignature = ['id' => (string) $file->getKey()];
     // Add any modifications that may have run on the file.
     if (array_key_exists($this->getFileModificationKey(), $options)) {
         $fileSignature[$this->getFileModificationKey()] = $options[$this->getFileModificationKey()];
     }
     return md5(json_encode($this->recursiveKeySort($fileSignature)));
 }
 public function it_generates_a_name_for_a_file_according_to_its_attributes_and_options(FileModel $fileModel)
 {
     $fileModel->getMimeType()->willReturn('image/png');
     $fileModel->getKey()->willReturn(999);
     $fileModel->setAttribute('slot', 'profile');
     $options = ['modifications' => ['shrink' => 'run shrink filter here', 'blur' => 'run blur filter here'], 'validators' => ['image_size' => 'run image size validator']];
     $fileName = $this->fileName($fileModel, $options);
     $mixedOptions = ['validators' => ['file_size' => 'run file size validator'], 'modifications' => ['blur' => 'run blur filter here', 'shrink' => 'run shrink filter here']];
     $this->fileName($fileModel, $mixedOptions)->shouldBeEqualTo($fileName);
 }
示例#3
0
 /**
  * @param $slot
  * @param Clippable $clippable
  * @return null|FileModel
  */
 public function getBySlot($slot, Clippable $clippable = null)
 {
     if ($clippable) {
         $query = FileModel::forClippable(get_class($clippable), $clippable->getKey());
     } else {
         $query = FileModel::unattached();
     }
     return $query->inSlot($slot)->first();
 }
示例#4
0
 public function onDelete(FileModel $fileModel, array $options = [])
 {
     $fileModel->setAttribute('mime_type', 'image/jpeg');
     return $fileModel;
 }
示例#5
0
 /**
  * Get all the files by mimetype or slot, attached or unattached to a model
  *
  * @param null|Clippable $clippable
  * @param null|string|array $mimeTypes
  * @param null|string|int|array $slot
  * @return \Illuminate\Database\Eloquent\Collection
  */
 public function getFilesFor(Clippable $clippable = null, $mimeTypes = null, $slot = null)
 {
     $query = $clippable ? $clippable->clippedFiles() : FileModel::query();
     // Filter by slot(s)
     if ($slot) {
         $slot = is_array($slot) ? $slot : [$slot];
         $query->whereIn('slot', $slot);
     }
     // Filter by file type(s)
     if ($mimeTypes) {
         $mimeTypes = is_array($mimeTypes) ? $mimeTypes : [$mimeTypes];
         $query->whereIn('mime_type', $mimeTypes);
     }
     return $query->get();
 }