Skip to content

Instantly share code, notes, and snippets.

@luisenriquecorona
Created July 19, 2019 01:11
Show Gist options
  • Save luisenriquecorona/a6ed4b44789843f5f334702f4df8827d to your computer and use it in GitHub Desktop.
Save luisenriquecorona/a6ed4b44789843f5f334702f4df8827d to your computer and use it in GitHub Desktop.
The GenericEncoder Class Now Uses EncoderFactory
class GenericEncoder
{
private $encoderFactory;
public function __construct(
EncoderFactory $encoderFactory
){
$this->encoderFactory = $encoderFactory;
}
public function encodeToFormat($data, string $format): string
{
$encoder = $this->encoderFactory
->createForFormat($format);
$data = $this->prepareData($data, $format);
return $encoder->encode($data);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment