src/FieldHandlers/FieldHandlerFactory.php
protected static function getHandler(Table $table, $field, array $options = [], View $view = null) : FieldHandlerInterface
    {
        if (empty($field)) {
            throw new InvalidArgumentException("Field parameter is empty");
        }

        // Save field name
        $fieldName = '';
        if (is_string($field)) {
            $fieldName = $field;
        }

        // Overwrite field with field difinitions options
        if (!empty($options['fieldDefinitions'])) {
            $field = $options['fieldDefinitions'];
        }

        // Prepare the stub field
        $stubFields = [];

        if (is_string($field)) {
            $stubFields = self::getStubFromString($fieldName);
        }
        if (is_array($field)) {
            $stubFields = self::getStubFromArray($fieldName, $field);
        }

        if (empty($stubFields)) {
            throw new InvalidArgumentException("Field can be either a string or an associative array");
        }

        $fieldDefinitions = $stubFields;
        if ($table instanceof HasFieldsInterface) {
            $fieldDefinitions = $table->getFieldsDefinitions($stubFields);
        }

        if (empty($fieldDefinitions[$fieldName])) {
            throw new RuntimeException("Failed to get definition for field '$fieldName'");
        }

        $field = new CsvField($fieldDefinitions[$fieldName]);
        $fieldType = $field->getType();

        $config = ConfigFactory::getByType($fieldType, $fieldName, $table);
        if ($view) {
            $config->setView($view);
        }

        return new FieldHandler($config);
    }
protected static function getHandler(Table $table, $field, array $options = [], View $view = null) : FieldHandlerInterface
    {
        if (empty($field)) {
            throw new InvalidArgumentException("Field parameter is empty");
        }

        // Save field name
        $fieldName = '';
        if (is_string($field)) {
            $fieldName = $field;
        }

        // Overwrite field with field difinitions options
        if (!empty($options['fieldDefinitions'])) {
            $field = $options['fieldDefinitions'];
        }

        // Prepare the stub field
        $stubFields = [];

        if (is_string($field)) {
            $stubFields = self::getStubFromString($fieldName);
        }
        if (is_array($field)) {
            $stubFields = self::getStubFromArray($fieldName, $field);
        }

        if (empty($stubFields)) {
            throw new InvalidArgumentException("Field can be either a string or an associative array");
        }

        $fieldDefinitions = $stubFields;
        if ($table instanceof HasFieldsInterface) {
            $fieldDefinitions = $table->getFieldsDefinitions($stubFields);
        }

        if (empty($fieldDefinitions[$fieldName])) {
            throw new RuntimeException("Failed to get definition for field '$fieldName'");
        }

        $field = new CsvField($fieldDefinitions[$fieldName]);
        $fieldType = $field->getType();

        $config = ConfigFactory::getByType($fieldType, $fieldName, $table);
        if ($view) {
            $config->setView($view);
        }

        return new FieldHandler($config);
    }
protected static function getHandler ( Table $ table , $ field , array $ options = [ ] , View $ view = null ) : FieldHandlerInterface { if ( empty ( $ field ) ) { throw new InvalidArgumentException ( "Field parameter is empty" ) ; } // Save field name $ fieldName = '' ; if ( is_string ( $ field ) ) { $ fieldName = $ field ; } // Overwrite field with field difinitions options if ( ! empty ( $ options [ 'fieldDefinitions' ] ) ) { $ field = $ options [ 'fieldDefinitions' ] ; } // Prepare the stub field $ stubFields = [ ] ; if ( is_string ( $ field ) ) { $ stubFields = self :: getStubFromString ( $ fieldName ) ; } if ( is_array ( $ field ) ) { $ stubFields = self :: getStubFromArray ( $ fieldName , $ field ) ; } if ( empty ( $ stubFields ) ) { throw new InvalidArgumentException ( "Field can be either a string or an associative array" ) ; } $ fieldDefinitions = $ stubFields ; if ( $ table instanceof HasFieldsInterface ) { $ fieldDefinitions = $ table -> getFieldsDefinitions ( $ stubFields ) ; } if ( empty ( $ fieldDefinitions [ $ fieldName ] ) ) { throw new RuntimeException ( "Failed to get definition for field '$fieldName'" ) ; } $ field = new CsvField ( $ fieldDefinitions [ $ fieldName ] ) ; $ fieldType = $ field -> getType ( ) ; $ config = ConfigFactory :: getByType ( $ fieldType , $ fieldName , $ table ) ; if ( $ view ) { $ config -> setView ( $ view ) ; } return new FieldHandler ( $ config ) ; }
Get field handler instance

This method returns an instance of the appropriate
FieldHandler class.

@throws \RuntimeException when failed to instantiate field handler
@param Table $table Table instance
@param string|array $field Field name
@param mixed[] $options Field options
@param \Cake\View\View $view Optional CakePHP view instance
@return \CsvMigrations\FieldHandlers\FieldHandlerInterface
Get field handler instance