Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Y
yii2-flysystem-rest-api
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Jobs
Commits
Open sidebar
Elias Luhr
yii2-flysystem-rest-api
Commits
5a4f85e0
Commit
5a4f85e0
authored
Oct 31, 2023
by
Elias Luhr
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'dev/FileStorageComponentInterface' into 'master'
add FileStorageComponentInterface See merge request
!2
parents
79c5159f
5f4bd0d6
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
175 additions
and
16 deletions
+175
-16
Module.php
src/Module.php
+3
-3
FileStorage.php
src/components/FileStorage.php
+2
-1
ApiController.php
src/controllers/ApiController.php
+0
-1
BaseController.php
src/controllers/BaseController.php
+2
-2
FileStorageComponentInterface.php
src/interfaces/FileStorageComponentInterface.php
+159
-0
FileStorageModel.php
src/models/FileStorageModel.php
+6
-6
StorageItem.php
src/models/StorageItem.php
+1
-1
FileStorageTrait.php
src/traits/FileStorageTrait.php
+2
-2
No files found.
src/Module.php
View file @
5a4f85e0
...
...
@@ -3,7 +3,7 @@
namespace
eluhr\flysystemRestApi
;
use
dmstr\web\traits\AccessBehaviorTrait
;
use
eluhr\flysystemRestApi\
components\FileStorag
e
;
use
eluhr\flysystemRestApi\
interfaces\FileStorageComponentInterfac
e
;
use
yii\di\Instance
;
class
Module
extends
\yii\base\Module
...
...
@@ -24,7 +24,7 @@ class Module extends \yii\base\Module
{
parent
::
init
();
// Ensure, that file storage component is instance of needed component
Instance
::
ensure
(
$this
->
fileStorage
,
FileStorage
::
class
);
// Ensure, that file storage component is instance of needed component
interface
Instance
::
ensure
(
$this
->
fileStorage
,
FileStorage
ComponentInterface
::
class
);
}
}
src/components/FileStorage.php
View file @
5a4f85e0
...
...
@@ -4,6 +4,7 @@ namespace eluhr\flysystemRestApi\components;
use
eluhr\flysystemRestApi\behaviors\PluginsBehavior
;
use
eluhr\flysystemRestApi\helpers\StorageItemHelper
;
use
eluhr\flysystemRestApi\interfaces\FileStorageComponentInterface
;
use
eluhr\flysystemRestApi\interfaces\PluginInterface
;
use
League\Flysystem\DirectoryListing
;
use
League\Flysystem\FileAttributes
;
...
...
@@ -28,7 +29,7 @@ use eluhr\flysystemRestApi\events\FileStorageEvent;
* @property FilesystemAdapter $adapter
* @property-read Filesystem $filesystem
*/
class
FileStorage
extends
Component
class
FileStorage
extends
Component
implements
FileStorageComponentInterface
{
/**
* Abstract adapter for the filesystem
...
...
src/controllers/ApiController.php
View file @
5a4f85e0
...
...
@@ -2,7 +2,6 @@
namespace
eluhr\flysystemRestApi\controllers
;
use
eluhr\flysystemRestApi\components\FileStorage
;
use
eluhr\flysystemRestApi\models\Directory
;
use
eluhr\flysystemRestApi\models\File
;
use
eluhr\flysystemRestApi\models\StorageItem
;
...
...
src/controllers/BaseController.php
View file @
5a4f85e0
...
...
@@ -2,7 +2,7 @@
namespace
eluhr\flysystemRestApi\controllers
;
use
eluhr\flysystemRestApi\
components\FileStorag
e
;
use
eluhr\flysystemRestApi\
interfaces\FileStorageComponentInterfac
e
;
use
eluhr\flysystemRestApi\Module
;
use
Yii
;
use
yii\base\InvalidConfigException
;
...
...
@@ -28,7 +28,7 @@ abstract class BaseController extends Controller
/**
* @throws InvalidConfigException
*/
public
function
getFileStorage
()
:
FileStorage
public
function
getFileStorage
()
:
FileStorage
ComponentInterface
{
return
Yii
::
$app
->
get
(
$this
->
module
->
fileStorage
);
}
...
...
src/interfaces/FileStorageComponentInterface.php
0 → 100644
View file @
5a4f85e0
<?php
/**
* @author: Jens Giessmann <jg@handcode.de>
* @copyright: 2023, Jens Giessmann
*/
namespace
eluhr\flysystemRestApi\interfaces
;
use
League\Flysystem\DirectoryListing
;
use
League\Flysystem\FilesystemAdapter
;
use
League\Flysystem\FilesystemReader
;
use
League\Flysystem\StorageAttributes
;
interface
FileStorageComponentInterface
{
/**
* @param string $path relative path to the file
* @param string $contents file contents as string
* @param array $config Config options may vary between adapters
*
* @return bool
*/
public
function
write
(
string
$path
,
string
$contents
,
array
$config
=
[])
:
bool
;
/**
* @param string $path relative path to the file
* @param resource $stream stream to write to
* @param array $config Config options may vary between adapters
*
* @return bool
*/
public
function
writeStream
(
string
$path
,
$stream
,
array
$config
=
[])
:
bool
;
/**
* @param string $sourcePath relative path to the source file
* @param string $destinationPath relative path to the destination file
* @param array $config Config options may vary between adapters
*
* @return bool
*/
public
function
move
(
string
$sourcePath
,
string
$destinationPath
,
array
$config
=
[])
:
bool
;
/**
* @param string $sourcePath relative path to the source file
* @param string $destinationPath relative path to the destination file
* @param array $config Config options may vary between adapters
*
* @return bool
*/
public
function
copy
(
string
$sourcePath
,
string
$destinationPath
,
array
$config
=
[])
:
bool
;
/**
* @param string $path relative path to the file
*
* @return string|false
*/
public
function
read
(
string
$path
);
/**
* @param string $path relative path to the file
*
* @return resource|false
*/
public
function
readStream
(
string
$path
);
/**
* @param string $path relative path to the file
*
* @return string|false
*/
public
function
visibility
(
string
$path
);
/**
* @param string $path relative path to the file
* @param string $visibility public|private
*
* @return bool
* @see Visibility
*/
public
function
setVisibility
(
string
$path
,
string
$visibility
)
:
bool
;
/**
* @param string $path relative path to the file
*
* @return bool
*/
public
function
delete
(
string
$path
)
:
bool
;
/**
* @param string $path relative path to the directory
*
* @return bool
*/
public
function
deleteDirectory
(
string
$path
)
:
bool
;
/**
* @param string $path relative path to the directory
*
* @return bool
*/
public
function
createDirectory
(
string
$path
)
:
bool
;
/**
* @param string $path relative path to the directory
* @param bool $recursive If true, list recursively the contents of the directory in a flat list.
*
* @return string|false
*/
public
function
listContents
(
string
$path
,
bool
$recursive
=
FilesystemReader
::
LIST_SHALLOW
)
:
DirectoryListing
|
false
;
/**
* @param string $path
*
* @return bool
*/
public
function
fileExists
(
string
$path
)
:
bool
;
/**
* File size in bytes
*
* @param string $path
*
* @return int|false
*/
public
function
fileSize
(
string
$path
)
:
bool
|
int
;
/**
* @param string $path
*
* @return string|false
* @link https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types
*/
public
function
mimeType
(
string
$path
)
:
bool
|
string
;
/**
* @param string $path
*
* @return int|false
*/
public
function
lastModified
(
string
$path
)
:
bool
|
int
;
/**
* @return FilesystemAdapter
*/
public
function
getAdapter
()
:
FilesystemAdapter
;
/**
* @param FilesystemAdapter $adapter
*/
public
function
setAdapter
(
FilesystemAdapter
$adapter
)
:
void
;
/**
* @param StorageAttributes $storageAttributes
*
* @return array
*/
public
static
function
buildItem
(
StorageAttributes
$storageAttributes
)
:
array
;
}
\ No newline at end of file
src/models/FileStorageModel.php
View file @
5a4f85e0
...
...
@@ -2,12 +2,12 @@
namespace
eluhr\flysystemRestApi\models
;
use
eluhr\flysystemRestApi\
components\FileStorag
e
;
use
eluhr\flysystemRestApi\
interfaces\FileStorageComponentInterfac
e
;
use
yii\base\Model
;
abstract
class
FileStorageModel
extends
Model
{
private
FileStorage
$_fileStorage
;
private
FileStorage
ComponentInterface
$_fileStorage
;
/**
* @inheritdoc
...
...
@@ -19,17 +19,17 @@ abstract class FileStorageModel extends Model
}
/**
* @return
\eluhr\flysystemRestApi\components\FileStorag
e
* @return
FileStorageComponentInterfac
e
*/
public
function
getFileStorage
()
:
\eluhr\flysystemRestApi\components\FileStorag
e
public
function
getFileStorage
()
:
FileStorageComponentInterfac
e
{
return
$this
->
_fileStorage
;
}
/**
* @param
\eluhr\flysystemRestApi\components\FileStorag
e $fileStorage
* @param
FileStorageComponentInterfac
e $fileStorage
*/
public
function
setFileStorage
(
\eluhr\flysystemRestApi\components\FileStorag
e
$fileStorage
)
:
void
public
function
setFileStorage
(
FileStorageComponentInterfac
e
$fileStorage
)
:
void
{
$this
->
_fileStorage
=
$fileStorage
;
}
...
...
src/models/StorageItem.php
View file @
5a4f85e0
...
...
@@ -167,7 +167,7 @@ class StorageItem extends ActiveRecord implements StorageAttributes
$transaction
->
rollBack
();
return
false
;
}
else
{
$items
[]
=
FileStorage
::
buildItem
(
$item
);
$items
[]
=
static
::
getFileStorage
()
::
buildItem
(
$item
);
}
}
...
...
src/traits/FileStorageTrait.php
View file @
5a4f85e0
...
...
@@ -2,12 +2,12 @@
namespace
eluhr\flysystemRestApi\traits
;
use
eluhr\flysystemRestApi\
components\FileStorag
e
;
use
eluhr\flysystemRestApi\
interfaces\FileStorageComponentInterfac
e
;
use
Yii
;
trait
FileStorageTrait
{
public
function
getFileStorage
()
:
FileStorag
e
public
static
function
getFileStorage
()
:
FileStorageComponentInterfac
e
{
return
Yii
::
$app
->
get
(
'fileStorage'
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment