Mmoreram\RSQueueBundle\Factory\SerializerFactory::get PHP Method

get() public method

Generate new Serializer
public get ( ) : SerializerInterface
return SerializerInterface Generated Serializer
    public function get()
    {
        if (class_exists($this->serializerType)) {
            if (in_array('Mmoreram\\RSQueueBundle\\Serializer\\Interfaces\\SerializerInterface', class_implements($this->serializerType))) {
                return new $this->serializerType();
            } else {
                throw new SerializerNotImplementsInterfaceException();
            }
        }
        $composedSerializerNamespace = '\\Mmoreram\\RSQueueBundle\\Serializer\\' . $this->serializerType . 'Serializer';
        if (class_exists($composedSerializerNamespace)) {
            return new $composedSerializerNamespace();
        }
        throw new SerializerNotFoundException();
    }

Usage Example

 /**
  * Tests class found with not implementation of SerializerInterface
  */
 public function testNotImplementingInterfaceFound()
 {
     $serializerFactory = new SerializerFactory('\\Mmoreram\\RSQueueBundle\\Tests\\Factory\\Serializer\\FooSerializer');
     try {
         $serializerFactory->get();
     } catch (SerializerNotImplementsInterfaceException $expected) {
         return;
     }
     $this->fail('An expected SerializerNotImplementsInterfaceException exception has not been raised.');
 }
SerializerFactory