Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: symfony/form
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v5.4.44
Choose a base ref
...
head repository: symfony/form
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 7.2
Choose a head ref
Loading
Showing 369 changed files with 5,317 additions and 12,072 deletions.
3 changes: 1 addition & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/Tests export-ignore
/phpunit.xml.dist export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/.git* export-ignore
8 changes: 8 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Please do not submit any Pull Requests here. They will be closed.
---

Please submit your PR here instead:
https://github.com/symfony/symfony

This repository is what we call a "subtree split": a read-only subset of that main repository.
We're looking forward to your PR there!
20 changes: 20 additions & 0 deletions .github/workflows/close-pull-request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Close Pull Request

on:
pull_request_target:
types: [opened]

jobs:
run:
runs-on: ubuntu-latest
steps:
- uses: superbrothers/close-pull-request@v3
with:
comment: |
Thanks for your Pull Request! We love contributions.
However, you should instead open your PR on the main repository:
https://github.com/symfony/symfony
This repository is what we call a "subtree split": a read-only subset of that main repository.
We're looking forward to your PR there!
63 changes: 21 additions & 42 deletions AbstractExtension.php
Original file line number Diff line number Diff line change
@@ -24,86 +24,67 @@ abstract class AbstractExtension implements FormExtensionInterface
*
* @var FormTypeInterface[]
*/
private $types;
private array $types;

/**
* The type extensions provided by this extension.
*
* @var FormTypeExtensionInterface[][]
*/
private $typeExtensions;
private array $typeExtensions;

/**
* The type guesser provided by this extension.
*
* @var FormTypeGuesserInterface|null
*/
private $typeGuesser;
private ?FormTypeGuesserInterface $typeGuesser = null;

/**
* Whether the type guesser has been loaded.
*
* @var bool
*/
private $typeGuesserLoaded = false;
private bool $typeGuesserLoaded = false;

