PHP Class Xpressengine\Storage\Storage

### app binding : xe.storage 으로 바인딩 되어 있음 Storage Facade 로 접근이 가능 ### 파일 저장 업로드된 파일을 저장하는 경우 Request 에서 반환하는 Symfony\Component\HttpFoundation\File\UploadedFile 객체를 전달 해야 합니다. php $uploadFile = Input::file('file'); Storage::upload($uploadFile, 'dir/path'); 업로드 되는 파일의 이름을 별도로 지정하고 싶은 경우 3번째 인자로 지정하고 싶은 이름을 넣어 주면 됩니다. php Storage::upload($uploadFile, 'dir/path', 'new_name'); 저장되는 저장소를 지정하고 싶은 경우 4번째 인자로 config 에 설정된 저장소 중 하나를 함께 전달 하면 됩니다. php Storage::upload($uploadFile, 'dir/path', 'new_name', 's3'); file content 를 직접 저장시킬 수 도 있습니다. 이때는 create 메서드를 사용합니다. $content = file_get_content('path/to/file'); Storage::create($content, 'dir/path', 'filename'); 또한 create 메서드를 통해 부모 자식관계를 형성할 수 있습니다. 이때는 5번째 인자로 부모에 해당하는 파일의 아이디를 전달하면 됩니다. php Storage::create($content, 'dir/path', 'filename', null, 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'); ### 다운로드 다운로드 시에는 download 메서드에 파일객체를 전달하면 됩니다. 이때 다운로드 되는 파일명을 변경하고자 하는 경우 변경할 이름도 함께 전달해야합니다. Storage::download($file, 'new_filename'); ### 연결 Storage 는 특정 대상이 파일을 소유하는 형태가 아닌 파일을 특정대상과 연결하는 방식으로 제공 됩니다. 특정 대상으로 부터 파일 업로드 후 연결 처리를 하기위해 다음과 같이 사용해야 합니다. php $uploadFile = Input::file('file'); $file = Storage::upload($file, 'dir/path'); Storage::bind('target id', $file); 연결을 끊는 동작은 unBind를 이용합니다. php Storage::unBind('target id', $file); 이때 파일에 연결된 대상이 더이상 존재하지 않는 경우 삭제를 원한다면 삭제처리를 하도록 추가 정보를 전달합니다. php Storage::unBind('target id', $file, true);
Author: XE Team (developers) ([email protected])
显示文件 Open project: xpressengine/xpressengine Class Usage Examples

Protected Properties

Property Type Description
$auth Xpressengine\User\GuardInterface Authenticator instance
$distributor Xpressengine\Storage\Distributor distributor instance
$files FilesystemHandler filesystem handler instance
$keygen Xpressengine\Keygen\Keygen key generator instance
$tempFiles TempFileCreator temporary file creator instance

Public Methods

Method Description
__construct ( FilesystemHandler $files, Xpressengine\User\GuardInterface $auth, Keygen $keygen, Xpressengine\Storage\Distributor $distributor, TempFileCreator $tempFiles ) constructor
bind ( string $fileableId, File $file ) : void set the target be have a file
bytesByMime ( callable $scope = null ) : array mime 별 파일 용량 정보 반환
countByMime ( callable $scope = null ) : array mime 별 파일 갯수 반환
create ( string $content, string $path, string $name, string | null $disk = null, string | null $originId = null, Xpressengine\User\UserInterface $user = null ) : File create file
createModel ( ) : File create file model
download ( File $file, string | null $name = null ) : void file download from storage
getDistributor ( ) : Xpressengine\Storage\Distributor distributor instance
getFilesystemHandler ( ) : FilesystemHandler file system handler instance
getModel ( ) : string Returns model class
getTempFileCreator ( ) : TempFileCreator Returns the TempFileCreator instance
has ( string $fileableId, File $file ) : boolean has
remove ( File $file ) : boolean remove file
setDistributor ( Xpressengine\Storage\Distributor $distributor ) : void set distributor instance
sync ( string $fileableId, array $fileIds = [] ) : void Sync fileable's files to fileable
unBind ( string $fileableId, File $file, boolean $remove = false ) : void set the target be not have a file
unBindAll ( string $fileableId ) : void unset all fileable's files to fileable
upload ( Symfony\Component\HttpFoundation\File\UploadedFile $uploaded, string $path, string | null $name = null, string | null $disk = null, Xpressengine\User\UserInterface $user = null ) : File file upload to storage

