Exemple #1
0
 /**
  * Wraps a type into a ResolvedFormTypeInterface implementation and connects
  * it with its parent type.
  *
  * @param FormTypeInterface $type The type to resolve.
  *
  * @return ResolvedFormTypeInterface The resolved type.
  */
 private function resolveAndAddType(FormTypeInterface $type)
 {
     $typeExtensions = array();
     $parentType = $type->getParent();
     $fqcn = get_class($type);
     $name = $type->getName();
     $hasCustomName = $name !== $fqcn;
     if ($parentType instanceof FormTypeInterface) {
         @trigger_error('Returning a FormTypeInterface from FormTypeInterface::getParent() is deprecated since version 2.8 and will be removed in 3.0.', E_USER_DEPRECATED);
         $this->resolveAndAddType($parentType);
         $parentType = $parentType->getName();
     }
     if ($hasCustomName) {
         foreach ($this->extensions as $extension) {
             $typeExtensions = array_merge($typeExtensions, $extension->getTypeExtensions($name));
         }
         if ($typeExtensions) {
             @trigger_error('Returning a type name from FormTypeExtensionInterface::getExtendedType() is deprecated since version 2.8 and will be removed in 3.0. Return the fully-qualified type class name instead.', E_USER_DEPRECATED);
         }
     }
     foreach ($this->extensions as $extension) {
         $typeExtensions = array_merge($typeExtensions, $extension->getTypeExtensions($fqcn));
     }
     $resolvedType = $this->resolvedTypeFactory->createResolvedType($type, $typeExtensions, $parentType ? $this->getType($parentType) : null);
     $this->types[$fqcn] = $resolvedType;
     if ($hasCustomName) {
         // Enable access by the explicit type name until Symfony 3.0
         $this->types[$name] = $resolvedType;
         $this->legacyNames[$name] = true;
     }
 }
Exemple #2
0
 /**
  * {@inheritdoc}
  */
 public function getType($name)
 {
     if (!is_string($name)) {
         throw new UnexpectedTypeException($name, 'string');
     }
     if (!isset($this->types[$name])) {
         /** @var FormTypeInterface $type */
         $type = null;
         foreach ($this->extensions as $extension) {
             /* @var FormExtensionInterface $extension */
             if ($extension->hasType($name)) {
                 $type = $extension->getType($name);
                 break;
             }
         }
         if (!$type) {
             throw new FormException(sprintf('Could not load type "%s"', $name));
         }
         $parentType = $type->getParent();
         $typeExtensions = array();
         foreach ($this->extensions as $extension) {
             /* @var FormExtensionInterface $extension */
             $typeExtensions = array_merge($typeExtensions, $extension->getTypeExtensions($name));
         }
         $this->addType($this->resolvedTypeFactory->createResolvedType($type, $typeExtensions, $parentType ? $this->getType($parentType) : null));
     }
     return $this->types[$name];
 }
Exemple #3
0
 public function testLegacyHasTypeAfterLoadingFromExtension()
 {
     $type = new LegacyFooType();
     $resolvedType = new ResolvedFormType($type);
     $this->resolvedTypeFactory->expects($this->once())->method('createResolvedType')->with($type)->willReturn($resolvedType);
     $this->extension2->addType($type);
     $this->assertTrue($this->registry->hasType('foo'));
 }
 /**
  * Wraps a type into a ResolvedFormTypeInterface implementation and connects
  * it with its parent type.
  *
  * @param FormTypeInterface $type The type to resolve.
  *
  * @return ResolvedFormTypeInterface The resolved type.
  */
 private function resolveType(FormTypeInterface $type)
 {
     $parentType = $type->getParent();
     if ($parentType instanceof FormTypeInterface) {
         $parentType = $this->resolveType($parentType);
     } elseif (null !== $parentType) {
         $parentType = $this->registry->getType($parentType);
     }
     return $this->resolvedTypeFactory->createResolvedType($type, array(), $parentType);
 }
