| @@ 36-79 (lines=44) @@ | ||
| 33 | * @link https://github.com/techdivision/import |
|
| 34 | * @link http://www.techdivision.com |
|
| 35 | */ |
|
| 36 | class CsvExportAdapterFactory implements ExportAdapterFactoryInterface |
|
| 37 | { |
|
| 38 | ||
| 39 | /** |
|
| 40 | * The DI container instance. |
|
| 41 | * |
|
| 42 | * @var \Symfony\Component\DependencyInjection\ContainerInterface |
|
| 43 | */ |
|
| 44 | protected $container; |
|
| 45 | ||
| 46 | /** |
|
| 47 | * Initialize the factory with the DI container instance. |
|
| 48 | * |
|
| 49 | * @param \Symfony\Component\DependencyInjection\ContainerInterface $container The DI container instance |
|
| 50 | */ |
|
| 51 | public function __construct(ContainerInterface $container) |
|
| 52 | { |
|
| 53 | $this->container = $container; |
|
| 54 | } |
|
| 55 | ||
| 56 | /** |
|
| 57 | * Creates and returns the export adapter for the subject with the passed configuration. |
|
| 58 | * |
|
| 59 | * @param \TechDivision\Import\Configuration\SubjectConfigurationInterface $subjectConfiguration The subject configuration |
|
| 60 | * |
|
| 61 | * @return \TechDivision\Import\Adapter\ExportAdapterInterface The export adapter instance |
|
| 62 | */ |
|
| 63 | public function createExportAdapter(SubjectConfigurationInterface $subjectConfiguration) |
|
| 64 | { |
|
| 65 | ||
| 66 | // load the export adapter configuration |
|
| 67 | $exportAdapterConfiguration = $subjectConfiguration->getExportAdapter(); |
|
| 68 | ||
| 69 | // load the serializer factory instance |
|
| 70 | $serializerFactory = $this->container->get($exportAdapterConfiguration->getSerializer()->getId()); |
|
| 71 | ||
| 72 | // create the instance and pass the export adapter configuration instance |
|
| 73 | $exportAdapter = $this->container->get(DependencyInjectionKeys::IMPORT_ADAPTER_EXPORT_CSV); |
|
| 74 | $exportAdapter->init($exportAdapterConfiguration, $serializerFactory); |
|
| 75 | ||
| 76 | // return the initialized export adapter instance |
|
| 77 | return $exportAdapter; |
|
| 78 | } |
|
| 79 | } |
|
| 80 | ||
| @@ 36-79 (lines=44) @@ | ||
| 33 | * @link https://github.com/techdivision/import |
|
| 34 | * @link http://www.techdivision.com |
|
| 35 | */ |
|
| 36 | class CsvImportAdapterFactory implements ImportAdapterFactoryInterface |
|
| 37 | { |
|
| 38 | ||
| 39 | /** |
|
| 40 | * The DI container instance. |
|
| 41 | * |
|
| 42 | * @var \Symfony\Component\DependencyInjection\ContainerInterface |
|
| 43 | */ |
|
| 44 | protected $container; |
|
| 45 | ||
| 46 | /** |
|
| 47 | * Initialize the factory with the DI container instance. |
|
| 48 | * |
|
| 49 | * @param \Symfony\Component\DependencyInjection\ContainerInterface $container The DI container instance |
|
| 50 | */ |
|
| 51 | public function __construct(ContainerInterface $container) |
|
| 52 | { |
|
| 53 | $this->container = $container; |
|
| 54 | } |
|
| 55 | ||
| 56 | /** |
|
| 57 | * Creates and returns the import adapter for the subject with the passed configuration. |
|
| 58 | * |
|
| 59 | * @param \TechDivision\Import\Configuration\SubjectConfigurationInterface $subjectConfiguration The subject configuration |
|
| 60 | * |
|
| 61 | * @return \TechDivision\Import\Adapter\ExportAdapterInterface The import adapter instance |
|
| 62 | */ |
|
| 63 | public function createImportAdapter(SubjectConfigurationInterface $subjectConfiguration) |
|
| 64 | { |
|
| 65 | ||
| 66 | // load the import adapter configuration |
|
| 67 | $importAdapterConfiguration = $subjectConfiguration->getImportAdapter(); |
|
| 68 | ||
| 69 | // load the serializer factory instance |
|
| 70 | $serializerFactory = $this->container->get($importAdapterConfiguration->getSerializer()->getId()); |
|
| 71 | ||
| 72 | // create the instance and pass the import adapter configuration instance |
|
| 73 | $importAdapter = $this->container->get(DependencyInjectionKeys::IMPORT_ADAPTER_IMPORT_CSV); |
|
| 74 | $importAdapter->init($importAdapterConfiguration, $serializerFactory); |
|
| 75 | ||
| 76 | // return the initialized import adapter instance |
|
| 77 | return $importAdapter; |
|
| 78 | } |
|
| 79 | } |
|
| 80 | ||