Private Methods

Method Description
makeFilename ( string $clientname ) : string make file name
makePath ( string $id, string $path ) : string make path name

Method Details

__construct() public method

constructor
public __construct ( FilesystemHandler $files, Xpressengine\User\GuardInterface $auth, Keygen $keygen, Xpressengine\Storage\Distributor $distributor, TempFileCreator $tempFiles )
$files FilesystemHandler filesystem handler instance
$auth Xpressengine\User\GuardInterface Authenticator instance
$keygen Xpressengine\Keygen\Keygen key generator instance
$distributor Xpressengine\Storage\Distributor distributor instance
$tempFiles TempFileCreator temporary file creator instance

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

bytesByMime() public method

mime 별 파일 용량 정보 반환
public bytesByMime ( callable $scope = null ) : array
$scope callable 검색 조건
return array ex.) [mime => bytes]

countByMime() public method

mime 별 파일 갯수 반환
public countByMime ( callable $scope = null ) : array
$scope callable 검색 조건
return array ex.) [mime => count]

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

createModel() public method

create file model
public createModel ( ) : File
return File

download() public method

file download from storage
public download ( File $file, string | null $name = null ) : void
$file File file instance
$name string | null name of be downloaded file
return void

getDistributor() public method

distributor instance
public getDistributor ( ) : Xpressengine\Storage\Distributor
return Xpressengine\Storage\Distributor

getFilesystemHandler() public method

file system handler instance
public getFilesystemHandler ( ) : FilesystemHandler
return FilesystemHandler

getModel() public method

Returns model class
public getModel ( ) : string
return string

getTempFileCreator() public method

Returns the TempFileCreator instance
public getTempFileCreator ( ) : TempFileCreator
return TempFileCreator

has() public method

has
public has ( string $fileableId, File $file ) : boolean
$fileableId string fileable identifier
$file File file instance
return boolean

remove() public method

remove file
public remove ( File $file ) : boolean
$file File file instance
return boolean

setDistributor() public method

set distributor instance
public setDistributor ( Xpressengine\Storage\Distributor $distributor ) : void
$distributor Xpressengine\Storage\Distributor distributor instance
return void

sync() public method

Sync fileable's files to fileable
public sync ( string $fileableId, array $fileIds = [] ) : void
$fileableId string fileable identifier
$fileIds array file identifier
return void

unBind() public method

set the target be not have a file
public unBind ( string $fileableId, File $file, boolean $remove = false ) : void
$fileableId string fileable identifier
$file File file instance
$remove boolean remove file when given true
return void

unBindAll() public method

unset all fileable's files to fileable
public unBindAll ( string $fileableId ) : void
$fileableId string fileable identifier
return void

upload() public method

file upload to storage
public upload ( Symfony\Component\HttpFoundation\File\UploadedFile $uploaded, string $path, string | null $name = null, string | null $disk = null, Xpressengine\User\UserInterface $user = null ) : File
$uploaded Symfony\Component\HttpFoundation\File\UploadedFile uploaded file instance
$path string be saved path
$name string | null be saved file name
$disk string | null disk name (ex. local, ftp, s3 ...)
$user Xpressengine\User\UserInterface user instance
return File

Property Details

$auth protected_oe property

Authenticator instance
protected GuardInterface,Xpressengine\User $auth
return Xpressengine\User\GuardInterface

$distributor protected_oe property

distributor instance
protected Distributor,Xpressengine\Storage $distributor
return Xpressengine\Storage\Distributor

$files protected_oe property

filesystem handler instance
protected FilesystemHandler,Xpressengine\Storage $files
return FilesystemHandler

$keygen protected_oe property

key generator instance
protected Keygen,Xpressengine\Keygen $keygen
return Xpressengine\Keygen\Keygen

$tempFiles protected_oe property

temporary file creator instance
protected TempFileCreator,Xpressengine\Storage $tempFiles
return TempFileCreator