Exemple #5
0
 /**
  * Wraps a type into a ResolvedFormTypeInterface implementation and connects
  * it with its parent type.
  *
  * @param FormTypeInterface $type The type to resolve.
  *
  * @return ResolvedFormTypeInterface The resolved type.
  */
 private function resolveType(FormTypeInterface $type)
 {
     $typeExtensions = array();
     $parentType = $type->getParent();
     $fqcn = get_class($type);
     foreach ($this->extensions as $extension) {
         $typeExtensions = array_merge($typeExtensions, $extension->getTypeExtensions($fqcn));
     }
     return $this->resolvedTypeFactory->createResolvedType($type, $typeExtensions, $parentType ? $this->getType($parentType) : null);
 }
Exemple #6
0
 /**
  * Wraps a type into a ResolvedFormTypeInterface implementation and connects
  * it with its parent type.
  *
  * @param FormTypeInterface $type The type to resolve.
  *
  * @return ResolvedFormTypeInterface The resolved type.
  */
 private function resolveAndAddType(FormTypeInterface $type)
 {
     $parentType = $type->getParent();
     if ($parentType instanceof FormTypeInterface) {
         $this->resolveAndAddType($parentType);
         $parentType = $parentType->getName();
     }
     $typeExtensions = array();
     foreach ($this->extensions as $extension) {
         $typeExtensions = array_merge($typeExtensions, $extension->getTypeExtensions($type->getName()));
     }
     $this->types[$type->getName()] = $this->resolvedTypeFactory->createResolvedType($type, $typeExtensions, $parentType ? $this->getType($parentType) : null);
 }
Exemple #7
0
 /**
  * Wraps a type into a ResolvedFormTypeInterface implementation and connects
  * it with its parent type.
  *
  * @param FormTypeInterface $type The type to resolve.
  *
  * @return ResolvedFormTypeInterface The resolved type.
  */
 private function resolveAndAddType(FormTypeInterface $type)
 {
     $parentType = $type->getParent();
     if ($parentType instanceof FormTypeInterface) {
         $this->resolveAndAddType($parentType);
         $parentType = $parentType->getName();
     }
     $typeExtensions = array();
     foreach ($this->extensions as $extension) {
         /* @var FormExtensionInterface $extension */
         $typeExtensions = array_merge($typeExtensions, $extension->getTypeExtensions($type->getName()));
     }
     set_error_handler(array('Symfony\\Component\\Form\\Test\\DeprecationErrorHandler', 'handleBC'));
     $this->addType($this->resolvedTypeFactory->createResolvedType($type, $typeExtensions, $parentType ? $this->getType($parentType) : null));
     restore_error_handler();
 }
Exemple #8
0
    /**
     * Wraps a type into a ResolvedFormTypeInterface implementation and connects
     * it with its parent type.
     *
     * @param FormTypeInterface $type The type to resolve.
     *
     * @return ResolvedFormTypeInterface The resolved type.
     */
    private function resolveType(FormTypeInterface $type)
    {
        $parentType = $type->getParent();

        if ($parentType instanceof FormTypeInterface) {
            $parentType = $this->resolveType($parentType);
        } elseif (null !== $parentType) {
            $parentType = $this->registry->getType($parentType);
        }

        return $this->resolvedTypeFactory->createResolvedType(
            $type,
            // Type extensions are not supported for unregistered type instances,
            // i.e. type instances that are passed to the FormFactory directly,
            // nor for their parents, if getParent() also returns a type instance.
            array(),
            $parentType
        );
    }
Exemple #9
0
 /**
  * Adds a type.
  *
  * @param FormTypeInterface $type The type
  *
  * @deprecated Deprecated since version 2.1, to be removed in 2.3. Use
  *             form extensions or type registration in the Dependency
  *             Injection Container instead.
  */
 public function addType(FormTypeInterface $type)
 {
     $parentType = $type->getParent();
     $this->registry->addType($this->resolvedTypeFactory->createResolvedType($type, array(), $parentType ? $this->registry->getType($parentType) : null));
 }
 /**
  * {@inheritdoc}
  */
 public function createResolvedType(FormTypeInterface $type, array $typeExtensions, ResolvedFormTypeInterface $parent = null)
 {
     return new ResolvedTypeDataCollectorProxy($this->proxiedFactory->createResolvedType($type, $typeExtensions, $parent), $this->dataCollector);
 }