create() public method

create file
public create ( string $content, string $path, string $name, string | null $disk = null, string | null $originId = null, Xpressengine\User\UserInterface $user = null ) : File
$content string file content
$path string directory for saved
$name string saved name
$disk string | null disk for saved
$originId string | null original file id
$user Xpressengine\User\UserInterface user instance
return File
コード例 #1
0
 /**
  * Create thumbnail images
  *
  * @param string           $origin   image content
  * @param CommandInterface $command  executable command
  * @param null|string      $code     dimension code
  * @param null|string      $disk     storage disk
  * @param null|string      $path     saved path
  * @param null|string      $originId origin file id
  * @return Image
  */
 public function createThumbnails($origin, CommandInterface $command, $code = null, $disk = null, $path = null, $originId = null)
 {
     $thumbnailer = $this->makeThumbnailer();
     $content = $thumbnailer->setOrigin($origin)->addCommand($command)->generate();
     $file = $this->storage->create($content, $path ?: '', implode('_', [$command->getName(), $command->getDimension()->getWidth() . 'x' . $command->getDimension()->getHeight(), hash('sha1', $content)]), $disk, $originId);
     return $this->make($file, ['type' => $command->getName(), 'code' => $code]);
 }
コード例 #2
0
 /**
  * 회원의 프로필 이미지를 등록한다.
  *
  * @param UserInterface $user        프로필 이미지를 등록할 회원
  * @param UploadedFile  $profileFile 프로필 이미지 파일
  *
  * @return string 등록한 프로필이미지 ID
  */
 public function updateUserProfileImage(UserInterface $user, UploadedFile $profileFile)
 {
     $disk = array_get($this->profileImgConfig, 'storage.disk');
     $path = array_get($this->profileImgConfig, 'storage.path');
     $size = array_get($this->profileImgConfig, 'size');
     // make fitted image
     /** @var ImageManager $imageManager */
     $imageManager = call_user_func($this->imageManagerResolver);
     $image = $imageManager->make($profileFile->getRealPath());
     $image = $image->fit($size['width'], $size['height']);
     // remove old profile image
     if (!empty($user->profileImageId)) {
         $file = File::find($user->profileImageId);
         if ($file !== null) {
             try {
                 $this->storage->remove($file);
             } catch (\Exception $e) {
             }
         }
     }
     // save image to storage
     $id = $user->getId();
     $file = $this->storage->create($image->encode()->getEncoded(), $path . "/{$id}", $id, $disk);
     return $file->id;
 }
コード例 #3
0
 public function testCreate()
 {
     list($handler, $repo, $auth, $keygen) = $this->getMocks();
     $instance = new Storage($handler, $repo, $auth, $keygen);
     $mockFile = m::mock('Xpressengine\\Storage\\File');
     $keygen->shouldReceive('generate')->andReturn('xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx');
     $handler->shouldReceive('store')->once()->with(m::on(function () {
         return true;
     }), m::on(function () {
         return true;
     }), 'local')->andReturn($mockFile);
     $repo->shouldReceive('insert')->once()->with($mockFile)->andReturn($mockFile);
     $file = $instance->create('file_get_content', 'path/to', 'filename', 'local', 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxy');
     $this->assertInstanceOf('Xpressengine\\Storage\\File', $file);
 }
コード例 #4
0
 /**
  * 회원의 프로필 이미지를 등록한다.
  *
  * @param MemberEntityInterface $member      프로필 이미지를 등록할 회원
  * @param UploadedFile          $profileFile 프로필 이미지 파일
  *
  * @return string 등록한 프로필이미지 ID
  */
 public function updateMemberProfileImage(MemberEntityInterface $member, UploadedFile $profileFile)
 {
     $disk = array_get($this->profileImgConfig, 'storage.disk');
     $path = array_get($this->profileImgConfig, 'storage.path');
     $size = array_get($this->profileImgConfig, 'size');
     // make fitted imageg
     /** @var ImageManager $imageManager */
     $imageManager = call_user_func($this->imageManagerResolver);
     $image = $imageManager->make($profileFile->getRealPath());
     $image = $image->fit($size['width'], $size['height']);
     // remove old profile image
     if ($member->profileImageId !== null && $member->profileImageId !== "") {
         $file = $this->storage->get($member->profileImageId);
         $this->storage->remove($file);
     }
     $id = $member->getId();
     // save image to storage
     $file = $this->storage->create($image->encode()->getEncoded(), $path . "/{$id}", $id, $disk);
     return $file->getId();
 }