Skip to content

Latest commit

 

History

History
50 lines (36 loc) · 1.1 KB

creating_factories.md

File metadata and controls

50 lines (36 loc) · 1.1 KB

Factories

Response factories have to implement Wtk\Response\Factory\FactoryInterface which requires:

function create(PrototypeInterface $prototype = null);

Example factory, which uses serializer to parse response content to specific format:

namespace My\Own\Factory;

use Wtk\Response;
use Wtk\Response\Prototype\PrototypeInterface;
use Wtk\Response\Factory\SerializerAwareFactory;

class MyFactory extends SerializerAwareFactory implements FactoryInterface
{
	public function create(PrototypeInterface $prototype = null)
    {
    	$response = new Response();

        if (null !== $prototype) {
            $response->setPrototype($prototype);
        }

        $response->setSerializer($this->getSerializer());

        /**
         * Here you can alter response any way you want...
         */

        return $response;
    }
}

Documentation