Skip to content

[FrameworkBundle] Allow custom services for validator mapping cache. #12975

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

Merged
merged 1 commit into from
Dec 24, 2014

Conversation

jakzal
Copy link
Contributor

@jakzal jakzal commented Dec 13, 2014

Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #12803
License MIT
Doc PR -
#9892 introduced DoctrineCache, but it's not really used by the FrameworkBundle. This was overlooked, therefore I think it should go into 2.5.

This PR will let us to configure a service id, instead of a driver name. The only exception is apc, which is converted to validator.mapping.cache.apc to keep BC.

Examples:

framework:
    validation:
        cache: apc # converted to validator.mapping.cache.apc
framework:
    validation:
        cache: my_custom_cache_service

It would be nice to be able to provide a doctrine service id, instead of CacheInterface implementation. It could be automatically decorated with DoctrineCache:

framework:
    validation:
        cache:
            doctrine: my_doctrine_cache_service # could be provided by DoctrineCacheBundle

I'll work on it next.

@fabpot
Copy link
Member

fabpot commented Dec 24, 2014

Thank you @jakzal.

@fabpot fabpot merged commit 4cdcf10 into symfony:2.5 Dec 24, 2014
fabpot added a commit that referenced this pull request Dec 24, 2014
…ing cache. (jakzal)

This PR was merged into the 2.5 branch.

Discussion
----------

[FrameworkBundle] Allow custom services for validator mapping cache.

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

#9892 introduced `DoctrineCache`, but it's not really used by the FrameworkBundle. This was overlooked, therefore I think it should go into 2.5.

This PR will let us to configure a service id, instead of a driver name. The only exception is apc, which is converted to `validator.mapping.cache.apc` to keep BC.

Examples:

```yaml
framework:
    validation:
        cache: apc # converted to validator.mapping.cache.apc
```

```yaml
framework:
    validation:
        cache: my_custom_cache_service
```

It would be nice to be able to provide a doctrine service id, instead of `CacheInterface` implementation. It could be automatically decorated with `DoctrineCache`:

```yaml
framework:
    validation:
        cache:
            doctrine: my_doctrine_cache_service # could be provided by DoctrineCacheBundle
```

I'll work on it next.

Commits
-------

4cdcf10 [FrameworkBundle] Allow custom services for validator mapping cache.
@jakzal jakzal deleted the validator-doctrine-cache branch December 24, 2014 11:29
@jakzal
Copy link
Contributor Author

jakzal commented Dec 24, 2014

Note that a cache service implementing our interface still needs to be created by the end user. At least it's possible now. I'll work on making it easier next.

@xabbuh
Copy link
Member

xabbuh commented Dec 29, 2014

Just two quick questions about this change:

  • Doesn't this break BC? If someone already used this feature by setting the cache option to foo and defined a validator.mapping.cache.foo service on their own? This won't not work anymore now since the foo service will probably not exist.
  • We are currently in the progress of adding documentation for the validation configuration options to the reference documentation (see [Reference] add validation config reference section symfony-docs#4673 and [Reference] document the 2.5 validation options symfony-docs#4682). Am I right that we needed to different descriptions for 2.3 and 2.5 (I thought the behaviour with this option was the same for 2.3 and 2.5 before this change, but this seems to be different now if I don't misunderstand anything).

@weaverryan
Copy link
Member

I agree with @xabbuh - this looks like a very small BC break. But if you're relying on this behavior, things would blow up when your container is being built, so it'll be an obvious (and small) BC break. So perhaps it's "ok"?

@cmodijk
Copy link

cmodijk commented Mar 11, 2015

@jakzal Did you ever get to implement the doctrine decorator?

@jakzal
Copy link
Contributor Author

jakzal commented Apr 21, 2015

@cmodijk no, but all you have to do in your own project is to register a new caching service:

        <service id="my_validator_mapping_cache" class="Symfony\Component\Validator\Mapping\Cache\DoctrineCache" public="false">
            <argument type="service">
                <service class="Doctrine\Common\Cache\ApcCache">
                    <call method="setNamespace">
                        <argument>%validator.mapping.cache.prefix%</argument>
                    </call>
                </service>
            </argument>
        </service>

and tell validator to use it:

framework:
    validation:
        cache: my_validator_mapping_cache

@cmodijk
Copy link

cmodijk commented Apr 23, 2015

Hmm yeah but it would be nice to directly give a doctrine cache service and that the wrapping is done by Symfony because of the fact that you have the https://github.com/doctrine/DoctrineCacheBundle that generates these service id's for you. Know you need to create your own service just to wrap around the cache. With the possibility to directly inject the doctrine cache service id you don't need anything extra.

@pwm
Copy link

pwm commented Jun 17, 2015

Hi, is there a way to do this using Redis?

@jakzal
Copy link
Contributor Author

jakzal commented Jun 18, 2015

@pwm yes, see the supported drivers here: https://github.com/doctrine/cache/tree/master/lib/Doctrine/Common/Cache

fabpot added a commit that referenced this pull request Jun 23, 2015
…ion for validator mapping (jakzal)

This PR was merged into the 2.8 branch.

Discussion
----------

[FrameworkBundle] Add a doctrine cache service definition for validator mapping

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

Following #12975, this PR only registers a new service so it's possible to use the new doctrine based cache implementation instead of the deprecated one. To use it, the end user would need to configure it in his `config.yml`:

```yaml
framework:
    validation:
        cache: validator.mapping.cache.doctrine.apc
```

In 3.0 we'll be able to replace the deprecated definition by aliasing `validator.mapping.cache.apc` to `validator.mapping.cache.doctrine.apc`.

I thought of automatic wrapping of services which implement doctrine interface, but decided it would be too magic.

I'm not convinced if APC is a good default anymore and hope for some discussion. I've used it as it's also used in serializer, and probably translation (see #13986). Since there's a built in opcache in more recent PHP versions, and apcu doesn't seem to be stable, there are better choices. Perhaps a better default would be a filesystem cache (not better performing, but it works anywhere).

Commits
-------

0642911 [FrameworkBundle] Add a doctrine cache service definition for validator mapping
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants