/** * 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 Codesleeve\Stapler\Attachment $attachedFile * @return SS3Client */ public function getS3Client($attachedFile) { $modelName = $attachedFile->getInstanceClass(); $attachmentName = $attachedFile->getConfig()->attachmentName; $key = "{$modelName}.{$attachmentName}"; if (array_key_exists($key, $this->s3Clients)) { return $this->s3Clients[$key]; } $this->s3Clients[$key] = $this->buildS3Client($attachedFile); return $this->s3Clients[$key]; }
/** * Build an attachment object. * * @param \Codesleeve\Stapler\Interpolator * * @return \Codesleeve\Stapler\Attachment */ protected function build_attachment() { $instance = $this->build_mock_instance(); $interpolator = new Interpolator(); $attachmentConfig = new \Codesleeve\Stapler\AttachmentConfig('photo', ['styles' => [], 'default_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; }
/** * 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); }