phapi/serializer

This package is abandoned and no longer maintained. No replacement package was suggested.

Phapi Serializer is a helper class for Serializer Middleware.

1.0.0 2015-07-02 08:44 UTC

This package is not auto-updated.

Last update: 2021-02-05 22:45:50 UTC


README

Build status Code Climate Test Coverage

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() or deserialize() 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.