src/Subjects/SubjectExecutor.php
/**
     * Executes the passed subject.
     *
     * @param \TechDivision\Import\Configuration\SubjectConfigurationInterface $subject  The subject configuration instance
     * @param array                                                            $matches  The bunch matches
     * @param string                                                           $serial   The UUID of the actual import
     * @param string                                                           $pathname The path to the file to import
     *
     * @return void
     */
Executes the passed subject.
@param \TechDivision\Import\Configuration\SubjectConfigurationInterface $subject  The subject configuration instance
@param array                                                            $matches  The bunch matches
@param string                                                           $serial   The UUID of the actual import
@param string                                                           $pathname The path to the file to import

@return void
Executes the passed subject . @param \ TechDivision \ Import \ Configuration \ SubjectConfigurationInterface $subject The subject configuration instance @param array $matches The bunch matches @param string $serial The UUID of the actual import @param string $pathname The path to the file to import @return void
public function execute(SubjectConfigurationInterface $subject, array $matches, $serial, $pathname)
    {
        $subjectInstance = $this->subjectFactory->createSubject($subject);
        $pluginConfiguration = $subject->getPluginConfiguration();
        $operationConfiguration = $pluginConfiguration->getOperationConfiguration();
        $subjectName = $subject->getName();
        $pluginName = $pluginConfiguration->getName();
        $operationName = $operationConfiguration->getName();
        try {
            $this->emitter->emit(EventNames::SUBJECT_IMPORT_START, $subjectInstance);
            $this->emitter->emit(sprintf('%s.%s.%s', $pluginName, $subjectName, EventNames::SUBJECT_IMPORT_START), $subjectInstance);
            $this->emitter->emit(sprintf('%s.%s.%s.%s', $operationName, $pluginName, $subjectName, EventNames::SUBJECT_IMPORT_START), $subjectInstance);
            $subjectInstance->setUp($serial);
            $this->callbackVisitor->visit($subjectInstance);
            $this->observerVisitor->visit($subjectInstance);
            $subjectInstance->import($serial, $pathname);
            if ($subjectInstance instanceof ExportableSubjectInterface) {
                try {
                    $this->emitter->emit(EventNames::SUBJECT_EXPORT_START, $subjectInstance);
                    $this->emitter->emit(sprintf('%s.%s.%s', $pluginName, $subjectName, EventNames::SUBJECT_EXPORT_START), $subjectInstance);
                    $this->emitter->emit(sprintf('%s.%s.%s.%s', $operationName, $pluginName, $subjectName, EventNames::SUBJECT_EXPORT_START), $subjectInstance);
                    $subjectInstance->export($matches[BunchKeys::FILENAME], $matches[BunchKeys::COUNTER]);
                    $this->emitter->emit(EventNames::SUBJECT_EXPORT_SUCCESS, $subjectInstance);
                    $this->emitter->emit(sprintf('%s.%s.%s', $pluginName, $subjectName, EventNames::SUBJECT_EXPORT_SUCCESS), $subjectInstance);
                    $this->emitter->emit(sprintf('%s.%s.%s.%s', $operationName, $pluginName, $subjectName, EventNames::SUBJECT_EXPORT_SUCCESS), $subjectInstance);
                } catch (\Exception $e) {
                    $this->emitter->emit(EventNames::SUBJECT_EXPORT_FAILURE, $subjectInstance);
                    $this->emitter->emit(sprintf('%s.%s.%s', $pluginName, $subjectName, EventNames::SUBJECT_EXPORT_FAILURE), $subjectInstance);
                    $this->emitter->emit(sprintf('%s.%s.%s.%s', $operationName, $pluginName, $subjectName, EventNames::SUBJECT_EXPORT_FAILURE), $subjectInstance);
                    throw $e;
                }
            }
            $subjectInstance->tearDown($serial);
            $this->emitter->emit(EventNames::SUBJECT_IMPORT_SUCCESS, $subjectInstance);
            $this->emitter->emit(sprintf('%s.%s.%s', $pluginName, $subjectName, EventNames::SUBJECT_IMPORT_SUCCESS), $subjectInstance);
            $this->emitter->emit(sprintf('%s.%s.%s.%s', $operationName, $pluginName, $subjectName, EventNames::SUBJECT_IMPORT_SUCCESS), $subjectInstance);
        } catch (\Exception $e) {
            $subjectInstance->tearDown($serial);
            $this->emitter->emit(EventNames::SUBJECT_IMPORT_FAILURE, $subjectInstance);
            $this->emitter->emit(sprintf('%s.%s.%s', $pluginName, $subjectName, EventNames::SUBJECT_IMPORT_FAILURE), $subjectInstance);
            $this->emitter->emit(sprintf('%s.%s.%s.%s', $operationName, $pluginName, $subjectName, EventNames::SUBJECT_IMPORT_FAILURE), $subjectInstance);
            throw $e;
        }
    }