/**
* {@inheritdoc}
*/
public function getType(string $name)
public function getType(string $name): FormTypeInterface
{
if (null === $this->types) {
if (!isset($this->types)) {
$this->initTypes();
}

if (!isset($this->types[$name])) {
throw new InvalidArgumentException(sprintf('The type "%s" cannot be loaded by this extension.', $name));
throw new InvalidArgumentException(\sprintf('The type "%s" cannot be loaded by this extension.', $name));
}

return $this->types[$name];
}

/**
* {@inheritdoc}
*/
public function hasType(string $name)
public function hasType(string $name): bool
{
if (null === $this->types) {
if (!isset($this->types)) {
$this->initTypes();
}

return isset($this->types[$name]);
}

/**
* {@inheritdoc}
*/
public function getTypeExtensions(string $name)
public function getTypeExtensions(string $name): array
{
if (null === $this->typeExtensions) {
if (!isset($this->typeExtensions)) {
$this->initTypeExtensions();
}

return $this->typeExtensions[$name]
?? [];
}

/**
* {@inheritdoc}
*/
public function hasTypeExtensions(string $name)
public function hasTypeExtensions(string $name): bool
{
if (null === $this->typeExtensions) {
if (!isset($this->typeExtensions)) {
$this->initTypeExtensions();
}

return isset($this->typeExtensions[$name]) && \count($this->typeExtensions[$name]) > 0;
}

/**
* {@inheritdoc}
*/
public function getTypeGuesser()
public function getTypeGuesser(): ?FormTypeGuesserInterface
{
if (!$this->typeGuesserLoaded) {
$this->initTypeGuesser();
@@ -117,7 +98,7 @@ public function getTypeGuesser()
*
* @return FormTypeInterface[]
*/
protected function loadTypes()
protected function loadTypes(): array
{
return [];
}
@@ -127,17 +108,15 @@ protected function loadTypes()
*
* @return FormTypeExtensionInterface[]
*/
protected function loadTypeExtensions()
protected function loadTypeExtensions(): array
{
return [];
}

/**
* Registers the type guesser.
*
* @return FormTypeGuesserInterface|null
*/
protected function loadTypeGuesser()
protected function loadTypeGuesser(): ?FormTypeGuesserInterface
{
return null;
}
@@ -147,7 +126,7 @@ protected function loadTypeGuesser()
*
* @throws UnexpectedTypeException if any registered type is not an instance of FormTypeInterface
*/
private function initTypes()
private function initTypes(): void
{
$this->types = [];

@@ -156,7 +135,7 @@ private function initTypes()
throw new UnexpectedTypeException($type, FormTypeInterface::class);
}

$this->types[\get_class($type)] = $type;
$this->types[$type::class] = $type;
}
}

@@ -166,7 +145,7 @@ private function initTypes()
* @throws UnexpectedTypeException if any registered type extension is not
* an instance of FormTypeExtensionInterface
*/
private function initTypeExtensions()
private function initTypeExtensions(): void
{
$this->typeExtensions = [];

@@ -186,7 +165,7 @@ private function initTypeExtensions()
*
* @throws UnexpectedTypeException if the type guesser is not an instance of FormTypeGuesserInterface
*/
private function initTypeGuesser()
private function initTypeGuesser(): void
{
$this->typeGuesserLoaded = true;

43 changes: 12 additions & 31 deletions AbstractRendererEngine.php
Original file line number Diff line number Diff line change
@@ -25,46 +25,38 @@ abstract class AbstractRendererEngine implements FormRendererEngineInterface, Re
*/
public const CACHE_KEY_VAR = 'cache_key';

/**
* @var array
*/
protected $defaultThemes;

/**
* @var array[]
*/
protected $themes = [];
protected array $themes = [];

/**
* @var bool[]
*/
protected $useDefaultThemes = [];
protected array $useDefaultThemes = [];

/**
* @var array[]
*/
protected $resources = [];
protected array $resources = [];

/**
* @var array<array<int|false>>
*/
private $resourceHierarchyLevels = [];
private array $resourceHierarchyLevels = [];

/**
* Creates a new renderer engine.
*
* @param array $defaultThemes The default themes. The type of these
* themes is open to the implementation.
*/
public function __construct(array $defaultThemes = [])
{
$this->defaultThemes = $defaultThemes;
public function __construct(
protected array $defaultThemes = [],
) {
}

/**
* {@inheritdoc}
*/
public function setTheme(FormView $view, $themes, bool $useDefaultThemes = true)
public function setTheme(FormView $view, mixed $themes, bool $useDefaultThemes = true): void
{
$cacheKey = $view->vars[self::CACHE_KEY_VAR];

@@ -78,10 +70,7 @@ public function setTheme(FormView $view, $themes, bool $useDefaultThemes = true)
unset($this->resources[$cacheKey], $this->resourceHierarchyLevels[$cacheKey]);
}

/**
* {@inheritdoc}
*/
public function getResourceForBlockName(FormView $view, string $blockName)
public function getResourceForBlockName(FormView $view, string $blockName): mixed
{
$cacheKey = $view->vars[self::CACHE_KEY_VAR];

@@ -92,10 +81,7 @@ public function getResourceForBlockName(FormView $view, string $blockName)
return $this->resources[$cacheKey][$blockName];
}

/**
* {@inheritdoc}
*/
public function getResourceForBlockNameHierarchy(FormView $view, array $blockNameHierarchy, int $hierarchyLevel)
public function getResourceForBlockNameHierarchy(FormView $view, array $blockNameHierarchy, int $hierarchyLevel): mixed
{
$cacheKey = $view->vars[self::CACHE_KEY_VAR];
$blockName = $blockNameHierarchy[$hierarchyLevel];
@@ -107,10 +93,7 @@ public function getResourceForBlockNameHierarchy(FormView $view, array $blockNam
return $this->resources[$cacheKey][$blockName];
}

/**
* {@inheritdoc}
*/
public function getResourceHierarchyLevel(FormView $view, array $blockNameHierarchy, int $hierarchyLevel)
public function getResourceHierarchyLevel(FormView $view, array $blockNameHierarchy, int $hierarchyLevel): int|false
{
$cacheKey = $view->vars[self::CACHE_KEY_VAR];
$blockName = $blockNameHierarchy[$hierarchyLevel];
@@ -133,10 +116,8 @@ public function getResourceHierarchyLevel(FormView $view, array $blockNameHierar
* Loads the cache with the resource for a given block name.
*
* @see getResourceForBlock()
*
* @return bool
*/
abstract protected function loadResourceForBlockName(string $cacheKey, FormView $view, string $blockName);
abstract protected function loadResourceForBlockName(string $cacheKey, FormView $view, string $blockName): bool;

/**
* Loads the cache with the resource for a specific level of a block hierarchy.
28 changes: 14 additions & 14 deletions AbstractType.php
Original file line number Diff line number Diff line change
@@ -21,46 +21,46 @@
abstract class AbstractType implements FormTypeInterface
{
/**
* {@inheritdoc}
* @return string|null
*/
public function buildForm(FormBuilderInterface $builder, array $options)
public function getParent()
{
return FormType::class;
}

/**
* {@inheritdoc}
* @return void
*/
public function buildView(FormView $view, FormInterface $form, array $options)
public function configureOptions(OptionsResolver $resolver)
{
}

/**
* {@inheritdoc}
* @return void
*/
public function finishView(FormView $view, FormInterface $form, array $options)
public function buildForm(FormBuilderInterface $builder, array $options)
{
}

/**
* {@inheritdoc}
* @return void
*/
public function configureOptions(OptionsResolver $resolver)
public function buildView(FormView $view, FormInterface $form, array $options)
{
}

/**
* {@inheritdoc}
* @return void
*/
public function getBlockPrefix()
public function finishView(FormView $view, FormInterface $form, array $options)
{
return StringUtil::fqcnToBlockPrefix(static::class) ?: '';
}

/**
* {@inheritdoc}
* @return string
*/
public function getParent()
public function getBlockPrefix()
{
return FormType::class;
return StringUtil::fqcnToBlockPrefix(static::class) ?: '';
}
}
Loading