8000 [Validator] Add ConstraintViolationBuilder methods: fromViolation(), setPath(), getViolation() by rela589n · Pull Request #60582 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Validator] Add ConstraintViolationBuilder methods: fromViolation(), setPath(), getViolation() #60582

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter
Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Symfony/Component/Console/Debug/CliRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function __construct(
public readonly TraceableCommand $command,
) {
parent::__construct(
attributes: ['_controller' => \get_class($command->command), '_virtual_type' => 'command'],
attributes: ['_controller' => $command->command::class, '_virtual_type' => 'command'],
server: $_SERVER,
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function testProcessValue()
$this->assertSame(CustomDefinition::class, $locator('bar')::class);
$this->assertSame(CustomDefinition::class, $locator('baz')::class);
$this->assertSame(CustomDefinition::class, $locator('some.service')::class);
$this->assertSame(CustomDefinition::class, \get_class($locator('inlines.service')));
$this->assertSame(CustomDefinition::class, $locator('inlines.service')::class);
}

public function testServiceWithKeyOverwritesPreviousInheritedKey()
Expand Down
15 changes: 15 additions & 0 deletions src/Symfony/Component/Dotenv/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ Getting Started
composer require symfony/dotenv
```

Usage
-----

> For an .env file with this format:

```env
YOUR_VARIABLE_NAME=my-string
```

```php
use Symfony\Component\Dotenv\Dotenv;

Expand All @@ -25,6 +34,12 @@ $dotenv->overload(__DIR__.'/.env');

// loads .env, .env.local, and .env.$APP_ENV.local or .env.$APP_ENV
$dotenv->loadEnv(__DIR__.'/.env');

// Usage with $_ENV
$envVariable = $_ENV['YOUR_VARIABLE_NAME'];

// Usage with $_SERVER
$envVariable = $_SERVER['YOUR_VARIABLE_NAME'];
```

Resources
Expand Down
5 changes: 5 additions & 0 deletions src/Symfony/Component/Form/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CHANGELOG
=========

7.4
---

* Add `input=date_point` to `DateTimeType`, `DateType` and `TimeType`

7.3
---

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Form\Extension\Core\DataTransformer;

use Symfony\Component\Clock\DatePoint;
use Symfony\Component\Form\DataTransformerInterface;
use Symfony\Component\Form\Exception\TransformationFailedException;

/**
* Transforms between a DatePoint object and a DateTime object.
*
* @implements DataTransformerInterface<DatePoint, \DateTime>
*/
final class DatePointToDateTimeTransformer implements DataTransformerInterface
{
/**
* Transforms a DatePoint into a DateTime object.
*
* @param DatePoint|null $value A DatePoint object
*
* @throws TransformationFailedException If the given value is not a DatePoint
*/
public function transform(mixed $value): ?\DateTime
{
if (null === $value) {
return null;
}

if (!$value instanceof DatePoint) {
throw new TransformationFailedException(\sprintf('Expected a "%s".', DatePoint::class));
}

return \DateTime::createFromImmutable($value);
}

/**
* Transforms a DateTime object into a DatePoint object.
*
* @param \DateTime|null $value A DateTime object
*
* @throws TransformationFailedException If the given value is not a \DateTime
*/
public function reverseTransform(mixed $value): ?DatePoint
{
if (null === $value) {
return null;
}

if (!$value instanceof \DateTime) {
throw new TransformationFailedException('Expected a \DateTime.');
}

return DatePoint::createFromMutable($value);
}
}
12 changes: 10 additions & 2 deletions src/Symfony/Component/Form/Extension/Core/Type/DateTimeType.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@

namespace Symfony\Component\Form\Extension\Core\Type;

use Symfony\Component\Clock\DatePoint;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Exception\LogicException;
use Symfony\Component\Form\Extension\Core\DataTransformer\ArrayToPartsTransformer;
use Symfony\Component\Form\Extension\Core\DataTransformer\DataTransformerChain;
use Symfony\Component\Form\Extension\Core\DataTransformer\DatePointToDateTimeTransformer;
use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeImmutableToDateTimeTransformer;
use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToArrayTransformer;
use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToHtml5LocalDateTimeTransformer;
Expand Down Expand Up @@ -178,7 +180,12 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
;
}

if ('datetime_immutable' === $options['input']) {
if ('date_point' === $options['input']) {
if (!class_exists(DatePoint::class)) {
throw new LogicException(\sprintf('The "symfony/clock" component is required to use "%s" with option "input=date_point". Try running "composer require symfony/clock".', self::class));
}
$builder->addModelTransformer(new DatePointToDateTimeTransformer());
} elseif ('datetime_immutable' === $options['input']) {
$builder->addModelTransformer(new DateTimeImmutableToDateTimeTransformer());
} elseif ('string' === $options['input']) {
$builder->addModelTransf F438 ormer(new ReversedTransformer(
Expand All @@ -194,7 +201,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
));
}

if (\in_array($options['input'], ['datetime', 'datetime_immutable'], true) && null !== $options['model_timezone']) {
if (\in_array($options['input'], ['datetime', 'datetime_immutable', 'date_point'], true) && null !== $options['model_timezone']) {
$builder->addEventListener(FormEvents::POST_SET_DATA, static function (FormEvent $event) use ($options): void {
$date = $event->getData();

Expand Down Expand Up @@ -283,6 +290,7 @@ public function configureOptions(OptionsResolver $resolver): void
$resolver->setAllowedValues('input', [
'datetime',
'datetime_immutable',
'date_point',
'string',
'timestamp',
'array',
Expand Down
12 changes: 10 additions & 2 deletions src/Symfony/Component/Form/Extension/Core/Type/DateType.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@

namespace Symfony\Component\Form\Extension\Core\Type;

use Symfony\Component\Clock\DatePoint;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Exception\LogicException;
use Symfony\Component\Form\Extension\Core\DataTransformer\DatePointToDateTimeTransformer;
use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeImmutableToDateTimeTransformer;
use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToArrayTransformer;
use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToLocalizedStringTransformer;
Expand Down Expand Up @@ -156,7 +158,12 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
;
}

if ('datetime_immutable' === $options['input']) {
if ('date_point' === $options['input']) {
if (!class_exists(DatePoint::class)) {
throw new LogicException(\sprintf('The "symfony/clock" component is required to use "%s" with option "input=date_point". Try running "composer require symfony/clock".', self::class));
}
$builder->addModelTransformer(new DatePointToDateTimeTransformer());
} elseif ('datetime_immutable' === $options['input']) {
$builder->addModelTransformer(new DateTimeImmutableToDateTimeTransformer());
} elseif ('string' === $options['input']) {
$builder->addModelTransformer(new ReversedTransformer(
Expand All @@ -172,7 +179,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
));
}

if (\in_array($options['input'], ['datetime', 'datetime_immutable'], true) && null !== $options['model_timezone']) {
if (\in_array($options['input'], ['datetime', 'datetime_immutable', 'date_point'], true) && null !== $options['model_timezone']) {
$builder->addEventListener(FormEvents::POST_SET_DATA, static function (FormEvent $event) use ($options): void {
$date = $event->getData();

10000 Expand Down Expand Up @@ -298,6 +305,7 @@ public function configureOptions(OptionsResolver $resolver): void
$resolver->setAllowedValues('input', [
'datetime',
'datetime_immutable',
'date_point',
'string',
'timestamp',
'array',
Expand Down
12 changes: 10 additions & 2 deletions src/Symfony/Component/Form/Extension/Core/Type/TimeType.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@

namespace Symfony\Component\Form\Extension\Core\Type;

use Symfony\Component\Clock\DatePoint;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Exception\InvalidConfigurationException;
use Symfony\Component\Form\Exception\LogicException;
use Symfony\Component\Form\Extension\Core\DataTransformer\DatePointToDateTimeTransformer;
use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeImmutableToDateTimeTransformer;
use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToArrayTransformer;
use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToStringTransformer;
Expand Down Expand Up @@ -190,7 +192,12 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
$builder->addViewTransformer(new DateTimeToArrayTransformer($options['model_timezone'], $options['view_timezone'], $parts, 'text' === $options['widget'], $options['reference_date']));
}

if ('datetime_immutable' === $options['input']) {
if ('date_point' === $options['input']) {
if (!class_exists(DatePoint::class)) {
throw new LogicException(\sprintf('The "symfony/clock" component is required to use "%s" with option "input=date_point". Try running "composer require symfony/clock".', self::class));
}
$builder->addModelTransformer(new DatePointToDateTimeTransformer());
} elseif ('datetime_immutable' === $options['input']) {
$builder->addModelTransformer(new DateTimeImmutableToDateTimeTransformer());
} elseif ('string' === $options['input']) {
$builder->addModelTransformer(new ReversedTransformer(
Expand All @@ -206,7 +213,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
));
}

if (\in_array($options['input'], ['datetime', 'datetime_immutable'], true) && null !== $options['model_timezone']) {
if (\in_array($options['input'], ['datetime', 'datetime_immutable', 'date_point'], true) && null !== $options['model_timezone']) {
$builder->addEventListener(FormEvents::POST_SET_DATA, static function (FormEvent $event) use ($options): void {
$date = $event->getData();

Expand Down Expand Up @@ -354,6 +361,7 @@ public function configureOptions(OptionsResolver $resolver): void
$resolver->setAllowedValues('input', [
'datetime',
'datetime_immutable',
'date_point',
'string',
'timestamp',
'array',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Symfony\Component\Form\Tests\Extension\Core\Type;

use Symfony\Component\Clock\DatePoint;
use Symfony\Component\Form\Exception\LogicException;
use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
use Symfony\Component\Form\FormError;
Expand Down Expand Up @@ -62,6 +63,37 @@ public function testSubmitDateTime()
$this->assertEquals($dateTime, $form->getData());
}

public function testSubmitDatePoint()
{
$form = $this->factory->create(static::TESTED_TYPE, null, [
'model_timezone' => 'UTC',
'view_timezone' => 'UTC',
'date_widget' => 'choice',
'years' => [2010],
'time_widget' => 'choice',
'input' => 'date_point',
]);

$input = [
'date' => [
'day' => '2',
'month' => '6',
'year' => '2010',
],
'time' => [
'hour' => '3',
'minute' => '4',
],
];

$form->submit($input);

$this->assertInstanceOf(DatePoint::class, $form->getData());
$datePoint = DatePoint::createFromMutable(new \DateTime('2010-06-02 03:04:00 UTC'));
$this->assertEquals($datePoint, $form->getData());
$this->assertEquals($input, $form->getViewData());
}

public function testSubmitDateTimeImmutable()
{
$form = $this->factory->create(static::TESTED_TYPE, null, [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Symfony\Component\Form\Tests\Extension\Core\Type;

use Symfony\Component\Clock\DatePoint;
use Symfony\Component\Form\ChoiceList\View\ChoiceView;
use Symfony\Component\Form\Exception\LogicException;
use Symfony\Component\Form\Extension\Core\Type\DateType;
F438 Expand Down Expand Up @@ -115,6 +116,27 @@ public function testSubmitFromSingleTextDateTime()
$this->assertEquals('02.06.2010', $form->getViewData());
}

public function testSubmitFromSingleTextDatePoint()
{
if (!class_exists(DatePoint::class)) {
self::markTestSkipped('The DatePoint class is not available.');
}

$form = $this->factory->create(static::TESTED_TYPE, null, [
'html5' => false,
'model_timezone' => 'UTC',
'view_timezone' => 'UTC',
'widget' => 'single_text',
'input' => 'date_point',
]);

$form->submit('2010-06-02');

$this->assertInstanceOf(DatePoint::class, $form->getData());
$this->assertEquals(DatePoint::createFromMutable(new \DateTime('2010-06-02 UTC')), $form->getData());
$this->assertEquals('2010-06-02', $form->getViewData());
}

public function testSubmitFromSingleTextDateTimeImmutable()
{
// we test against "de_DE", so we need the full implementation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Symfony\Component\Form\Tests\Extension\Core\Type;

use Symfony\Component\Clock\DatePoint;
use Symfony\Component\Form\ChoiceList\View\ChoiceView;
use Symfony\Component\Form\Exception\InvalidConfigurationException;
use Symfony\Component\Form\Exception\LogicException;
Expand Down Expand Up @@ -45,6 +46,32 @@ public function testSubmitDateTime()
$this->assertEquals($input, $form->getViewData());
}

public function testSubmitDatePoint()
{
if (!class_exists(DatePoint::class)) {
self::markTestSkipped('The DatePoint class is not available.');
}

$form = $this->factory->create(static::TESTED_TYPE, null, [
'model_timezone' => 'UTC',
'view_timezone' => 'UTC',
'widget' => 'choice',
'input' => 'date_point',
]);

$input = [
'hour' => '3',
'minute' => '4',
];

$form->submit($input);

$this->assertInstanceOf(DatePoint::class, $form->getData());
$datePoint = DatePoint::createFromMutable(new \DateTime('1970-01-01 03:04:00 UTC'));
$this->assertEquals($datePoint, $form->getData());
$this->assertEquals($input, $form->getViewData());
}

public function testSubmitDateTimeImmutable()
{
$form = $this->factory->create(static::TESTED_TYPE, null, [
Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Component/Form/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"symfony/validator": "^6.4|^7.0",
"symfony/dependency-injection": "^6.4|^7.0",
"symfony/expression-language": "^6.4|^7.0",
"symfony/clock": "^6.4|^7.0",
"symfony/config": "^6.4|^7.0",
"symfony/console": "^6.4|^7.0",
"symfony/html-sanitizer": "^6.4|^7.0",
Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Component/Scheduler/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ CHANGELOG
---

* Add `TriggerNormalizer`
* Throw exception when multiple schedule provider services are registered under the same scheduler name

7.2
---
Expand Down
Loading
Loading
0