PHPackages                             pluggit/storage - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [File &amp; Storage](/categories/file-storage)
4. /
5. pluggit/storage

ActiveLib[File &amp; Storage](/categories/file-storage)

pluggit/storage
===============

Virtual storage abstraction layer

0.0.8(6y ago)328.2k[4 PRs](https://github.com/CMProductions/storage/pulls)MITPHP

Since Aug 4Pushed 2y ago17 watchersCompare

[ Source](https://github.com/CMProductions/storage)[ Packagist](https://packagist.org/packages/pluggit/storage)[ RSS](/packages/pluggit-storage/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (5)Dependencies (7)Versions (13)Used By (0)

Pluggit - Storage
=================

[](#pluggit---storage)

[![Scrutinizer Code Quality](https://camo.githubusercontent.com/527155f2bd9906ca0319d93287fd794dd4ca87ef66aaf60b61f7187574769fc6/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f434d50726f64756374696f6e732f73746f726167652f6261646765732f7175616c6974792d73636f72652e706e673f623d6d617374657226733d35326638333034393365353837656265626164303537623362616434346333616164363565346666)](https://scrutinizer-ci.com/g/CMProductions/storage/?branch=master) [![Build Status](https://camo.githubusercontent.com/f9f84ed56fc5e599d74482182fad822387274469a2a4237a3ca94ad2c5ac35fb/68747470733a2f2f7472617669732d63692e6f72672f434d50726f64756374696f6e732f73746f726167652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/CMProductions/storage) [![Code Coverage](https://camo.githubusercontent.com/33fdac417c7c778dff9717080c4a9490763af24a17b4466657d4002ee7bdd553/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f434d50726f64756374696f6e732f73746f726167652f6261646765732f636f7665726167652e706e673f623d6d617374657226733d65643935613364663963326636353762303638656534356438653238356530393032306130356162)](https://scrutinizer-ci.com/g/CMProductions/storage/?branch=master)

Storage is a filesystem abstraction which allows you to easily swap out a local filesystem for a remote one.

TLDR;
-----

[](#tldr)

```
//one adapter (save data to S3)
$s3Adapter = new \Cmp\Storage\Adapter\S3AWSAdapter();
$s3Adapter->put('/tmp/test.txt',"this is a test");

//two adapters with a fallback strategy and decorated with a logger
$s3Adapter = new \Cmp\Storage\Adapter\S3AWSAdapter();
$fallBackAdapter = (new StorageBuilder())->addAdapter($s3Adapter)
    ->addAdapter($s3Adapter) //the order matters with FallBackChainStrategy
    ->addAdapter($fileSystemAdapter)
    ->setLogger(new Logger())
    ->build(new \Cmp\Storage\Strategy\FallBackChainStrategy());

//it saves data to S3 and if fails save the data to FS
$fallBackAdapter->put('/tmp/test.txt',"this is a test");

//one step more fs adapter bind to one folder and strategy to another folder
$vfs = new \Cmp\Storage\MountableVirtualStorage($fileSystemStorage); //bind to any path that non match with mountpoint folders
$localMountPoint = new \Cmp\Storage\MountPoint('/tmp', $fileSystemAdapter);
$publicMountPoint = new \Cmp\Storage\MountPoint('/var/www/app/public', $fallBackAdapter);
$vfs->registerMountPoint($localMountPoint);
$vfs->registerMountPoint($publicMountPoint);

/*
//move file from /tmp (FS) to /var/www/app/public (S3) and if fails try to move from /tmp (FS) to /var/www/app/public (FS)
*/
$vfs->move('/tmp/testfile.jpg','/var/www/app/public/avatar.jpg' );
```

Installation
------------

[](#installation)

Add this repo to your composer.json

```
"repositories": {
  "pluggit/storage": {
    "type": "vcs",
    "url": "git@github.com:CMProductions/storage.git"
  }
}
```

Then require it as usual:

```
composer require "pluggit/storage"
```

\##Adapters

It provides a generic API for handling common tasks across multiple file storage engines. If you want add a new one, you have to implements `\Cmp\Storage\AdapterInterface`.

The adapter interface contains these methods:

- `exists`
- `get`
- `getStream`
- `rename`
- `copy`
- `delete`
- `put`
- `putStream`
- `getName`

### Builtin

[](#builtin)

This libs is shipped with two builtin adapters ready to use.

- FileSystem: This adapter interacts directly with the host filesystem.
- S3AWS: This adapter interacts with Amazon S3 service. (You must add some env parameters to use it)

Strategies
----------

[](#strategies)

It allows you specify different call strategies when you have been registered more than one adapter. If you want create a custom call strategy you must extend `\Cmp\Storage\Strategy\AbstractStorageCallStrategies`

***Note:*** By default the lib uses the CallAllStrategy.

Mountpoints
-----------

[](#mountpoints)

Some times you will want use different adapters or strategies depending of the path you are working. We solve this using the MountableVirtualStorage. MountableVirtualStorage needs be constructed with one VirtualStorage implementation (Adapter or Strategy) and it binds this VirtualStorage to '/'.

After that you can register new mount points.

Example:

```
 $s3Adapter = new \Cmp\Storage\Adapter\S3AWSAdapter();
 $fileSystemAdapter = new \Cmp\Storage\Adapter\FileSystemAdapter();

 $localMountPoint = new \Cmp\Storage\MountPoint('/tmp', $fileSystemAdapter);
 $publicMountPoint = new \Cmp\Storage\MountPoint('/var/www/app/public', $s3Adapter);

 $vfs = new \Cmp\Storage\MountableVirtualStorage($fileSystemStorage); //bind to /
 $vfs->registerMountPoint($localMountPoint);
 $vfs->registerMountPoint($publicMountPoint);

 $vfs->delete('/tmp/testfile'); //running over filesystem adapter
 $vfs->put('/var/www/app/public/testfile', '..some content..')); //running over AWS S3 adapter
```

- Movement between mount points are also allowed.
- You can register adapters, strategies or any class that implements VirtualStorage

### Builtin

[](#builtin-1)

There are two ready to use strategies.

- `\Cmp\Storage\StrategyFallBackChainStrategy` : This strategy call each adapter by insertion order since one of them return a some result. (In case of error, it will be logged silently)
- `\Cmp\Storage\Strategy\CallAllStrategy` : This strategy call all providers to apply the same action. (perfect for fist migration steps)

Logging
-------

[](#logging)

The lib provides a default stdout logger but you can change in any moment by any PSR-3 logger compliant.

StorageBuilder
--------------

[](#storagebuilder)

The storage builder takes te responsibility of create an abstract storage for you.

The available functions are:

**Fluid calls:**

- `setStrategy(AbstractStorageCallStrategy $strategy)` : Set a custom strategy
- `setLogger(LoggerInterface $logger)` : Set custom logger
- `addAdapter($adapter)` : Add a new adapter
- `build(AbstractStorageCallStrategy $callStrategy = null, LoggerInterface $logger = null)` : Build the virtual storage

**Non fluid calls:**

- `getStrategy()` : Get the current strategy
- `getLogger()` :Get the current Logger
- `hasLoadedAdapters()`Check if one or more adapters has been loaded

Functions available from storage
--------------------------------

[](#functions-available-from-storage)

### Exists

[](#exists)

Check whether a file exists.

### Get

[](#get)

Read a file and return the content.

### GetStream

[](#getstream)

Retrieves a read-stream for a file.

### Rename

[](#rename)

Rename a file.

### Copy

[](#copy)

Copy a file.

### Delete

[](#delete)

Delete a file or directory (even if is not empty).

### Put

[](#put)

Create a file or update if exists. It will create the missing folders.

### PutStream

[](#putstream)

Create a file or update if exists. It will create the missing folders.

***Note:*** Use stream functions for big files.

### Requirements

[](#requirements)

- php 5.6

### Contribution

[](#contribution)

- Fork the repo.
- Fix an issue or add a new adapter or improve something or whatever you want.
- Follow the PSR-2 style.
- Run `make tests`. (add more tests if is needed).
- Make a pull request.

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity27

Limited adoption so far

Community19

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 63.1% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~189 days

Recently: every ~321 days

Total

8

Last Release

2247d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/2595584d57cbf851b56dc1935d9e34d96045fc7b4ca3c64058caa3ed5e3fb504?d=identicon)[techCMP](/maintainers/techCMP)

---

Top Contributors

[![jmartin82](https://avatars.githubusercontent.com/u/152270?v=4)](https://github.com/jmartin82 "jmartin82 (41 commits)")[![jmartinmad](https://avatars.githubusercontent.com/u/17850794?v=4)](https://github.com/jmartinmad "jmartinmad (6 commits)")[![hmoragrega](https://avatars.githubusercontent.com/u/3494001?v=4)](https://github.com/hmoragrega "hmoragrega (5 commits)")[![marclop](https://avatars.githubusercontent.com/u/7286993?v=4)](https://github.com/marclop "marclop (4 commits)")[![joancmp](https://avatars.githubusercontent.com/u/25739876?v=4)](https://github.com/joancmp "joancmp (3 commits)")[![jaroslawgabaracmp](https://avatars.githubusercontent.com/u/20397078?v=4)](https://github.com/jaroslawgabaracmp "jaroslawgabaracmp (2 commits)")[![scrutinizer-auto-fixer](https://avatars.githubusercontent.com/u/6253494?v=4)](https://github.com/scrutinizer-auto-fixer "scrutinizer-auto-fixer (2 commits)")[![joangoat](https://avatars.githubusercontent.com/u/39056218?v=4)](https://github.com/joangoat "joangoat (1 commits)")[![tetreum](https://avatars.githubusercontent.com/u/1708730?v=4)](https://github.com/tetreum "tetreum (1 commits)")

---

Tags

owner-jordi-m

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/pluggit-storage/health.svg)

```
[![Health](https://phpackages.com/badges/pluggit-storage/health.svg)](https://phpackages.com/packages/pluggit-storage)
```

###  Alternatives

[league/flysystem-aws-s3-v3

AWS S3 filesystem adapter for Flysystem.

1.6k263.6M790](/packages/league-flysystem-aws-s3-v3)[aws/aws-sdk-php-laravel

A simple Laravel 9/10/11/12/13 service provider for including the AWS SDK for PHP.

1.7k35.6M75](/packages/aws-aws-sdk-php-laravel)[humanmade/s3-uploads

WordPress plugin to store uploads on S3

2.1k2.4M9](/packages/humanmade-s3-uploads)[mreduar/s3m

Multipart Uploads using Laravel and AWS S3

173.6k](/packages/mreduar-s3m)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
