eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\ConverterRegistry::getConverter PHP Method

getConverter() public method

Returns converter for $typeName.
public getConverter ( string $typeName ) : eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\Converter
$typeName string
return eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\Converter
    public function getConverter($typeName)
    {
        if (!isset($this->converterMap[$typeName])) {
            throw new NotFound($typeName);
        } elseif (!$this->converterMap[$typeName] instanceof Converter) {
            if (!is_callable($this->converterMap[$typeName])) {
                throw new \RuntimeException("Converter '{$typeName}' is neither callable or instance");
            }
            $factory = $this->converterMap[$typeName];
            $this->converterMap[$typeName] = call_user_func($factory);
            if (!$this->converterMap[$typeName] instanceof Converter) {
                throw new \RuntimeException("Converter '{$typeName}' callable did not return a converter, instead: " . gettype($this->converterMap[$typeName]));
            }
        }
        return $this->converterMap[$typeName];
    }

Usage Example

 /**
  * Determines the necessary update actions
  *
  * @param \eZ\Publish\SPI\Persistence\Content\Type $fromType
  * @param \eZ\Publish\SPI\Persistence\Content\Type $toType
  *
  * @return \eZ\Publish\Core\Persistence\Legacy\Content\Type\ContentUpdater\Action[]
  */
 public function determineActions(Type $fromType, Type $toType)
 {
     $actions = array();
     foreach ($fromType->fieldDefinitions as $fieldDef) {
         if (!$this->hasFieldDefinition($toType, $fieldDef)) {
             $actions[] = new ContentUpdater\Action\RemoveField($this->contentGateway, $fieldDef, $this->storageHandler);
         }
     }
     foreach ($toType->fieldDefinitions as $fieldDef) {
         if (!$this->hasFieldDefinition($fromType, $fieldDef)) {
             $actions[] = new ContentUpdater\Action\AddField($this->contentGateway, $fieldDef, $this->converterRegistry->getConverter($fieldDef->fieldType), $this->storageHandler);
         }
     }
     return $actions;
 }
All Usage Examples Of eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\ConverterRegistry::getConverter