phapi / serializer
Phapi Serializer is a helper class for Serializer Middleware.
Installs: 1 674
Dependents: 4
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: >=5.6.0
- phapi/contract: 1.*
- phapi/exception: 1.*
- phapi/http: 1.*
Requires (Dev)
- codeclimate/php-test-reporter: dev-master
- mockery/mockery: 0.9.*
- phpunit/phpunit: 4.6.*
This package is not auto-updated.
Last update: 2021-02-05 22:45:50 UTC
README
The serializer and deserializer helper classes implements a majority of the SerializerMiddleware Contract.
Each serializer middleware package should always contain two classes: a serializer and a deserializer.
You can dramatically shorten the amount of time and code by using the Phapi Serializer Helper classes.
$ php composer.phar require phapi/serializer:1.*
These classes contains a wast majority of the needed code for a serializer. Since there is only two things that is different between different serializers there is no point in writing the same code over and over again in each serializer.
The two things that separates serializers are:
- A list of supported mime types
- The
serialize()
ordeserialize()
method. Note that the method should throw an InternalServerError if the serialize/deserialize fails.
Here's an example that can be used as a starting point for a new serializer:
<?php namespace Phapi\Middleware\Serializer\Example; use Phapi\Exception\InternalServerError; use Phapi\Serializer\Serializer; class Example extends Serializer { /** * Valid mime types * * @var array */ protected $mimeTypes = [ 'application/example' ]; /** * Serialize body * * @param array $unserializedBody * @return string * @throws InternalServerError */ protected function serialize(array $unserializedBody = []) { } }
Example:
See the Json serializer and deserializer for a working example.
Phapi
This is a Phapi package used by the Phapi Framework.
License
Serializer is licensed under the MIT License - see the license.md file for details
Contribute
Contribution, bug fixes etc are always welcome.