registerConverter

Declare a converter and assign types to it.

@param  string             $name
@param  ConverterInterface $converter
@param  array              $types
@param  bool               $strict
@return ConverterHolder    $this
970361
public function registerConverter($name, ConverterInterface $converter, array $types, $strict = null)
    {
        $this->addConverter($name, $converter, $strict);

        foreach ($types as $type) {
            $this->addTypeToConverter($name, $type);
        }

        return $this;
    }
1104152
protected function converter_deps($main_setting, $converters) {
        foreach ($this->settings as $setting) {
            $name = $setting->get_name();
            if (in_array($name, $converters)) {
                $setvalue = convert_helper::export_converter_dependencies($name, $main_setting->get_name());
                if ($setvalue !== false) {
                    $setting->add_dependency($main_setting, $setvalue, array('value' => $name));
                }
            }
        }
    }
1323606
public <R, W> JSONer register(Converter<R, W> converter, String... properties) {
        for (String property : checkNotNull(properties)) {
            converts.put(property, checkNotNull(converter));
        }
        return this;
    }
1238125
public function setTypeConverterOptions($typeConverter, array $options)
    {
        foreach ($this->getTypeConvertersWithParentClasses($typeConverter) as $typeConverter) {
            $this->configuration[$typeConverter] = $options;
        }
        return $this;
    }
926981
public function extendType($superType, $type, ConverterInterface $converter = null, NormalizerInterface $normalizer = null)
    {
        $handler = $this->cast($this->graphNode->getResourceHandler($superType));

        if (!isset($handler->converters[$superType])) {
            throw new \InvalidArgumentException(sprintf(
                'The extended type "%s" can\'t be found.',
                $superType
            ));
        }

        if ($converter === null) {
            $converter = $handler->converters[$superType];
        }

        if ($normalizer === null) {
            $normalizer = isset($handler->normalizers[$superType]) ? $handler->normalizers[$superType] : null;
        }

        $this->setType($type, $converter, $normalizer);
    }
1179
public function registerHelper($name, $helper = false)
    {
        if (is_array($name)) {
            foreach ($name as $n => $helper) {
                $this->registerHelper($n, $helper);
            }
        } elseif (is_object($name)) {
            $this->registerJavascriptObject('helper', $this->wrapHelperObject($name));
        } elseif ($helper === false) {
            $this->registerJavascriptObject('helper', $name);
        } elseif (is_callable($helper)) {
            $this->registerJavascriptFunction('helper', $name, $this->wrapHelperCallable($name, $helper));
        } else {
            $this->registerJavascriptFunction('helper', $name, $helper);
        }
    }
843581
public void registerConvertor(Class src, Class dest, Convertor convertor) {
        repository.registerConvertor(src, dest, convertor);
    }
424653
public static function register($name, $class)
    {
        if (isset(self::$converterMap[$name])) {
            throw new InvalidArgumentException(
                sprintf('The attribute converter name "%s" is already registered.', $name)
            );
        }

        self::$converterMap[$name] = $class;
    }
19723
public function converter(callable $converter, string ...$types): BuilderInterface
    {
        $this->resolver->converter($converter, ...$types);

        return $this;
    }
478549
@Override
    public void addConverter(Class<?> from, Class<?> to, Converter converter) {
        Map toMap = fromMap.get(from);
        if (toMap == null) {
            toMap = new HashMap<Class<?>, Map<Class<?>, Converter>>();
            fromMap.put(from, toMap);
        }
        toMap.put(to, converter);
    }
1129948
public function setConvertors(array $convertors)
	{
		$this->callbacks  = [];
		$this->matchGroup = [];
		$this->groups     = [];
		$this->regexps    = [];
		foreach ($convertors as $convertor)
		{
			$this->addConvertor($convertor);
		}

		// Sort regexps by length to keep their order consistent
		$this->sortRegexps();

		// Add regexp groups
		foreach ($this->groups as $group => $captures)
		{
			sort($captures);
			$this->regexps[$group] = '(?<' . $group . '>' . implode('|', $captures) . ')';
		}

		$this->regexp = '(^(?:' . implode('|', $this->regexps) . ')$)';
	}
444659
public static function registerEnumType($name, callable $constructor, callable $serializer = null)
    {
        if (static::hasType($name)) {
            return;
        }

        $serializer = $serializer ?? function ($value) { return ($value === null) ? null : (string)$value; };

        // Register and customize the type
        static::addType($name, static::class);

        /** @var EnumerationBridge $type */
        $type              = static::getType($name);
        $type->name        = $name;
        $type->constructor = $constructor;
        $type->serializer  = $serializer;
    }
1052576
protected void secondary(final String name, final AttributeConverter<? extends Object> converter) {
        secondaries.add(name);
        converters.put(name, converter);
    }
152204
public void addConverterComponent(ValueConverter<?, ?> converter) {

    if (converter instanceof AbstractRecursiveValueConverter) {
      ((AbstractRecursiveValueConverter<?, ?>) converter).setComposedValueConverter(this);
    }
    if (converter instanceof AbstractComponent) {
      ((AbstractComponent) converter).initialize();
    }
    addConverter(converter);
  }
626544
private void register(String converterClassName) {

    Class<Converter> converterClass = ObjectUtils.loadClass(converterClassName);

    if (ObjectUtils.assignableTo(converterClass, Converter.class)) {
      try {
        Converter<?, ?> converter = (Converter<?, ?>) converterClass.newInstance();
        register(converter);
      }
      catch (Exception ignore) {
      }
    }
  }
527521
public function checkScope($name, $strict = false)
  {
      if (!$this->hasScope($name, $strict)) {
          throw new Exceptions\OutOfScopeException("Scope $name is not registered!");
      }
  }
1136524
public static function createConvertType(
        string $name,
        string $type,
        bool $emptyToNull = false
    ): DenormalizationFieldMappingBuilderInterface {
        $self = new self($name);
        $self->fieldDenormalizer = new ConvertTypeFieldDenormalizer(new PropertyAccessor($name), $type, $emptyToNull);

        return $self;
    }