PHP Classes

Yii2 MultiFS: File system providers to access configurable paths

Recommend this page to a friend!
  Info   View files Documentation   View files View files (61)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog (1)    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 19 All time: 11,204 This week: 488Up
Version License PHP version Categories
yii2-multifs 1.0MIT/X Consortium ...5PHP 5, Files and Folders, Libraries
Description 

Author

This package implements file system providers to access configurable paths.

It provides classes that implement PHP file system iterator interfaces that can access directories and files with paths based on configuration values from the YII framework.

The package also provides a file uploading handling that can use the file system classes to implement the processing of files uploaded to a site using these classes.

Innovation Award
PHP Programming Innovation award nominee
January 2023
Number 3
PHP is a flexible language in many aspects. One of these aspects is that it allows applications to provide classes that emulate several operations developers can execute when accessing files and directories.

For instance, PHP provides file system iterator classes that allow applications to traverse the files and directories contained in a given directory.

This package implements file system classes that file system iterator classes can access to traverse directories so that the full path is defined dynamically from application configuration values loaded using the Yii2 framework configuration access classes.

It also provides file upload handling support that uses these file system access classes to store the uploaded file contents in directories with paths that depend on the current application configuration.

This way, this application provides flexibility to application developers, so they do not have to hardcode the full application paths of the directories where important application files are stored.

Manuel Lemos
Picture of Insolita
  Performance   Level  
Name: Insolita <contact>
Classes: 20 packages by
Country: Russian Federation Russian Federation
Age: 38
All time rank: 335592 in Russian Federation Russian Federation
Week rank: 353 Up16 in Russian Federation Russian Federation Up
Innovation award
Innovation award
Nominee: 14x

Documentation

Multifs Manager

- Provide Multifs Manager based on (League\Flysystem\MountManager) for work with set of filesystems (League\Flysystem\Filesystem); - Provide flexible Uploader service with support different strategies for resolve file naming, file path structure, and file saving - Provide sample Upload,View and Delete Actions with output compatible with trntv\filekit\widget\Upload

Status

Installation

The preferred way to install this extension is through composer.

Either run

composer require --prefer-dist insolita/yii2-multifs "~1.0.0"

or add

"insolita/yii2-multifs": "~0.0.1"

to the require section of your composer.json file.

Usage

Once the extension is installed, simply use it in your code by :

Define in bootstrap neccessary filesystems

 $avatars = (new \insolita\multifs\builders\LocalFsBuilder('@app/web/uploads/avatars'))->build();
 $covers = (new \insolita\multifs\builders\LocalFsBuilder('@app/web/uploads/covers'))->build();
 $attach = (new \insolita\multifs\builders\LocalFsBuilder('@app/web/uploads/attach'))->build();
 $data = (new \insolita\multifs\builders\LocalFsBuilder('@data'))->build();

(Ensure that aliases already defined)

Register in container:

 \insolita\multifs\contracts\IMultifsManager::class                                              => [
                \insolita\multifs\MultiFsManager::class,
                [
                    [
                        'avatars'  => $avatars,
                        'covers'   => $covers,
                        'attach'   => $attach,
                        'internal' => $data,
                    ],
                ],
            ],
            \insolita\multifs\contracts\IUploader::class=>[
                \insolita\multifs\Uploader::class,
                [
                    \yii\di\Instance::of(\insolita\multifs\contracts\IMultifsManager::class),
                    'attach'
                ]
            ],

also you can add components aliases


'components'=>[
   'multifs'=>\insolita\multifs\contracts\IMultifsManager::class,
   'uploader'=>\insolita\multifs\contracts\IUploader::class,
]

On fly usage


      echo Yii::$app->multifs->listPrefixes();
      Yii::$app->multifs->mountFilesystem('special', new Filesystem(new Adapter(...)));
      Yii::$app->multifs->write('special://some/file/path/name.txt','Hello Test');
      $fs = Yii::$app->multifs->getFilesystem('internal');
      Vardumper::dump($fs->listConents('',true));

Uploader


     $file = \yii\web\UploadedFile::getInstanceByName('file');
     $path = Yii::$app->uploader->setFsPrefix('avatars')
               ->setFileNameStrategy(new insolita\multifs\strategy\filename\AsIsStrategy())
               ->setFilePathStrategy(new insolita\multifs\strategy\filename\NameHashStrategy())
               ->setFileSaveStrategy(new insolita\multifs\strategy\filename\ExceptionSaveExistsStrategy())
               ->save($file);

    \Yii::$app->response->sendStreamAsFile(Yii::$app->multifs->readStream($path),
                                            pathinfo($path, PATHINFO_BASENAME),
                                            [
                                               'mimeType' => $file->getType(),
                                               'inline'=>true
                                            ]);

Other documentation will be later; see tests


  Files folder image Files  
