Download the PHP package naucon/storage without Composer
On this page you can find all versions of the php package naucon/storage. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download naucon/storage
More information about naucon/storage
Files in naucon/storage
Package storage
Short Description Storage Abstraction Layer .
License MIT
Homepage https://github.com/naucon/storage
Informations about the package storage
naucon Storage Package
About
This package is an abstraction layer for key/value Stores (storages). The goal is to decouple a concrete key/value store from the business logic.
Features
- storage manager as abstraction layer for storages or stores with basic CRUD operations.
- storage factory and registry to manage multiple storages or stores.
- chained storages to save entities in multiple storages or stores.
- support composite identifiers / keys.
Adapters
- array (in-memory)
- file system
- native session
- bridge to symfony session handler
- redis (predis) - requires redis 2.8 or higher
- doctrine ORM
- PSR-6 Cache
- PSR-16 Simple Cache
- null storage (stores nothing, no-memory)
Compatibility
- PHP 7.1 to 7.4
Installation
install the latest version via composer
Usage
Getting started
To use the storage we need a model (plain-old php objects). This model will be serialized so it is a good idea that the model implements the Serializable
interface - even if it is not mandatory.
With a defined model we are able to create a StorageManager
. The StorageManager
provides all the basic CRUD operations create()
, has()
, find()
, flush()
, remove()
.
To work it requires a storage provider. The provider implements a concrete storage or store. In this example we use the ArrayStorage
but you can choose any other supported provider or build a custom storage to your needs.
To save an entry in the storage we call flush($identifier, $model)
To create a new instance of the model you can call StorageManager::create()
. Requires a storage that implements CreateAwareInterface
. The created instance will not be in the storage until you flush()
it.
To retrieve an entry from the storage we call StorageManager::find($identifier)
. If no entry was found you get null
in return.
To verify if a storage contains an entry you can call StorageManager::has($identifier)
.
To always get a model instance you can call StorageManager::findOrCreate($identifier)
. That will create a new model instance if no entry was found. Requires a storage that implements CreateAwareInterface
.
The created instance will not be in the storage until you flush()
it.
To remove an entry from storage you can call StorageManager::remove($identifier, $model)
.
Remove all entries from the storage with StorageManager::removeAll()
.
With StorageManager::findAll()
you can retrieve all entries from the storage.
With StorageManager::findMultiple(array $identifiers)
you can retrieve multiple entries from the storage.
Doctrine ORM
The identifier must be handled by the storage component. Therefor doctrine ORM must use "NONE" as a Identifier Generation Strategies
XML
YAML
Annotation
Advanced Usage
Composite Identifiers / keys
The Identifier can be an integer, string or array of composite identifiers (keys).
A composite identifier has to follow the format of the upper example.
StorageChain
Use the StorageChain
to save an entry in multiple storages at the same time.
The StorageChain
provides all the basic CRUD operations has()
, find()
, flush()
, remove()
. Except create()
and findOrCreate()
these two methods are not supported.
StorageFactory
To manage multiple storages and/or different models you can use the StorageFactory
.
Combining Everything
Because the StorageManager
and StorageChain
implementing the same StorageInterface
as the concrete storage provide you can combine them.
Example
Start the build-in webserver to see the examples in action:
open url in browser
For the doctrine example please have a look at README.md in the example/doctrine
directory.
License
The MIT License (MIT)
Copyright (c) 2015 Sven Sanzenbacher
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
All versions of storage with dependencies
naucon/utility Version ~1.0
naucon/registry Version ~1.0
doctrine/common Version ^3.0.3