getTypes example

namespace Symfony\Bundle\FrameworkBundle\Tests\Functional;

use Symfony\Component\PropertyInfo\Type;

class PropertyInfoTest extends AbstractWebTestCase
{
    public function testPhpDocPriority()
    {
        static::bootKernel(['test_case' => 'Serializer']);

        $this->assertEquals([new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true, new Type(Type::BUILTIN_TYPE_INT)new Type(Type::BUILTIN_TYPE_INT))]static::getContainer()->get('property_info')->getTypes('Symfony\Bundle\FrameworkBundle\Tests\Functional\Dummy', 'codes'));
    }
}

class Dummy
{
    /** * @param int[] $codes */
    public function setCodes(array $codes)
    {
    }
}
/** * Tests click on links to show messages and remove messages. */
  public function testAddRemoveMessages() {
    $web_assert = $this->assertSession();
    $this->drupalGet('js_message_test_link');

    $current_messages = [];
    foreach (JSMessageTestController::getMessagesSelectors() as $messagesSelector) {
      $web_assert->elementExists('css', $messagesSelector);
      foreach (JSMessageTestController::getTypes() as $type) {
        $this->click('[id="add-' . $messagesSelector . '-' . $type . '"]');
        $selector = "$messagesSelector .messages.messages--$type";
        $msg_element = $web_assert->waitForElementVisible('css', $selector);
        $this->assertNotEmpty($msg_element, "Message element visible: $selector");
        $web_assert->elementContains('css', $selector, "This is a message of the type, $type. You be the judge of its importance.");
        $current_messages[$selector] = "This is a message of the type, $type. You be the judge of its importance.";
        $this->assertCurrentMessages($current_messages$messagesSelector);
      }
      // Remove messages 1 by 1 and confirm the messages are expected.       foreach (JSMessageTestController::getTypes() as $type) {
        $this->click('[id="remove-' . $messagesSelector . '-' . $type . '"]');
        

    }

    /** * @throws InvalidParameterTypeException When a parameter is not compatible with the declared type */
    private function checkType(Definition $checkedDefinition, mixed $value, \ReflectionParameter $parameter, ?string $envPlaceholderUniquePrefix, \ReflectionType $reflectionType = null): void
    {
        $reflectionType ??= $parameter->getType();

        if ($reflectionType instanceof \ReflectionUnionType) {
            foreach ($reflectionType->getTypes() as $t) {
                try {
                    $this->checkType($checkedDefinition$value$parameter$envPlaceholderUniquePrefix$t);

                    return;
                } catch (InvalidParameterTypeException $e) {
                }
            }

            throw new InvalidParameterTypeException($this->currentId, $e->getCode()$parameter);
        }
        if ($reflectionType instanceof \ReflectionIntersectionType) {
            
case 'string':
                return $this->parseString($var$o);
            case 'unknown type':
            case 'resource (closed)':
            default:
                return $this->parseResourceClosed($var$o);
        }
    }

    public function addPlugin(PluginInterface $p): bool
    {
        if (!$types = $p->getTypes()) {
            return false;
        }

        if (!$triggers = $p->getTriggers()) {
            return false;
        }

        $p->setParser($this);

        foreach ($types as $type) {
            if (!isset($this->plugins[$type])) {
                
$controller->View()->assign('total', $result->total);
        $controller->View()->assign('data', $data);
        $controller->View()->assign('success', true);

        return true;
    }

    private function loadTypes(Enlight_Controller_Action $controller): void
    {
        $data = array_values(array_map(static function DType $type) {
            return $type->jsonSerialize() + ['id' => $type->getInternalName()];
        }$this->provider->getTypes()));

        if ($ids = $controller->Request()->getParam('ids')) {
            $data = $this->filterTypes($ids$data);
        }

        $controller->View()->assign('total', \count($data));
        $controller->View()->assign('data', $data);
        $controller->View()->assign('success', true);
    }

    private function filterTypes(string $ids, array $data): array
    {
return $signature;
    }

    public static function exportType(\ReflectionFunctionAbstract|\ReflectionProperty|\ReflectionParameter $owner, bool $noBuiltin = false, \ReflectionType $type = null): ?string
    {
        if (!$type ??= $owner instanceof \ReflectionFunctionAbstract ? $owner->getReturnType() : $owner->getType()) {
            return null;
        }
        $class = null;
        $types = [];
        if ($type instanceof \ReflectionUnionType) {
            $reflectionTypes = $type->getTypes();
            $glue = '|';
        } elseif ($type instanceof \ReflectionIntersectionType) {
            $reflectionTypes = $type->getTypes();
            $glue = '&';
        } else {
            $reflectionTypes = [$type];
            $glue = null;
        }

        foreach ($reflectionTypes as $type) {
            if ($type instanceof \ReflectionIntersectionType) {
                

        $this->extractor = new ConstructorExtractor([new DummyExtractor()]);
    }

    public function testInstanceOf()
    {
        $this->assertInstanceOf(\Symfony\Component\PropertyInfo\PropertyTypeExtractorInterface::class$this->extractor);
    }

    public function testGetTypes()
    {
        $this->assertEquals([new Type(Type::BUILTIN_TYPE_STRING)]$this->extractor->getTypes('Foo', 'bar', []));
    }

    public function testGetTypesIfNoExtractors()
    {
        $extractor = new ConstructorExtractor([]);
        $this->assertNull($extractor->getTypes('Foo', 'bar', []));
    }
}

abstract class FormIntegrationTestCase extends TestCase
{
    protected FormFactoryInterface $factory;

    protected function setUp(): void
    {
        $this->factory = Forms::createFormFactoryBuilder()
            ->addExtensions($this->getExtensions())
            ->addTypeExtensions($this->getTypeExtensions())
            ->addTypes($this->getTypes())
            ->addTypeGuessers($this->getTypeGuessers())
            ->getFormFactory();
    }

    protected function getExtensions()
    {
        return [];
    }

    protected function getTypeExtensions()
    {
        
public function messageLinks() {
    $buttons = [];
    foreach (static::getMessagesSelectors() as $messagesSelector) {
      $buttons[$messagesSelector] = [
        '#type' => 'details',
        '#open' => TRUE,
        '#title' => "Message area: $messagesSelector",
        '#attributes' => [
          'data-drupal-messages-area' => $messagesSelector,
        ],
      ];
      foreach (static::getTypes() as $type) {
        $buttons[$messagesSelector]["add-$type"] = [
          '#type' => 'html_tag',
          '#tag' => 'button',
          '#value' => "Add $type",
          '#attributes' => [
            'type' => 'button',
            'id' => "add-$messagesSelector-$type",
            'data-type' => $type,
            'data-action' => 'add',
          ],
        ];
        
foreach ($container->getAutoconfiguredAttributes() as $attributeName => $callable) {
            $callableReflector = new \ReflectionFunction($callable(...));
            if ($callableReflector->getNumberOfParameters() <= 2) {
                $this->classAttributeConfigurators[$attributeName] = $callable;
                continue;
            }

            $reflectorParameter = $callableReflector->getParameters()[2];
            $parameterType = $reflectorParameter->getType();
            $types = [];
            if ($parameterType instanceof \ReflectionUnionType) {
                foreach ($parameterType->getTypes() as $type) {
                    $types[] = $type->getName();
                }
            } elseif ($parameterType instanceof \ReflectionNamedType) {
                $types[] = $parameterType->getName();
            } else {
                throw new LogicException(sprintf('Argument "$%s" of attribute autoconfigurator should have a type, use one or more of "\ReflectionClass|\ReflectionMethod|\ReflectionProperty|\ReflectionParameter|\Reflector" in "%s" on line "%d".', $reflectorParameter->getName()$callableReflector->getFileName()$callableReflector->getStartLine()));
            }

            try {
                $attributeReflector = new \ReflectionClass($attributeName);
            } catch (\ReflectionException) {
                
protected function setUp(): void
    {
        $this->extractor = new PhpDocExtractor();
    }

    /** * @dataProvider typesProvider */
    public function testExtract($property, array $type = null, $shortDescription$longDescription)
    {
        $this->assertEquals($type$this->extractor->getTypes('Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy', $property));
        $this->assertSame($shortDescription$this->extractor->getShortDescription('Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy', $property));
        $this->assertSame($longDescription$this->extractor->getLongDescription('Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy', $property));
    }

    public function testParamTagTypeIsOmitted()
    {
        $this->assertNull($this->extractor->getTypes(OmittedParamTagTypeDocBlock::class, 'omittedType'));
    }

    public static function invalidTypesProvider()
    {
        
continue;
            }

            if ($attributeContext[self::DEEP_OBJECT_TO_POPULATE] ?? $this->defaultContext[self::DEEP_OBJECT_TO_POPULATE] ?? false) {
                try {
                    $attributeContext[self::OBJECT_TO_POPULATE] = $this->getAttributeValue($object$attribute$format$attributeContext);
                } catch (NoSuchPropertyException) {
                }
            }

            $types = $this->getTypes($resolvedClass$attribute);

            if (null !== $types) {
                try {
                    $value = $this->validateAndDenormalize($types$resolvedClass$attribute$value$format$attributeContext);
                } catch (NotNormalizableValueException $exception) {
                    if (isset($context['not_normalizable_value_exceptions'])) {
                        $context['not_normalizable_value_exceptions'][] = $exception;
                        continue;
                    }
                    throw $exception;
                }
            }
$loaded = false;
        $enabledForClass = $this->isAutoMappingEnabledForClass($metadata$this->classValidatorRegexp);
        foreach ($properties as $property) {
            if (false === $this->accessExtractor->isWritable($className$property)) {
                continue;
            }

            if (!property_exists($className$property)) {
                continue;
            }

            $types = $this->typeExtractor->getTypes($className$property);
            if (null === $types) {
                continue;
            }

            $enabledForProperty = $enabledForClass;
            $hasTypeConstraint = false;
            $hasNotNullConstraint = false;
            $hasNotBlankConstraint = false;
            $allConstraint = null;
            foreach ($metadata->getPropertyMetadata($property) as $propertyMetadata) {
                // Enabling or disabling auto-mapping explicitly always takes precedence
return null;
        }

        return self::getTypeHintForType($type$r$noBuiltin);
    }

    private static function getTypeHintForType(\ReflectionType $type, \ReflectionFunctionAbstract $r, bool $noBuiltin): ?string
    {
        $types = [];
        $glue = '|';
        if ($type instanceof \ReflectionUnionType) {
            $reflectionTypes = $type->getTypes();
        } elseif ($type instanceof \ReflectionIntersectionType) {
            $reflectionTypes = $type->getTypes();
            $glue = '&';
        } elseif ($type instanceof \ReflectionNamedType) {
            $reflectionTypes = [$type];
        } else {
            return null;
        }

        foreach ($reflectionTypes as $type) {
            if ($type instanceof \ReflectionIntersectionType) {
                
/** @var \ReflectionNamedType|\ReflectionUnionType|null */
        $type = $parameters[0]->getType();

        if (!$type) {
            throw new RuntimeException(sprintf('Invalid handler service "%s": argument "$%s" of method "%s::%s()" must have a type-hint corresponding to the message class it handles.', $serviceId$parameters[0]->getName()$handlerClass->getName()$methodName));
        }

        if ($type instanceof \ReflectionUnionType) {
            $types = [];
            $invalidTypes = [];
            foreach ($type->getTypes() as $type) {
                if (!$type->isBuiltin()) {
                    $types[] = (string) $type;
                } else {
                    $invalidTypes[] = (string) $type;
                }
            }

            if ($types) {
                return ('__invoke' === $methodName) ? $types : array_fill_keys($types$methodName);
            }

            
Home | Imprint | This part of the site doesn't use cookies.