Commit Graph

41010 Commits

Author SHA1 Message Date
Fabien Potencier
563900ffaa fixed CS 2019-03-31 19:31:00 +02:00
Fabien Potencier
dad5b01b9c feature #26890 [Inflector] Support pluralization in the inflector (mbabker)
This PR was merged into the 4.3-dev branch.

Discussion
----------

[Inflector] Support pluralization in the inflector

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | not yet
| Fixed tickets | N/A
| License       | MIT
| Doc PR        | Not Yet

At present the inflector only supports singularizing plural words, this PR adds the capability to pluralize singular words.

Commits
-------

06920a79c4 Support pluralization in the inflector
2019-03-31 19:29:55 +02:00
Samuel ROZE
0b5004f59f Add psr/cache on Messenger's dependencies 2019-03-31 18:23:22 +01:00
Fabien Potencier
592e72fc9c feature #28637 [Validator] add number constraints (jschaedl)
This PR was squashed before being merged into the 4.3-dev branch (closes #28637).

Discussion
----------

[Validator] add number constraints

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #28608
| License       | MIT
| Doc PR        | tbd.

I added the following constraints:
* `Positive`
* `PositiveOrZero`
* `Negative`
* `NegativeOrZero`

Commits
-------

01870398eb [Validator] add number constraints
2019-03-31 19:19:07 +02:00
Jan Schädlich
01870398eb [Validator] add number constraints 2019-03-31 19:18:59 +02:00
Nicolas Grekas
6070151495 minor #30800 [Messenger] fix review (nicolas-grekas)
This PR was merged into the 4.3-dev branch.

Discussion
----------

[Messenger] fix review

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

Fixes my review left in #30754
/cc @weaverryan FYI

Commits
-------

a3de9020c8 [Messenger] fix review
2019-03-31 19:13:48 +02:00
Vincent Touzet
4811400372 [Messenger] Remove unused option in the Doctrine transport 2019-03-31 19:12:50 +02:00
Samuel ROZE
a9459c0980 minor #30799 [Messenger] Fix the Doctrine transport to use the new interface (sroze)
This PR was merged into the 4.3-dev branch.

Discussion
----------

[Messenger] Fix the Doctrine transport to use the new interface

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #29007
| License       | MIT
| Doc PR        | ø

Commits
-------

75e3355da5 Fix the Doctrine transport to use the new interface
2019-03-31 18:12:31 +01:00
Nicolas Grekas
a3de9020c8 [Messenger] fix review 2019-03-31 19:00:04 +02:00
Samuel ROZE
75e3355da5 Fix the Doctrine transport to use the new interface 2019-03-31 17:52:51 +01:00
Fabien Potencier
343d28e3d1 feature #30754 [Messenger] New messenger:stop-workers Command (weaverryan)
This PR was squashed before being merged into the 4.3-dev branch (closes #30754).

Discussion
----------

[Messenger] New messenger:stop-workers Command

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | Kinda of #29451
| License       | MIT
| Doc PR        | symfony/symfony-docs#11236

o/ me again.

This requires and is built on top of #30708

When you deploy, all workers need to be stopped and restarted. That's not currently possible, unless you manually track the pids and send a SIGTERM signal. We can make that much easier :).

Now run:

```
bin/console messenger:stop-workers
```

And it will signal to all workers (even if they're distributed on other servers) that they should stop, once they finish processing their current message. This is done via a key in `cache.app`.

Cheers!

Commits
-------

58971627f5 [Messenger] New messenger:stop-workers Command
2019-03-31 18:41:56 +02:00
Ryan Weaver
58971627f5 [Messenger] New messenger:stop-workers Command 2019-03-31 18:41:31 +02:00
Fabien Potencier
8c2ade9173 bug #30794 [EventDispatcher] Fix BC/FC layer (chalasr)
This PR was merged into the 4.3-dev branch.

Discussion
----------

[EventDispatcher] Fix BC/FC layer

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | n/a
| License       | MIT
| Doc PR        | n/a

Fixes
> TypeError: Argument 3 passed to Symfony\Component\EventDispatcher\EventDispatcher::doDispatch() must be an instance of Symfony\Component\EventDispatcher\Event

Spotted in https://github.com/lexik/LexikJWTAuthenticationBundle/pull/637

Commits
-------

caa0aded89 [EventDispatcher] Fix BC layer
2019-03-31 18:36:43 +02:00
Samuel ROZE
fd4146c768 Add back missing uses 2019-03-31 17:35:18 +01:00
Fabien Potencier
825335374a bug #30756 Changing to MessageDecodingFailedException so that invalid messages are rejected (weaverryan)
This PR was merged into the 4.3-dev branch.

Discussion
----------

Changing to MessageDecodingFailedException so that invalid messages are rejected

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | yes
| New feature?  |  no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes    <!-- please add some, will be required by reviewers -->
| Fixed tickets | #30649
| License       | MIT
| Doc PR        | not needed for bug fix

Bug fix if a message body is completely blank. I'm fixing this on master only, because in 4.2 and earlier, there is actually no system in place to fail serialization and cause the messages to be rejected. In 4.3, we just need to throw this exception.

Cheers!

Commits
-------

4be827d3ca Changing to MessageDecodingFailedException so that invalid messages are rejected
2019-03-31 18:34:24 +02:00
Fabien Potencier
177a0d9320 bug #30798 [Messenger] Updating SyncTransport for recent changes + tests (weaverryan)
This PR was merged into the 4.3-dev branch.

Discussion
----------

[Messenger] Updating SyncTransport for recent changes + tests

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | none
| License       | MIT
| Doc PR        | not needed

When making the `SyncTransport`, I neglected having at least one test in each of these classes, which allowed the test suite to pass, even after some interface changes made these classes fail. Fixed all of that :)

Commits
-------

2df023be46 Updating SyncTransport for recent changes + tests
2019-03-31 18:31:45 +02:00
Fabien Potencier
3abca64c5d feature #30707 [Messenger][DX] Allow stamps to be passed directly to MessageBusInterface::dispatch() (weaverryan)
This PR was merged into the 4.3-dev branch.

Discussion
----------

[Messenger][DX] Allow stamps to be passed directly to MessageBusInterface::dispatch()

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | yes
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | none
| License       | MIT
| Doc PR        | TODO

Me again o/!

This proposal is *purely* for DX. With `DelayStamp`, the proposal of QueueNameStamp and future things like `AmqpRoutingKeyStamp`, stamps are becoming more common for end users to use. This changes how it looks to use them:

```php
// before
$bus->dispatch(new Envelope(new SendSmsNotification('Hi!'), new DelayStamp(10), new QueueNameStamp('low')));

// after
$bus->dispatch(new SendSmsNotification('Hi!'), [new DelayStamp(10), new QueueNameStamp('low')]);
```

It's definitely a BC break, which is allowed because the component is experimental, though it should be minimized. This BC break shouldn't be felt by most end users, as creating your own bus is an advanced use-case. Even if you decorated it, you'll get an obvious error.

Commits
-------

e861de7e61 Allow stamps to be passed directly to MessageBusInterface::dispatch()
2019-03-31 18:29:02 +02:00
Samuel ROZE
e897e6cc4e Add missing word in CHANGELOG 2019-03-31 17:26:00 +01:00
Samuel ROZE
d9e2732a7d feature #29007 [Messenger] Add a Doctrine transport (vincenttouzet)
This PR was merged into the 4.3-dev branch.

Discussion
----------

[Messenger] Add a Doctrine transport

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets |
| License       | MIT
| Doc PR        | symfony/symfony-docs#10616
| DoctrineBundle PR | doctrine/DoctrineBundle#868

As discussed with @sroze at PHPForum in Paris I've worked on adding a Doctrine transport to the Messenger component.

Actually `AMQP` is the only supported transport and it could be a good thing to support multiple transports. Having a Doctrine transport could help users to start using the component IMHO (Almost all projects use a database).

# How it works

The code is splitted betwwen this PR and the one on the DoctrineBundle : doctrine/DoctrineBundle#868

## Configuration

To configure a Doctrine transport the dsn MUST have the format `doctrine://<entity_manager_name>` where `<entity_manager_name>` is the name of the entity manager (usually `default`)
```yml
        # config/packages/messenger.yaml
        framework:
            messenger:
                transports:
                    my_transport: "doctrine://default?queue=important"
```

## Table schema

Dispatched messages are stored into a database table with the following schema:

| Column       | Type     | Options                  | Description                                                       |
|--------------|----------|--------------------------|-------------------------------------------------------------------|
| id           | bigint   | AUTO_INCREMENT, NOT NULL | Primary key                                                       |
| body         | text     | NOT NULL                 | Body of the message                                               |
| headers      | text     | NOT NULL                 | Headers of the message                                            |
| queue      | varchar(32)     | NOT NULL                 | Headers of the message                                            |
| created_at   | datetime | NOT NULL                 | When the message was inserted onto the table. (automatically set) |
| available_at       | datetime   | NOT NULL                 | When the message is available to be handled                      |
| delivered_at | datetime | NULL                     | When the message was delivered to a worker                        |

## Message dispatching

When dispatching a message a new row is inserted into the table. See `Symfony\Component\Messenger\Transport\Doctrine::publish`

## Message consuming

The message is retrieved by the `Symfony\Component\Messenger\Transport\Doctrine\DoctrineReceiver`. It calls the `Symfony\Component\Messenger\Transport\Doctrine::get` method to get the next message to handle.

### Getting the next message

* Start a transaction
* Lock the table to get the first message to handle (The lock is done with the `SELECT ... FOR UPDATE` query)
* Update the message in database to update the delivered_at columns
* Commit the transaction

### Handling the message

The retrieved message is then passed to the handler. If the message is correctly handled the receiver call the `Symfony\Component\Messenger\Transport\Doctrine::ack` which delete the message from the table.

If an error occured the receiver call the `Symfony\Component\Messenger\Transport\Doctrine::nack` method which update the message to set the delivered_at column to `null`.

## Message requeueing

It may happen that a message is stuck in `delivered` state but the handler does not really handle the message (Database connection error, server crash, ...). To requeue messages the `DoctrineReceiver` call the `Symfony\Component\Messenger\Transport\Doctrine::requeueMessages`. This method update all the message with a  `delivered_at` not null since more than the "redeliver timeout" (default to 3600 seconds)

# TODO

- [x] Add tests
- [x] Create DOC PR
- [x] PR on doctrine-bundle for transport factory
- [x] Add a `available_at` column
- [x] Add a `queue` column
- [x] Implement the retry functionnality : See #30557
- [x] Rebase after #29476

Commits
-------

88d008c828 [Messenger] Add a Doctrine transport
2019-03-31 17:25:18 +01:00
Ryan Weaver
e861de7e61 Allow stamps to be passed directly to MessageBusInterface::dispatch()
And changing signature of Envelope::__construct() to accept an array of envelopes
2019-03-31 12:05:21 -04:00
Ryan Weaver
4be827d3ca Changing to MessageDecodingFailedException so that invalid messages are rejected 2019-03-31 11:54:28 -04:00
Ryan Weaver
2df023be46 Updating SyncTransport for recent changes + tests 2019-03-31 11:45:52 -04:00
Fabien Potencier
88042a317a feature #30628 Making the serializer configurable by transport (weaverryan)
This PR was merged into the 4.3-dev branch.

Discussion
----------

Making the serializer configurable by transport

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | yes
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #30293 (already closed, but I don't think this was reasonably possible before)
| License       | MIT
| Doc PR        | TODO - as many of the new messenger PRs will be done at once

Use cases:
* #30293
* Transport A will be consumed by your Symfony app (so native php serialization is cool) but transport B will be consumed by another app, so you want to serialize as JSON
* Upgrading from Symfony 4.2 to 4.3. The change to the `PhpSerialize` means that messages that were sent to the queue on 4.2, will fail on 4.3. The solution is to use the old serializer in your config. This would allow you to make your existing transport use the old serializer, then migrate to a new transport using the new serializer (then remove the old one later).

Thanks!

Commits
-------

ef6f23e8b9 Making the serializer configurable by transport
2019-03-31 16:55:57 +02:00
Ryan Weaver
ef6f23e8b9 Making the serializer configurable by transport 2019-03-31 16:54:31 +02:00
Vincent Touzet
88d008c828 [Messenger] Add a Doctrine transport 2019-03-31 16:05:11 +02:00
Fabien Potencier
07276642de fixed typo 2019-03-31 15:49:16 +02:00
Fabien Potencier
dd47fda441 fixed bad merge 2019-03-31 14:18:54 +02:00
Fabien Potencier
460da96f45 feature #30569 [FrameworkBundle][HttpKernel] Provide intuitive error message when a controller fails because it's not registered as a service (moynzzz)
This PR was squashed before being merged into the 4.3-dev branch (closes #30569).

Discussion
----------

[FrameworkBundle][HttpKernel] Provide intuitive error message when a controller fails because it's not registered as a service

| Q             | A
| ------------- | ---
| Branch?       | master <!-- see below -->
| Bug fix?      | no
| New feature?  | yes <!-- don't forget to update src/**/CHANGELOG.md files -->
| BC breaks?    | no     <!-- see https://symfony.com/bc -->
| Deprecations? | no <!-- don't forget to update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tests pass?   | yes    <!-- please add some, will be required by reviewers -->
| Fixed tickets | #27787, symfony/symfony-docs#7988 <!-- #-prefixed issue number(s), if any -->
| License       | MIT
| Doc PR        | none <!-- required for new features -->

<!--
Write a short README entry for your feature/bugfix here (replace this comment block.)
This will help people understand your PR and can be used as a start of the Doc PR.
Additionally:
 - Bug fixes must be submitted against the lowest branch where they apply
   (lowest branches are regularly merged to upper ones so they get the fixes too).
 - Features and deprecations must be submitted against the master branch.
-->

Create a very late controller argument value resolver to throw an intuitive error message when controller fails because it is not registered as a service.

Commits
-------

fbfc623b72 [FrameworkBundle][HttpKernel] Provide intuitive error message when a controller fails because it's not registered as a service
2019-03-31 14:12:04 +02:00
Simeon Kolev
fbfc623b72 [FrameworkBundle][HttpKernel] Provide intuitive error message when a controller fails because it's not registered as a service 2019-03-31 14:11:56 +02:00
Robin Chalas
caa0aded89 [EventDispatcher] Fix BC layer 2019-03-31 14:11:52 +02:00
Fabien Potencier
b14d5cd358 feature #26484 [Validator] String normalization options for string-based validators (renan-taranto)
This PR was merged into the 4.3-dev branch.

Discussion
----------

[Validator] String normalization options for string-based validators

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #26239
| License       | MIT
| Doc PR        | https://github.com/symfony/symfony-docs/pull/9433

Todo:
- [x] Document the new options
- [x] Update Doc PR

Add trimming options to the string constraints.

Commits
-------

708d759b8d [Validator] String normalization options for string-based validators
2019-03-31 13:55:59 +02:00
Fabien Potencier
6bc2ae4018 feature #30320 [Form][TwigBridge] Add row_attr to form theme (alexander-schranz)
This PR was squashed before being merged into the 4.3-dev branch (closes #30320).

Discussion
----------

[Form][TwigBridge] Add row_attr to form theme

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | waiting for confirmation to implement
| Fixed tickets |
| License       | MIT
| Doc PR        | symfony/symfony-docs#... <!-- required for new features -->

Currently you need to copy the whole form_row block if you just want to add a class to the form_row div. Instead we could introduce a `row_attr` which can then simple be set the following in the theme e.g.:

```twig
{% block form_row %}
    {% set row_attr = { class: 'form__field' } %}
    {{ parent() }}
{% endblock %}
```

or in php:

```
$builder->add('test', TextType::class, ['row_attr' => ['class' => 'form__field']]);
```

Commits
-------

7ab1b00e02 [Form][TwigBridge] Add row_attr to form theme
2019-03-31 13:48:32 +02:00
Alexander Schranz
7ab1b00e02 [Form][TwigBridge] Add row_attr to form theme 2019-03-31 13:48:18 +02:00
Fabien Potencier
ce24e15775 feature #30371 [OptionsResolver] Add a new method addNormalizer and normalization hierarchy (yceruto)
This PR was squashed before being merged into the 4.3-dev branch (closes #30371).

Discussion
----------

[OptionsResolver] Add a new method addNormalizer and normalization hierarchy

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #30310
| License       | MIT
| Doc PR        | https://github.com/symfony/symfony-docs/pull/11103

### 3rd-party package

<details><summary>Given: (CLICK ME)</summary>
<p>

Generic type:
```php
class FooType extends AbstractType
{
    private $registry;

    public function __construct(ManagerRegistry $registry)
    {
        $this->registry = $registry;
    }

    // buildForm ...

    public function configureOptions(OptionsResolver $resolver): void
    {
        $resolver->setRequired('class');
        $resolver->setDefaults([
            'em' => null,
            'query' => null,
        ]);
        $resolver->setAllowedTypes('em', ['null', 'string']);
        $resolver->setAllowedTypes('query', ['null', 'callable']);

        $resolver->setNormalizer('em', function (Options $options, $em) {
            if (null !== $em) {
                return $this->registry->getManager($em);
            }

            return $this->registry->getManagerForClass($options['class']);
        });

        $resolver->setNormalizer('query', function (Options $options, $query) {
            if (\is_callable($query)) {
                $query = $query($options['em']->getRepository($options['class']));

                if (!$query instanceof Query) {
                    throw new UnexpectedTypeException($query, 'Doctrine\ORM\Query');
                }
            }

            return $query;
        });
    }
}
```
</p>
</details>

### App context

<details><summary>Before (CLICK ME)</summary>
<p>

Normalizing the new allowed value will require to override the parent's normalizer:
```php
class BarType extends AbstractType
{
    private $registry;

    public function __construct(ManagerRegistry $registry)
    {
        $this->registry = $registry;
    }

    // buildForm ...

    public function configureOptions(OptionsResolver $resolver): void
    {
        $resolver->addAllowedTypes('em', 'Doctrine\ORM\EntityManagerInterface');

        $resolver->setNormalizer('em', function (Options $options, $em) {
            if ($em instanceof EntityManagerInterface) {
                return $em;
            }

            if (null !== $em) {
                return $this->registry->getManager($em);
            }

            return $this->registry->getManagerForClass($options['class']);
        });

        $resolver->addAllowedTypes('query', 'string');

        $resolver->setNormalizer('query', function (Options $options, $query) {
            if (\is_callable($query)) {
                $query = $query($options['em']->getRepository($options['class']));

                if (!$query instanceof Query) {
                    throw new UnexpectedTypeException($query, 'Doctrine\ORM\Query');
                }
            }

            if (\is_string($query)) {
                $query = $options['em']->createQuery($query);
            }

            return $query;
        });
    }

    public function getParent()
    {
        return FooType::class;
    }
}
```
</p>
</details>

<details><summary>After (CLICK ME)</summary>
<p>

The new normalizer is added to the stack and it'll receive the previously normalized value or if `forcePrepend = true` the validated value:
```php
class BarType extends AbstractType
{
    // buildForm ...

    public function configureOptions(OptionsResolver $resolver): void
    {
        $resolver->addAllowedTypes('em', 'Doctrine\ORM\EntityManagerInterface');

        $resolver->addNormalizer('em', function (Options $options, $em) {
            if ($em instanceof EntityManagerInterface) {
                return $em;
            }

            return $em;
        }, true); // $forcePrepend = true (3rd argument)

        $resolver->addAllowedTypes('query', 'string');

        $resolver->addNormalizer('query', function (Options $options, $query) {
            if (\is_string($query)) {
                $query = $options['em']->createQuery($query);
            }

            return $query;
        });
    }

    public function getParent()
    {
        return FooType::class;
    }
}
```
</p>
</details>

Commits
-------

cf41254223 [OptionsResolver] Add a new method addNormalizer and normalization hierarchy
2019-03-31 13:47:22 +02:00
Yonel Ceruto
cf41254223 [OptionsResolver] Add a new method addNormalizer and normalization hierarchy 2019-03-31 13:47:13 +02:00
Fabien Potencier
7554cf6f1d feature #27735 [Validator][DoctrineBridge][FWBundle] Automatic data validation (dunglas)
This PR was merged into the 4.3-dev branch.

Discussion
----------

[Validator][DoctrineBridge][FWBundle] Automatic data validation

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes<!-- don't forget to update src/**/CHANGELOG.md files -->
| BC breaks?    | no     <!-- see https://symfony.com/bc -->
| Deprecations? | no <!-- don't forget to update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tests pass?   | yes    <!-- please add some, will be required by reviewers -->
| Fixed tickets | n/a   <!-- #-prefixed issue number(s), if any -->
| License       | MIT
| Doc PR        | https://github.com/symfony/symfony-docs/pull/11132

This feature automatically adds some validation constraints by inferring existing metadata. To do so, it uses the PropertyInfo component and Doctrine metadata, but it has been designed to be easily extendable.

Example:

```php
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 */
class Dummy
{
    /**
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     * @ORM\Column(type="integer")
     */
    public $id;

    /**
     * @ORM\Column(nullable=true)
     */
    public $columnNullable;

    /**
     * @ORM\Column(length=20)
     */
    public $columnLength;

    /**
     * @ORM\Column(unique=true)
     */
    public $columnUnique;
}

$manager = $this->managerRegistry->getManager();
$manager->getRepository(Dummy::class);

$firstOne = new Dummy();
$firstOne->columnUnique = 'unique';
$firstOne->columnLength = '0';

$manager->persist($firstOne);
$manager->flush();

$dummy = new Dummy();
$dummy->columnNullable = 1; // type mistmatch
$dummy->columnLength = '012345678901234567890'; // too long
$dummy->columnUnique = 'unique'; // not unique

$res = $this->validator->validate($dummy);
dump((string) $res);

/*
Object(App\Entity\Dummy).columnUnique:\n
    This value is already used. (code 23bd9dbf-6b9b-41cd-a99e-4844bcf3077f)\n
Object(App\Entity\Dummy).columnLength:\n
    This value is too long. It should have 20 characters or less. (code d94b19cc-114f-4f44-9cc4-4138e80a87b9)\n
Object(App\Entity\Dummy).id:\n
    This value should not be null. (code ad32d13f-c3d4-423b-909a-857b961eb720)\n
Object(App\Entity\Dummy).columnNullable:\n
    This value should be of type string. (code ba785a8c-82cb-4283-967c-3cf342181b40)\n
*/
```

It also works for DTOs:

```php

class MyDto
{
    /** @var string */
    public $name;
}

$dto = new MyDto();
$dto->name = 1; // type error

dump($validator->validate($dto));

/*
Object(MyDto).name:\n
    This value should be of type string. (code ba785a8c-82cb-4283-967c-3cf342181b40)\n
*/
```

Supported constraints currently are:

* `@NotNull` (using PropertyInfo type extractor, so supports Doctrine metadata, getters/setters and PHPDoc)
* `@Type` (using PropertyInfo type extractor, so supports Doctrine metadata, getters/setters and PHPDoc)
* `@UniqueEntity` (using Doctrine's `unique` metadata)
* `@Length` (using Doctrine's `length` metadata)

Many users don't understand that the Doctrine mapping doesn't validate anything (it's just a hint for the schema generator). It leads to usability and security issues (that are not entirely fixed by this PR!!).
Even the ones who add constraints often omit important ones like `@Length`, or `@Type` (important when building web APIs).
This PR aims to improve things a bit, and ease the development process in RAD and when prototyping. It provides an upgrade path to use proper validation constraints.

I plan to make it opt-in, disabled by default, but enabled in the default Flex recipe. (= off by default when using components, on by default when using the full stack framework)

TODO:

* [x] Add configuration flags
* [x] Move the Doctrine-related DI logic from the extension to DoctrineBundle: doctrine/DoctrineBundle#831
* [x] Commit the tests

Commits
-------

2d64e703c2 [Validator][DoctrineBridge][FWBundle] Automatic data validation
2019-03-31 13:41:16 +02:00
Fabien Potencier
cbbfe84154 minor #30793 [Messenger] Remove the mention of handler in the ReceiverInterface::get phpdoc. (sroze)
This PR was merged into the 4.3-dev branch.

Discussion
----------

[Messenger] Remove the mention of handler in the `ReceiverInterface::get` phpdoc.

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | https://github.com/symfony/symfony/pull/30708#pullrequestreview-220830730
| License       | MIT
| Doc PR        | ø

As spotted by @Tobion, we don't have an handler as an argument anymore.

Commits
-------

9c63112d7c Remove the mention of handler in the phpdoc.
2019-03-31 12:26:30 +02:00
Fabien Potencier
3df44f5679 feature #30758 [PropertyAccess] Allow Can Accessor in Property Access (ragboyjr)
This PR was merged into the 4.3-dev branch.

Discussion
----------

[PropertyAccess] Allow Can Accessor in Property Access

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no     <!-- see https://symfony.com/bc -->
| Deprecations? | no <!-- don't forget to update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tests pass?   | yes    <!-- please add some, will be required by reviewers -->
| Fixed tickets |
| License       | MIT
| Doc PR        |

- Added ability to support `can` methods in the property access
  in order to be compatible with PropertyInfo component
  which allows for `can` accessors

Commits
-------

a4c95745bb [PropertyAccess] Allow Can Accessor in Property Access
2019-03-31 12:12:59 +02:00
Samuel ROZE
9c63112d7c Remove the mention of handler in the phpdoc. 2019-03-31 11:12:50 +01:00
Fabien Potencier
6d51eaf5fc fixed CS 2019-03-31 12:10:11 +02:00
Fabien Potencier
e92c120f27 feature #30116 [Filesystem] Fix mirroring a directory into itself or in his child with realpath checks (Fleuv, XuruDragon)
This PR was merged into the 4.3-dev branch.

Discussion
----------

[Filesystem] Fix mirroring a directory into itself or in his child with realpath checks

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | yes
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | none / PR #29857
| License       | MIT
| Doc PR        | n/a

This this the continuity of #29857 by @Fleuv

Fix a bug while trying to mirror a directory into itself or in a child
Adding handle real path checks when mirroring.

Commits
-------

8011f494d4 Handling relative/absolute path
59437a4af9 Skipping iterations in the mirror() method where the iterated file's path name is equal to the target path
2019-03-31 11:15:35 +02:00
Fabien Potencier
67083b6f93 feature #28879 [Debug] Mimic __toString php behavior in FlattenException (Deltachaos)
This PR was merged into the 4.3-dev branch.

Discussion
----------

[Debug] Mimic __toString php behavior in FlattenException

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | n/a
| License       | MIT
| Doc PR        | symfony/symfony-docs#

The `Symfony\Component\Debug\Exception\FlattenException` object is returned by `Symfony\Component\HttpKernel\DataCollector\ExceptionDataCollector::getException` method, but the docblock of this method indicates that it should return `\Exception` object.

As the `FlattenException` class should behave as much as possible like a php `\Exception` object, it should implement the same methods as `\Exception`.

This PR is adding `__toString` and `getTraceAsString` methods. Those methods are (in my opinion) the most useful methods of a `\Exception` object. A potential use case (where i am stumbled across this inconsistency) is to get the last exception of a request in a `WebTestCase` using the profiler and printing the trace.

Commits
-------

514a1b506c [Debug] Mimic __toString php behavior in FlattenException
2019-03-31 11:12:58 +02:00
Fabien Potencier
47242e36e0 fixed CS 2019-03-31 10:40:49 +02:00
Fabien Potencier
2bd27ffd1b feature #29495 [Ldap] Implement pagination (kevans91)
This PR was squashed before being merged into the 4.3-dev branch (closes #29495).

Discussion
----------

[Ldap] Implement pagination

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | yno
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | N/A (cannot test at the moment)
| Fixed tickets | N/A
| License       | MIT
| Doc PR        | N/A

Implement pagination support in the ExtLdap adapter. In a more abstract sense, other adapters should use a query's pageSize option to determine if pagination is being needed. Pagination is required in some environments that frequently query for more results than the remote server is willing to allow.

BC break was avoided by having Query->getResource() return the first result, if available.

A small hack is included to work around php-ldap failing to reset pagination properly; the LDAP_OPT_SERVER_CONTROLS are sent with every request, whether pagination has been 'reset' by sending a 0-page request or not. This appears to be a php-ldap bug that will need to be addressed there, but we can work-around it for now by doing both: setting the 0-page option *and* unsetting the OID directly. This was resulting in odd results, like queries returning 0 results or returning < server_page_size results for a query that should have returned >= server_page_size.

Commits
-------

b96347485c [Ldap] Implement pagination
2019-03-31 10:40:08 +02:00
Kyle Evans
b96347485c [Ldap] Implement pagination 2019-03-31 10:39:25 +02:00
Fabien Potencier
5e079536c9 [LDAP] fixed typos and CS 2019-03-31 10:31:43 +02:00
Fabien Potencier
22234e331e feature #29448 [Ldap] Entry move support (kevans91)
This PR was squashed before being merged into the 4.3-dev branch (closes #29448).

Discussion
----------

[Ldap] Entry move support

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | no (see [1])
| Fixed tickets | N/A
| License       | MIT
| Doc PR        | N/A (see [2])

Add Move support to the ldap EntryManagerInterface and the ExtLdap adapter. This is used to re-parent an entry to another part of the directory. The interface to do so need not be complicated, requiring only the entry to be moved and the parent DN to be moved to.

Underlying implementations may require a 'newrdn' attribute -- this is generally the RDN w.r.t. the immediate parent of the entry, which is easily parsed.

I've attempted to implement it as the rename functionality was originally implemented: adding an interface to be deprecated effective immediately, presumably to allow it to be backported without breaking existing interfaces, and then implementing this interface in the ExtLdap adapter.

[1] I do not have the capacity to run the ldap tests for this locally due to current $work situation; I have no reason to believe this test will fail as written, though. This functionality has been used as currently implemented (against Windows ADS) for some time in my production environment, so it has been functionally tested otherwise.

[2] No doc PR has been created for this feature addition, since it's a minor addition. The LDAP documentation should likely be amended to include rename functionality as well as this.

Commits
-------

32743c850f [Ldap] Entry move support
2019-03-31 10:29:16 +02:00
Kyle Evans
32743c850f [Ldap] Entry move support 2019-03-31 10:29:07 +02:00
Fabien Potencier
c9b8ca631c minor #30788 [Mailer] Remove unneeded catch in ping() (sstok)
This PR was merged into the 4.3-dev branch.

Discussion
----------

[Mailer] Remove unneeded catch in ping()

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes?
| Fixed tickets |
| License       | MIT
| Doc PR        |

The stop() method doesn't throw.

Commits
-------

907adf47e3 [Mailer] Remove unneeded catch in ping()
2019-03-30 17:00:28 +01:00
Sebastiaan Stok
907adf47e3
[Mailer] Remove unneeded catch in ping()
The stop() method doesn't throw
2019-03-30 16:56:09 +01:00