Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature #22113 [Lock] Include lock component in framework bundle (jde…
…russe) This PR was squashed before being merged into the 3.4 branch (closes #22113). Discussion ---------- [Lock] Include lock component in framework bundle | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | none | License | MIT | Doc PR | symfony/symfony-docs#8066 ## Usage use the best available "out of box" store (semaphore if available, filesyste otherwise) ```yml framework: lock: ~ # lock: true ``` ```php $this->get('lock')->acquire(); $this->get('lock.factory')->createLock('my resource')->acquire(); ``` use a specific store ```yml framework: lock: flock # lock: semaphore # lock: redis://localhost # lock: "%env(MEMCACHED_DSN)%" # lock: ["%env(REDIS_DSN_1)%", "%env(REDIS_DSN_2)%"] ``` ```php $this->get('lock')->acquire(); $this->get('lock.factory')->createLock('my resource')->acquire(); ``` use a named lock ```yml framework: lock: foo: flock bar: redis://localhost ``` ```php $this->get('lock.foo')->acquire(); $this->get('lock.bar.factory')->createLock('my resource')->acquire(); ``` factory usage ```xml <service id="acme" class="AppBundle\Acme"> <argument type="service"> <service class="Symfony\Component\Lock\Lock"> <factory service="lock.foo.factory" method="createLock" /> <argument>my resource</argument> <argument>30</argument> <!-- optional TTL --> </service> </argument> </service> ``` * [x] Tests Commits ------- b4b00c9 [Lock] Include lock component in framework bundle
- Loading branch information
Showing
18 changed files
with
618 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/Symfony/Bundle/FrameworkBundle/Resources/config/lock.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?xml version="1.0" ?> | ||
|
||
<container xmlns="http://symfony.com/schema/dic/services" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> | ||
|
||
<services> | ||
<defaults public="false" /> | ||
|
||
<service id="lock.store.flock" class="Symfony\Component\Lock\Store\FlockStore" /> | ||
|
||
<service id="lock.store.semaphore" class="Symfony\Component\Lock\Store\SemaphoreStore" /> | ||
|
||
<service id="lock.store.memcached.abstract" class="Symfony\Component\Lock\Store\MemcachedStore" abstract="true"> | ||
<argument /> <!-- Memcached connection service --> | ||
</service> | ||
|
||
<service id="lock.store.redis.abstract" class="Symfony\Component\Lock\Store\RedisStore" abstract="true"> | ||
<argument /> <!-- Redis connection service --> | ||
</service> | ||
|
||
<service id="lock.store.combined.abstract" class="Symfony\Component\Lock\Store\CombinedStore" abstract="true"> | ||
<argument /> <!-- List of stores --> | ||
<argument type="service" id="lock.strategy.majority" /> <!-- Strategy --> | ||
</service> | ||
|
||
<service id="lock.strategy.majority" class="Symfony\Component\Lock\Strategy\ConsensusStrategy" /> | ||
|
||
<service id="lock.factory.abstract" class="Symfony\Component\Lock\Factory" abstract="true"> | ||
<tag name="monolog.logger" channel="lock" /> | ||
<argument /> <!-- Store --> | ||
<call method="setLogger"> | ||
<argument type="service" id="logger" on-invalid="ignore" /> | ||
</call> | ||
</service> | ||
|
||
</services> | ||
</container> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/lock.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version="1.0" ?> | ||
<container xmlns="http://symfony.com/schema/dic/services" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns:framework="http://symfony.com/schema/dic/symfony" | ||
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd | ||
http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd"> | ||
|
||
<framework:config> | ||
<framework:lock/> | ||
</framework:config> | ||
</container> |
22 changes: 22 additions & 0 deletions
22
src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/lock_named.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?xml version="1.0" ?> | ||
<container xmlns="http://symfony.com/schema/dic/services" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns:framework="http://symfony.com/schema/dic/symfony" | ||
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd | ||
http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd"> | ||
|
||
|
||
<parameters> | ||
<parameter key="env(REDIS_URL)">redis://paas.com</parameter> | ||
</parameters> | ||
|
||
<framework:config> | ||
<framework:lock> | ||
<framework:resource name="foo">semaphore</framework:resource> | ||
<framework:resource name="bar">flock</framework:resource> | ||
<framework:resource name="baz">semaphore</framework:resource> | ||
<framework:resource name="baz">flock</framework:resource> | ||
<framework:resource name="qux">%env(REDIS_URL)%</framework:resource> | ||
</framework:lock> | ||
</framework:config> | ||
</container> |
2 changes: 2 additions & 0 deletions
2
src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/lock.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
framework: | ||
lock: ~ |
9 changes: 9 additions & 0 deletions
9
src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/lock_named.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
parameters: | ||
env(REDIS_DSN): redis://paas.com | ||
|
||
framework: | ||
lock: | ||
foo: semaphore | ||
bar: flock | ||
baz: [semaphore, flock] | ||
qux: "%env(REDIS_DSN)%" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.