src/Plugins/PluginFactory.php
/**
     * Factory method to create new plugin instance.
     *
     * @param \TechDivision\Import\Configuration\PluginConfigurationInterface $pluginConfiguration The plugin configuration
     *
     * @return \TechDivision\Import\Plugins\PluginInterface The plugin instance
     */
Factory method to create new plugin instance.


Factory method to create new plugin instance .
public function createPlugin(PluginConfigurationInterface $pluginConfiguration)
    {
        $pluginInstance = $this->container->get($pluginConfiguration->getId());
        $pluginInstance->setPluginConfiguration($pluginConfiguration);
        $importAdapter = $this->container->get($pluginConfiguration->getImportAdapter()->getId());
        if ($importAdapter instanceof ImportAdapterInterface) {
            $pluginInstance->setImportAdapter($importAdapter);
            $this->getSystemLogger()->warning(
                sprintf(
                    'Direct injection of import adapter with DI ID "%s" is deprecated since version 3.0.0, please use factory instead',
                    $pluginConfiguration->getImportAdapter()->getId()
                )
            );
        } elseif ($importAdapter instanceof ImportAdapterFactoryInterface) {
            $pluginInstance->setImportAdapter($importAdapter->createImportAdapter($pluginConfiguration));
        } else {
            throw new \Exception(
                sprintf(
                    'Expected either an instance of ImportAdapterInterface or ImportAdapterFactoryInterface for DI ID "%s"',
                    $pluginConfiguration->getImportAdapter()->getId()
                )
            );
        }
        if ($pluginInstance instanceof ExportablePluginInterface) {
            $exportAdapter = $this->container->get($pluginConfiguration->getExportAdapter()->getId());
            if ($exportAdapter instanceof ExportAdapterInterface) {
                $pluginInstance->setExportAdapter($exportAdapter);
                $this->getSystemLogger()->warning(
                    sprintf(
                        'Direct injection of export adapter with DI ID "%s" is deprecated since version 3.0.0, please use factory instead',
                        $pluginConfiguration->getExportAdapter()->getId()
                    )
                );
            } elseif ($exportAdapter instanceof ExportAdapterFactoryInterface) {
                $pluginInstance->setExportAdapter($exportAdapter->createExportAdapter($pluginConfiguration));
            } else {
                throw new \Exception(
                    sprintf(
                        'Expected either an instance of ExportAdapterInterface or ExportAdapterFactoryInterface for DI ID "%s"',
                        $pluginConfiguration->getExportAdapter()->getId()
                    )
                );
            }
        }
        return $pluginInstance;
    }
public function createPlugin ( PluginConfigurationInterface $ pluginConfiguration ) { $ pluginInstance = $ this -> container -> get ( $ pluginConfiguration -> getId ( ) ) ; $ pluginInstance -> setPluginConfiguration ( $ pluginConfiguration ) ; $ importAdapter = $ this -> container -> get ( $ pluginConfiguration -> getImportAdapter ( ) -> getId ( ) ) ; if ( $ importAdapter instanceof ImportAdapterInterface ) { $ pluginInstance -> setImportAdapter ( $ importAdapter ) ; $ this -> getSystemLogger ( ) -> warning ( sprintf ( 'Direct injection of import adapter with DI ID "%s" is deprecated since version 3.0.0, please use factory instead' , $ pluginConfiguration -> getImportAdapter ( ) -> getId ( ) ) ) ; } elseif ( $ importAdapter instanceof ImportAdapterFactoryInterface ) { $ pluginInstance -> setImportAdapter ( $ importAdapter -> createImportAdapter ( $ pluginConfiguration ) ) ; } else { throw new \ Exception ( sprintf ( 'Expected either an instance of ImportAdapterInterface or ImportAdapterFactoryInterface for DI ID "%s"' , $ pluginConfiguration -> getImportAdapter ( ) -> getId ( ) ) ) ; } if ( $ pluginInstance instanceof ExportablePluginInterface ) { $ exportAdapter = $ this -> container -> get ( $ pluginConfiguration -> getExportAdapter ( ) -> getId ( ) ) ; if ( $ exportAdapter instanceof ExportAdapterInterface ) { $ pluginInstance -> setExportAdapter ( $ exportAdapter ) ; $ this -> getSystemLogger ( ) -> warning ( sprintf ( 'Direct injection of export adapter with DI ID "%s" is deprecated since version 3.0.0, please use factory instead' , $ pluginConfiguration -> getExportAdapter ( ) -> getId ( ) ) ) ; } elseif ( $ exportAdapter instanceof ExportAdapterFactoryInterface ) { $ pluginInstance -> setExportAdapter ( $ exportAdapter -> createExportAdapter ( $ pluginConfiguration ) ) ; } else { throw new \ Exception ( sprintf ( 'Expected either an instance of ExportAdapterInterface or ExportAdapterFactoryInterface for DI ID "%s"' , $ pluginConfiguration -> getExportAdapter ( ) -> getId ( ) ) ) ; } } return $ pluginInstance ; }
Factory method to create new plugin instance.
Factory method to create new plugin instance .
// load the plugin instance from the DI container and set the plugin configuration // load the import adapter instance from the DI container and set it on the plugin instance // query whether or not we've found a factory or the instance itself // log a warning, that this is deprecated // query whether or not we've a plugin instance that implements the exportable plugin interface // load the export adapter instance from the DI container and set it on the plugin instance // query whether or not we've found a factory or the instance itself // inject the export adapter into the subject // log a warning, that this is deprecated // return the plugin instance