File Role Description
Files folder imagesrc (2 files, 6 directories)
Files folder imagetests (4 files, 2 directories)
Accessible without login Plain text file .scrutinizer.yml Data Auxiliary data
Accessible without login Plain text file .travis.yml Data Auxiliary data
Accessible without login Plain text file CHANGELOG.md Data Auxiliary data
Accessible without login Plain text file codeception.yml Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  src  
File Role Description
Files folder imageactions (3 files)
Files folder imagebuilders (3 files)
Files folder imagecontracts (6 files)
Files folder imageentity (4 files)
Files folder imagestrategy (3 directories)
Files folder imageuploader (1 file, 1 directory)
  Plain text file MultiFsManager.php Class Class source
  Plain text file Uploader.php Class Class source

  Files folder image Files  /  src  /  actions  
File Role Description
  Plain text file DeleteAction.php Class Class source
  Plain text file UploadAction.php Class Class source
  Plain text file ViewAction.php Class Class source

  Files folder image Files  /  src  /  builders  
File Role Description
  Plain text file ContextBuilder.php Class Class source
  Plain text file FileUrlManager.php Class Class source
  Plain text file LocalFsBuilder.php Class Class source

  Files folder image Files  /  src  /  contracts  
File Role Description
  Plain text file IContextBuilder.php Class Class source
  Plain text file IFileObject.php Class Class source
  Plain text file IFilesystemBuilder.php Class Class source
  Plain text file IFileUrlManager.php Class Class source
  Plain text file IMultifsManager.php Class Class source
  Plain text file IUploader.php Class Class source

  Files folder image Files  /  src  /  entity  
File Role Description
  Plain text file Context.php Class Class source
  Plain text file UploadedFile.php Class Class source
  Plain text file UploaderErrors.php Class Class source
  Plain text file UploaderResponse.php Class Class source

  Files folder image Files  /  src  /  strategy  
File Role Description
Files folder imagefilename (5 files)
Files folder imagefilepath (5 files)
Files folder imagefilesave (6 files)

  Files folder image Files  /  src  /  strategy  /  filename  
File Role Description
  Plain text file AsIsStrategy.php Class Class source
  Plain text file IFileNameStrategy.php Class Class source
  Plain text file RandomContextPrefixedStrategy.php Class Class source
  Plain text file RandomStringStrategy.php Class Class source
  Plain text file SlugTimeStampedStrategy.php Class Class source

  Files folder image Files  /  src  /  strategy  /  filepath  
File Role Description
  Plain text file ContextNameHashStrategy.php Class Class source
  Plain text file DateStrategy.php Class Class source
  Plain text file DirLimitationStrategy.php Class Class source
  Plain text file IFilePathStrategy.php Class Class source
  Plain text file NameHashStrategy.php Class Class source

  Files folder image Files  /  src  /  strategy  /  filesave  
File Role Description
  Plain text file DeletePreviousExistsStrategy.php Class Class source
  Plain text file ExceptionSaveExistsStrategy.php Class Class source
  Plain text file IFileSaveStrategy.php Class Class source
  Plain text file OverwriteExistsStrategy.php Class Class source
  Plain text file RenameIfNotEqualsStrategy.php Class Class source
  Plain text file RenameOnExistsStrategy.php Class Class source

  Files folder image Files  /  src  /  uploader  
File Role Description
Files folder imageevents (4 files)
  Plain text file BaseUploader.php Class Class source

  Files folder image Files  /  src  /  uploader  /  events  
File Role Description
  Plain text file AfterDeleteUploadEvent.php Class Class source
  Plain text file AfterSaveUploadEvent.php Class Class source
  Plain text file BeforeDeleteUploadEvent.php Class Class source
  Plain text file BeforeSaveUploadEvent.php Class Class source

  Files folder image Files  /  tests  
File Role Description
Files folder imageconfig (2 files)
Files folder imageunit (10 files)
  Accessible without login Plain text file .env Data Auxiliary data
  Accessible without login Plain text file bootstrap.php Example Example script
  Accessible without login Plain text file unit.suite.yml Data Auxiliary data
  Accessible without login Plain text file yii Example Example script

  Files folder image Files  /  tests  /  config  
File Role Description
  Plain text file base.php Class Class source
  Plain text file console.php Class Class source

  Files folder image Files  /  tests  /  unit  
File Role Description
  Plain text file ActionsTest.php Class Class source
  Accessible without login Plain text file bootstrap.php Aux. Auxiliary script
  Plain text file CustomContext.php Class Class source
  Plain text file DummyUser.php Class Class source
  Plain text file MultiFsTest.php Class Class source
  Plain text file NameStrategyTest.php Class Class source
  Plain text file PathStrategyTest.php Class Class source
  Plain text file SaveStrategyTest.php Class Class source
  Plain text file TestFsBuildTrait.php Class Class source
  Plain text file UploaderTest.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:19
This week:0
All time:11,204
This week:488Up