src/Subjects/SubjectFactory.php
/**
     * Factory method to create new subject instance.
     *
     * @param \TechDivision\Import\Configuration\SubjectConfigurationInterface $subjectConfiguration The subject configuration
     *
     * @return \TechDivision\Import\Subjects\SubjectInterface The subject instance
     */
Factory method to create new subject instance.


Factory method to create new subject instance .
public function createSubject(SubjectConfigurationInterface $subjectConfiguration)
    {
        $subjectInstance = $this->container->get($subjectConfiguration->getId());
        $subjectInstance->setConfiguration($subjectConfiguration);
        $importAdapter = $this->container->get($subjectConfiguration->getImportAdapter()->getId());
        if ($importAdapter instanceof ImportAdapterInterface) {
            $subjectInstance->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',
                    $subjectConfiguration->getImportAdapter()->getId()
                )
            );
        } elseif ($importAdapter instanceof ImportAdapterFactoryInterface) {
            $subjectInstance->setImportAdapter($importAdapter->createImportAdapter($subjectConfiguration));
        } else {
            throw new \Exception(
                sprintf(
                    'Expected either an instance of ImportAdapterInterface or ImportAdapterFactoryInterface for DI ID "%s"',
                    $subjectConfiguration->getImportAdapter()->getId()
                )
            );
        }
        if ($subjectInstance instanceof ExportableSubjectInterface) {
            $exportAdapter = $this->container->get($subjectConfiguration->getExportAdapter()->getId());
            if ($exportAdapter instanceof ExportAdapterInterface) {
                $subjectInstance->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',
                        $subjectConfiguration->getExportAdapter()->getId()
                    )
                );
            } elseif ($exportAdapter instanceof ExportAdapterFactoryInterface) {
                $subjectInstance->setExportAdapter($exportAdapter->createExportAdapter($subjectConfiguration));
            } else {
                throw new \Exception(
                    sprintf(
                        'Expected either an instance of ExportAdapterInterface or ExportAdapterFactoryInterface for DI ID "%s"',
                        $subjectConfiguration->getExportAdapter()->getId()
                    )
                );
            }
        }
        if ($subjectInstance instanceof NumberConverterSubjectInterface) {
            $subjectInstance->setNumberConverter($this->numberConverterFactory->createNumberConverter($subjectConfiguration));
        }
        if ($subjectInstance instanceof DateConverterSubjectInterface) {
            $subjectInstance->setDateConverter($this->dateConverterFactory->createDateConverter($subjectConfiguration));
        }
        if ($subjectInstance instanceof FilesystemSubjectInterface) {
            $filesystemAdapterFactory = $this->container->get($subjectConfiguration->getFilesystemAdapter()->getId());
            $subjectInstance->setFilesystemAdapter($filesystemAdapterFactory->createFilesystemAdapter($subjectConfiguration));
        }
        return $subjectInstance;
    }
public function createSubject ( SubjectConfigurationInterface $ subjectConfiguration ) { $ subjectInstance = $ this -> container -> get ( $ subjectConfiguration -> getId ( ) ) ; $ subjectInstance -> setConfiguration ( $ subjectConfiguration ) ; $ importAdapter = $ this -> container -> get ( $ subjectConfiguration -> getImportAdapter ( ) -> getId ( ) ) ; if ( $ importAdapter instanceof ImportAdapterInterface ) { $ subjectInstance -> 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' , $ subjectConfiguration -> getImportAdapter ( ) -> getId ( ) ) ) ; } elseif ( $ importAdapter instanceof ImportAdapterFactoryInterface ) { $ subjectInstance -> setImportAdapter ( $ importAdapter -> createImportAdapter ( $ subjectConfiguration ) ) ; } else { throw new \ Exception ( sprintf ( 'Expected either an instance of ImportAdapterInterface or ImportAdapterFactoryInterface for DI ID "%s"' , $ subjectConfiguration -> getImportAdapter ( ) -> getId ( ) ) ) ; } if ( $ subjectInstance instanceof ExportableSubjectInterface ) { $ exportAdapter = $ this -> container -> get ( $ subjectConfiguration -> getExportAdapter ( ) -> getId ( ) ) ; if ( $ exportAdapter instanceof ExportAdapterInterface ) { $ subjectInstance -> 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' , $ subjectConfiguration -> getExportAdapter ( ) -> getId ( ) ) ) ; } elseif ( $ exportAdapter instanceof ExportAdapterFactoryInterface ) { $ subjectInstance -> setExportAdapter ( $ exportAdapter -> createExportAdapter ( $ subjectConfiguration ) ) ; } else { throw new \ Exception ( sprintf ( 'Expected either an instance of ExportAdapterInterface or ExportAdapterFactoryInterface for DI ID "%s"' , $ subjectConfiguration -> getExportAdapter ( ) -> getId ( ) ) ) ; } } if ( $ subjectInstance instanceof NumberConverterSubjectInterface ) { $ subjectInstance -> setNumberConverter ( $ this -> numberConverterFactory -> createNumberConverter ( $ subjectConfiguration ) ) ; } if ( $ subjectInstance instanceof DateConverterSubjectInterface ) { $ subjectInstance -> setDateConverter ( $ this -> dateConverterFactory -> createDateConverter ( $ subjectConfiguration ) ) ; } if ( $ subjectInstance instanceof FilesystemSubjectInterface ) { $ filesystemAdapterFactory = $ this -> container -> get ( $ subjectConfiguration -> getFilesystemAdapter ( ) -> getId ( ) ) ; $ subjectInstance -> setFilesystemAdapter ( $ filesystemAdapterFactory -> createFilesystemAdapter ( $ subjectConfiguration ) ) ; } return $ subjectInstance ; }
Factory method to create new subject instance.
Factory method to create new subject instance .
// load the subject instance from the DI container and set the subject configuration // load the import adapter instance from the DI container and set it on the subject 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 subject instance that implements the exportable subject interface // load the export adapter instance from the DI container and set it on the subject 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 // load te number converter instance from the DI container and set it on the subject instance // load te date converter instance from the DI container and set it on the subject instance // load the filesystem adapter instance from the DI container and set it on the subject instance // return the initialized subject instance