Commit Graph

317 Commits

Author SHA1 Message Date
Fabien Potencier
a3078804ef feature #22597 [Lock] Re-add the Lock component in 3.4 (jderusse)
This PR was squashed before being merged into the 3.4 branch (closes #22597).

Discussion
----------

[Lock] Re-add the Lock component in 3.4

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

This PR reverts #22590 as decided in  #22580.

Commits
-------

3b6c495c89 [Lock] Re-add the Lock component in 3.4
2017-05-24 08:31:10 +02:00
Jérémy Derussé
3b6c495c89 [Lock] Re-add the Lock component in 3.4 2017-05-24 08:31:08 +02:00
Fabien Potencier
7b59412301 updated version to 3.4 2017-05-17 18:21:40 +02:00
Fabien Potencier
37ec869511 [Lock] remove the component from 3.3 2017-04-30 08:55:30 -07:00
Kévin Dunglas
053de25edf Add a new Link component 2017-04-10 09:55:52 -07:00
Christian Flothmann
70e638039c fix required Twig version 2017-03-29 23:33:32 +02:00
Fabien Potencier
858af7158f feature #21093 [Lock] Create a lock component (jderusse)
This PR was squashed before being merged into the 3.3-dev branch (closes #21093).

Discussion
----------

[Lock] Create a lock component

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

This PR aim to add a new component Lock going further than the FileSystem\LockHandler by allowing remote backend (like Redis, memcache, etc)
Inspired by

## Usage

The simplest way to use lock is to inject an instance of a Lock in your service
```php
class MyService
{
    private $lock;

    public function __construct(LockInterface $lock)
    {
        $this->lock = $lock;
    }

    public function run()
    {
        $this->lock->acquire(true);

        // If I'm here, no exception had been raised. Lock is acquired
        try {
            // do my job
        } finally {
            $this->lock->release();
        }
    }
}
```
Configured with something like
```yaml
services:
    app.my_service:
        class: AppBundle\MyService
        arguments:
            - app.lock.my_service
    app.lock.my_service:
        class: Symfony\Component\Lock\Lock
        factory: ['@locker', createLock]
        arguments: ['my_service']
```

If you need to lock serveral resource on runtime, wou'll nneed to inject the LockFactory.
```php
class MyService
{
    private $lockFactory;

    public function __construct(LockFactoryInterface $lockFactory)
    {
        $this->lockFactory = $lockFactory;
    }

    public function run()
    {
        foreach ($this->items as $item) {
            $lock = $this->lockFactory->createLock((string) $item);

            try {
                $lock->acquire();
            } catch (LockConflictedException $e) {
                continue;
            }

            // When I'm here, no exception had been, raised. Lock is acquired
            try {
                // do my job
            } finally {
                $lock->release();
            }
        }
    }
}
```
Configured with something like
```yaml
services:
    app.my_service:
        class: AppBundle\MyService
        arguments:
            - '@locker'
```

This component allow you to refresh an expirable lock.
This is usefull, if you run a long operation split in several small parts.
If you lock with a ttl for the overall operatoin time and your process crash, the lock will block everybody for the defined TTL.
But thank to the refresh method, you're able to lock for a small TTL, and refresh it between each parts.
```php
class MyService
{
    private $lock;

    public function __construct(LockInterface $lock)
    {
        $this->lock = $lock;
    }

    public function run()
    {
        $this->lock->acquire(true);

        try {
            do {
                $finished = $this->performLongTask();

                // Increase the expire date by 300 more seconds
                $this->lock->refresh();
            } while (!$finished)
            // do my job
        } finally {
            $this->lock->release();
        }
    }
}
```

## Naming anc implementation choise

```
$lock->acquire()
vs
$lock->lock()
```

Choose to use acquire, because this component is full of `lock` Symfony\Component\Lock\Lock::Lock` raised a E_TOO_MANY_LOCK in my head.

```
$lock->acquire(false);
$lock->acquire(true);
vs
$lock->aquire()
$lock->waitAndAquire()
```

Not a big fan of flag feature and 2. But I choose to use the blocking flag to offer a simple (and common usecase) implementation

```
$lock = $factory->createLock($key);
$lock->acquire();
vs
$lock->aquire($key)
```

I choose to a the pool of locks implementation. It allow the user to create 2 instances and use cross lock even in the same process.

```
interface LockInterface
final class Lock implements LockInterface
vs
final class Lock
```

I choose to use a Interface even if there is only one implementaiton to offer an extension point here

# TODO

## In this PR
* [x] tests
* [x] add logs
* [x] offer several redis connectors
* [x] try other store implementation to validate the architecture/interface

## In other PR
* documentation
* add configuration in framework bundle
* add stop watch in the debug bar
* improve the combined store (takes the drift into account and elapsed time between each store)
* implement other stores (memcache, ...)
* use this component in session manipulation (fixes #4976)

Commits
-------

018e0fc330 [Lock] Create a lock component
2017-03-22 11:45:21 -07:00
Jérémy Derussé
018e0fc330 [Lock] Create a lock component 2017-03-22 11:45:19 -07:00
Nicolas Grekas
398d78d758 Merge branch '3.2'
* 3.2:
  [Cache] cache/integration-tests is now compatible with phpunit namespaces
  [FrameworkBundle] Fix translation dep constraint
  [Workflow] Added more tests
  [Cache] Enhance error reporting for FilesystemAdapter
2017-03-17 15:59:00 +01:00
Nicolas Grekas
98111d33bc Merge branch '2.8' into 3.2
* 2.8:
  move conflict section of composer.json
2017-02-18 18:38:20 +01:00
Nicolas Grekas
3348879141 Merge branch '2.7' into 2.8
* 2.7:
  move conflict section of composer.json
2017-02-18 18:37:18 +01:00
Nicolas Grekas
64b2e56021 move conflict section of composer.json 2017-02-18 18:36:41 +01:00
Nicolas Grekas
7a618fbd5f Merge branch '3.2'
* 3.2:
  Fix typo in process error message
  Update to PHPUnit namespaces
  Minor typo fix messsagesData -> messagesData
  remove translation data collector when not usable
2017-02-18 18:35:19 +01:00
Nicolas Grekas
66cad2e4c5 Merge branch '2.8' into 3.2
* 2.8:
  Update to PHPUnit namespaces
  Minor typo fix messsagesData -> messagesData
  remove translation data collector when not usable
2017-02-18 18:28:00 +01:00
Nicolas Grekas
33bae93a44 Merge branch '2.7' into 2.8
* 2.7:
  Update to PHPUnit namespaces
  remove translation data collector when not usable
2017-02-18 18:06:33 +01:00
Peter Rehm
ddd2dff9b2 Update to PHPUnit namespaces 2017-02-18 08:02:39 -08:00
Fabien Potencier
bcd897cfd4 feature #21265 [DI] Implement PSR-11 (greg0ire)
This PR was merged into the 3.3-dev branch.

Discussion
----------

[DI] Implement PSR-11

TODO:

- [x] wait for a stable version of the psr/container package;
- [x] ~~deprecate instanciating ServiceNotFoundException directly, or using any of its methods directly;~~ not relevant anymore
- [x] act on the outcome of https://github.com/php-fig/container/issues/8 (solved in https://github.com/php-fig/container/issues/9) ;
- [x] ~~solve the mandatory NotFoundExceptionInterface on non-existing service
problem (with a flag ?);~~ non-issue, see comments below
- [x] provide meta-package psr/container-implementation if all problems can
be solved.

| Q             | A
| ------------- | ---
| Branch?       | master
| New feature?  | yes
| BC breaks?    | not at the moment
| Tests pass?   | didn't pass before pushing, or even starting to code, will see Travis
| License       | MIT
| Doc PR        | TODO

This PR is a first attempt at implementing PSR-11, or at least trying to get closer to it.
Delegate lookup is optional, and thus not implemented for now.

Commits
-------

bde0efd01c Implement PSR-11
2017-02-08 16:52:20 +01:00
Nicolas Grekas
55a34b7b51 Merge branch '3.2'
* 3.2:
  Add HEADER_FORWARDED to setTrustedHeaderName docs
  Fix phpDoc typo
  [FrameworkBundle][Console] JsonDescriptor: Respect original output
  Remove dead code
  Enable dump() in autoload-dev
  add missing functional Serializer test case
2017-02-02 14:49:58 +01:00
Nicolas Grekas
4fd91481c2 Merge branch '2.8' into 3.2
* 2.8:
  Add HEADER_FORWARDED to setTrustedHeaderName docs
  Fix phpDoc typo
  [FrameworkBundle][Console] JsonDescriptor: Respect original output
  Enable dump() in autoload-dev
2017-02-02 14:47:35 +01:00
Nicolas Grekas
0a6d3c6d00 Merge branch '2.7' into 2.8
* 2.7:
  Add HEADER_FORWARDED to setTrustedHeaderName docs
  Fix phpDoc typo
  [FrameworkBundle][Console] JsonDescriptor: Respect original output
  Enable dump() in autoload-dev
2017-02-02 14:38:20 +01:00
Grégoire Paris
bde0efd01c
Implement PSR-11
Delegate lookup is optional and thus, not implemented.
2017-02-02 08:42:59 +01:00
Nicolas Grekas
89e0088c57 Enable dump() in autoload-dev 2017-02-01 13:47:47 +01:00
Fabien Potencier
9f3072c416 Merge branch '3.2'
* 3.2:
  fixed typo
  fixed composer.json
  [HttpKernel] Fix Bundle name regression
  always check for all fields to be mapped
  clarify exception when no args are configured
  [PropertyAccess] Handle interfaces in the invalid argument exception
  [DI] Fix defaults overriding empty strings in AutowirePass
  [Debug] Workaround "null" $context
  [Debug] Remove $context arg from handleError(), preparing for PHP 7.2
  [FrameworkBundle] Dont wire "annotations.cached_reader" before removing passes
  [Routing] Fix BC break in AnnotationClassLoader defaults attributes handling
  Fix tests with ICU 57.1
  Fix the condition checking the minimum ICU version
2017-01-27 18:39:08 -08:00
Fabien Potencier
09d5f4eb72 Merge branch '3.1' into 3.2
* 3.1:
  fixed typo
  fixed composer.json
  always check for all fields to be mapped
  clarify exception when no args are configured
  [PropertyAccess] Handle interfaces in the invalid argument exception
  [DI] Fix defaults overriding empty strings in AutowirePass
  [Debug] Workaround "null" $context
  [Debug] Remove $context arg from handleError(), preparing for PHP 7.2
  [Routing] Fix BC break in AnnotationClassLoader defaults attributes handling
  Fix tests with ICU 57.1
  Fix the condition checking the minimum ICU version
2017-01-27 18:37:08 -08:00
Fabien Potencier
137a7748d6 fixed typo 2017-01-27 17:00:17 -08:00
Fabien Potencier
537b932302 fixed typo 2017-01-27 16:27:58 -08:00
Fabien Potencier
f904f0406d Merge branch '2.8' into 3.1
* 2.8:
  fixed composer.json
2017-01-27 16:21:39 -08:00
Fabien Potencier
4b5930ca44 fixed composer.json 2017-01-27 16:19:36 -08:00
Fabien Potencier
e8895ad102 Merge branch '2.8' into 3.1
* 2.8:
  always check for all fields to be mapped
  clarify exception when no args are configured
  [PropertyAccess] Handle interfaces in the invalid argument exception
  [DI] Fix defaults overriding empty strings in AutowirePass
  [Debug] Workaround "null" $context
  [Debug] Remove $context arg from handleError(), preparing for PHP 7.2
  [Routing] Fix BC break in AnnotationClassLoader defaults attributes handling
  Fix tests with ICU 57.1
  Fix the condition checking the minimum ICU version
2017-01-27 16:04:57 -08:00
Fabien Potencier
791b143914 Merge branch '2.7' into 2.8
* 2.7:
  always check for all fields to be mapped
  clarify exception when no args are configured
  [PropertyAccess] Handle interfaces in the invalid argument exception
  [Debug] Workaround "null" $context
  [Debug] Remove $context arg from handleError(), preparing for PHP 7.2
  [Routing] Fix BC break in AnnotationClassLoader defaults attributes handling
  Fix tests with ICU 57.1
  Fix the condition checking the minimum ICU version
2017-01-27 15:54:58 -08:00
Robin Chalas
1d298f0417
[Routing] Fix BC break in AnnotationClassLoader defaults attributes handling 2017-01-23 21:38:04 +01:00
Nicolas Grekas
848a33ed3e [Cache] Implement PSR-16 SimpleCache v1.0 2017-01-23 14:57:50 +01:00
Fabien Potencier
5a6be8ae9c [Dotenv] added the component 2017-01-12 08:39:44 -08:00
Fabien Potencier
fa7ebc57de [WebServerBundle] moved most of the logic in a new class 2016-12-30 08:54:40 +01:00
Fabien Potencier
a4edafbd7d updated version to 3.3 2016-11-19 12:35:20 -08:00
Fabien Potencier
c57d8edcc3 Merge branch '3.1'
* 3.1:
  [Debug] Remove GLOBALS from exception context to avoid endless recursion
  [Serializer] Improve test coverage of the MaxDepth annotation
  DX: replace @link with @see annotation
  bumped min version of Twig to 1.28
2016-11-16 17:18:16 -05:00
Fabien Potencier
a43ccb10a0 Merge branch '2.8' into 3.1
* 2.8:
  DX: replace @link with @see annotation
  bumped min version of Twig to 1.28
2016-11-16 17:17:09 -05:00
Fabien Potencier
7487ccb501 Merge branch '2.7' into 2.8
* 2.7:
  bumped min version of Twig to 1.28
2016-11-16 17:16:08 -05:00
Fabien Potencier
b8f7614388 bumped min version of Twig to 1.28 2016-11-12 09:04:32 -08:00
Fabien Potencier
de4a650d8c Merge branch '3.1'
* 3.1:
  [TwigBridge] removed deprecations added in Twig 1.27
  PHP CS Fixer: use php_unit_dedicate_assert
  3.0 Upgrade Guide: Added details describing how to pass data to a form through the options resolver
  fixed Filesystem:makePathRelative and added 2 more testcases
  no 304 response if method is not cacheable
  move tags from decorated to decorating service
2016-10-17 21:30:21 -07:00
Fabien Potencier
f07bf03667 Merge branch '2.8' into 3.1
* 2.8:
  [TwigBridge] removed deprecations added in Twig 1.27
  PHP CS Fixer: use php_unit_dedicate_assert
  3.0 Upgrade Guide: Added details describing how to pass data to a form through the options resolver
  fixed Filesystem:makePathRelative and added 2 more testcases
  no 304 response if method is not cacheable
  move tags from decorated to decorating service
2016-10-17 21:30:12 -07:00
Fabien Potencier
ee8203a599 Merge branch '2.7' into 2.8
* 2.7:
  [TwigBridge] removed deprecations added in Twig 1.27
  PHP CS Fixer: use php_unit_dedicate_assert
  fixed Filesystem:makePathRelative and added 2 more testcases
  no 304 response if method is not cacheable
  move tags from decorated to decorating service
2016-10-17 21:28:30 -07:00
Fabien Potencier
f0849d8331 [TwigBridge] removed deprecations added in Twig 1.27 2016-10-17 18:02:36 -07:00
Fabien Potencier
3ee28b5629 Merge branch '3.1'
* 3.1:
  fixed Twig support for 1.26 and 2.0
  Fix indexBy type extraction
2016-09-28 18:19:22 -07:00
Fabien Potencier
6d1d35d83f Merge branch '2.8' into 3.1
* 2.8:
  fixed Twig support for 1.26 and 2.0
  Fix indexBy type extraction
2016-09-28 18:19:09 -07:00
Fabien Potencier
28571d2cfb Merge branch '2.7' into 2.8
* 2.7:
  fixed Twig support for 1.26 and 2.0
2016-09-28 18:16:22 -07:00
Fabien Potencier
24e9cf2155 fixed Twig support for 1.26 and 2.0 2016-09-28 18:04:26 -07:00
Nicolas Grekas
f5c1b1c077 Merge branch '3.1'
* 3.1:
  [travis/appveyor] Wire simple-phpunit
  [Console] fixed PHP7 Errors are now handled and converted to Exceptions
  Fix #19721
  Fix translation:update command count
  bumped Symfony version to 2.8.12
  updated VERSION for 2.8.11
  updated CHANGELOG for 2.8.11
  bumped Symfony version to 2.7.19
  updated VERSION for 2.7.18
  update CONTRIBUTORS for 2.7.18
  updated CHANGELOG for 2.7.18
  [Security] Optimize RoleHierarchy's buildRoleMap method
  [FrameworkBundle] Fix Incorrect line break in exception message (500 debug page)
  [Security] Added note inside phpdoc.
  Minor cleanups and improvements
  [form] lazy trans `post_max_size_message`.
  [DI] Fix setting synthetic services on ContainerBuilder
  [ClassLoader] Fix ClassCollectionLoader inlining with declare(strict_types=1)
2016-09-12 21:03:45 +02:00
Fabien Potencier
fad40286ee Merge branch '2.8' into 3.1
* 2.8:
  [travis/appveyor] Wire simple-phpunit
  [Console] fixed PHP7 Errors are now handled and converted to Exceptions
  Fix #19721
  Fix translation:update command count
  bumped Symfony version to 2.8.12
  updated VERSION for 2.8.11
  updated CHANGELOG for 2.8.11
  bumped Symfony version to 2.7.19
  updated VERSION for 2.7.18
  update CONTRIBUTORS for 2.7.18
  updated CHANGELOG for 2.7.18
  [Security] Optimize RoleHierarchy's buildRoleMap method
2016-09-12 11:17:37 -07:00
Fabien Potencier
1e91ed7783 Merge branch '2.7' into 2.8
* 2.7:
  [travis/appveyor] Wire simple-phpunit
  [Console] fixed PHP7 Errors are now handled and converted to Exceptions
  Fix #19721
  bumped Symfony version to 2.7.19
  updated VERSION for 2.7.18
  update CONTRIBUTORS for 2.7.18
  updated CHANGELOG for 2.7.18
  [Security] Optimize RoleHierarchy's buildRoleMap method
2016-09-12 11:14:50 -07:00