Download the PHP package peekandpoke/slumber without Composer
On this page you can find all versions of the php package peekandpoke/slumber. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download peekandpoke/slumber
More information about peekandpoke/slumber
Files in peekandpoke/slumber
Package slumber
Short Description Serialization through Annotations
License BSD-3-Clause
Informations about the package slumber
Slumber
What is Slumber? It is a tool for mapping data from objects to arrays and vice versa.
It gives you the possibility to easily map your domain model to JSON. Or to map from JSON to your domain model classes.
Slumber uses Doctrine Annotations. The annotations are used to mark which properties of your classes are to be mapped and in which way.
(PHP5.6 compatibility until v0.4.x)
Basic example
The "trademark" of the slumber annotated classes are annotations like these:
might output the following:
Getting started
Array codec example
In order to get the ArrayCodec into our hands we have to set it up:
Mapping
In order to fully control serialization and de-serialization there is a set of annotations that can be used.
Mapping scalars
You will find the implementation of all mappers here
Slumber\AsBool()
Maps values from and to booleans.
maps to
maps to
The same behaviour applys for the opposite direction. For more details on how the mapper works have a look here
Slumber\AsDecimal()
Maps values from and to floating point values.
maps to
maps to
The same behaviour applys for the opposite direction. For more details on how the mapper works have a look here
Slumber\AsInteger()
Maps values from and to floating point values.
maps to
maps to
The same behaviour applys for the opposite direction. For more details on how the mapper works have a look here
Slumber\AsIs()
Maps values from and to as they are.
maps to
maps to
The same behaviour applys for the opposite direction. For more details on how the mapper works have a look here
Slumber\AsString()
Maps values from and to floating point values.
maps to
maps to
The same behaviour applys for the opposite direction. For more details on how the mapper works have a look here
Mapping Nested Objects
Slumber\AsObject()
Maps from and to nested objects.
maps to
maps to
The same behaviour applys for the opposite direction. For more details on how the mapper works have a look here
Slumber\AsEnum()
Maps values from and to enum values.
For this to work we need an Enum class. For details on the Enums have a look at here.
maps to
maps to
The same behaviour applys for the opposite direction. For more details on how the mapper works have a look here
Mapping Collections, Lists, KeyValue-Pairs
Slumber\AsList()
Maps values from and to lists (arrays without indexes).
The annotations expects a nested annotation that controls the shape of the elements within the collection.
maps to
maps to
The same behaviour applys for the opposite direction. For more details on how the mapper works have a look here
Similarly one would map to a list of objects:
Slumber\AsMap()
Maps values from and to KeyValue-Pairs (arrays with indexes).
The annotations expects a nested annotation that controls the shape of the elements within the collection.
maps to
maps to
The same behaviour applys for the opposite direction. For more details on how the mapper works have a look here
Similarly one would map to a list of objects:
Slumber\AsKeyValuePairs()
Maps values from and to special shaped KeyValue-Pairs. This can be useful in terms of database indexing.
The annotations expects a nested annotation that controls the shape of the elements within the collection.
maps to
maps to
The same behaviour applys for the opposite direction. For more details on how the mapper works have a look here
Similarly one would map to a list of objects:
Polymorphism example
When serializing the polymorphism information is not needed. Since we know exactly which class we have in our hand to serialize.
But while de-serialization polymorphism needs to be annotated explicitly. Only by doing this we can know which classes to instantiate. We also need a field in the data, which acts as the discriminator.
TICKETS:
next ticket number: 14
PRIO I
SLUMBER-13 - 0%
( ) unit test for polymorphics that fall back to the default
( ) a) discriminator no set
( ) b) unknown discriminator set
SLUMBER-12 - 50% - Implement aliases class for repositories -> in order to store multiple type in one collection we must be able to specify alias classes for repositories (x) reported 2016-11-15 (x) implemented 2016-11-15 ( ) unit-tests
SLUMBER-4 - 0% - Refactor the hardcoded visitors in the MongoDbCodec set to come from the MongoDbEntityConfig
-> the config reader must automatically add the visitors (can user override these somehow?)
-> it is more generic and will work fine in conjunction with user-attached listeners
(x) reported 2016-05-01
SLUMBER-7 - 0% -
PRIO II
SLUMBER-3 - 0% - Let visitors like onPreCreate() pass an event class instead of multiple parameters -> better extensibility -> event propagation could be stopped (x) reported 2016-05-01
SLUMBER-2 - 0% - setting and reading of properties through getters and setters first. If not possible use reflection
-> reading and writing of inherited private properties will be possible
-> +33% speed
(x) reported 2016-05-01
SLUMBER-8 - 0% - implement GeoJSON support for Data\MongoDB
-> implement GeoSpatialIndex for GeoJson types
-> implement GeoJsonPolygon, GeoJsonMultiPolygon and other GeoJson types
(x) reported 2016-05-12
SLUMBER-7 - IRepository::save should return a more specific result than @return array|null (x) reported 2016-05-12
PRIO III
SLUMBER-6 - 0% - Make Slumber\Swagger an own package and base it on a generic code generation component -> this is a project of its own -> get rid of gossi/php-code-gen (x) reported 2016-05-01
Completed
SLUMBER-1 - 100% - Remove @AsOne2One annotation and do similar as with @AsId -> currently entities marked like this cannot be used with the ArrayCodec (which is broken behaviour) (x) completed 2016-05-11
SLUMBER-5 - 100% - move Slumber\MongoDb to Slumber\Data\MongoDb -> Slumber\Data will be the home of all database things (x) completed 2016-05-11
SLUMBER-9 - 100% - implement polymorphic slumbering and awaking (x) reported 2016-05-14 (x) completed 2016-10-01 (x) unit-tests
SLUMBER-10 - 100% implement usage of collection classes for all AsCollection mappings -> This will make it possible to wrap incoming arrays into Collection classes. -> This will increase convenience for operations on array since the code will be encapsulated alongside the data -> Example: a TagsSet collection type which contains tags, could have methods like has(), addUnique(), remove() (x) reported 2016-11-01 (x) completed 2016-11-13 (x) unit-tests
SLUMBER-11 - 100% implement LazyDbRefCollection for storing lists of referenced objects (x) reported 2016-11-13 (x) completed 2016-11-13 (x) unit-tests
All versions of slumber with dependencies
psr/log Version ^1.0.2
psr/container Version ^1.0
symfony/finder Version ^3.3.10
peekandpoke/psi Version ^1.0.1
doctrine/common Version ^2.8.1
peekandpoke/php-types Version ~1.2.0