bind() public method

set the target be have a file
public bind ( string $fileableId, File $file ) : void
$fileableId string fileable identifier
$file File file instance
return void
コード例 #1
0
ファイル: Handler.php プロジェクト: khongchi/plugin-board
 /**
  * update document
  *
  * @param ItemEntity $item board item entity
  * @return void
  */
 public function put(ItemEntity $item)
 {
     $doc = $item->getDocument();
     // 비회원 글 수정시 비밀번호를 입력 안한 경우
     $origin = $doc->getOriginal();
     if ($origin['certifyKey'] != '' && $doc->certifyKey == '') {
         $doc->certifyKey = $origin['certifyKey'];
     }
     $doc = $this->document->put($doc);
     if ($item->slug != $item->getSlug()->slug) {
         $slugEntity = $item->getSlug();
         $slugEntity->slug = $item->slug;
         $this->slug->update($item->getSlug());
     }
     // file 이 없어진걸 처리해야해.. 파일을 삭제한 경우를 말이지!
     $currentFileIds = [];
     /** @var \Xpressengine\Storage\File $file */
     foreach ($this->storage->getsByTargetId($item->id) as $file) {
         $currentFileIds[] = $file->getId();
     }
     $uploadedFileIds = [];
     /** @var \Xpressengine\Storage\File $file */
     foreach ($item->getFiles() as $file) {
         $uploadedFileIds[] = $file->getId();
         $this->storage->bind($doc->id, $file);
     }
     $files = $this->storage->getsIn(array_diff($currentFileIds, $uploadedFileIds));
     foreach ($files as $file) {
         $this->storage->unBind($item->id, $file, true);
     }
 }
コード例 #2
0
 /**
  * Set site representative image
  *
  * @param Image $image image instance
  * @return void
  */
 public function setSiteImage(Image $image)
 {
     $this->storage->removeAll($this->get('uuid'));
     $this->storage->bind($this->get('uuid'), $image->getFile());
     $this->image = $image;
 }
コード例 #3
0
 public function testBind()
 {
     list($handler, $auth, $keygen, $distributor, $temps) = $this->getMocks();
     $instance = new Storage($handler, $auth, $keygen, $distributor, $temps);
     $mockFile = m::mock('Xpressengine\\Storage\\File')->shouldAllowMockingProtectedMethods();
     $mockConn = m::mock('stdClass');
     $mockFile->shouldReceive('getConnection')->andReturn($mockConn);
     $mockFile->shouldReceive('getFileableTable')->andReturn('fileable_table');
     $mockFile->shouldReceive('getKey')->andReturn('file-id');
     $mockConn->shouldReceive('table')->once()->with('fileable_table')->andReturnSelf();
     $mockConn->shouldReceive('insert')->once()->with(m::on(function ($args) {
         return $args['fileId'] == 'file-id' && $args['fileableId'] == 'fileable-id';
     }))->andReturnSelf();
     $mockFile->shouldReceive('increment')->andReturn(true);
     $instance->bind('fileable-id', $mockFile);
 }
コード例 #4
0
ファイル: Setting.php プロジェクト: xpressengine/xpressengine
 /**
  * Set site representative image
  *
  * @param Image $image image instance
  * @return void
  */
 public function setSiteImage(Image $image)
 {
     $this->storage->unBindAll($this->get('uuid'));
     $this->storage->bind($this->get('uuid'), $image);
     $this->image = $image;
 }
コード例 #5
0
 public function testBind()
 {
     list($handler, $repo, $auth, $keygen) = $this->getMocks();
     $mockFile = m::mock('Xpressengine\\Storage\\File');
     $mockFile->id = 'fileidstring';
     $repo->shouldReceive('relating')->once()->with('targetidstring', 'fileidstring')->andReturnNull();
     $instance = new Storage($handler, $repo, $auth, $keygen);
     $instance->bind('targetidstring', $mockFile);
 }