Example #1
0
 /**
  * Move an uploaded file to it's intended destination.
  *
  * @param  string $file
  * @param  string $filePath
  */
 public function move($file, $filePath)
 {
     $objectConfig = $this->attachedFile->s3_object_config;
     $fileSpecificConfig = ['Key' => $filePath, 'SourceFile' => $file, 'ContentType' => $this->attachedFile->contentType()];
     $mergedConfig = array_merge($objectConfig, $fileSpecificConfig);
     $this->ensureBucketExists($mergedConfig['Bucket']);
     $this->s3Client->putObject($mergedConfig);
 }
Example #2
0
 /**
  * Return an S3Client object for a specific attachment type.
  * If no instance has been defined yet we'll buld one and then
  * cache it on the s3Clients property (for the current request only).
  *
  * @param  Attachment $attachedFile
  * @return S3Client
  */
 public static function getS3ClientInstance(Attachment $attachedFile)
 {
     $modelName = $attachedFile->getInstanceClass();
     $attachmentName = $attachedFile->getConfig()->name;
     $key = "{$modelName}.{$attachmentName}";
     if (array_key_exists($key, static::$s3Clients)) {
         return static::$s3Clients[$key];
     }
     static::$s3Clients[$key] = static::buildS3Client($attachedFile);
     return static::$s3Clients[$key];
 }
Example #3
0
 /**
  * Generates the id partition of a record, e.g
  * return /000/001/234 for an id of 1234.
  *
  * @param Attachment $attachment
  * @param string $styleName
  * @return mixed
  */
 protected function idPartition(Attachment $attachment, $styleName = '')
 {
     $id = $this->ensurePrintable($attachment->getInstance()->getKey());
     if (is_numeric($id)) {
         return implode('/', str_split(sprintf('%09d', $id), 3));
     } elseif (is_string($id)) {
         return implode('/', array_slice(str_split($id, 3), 0, 3));
     } else {
         return null;
     }
 }
Example #4
0
 /**
  * Move an uploaded file to it's intended destination.
  * The file can be an actual uploaded file object or the path to
  * a resized image file on disk.
  *
  * @param  UploadedFile $file 
  * @param  string $filePath
  * @return void 
  */
 public function move($file, $filePath)
 {
     $this->getS3Client()->putObject(['Bucket' => $this->getBucket(), 'Key' => $filePath, 'SourceFile' => $file, 'ContentType' => $this->attachedFile->contentType(), 'ACL' => $this->attachedFile->ACL]);
 }
Example #5
0
 /**
  * Return the path (on disk) of a file upload.
  *
  * @param  string $styleName
  * @return string
  */
 public function path($styleName)
 {
     return $this->attachedFile->getInterpolator()->interpolate($this->attachedFile->path, $this->attachedFile, $styleName);
 }
 /**
  * Build an attachment object.
  *
  * @param  \Codesleeve\Stapler\Interpolator
  * @return \Codesleeve\Stapler\Attachment
  */
 protected function build_attachment()
 {
     Stapler::boot();
     $instance = $this->build_mock_instance();
     $interpolator = new Interpolator();
     $attachmentConfig = new \Codesleeve\Stapler\AttachmentConfig('photo', ['styles' => [], 'placeholder_style' => 'original', 'url' => '/system/:attachment/:id_partition/:style/:filename', 'path' => ':app_root/public:url']);
     $imagine = m::mock('Imagine\\Image\\ImagineInterface');
     $resizer = new \Codesleeve\Stapler\File\Image\Resizer($imagine);
     $attachment = new \Codesleeve\Stapler\Attachment($attachmentConfig, $interpolator, $resizer);
     $attachment->setInstance($instance);
     $storageDriver = new \Codesleeve\Stapler\Storage\Filesystem($attachment);
     $attachment->setStorageDriver($storageDriver);
     return $attachment;
 }
 /**
  * Register Codesleeve\Stapler\Attachment with the container.
  * 
  * @return void
  */
 protected function registerAttachment()
 {
     $this->app->bind('Attachment', function ($app, $params) {
         $config = $app->make('Config', ['name' => $params['name'], 'options' => $params['options']]);
         $interpolator = $app->make('Interpolator');
         $imageProcessor = $app->make($params['options']['image_processing_library']);
         $resizer = $app->make('Resizer', ['imageProcessor' => $imageProcessor]);
         $IOWrapper = $app->make('IOWrapper');
         $attachment = new Attachment($config, $interpolator, $resizer, $IOWrapper);
         $storageDriver = $app->make($params['options']['storage'], ['attachment' => $attachment]);
         $attachment->setStorageDriver($storageDriver);
         return $attachment;
     });
 }