public function execute ( SubjectConfigurationInterface $ subject , array $ matches , $ serial , $ pathname ) { $ subjectInstance = $ this -> subjectFactory -> createSubject ( $ subject ) ; $ pluginConfiguration = $ subject -> getPluginConfiguration ( ) ; $ operationConfiguration = $ pluginConfiguration -> getOperationConfiguration ( ) ; $ subjectName = $ subject -> getName ( ) ; $ pluginName = $ pluginConfiguration -> getName ( ) ; $ operationName = $ operationConfiguration -> getName ( ) ; try { $ this -> emitter -> emit ( EventNames :: SUBJECT_IMPORT_START , $ subjectInstance ) ; $ this -> emitter -> emit ( sprintf ( '%s.%s.%s' , $ pluginName , $ subjectName , EventNames :: SUBJECT_IMPORT_START ) , $ subjectInstance ) ; $ this -> emitter -> emit ( sprintf ( '%s.%s.%s.%s' , $ operationName , $ pluginName , $ subjectName , EventNames :: SUBJECT_IMPORT_START ) , $ subjectInstance ) ; $ subjectInstance -> setUp ( $ serial ) ; $ this -> callbackVisitor -> visit ( $ subjectInstance ) ; $ this -> observerVisitor -> visit ( $ subjectInstance ) ; $ subjectInstance -> import ( $ serial , $ pathname ) ; if ( $ subjectInstance instanceof ExportableSubjectInterface ) { try { $ this -> emitter -> emit ( EventNames :: SUBJECT_EXPORT_START , $ subjectInstance ) ; $ this -> emitter -> emit ( sprintf ( '%s.%s.%s' , $ pluginName , $ subjectName , EventNames :: SUBJECT_EXPORT_START ) , $ subjectInstance ) ; $ this -> emitter -> emit ( sprintf ( '%s.%s.%s.%s' , $ operationName , $ pluginName , $ subjectName , EventNames :: SUBJECT_EXPORT_START ) , $ subjectInstance ) ; $ subjectInstance -> export ( $ matches [ BunchKeys :: FILENAME ] , $ matches [ BunchKeys :: COUNTER ] ) ; $ this -> emitter -> emit ( EventNames :: SUBJECT_EXPORT_SUCCESS , $ subjectInstance ) ; $ this -> emitter -> emit ( sprintf ( '%s.%s.%s' , $ pluginName , $ subjectName , EventNames :: SUBJECT_EXPORT_SUCCESS ) , $ subjectInstance ) ; $ this -> emitter -> emit ( sprintf ( '%s.%s.%s.%s' , $ operationName , $ pluginName , $ subjectName , EventNames :: SUBJECT_EXPORT_SUCCESS ) , $ subjectInstance ) ; } catch ( \ Exception $ e ) { $ this -> emitter -> emit ( EventNames :: SUBJECT_EXPORT_FAILURE , $ subjectInstance ) ; $ this -> emitter -> emit ( sprintf ( '%s.%s.%s' , $ pluginName , $ subjectName , EventNames :: SUBJECT_EXPORT_FAILURE ) , $ subjectInstance ) ; $ this -> emitter -> emit ( sprintf ( '%s.%s.%s.%s' , $ operationName , $ pluginName , $ subjectName , EventNames :: SUBJECT_EXPORT_FAILURE ) , $ subjectInstance ) ; throw $ e ; } } $ subjectInstance -> tearDown ( $ serial ) ; $ this -> emitter -> emit ( EventNames :: SUBJECT_IMPORT_SUCCESS , $ subjectInstance ) ; $ this -> emitter -> emit ( sprintf ( '%s.%s.%s' , $ pluginName , $ subjectName , EventNames :: SUBJECT_IMPORT_SUCCESS ) , $ subjectInstance ) ; $ this -> emitter -> emit ( sprintf ( '%s.%s.%s.%s' , $ operationName , $ pluginName , $ subjectName , EventNames :: SUBJECT_IMPORT_SUCCESS ) , $ subjectInstance ) ; } catch ( \ Exception $ e ) { $ subjectInstance -> tearDown ( $ serial ) ; $ this -> emitter -> emit ( EventNames :: SUBJECT_IMPORT_FAILURE , $ subjectInstance ) ; $ this -> emitter -> emit ( sprintf ( '%s.%s.%s' , $ pluginName , $ subjectName , EventNames :: SUBJECT_IMPORT_FAILURE ) , $ subjectInstance ) ; $ this -> emitter -> emit ( sprintf ( '%s.%s.%s.%s' , $ operationName , $ pluginName , $ subjectName , EventNames :: SUBJECT_IMPORT_FAILURE ) , $ subjectInstance ) ; throw $ e ; } }
Executes the passed subject.
Executes the passed subject .
// initialize the subject and import the bunch // load the plug-in an operation configuartion // load the subject + plug-in ID  as well as th operation name to prepare the events // invoke the event that has to be fired before the subject's import method will be invoked // setup the subject instance // initialize the callbacks/observers // finally import the CSV file // query whether or not, we've to export artefacts // invoke the event that has to be fired before the subject's export method will be invoked // export the artefacts if available // invoke the event that has to be fired after the subject's export method has been invoked // invoke the event that has to be fired when the subject's export method throws an exception // re-throw the exception // tear down the subject instance // invoke the event that has to be fired after the subject's import method has been invoked // tear down the subject instance // invoke the event that has to be fired when the subject's import method throws an exception // re-throw the exception