Skip to content

Commit ac43476

Browse files
pinkeendaum
authored andcommitted
Symfony 4.0 compat (#185)
* Allow symfony 4.0 components as deps, adjust tests, allow to define directories to be scanned for annotations * Made README more clear about symfony version support
1 parent 5bddb8f commit ac43476

File tree

14 files changed

+117
-28
lines changed

14 files changed

+117
-28
lines changed

.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,16 @@ php:
1010
- hhvm
1111

1212
matrix:
13+
include:
14+
- php: 7.1
15+
env: DEPENDENCIES=beta
1316
allow_failures:
1417
- php: hhvm
1518

1619
install:
1720
- sh -c "sudo apt-get -y install uuid-dev libgearman-dev gearman gearman-job-server"
1821
before_script:
22+
- if [ "$DEPENDENCIES" = "beta" ]; then composer config minimum-stability beta; fi;
1923
- if [[ $TRAVIS_PHP_VERSION = 5.* ]]; then curl -L -o gearman.tgz http://pecl.php.net/get/gearman/1.1.2; fi;
2024
- if [[ $TRAVIS_PHP_VERSION = 7.* ]]; then curl -L -o gearman.tgz https://github.com/wcgallego/pecl-gearman/archive/gearman-2.0.1.tar.gz; fi;
2125
- tar -xzf gearman.tgz

DependencyInjection/Configuration.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ public function getConfigTreeBuilder()
5555
->end()
5656
->end()
5757
->end()
58+
->arrayNode('resources')
59+
->scalarPrototype()->end()
60+
->end()
5861
->arrayNode('servers')
5962
->performNoDeepMerging()
6063
->defaultValue(array(

DependencyInjection/GearmanExtension.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ public function load(array $config, ContainerBuilder $container)
4848
$config['bundles']
4949
);
5050

51+
$container->setParameter(
52+
'gearman.resources',
53+
$config['resources']
54+
);
55+
5156
$container->setParameter(
5257
'gearman.servers',
5358
$config['servers']

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
GearmanBundle for Symfony2/3
1+
GearmanBundle for Symfony2, 3 and 4
22
=====
33
[![SensioLabsInsight](https://insight.sensiolabs.com/projects/cf3d97c6-e026-4489-8493-a3f4a1e75a68/mini.png)](https://insight.sensiolabs.com/projects/cf3d97c6-e026-4489-8493-a3f4a1e75a68)
44
[![Build Status](https://travis-ci.org/mmoreram/GearmanBundle.png?branch=master)](https://travis-ci.org/mmoreram/GearmanBundle)
@@ -8,7 +8,7 @@ GearmanBundle for Symfony2/3
88
[![License](https://poser.pugx.org/mmoreram/gearman-bundle/license.png)](https://packagist.org/packages/mmoreram/gearman-bundle)
99
[![Total Downloads](https://poser.pugx.org/mmoreram/gearman-bundle/downloads.png)](https://packagist.org/packages/mmoreram/gearman-bundle)
1010

11-
GearmanBundle is a bundle for Symfony2/3 intended to provide an easy way to
11+
GearmanBundle is a bundle for Symfony2/3/4 intended to provide an easy way to
1212
support developers who need to use job queues. For example: mail queues, Solr
1313
generation queues or Database upload queues.
1414

@@ -22,7 +22,9 @@ them with us, don't hesitate to open a RFC issue or a Pull Request.
2222

2323
Tags
2424
----
25-
* Use tags under 4.X for Symfony2.X versions. 4.X support Symfony 3.X+
25+
* Symfony 4.0 is supported by tags 4.1+ (they still work with Symfony 3.X)
26+
* All 4.X tags support Symfony 3.X
27+
* Use tags lower than 4.X for Symfony 2.X versions
2628
* Use last unstable version ( alias of `dev-master` ) to stay always in last commit
2729
* Use last stable version tag to stay in a stable release.
2830
* [![Latest Unstable Version](https://poser.pugx.org/mmoreram/gearman-bundle/v/unstable.png)](https://packagist.org/packages/mmoreram/gearman-bundle) [![Latest Stable Version](https://poser.pugx.org/mmoreram/gearman-bundle/v/stable.png)](https://packagist.org/packages/mmoreram/gearman-bundle)

Resources/config/eventDispatchers.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ services:
1111
gearman.dispatcher.callbacks:
1212
parent: gearman.dispatcher.abstract
1313
class: "%gearman.dispatcher.callbacks.class%"
14+
public: true

Resources/config/generators.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ services:
55
#
66
gearman.unique_job_identifier:
77
class: "%gearman.unique_job_identifier.class%"
8+
public: true
89
arguments:
910
- "%gearman.default.settings.generate_unique_key%"

Resources/config/services.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,19 @@ services:
55
#
66
gearman.parser:
77
class: "%gearman.parser.class%"
8+
public: true
89
arguments:
910
- "@kernel"
1011
- "@annotation_reader"
1112
- "@gearman.external.symfony_finder"
1213
- "%gearman.bundles%"
14+
- "%gearman.resources%"
1315
- "%gearman.servers%"
1416
- "%gearman.default.settings%"
1517

1618
gearman.cache.wrapper:
1719
class: "%gearman.cache.wrapper.class%"
20+
public: true
1821
arguments:
1922
- "@gearman.parser"
2023
- "@doctrine_cache.providers.gearman_cache"
@@ -27,24 +30,28 @@ services:
2730

2831
gearman.describer:
2932
class: "%gearman.describer.class%"
33+
public: true
3034
arguments:
3135
- "@kernel"
3236

3337
gearman.abstract.service:
34-
abstract: true
38+
abstract: true
39+
public: true
3540
arguments:
3641
- "@gearman.cache.wrapper"
3742
- "%gearman.default.settings%"
3843

3944
gearman.execute:
4045
class: "%gearman.execute.class%"
46+
public: true
4147
parent: gearman.abstract.service
4248
calls:
4349
- [setContainer, ["@service_container"]]
4450
- [setEventDispatcher, ["@event_dispatcher"]]
4551

4652
gearman:
4753
class: "%gearman.client.class%"
54+
public: true
4855
parent: gearman.abstract.service
4956
calls:
5057
- [initTaskStructure, []]

Resources/docs/configuration.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ config gearman cache, using doctrine cache.
4141
- DependencyInjection
4242
- Resources
4343
44+
# Resources - list of directories (relative to kernel root dir) which will be searched for workers
45+
# This is useful if you don't have an "AppBundle"
46+
resources:
47+
Dir/With/Workers
48+
4449
# default values
4550
# All these values will be used if are not overwritten in Workers or jobs
4651
defaults:

Service/GearmanParser.php

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,13 @@ class GearmanParser
6868
*/
6969
private $bundles;
7070

71+
/**
72+
* @var array
73+
*
74+
* Namespaces paths to be searched
75+
*/
76+
private $resources;
77+
7178
/**
7279
* @var array
7380
*
@@ -82,13 +89,21 @@ class GearmanParser
8289
*/
8390
private $defaultSettings;
8491

92+
/**
93+
* Root kernel directory
94+
*
95+
* @var string
96+
*/
97+
private $rootDir;
98+
8599
/**
86100
* Construct method
87101
*
88102
* @param KernelInterface $kernel Kernel instance
89103
* @param Reader $reader Reader
90104
* @param Finder $finder Finder
91-
* @param array $bundles Bundle array where to parse workers, defined on condiguration
105+
* @param array $bundles Bundle array where to parse workers, defined in configuration
106+
* @param array $resources Array of namespace paths to be searched for worker annotations
92107
* @param array $servers Server list defined on configuration
93108
* @param array $defaultSettings Default settings defined on configuration
94109
*/
@@ -97,6 +112,7 @@ public function __construct(
97112
Reader $reader,
98113
Finder $finder,
99114
array $bundles,
115+
array $resources,
100116
array $servers,
101117
array $defaultSettings
102118
)
@@ -106,8 +122,10 @@ public function __construct(
106122
$this->reader = $reader;
107123
$this->finder = $finder;
108124
$this->bundles = $bundles;
125+
$this->resources = $resources;
109126
$this->servers = $servers;
110127
$this->defaultSettings = $defaultSettings;
128+
$this->rootDir = $this->kernel->getRootDir();
111129
}
112130

113131
/**
@@ -117,7 +135,8 @@ public function __construct(
117135
*/
118136
public function load()
119137
{
120-
list($paths, $excludedPaths) = $this->loadNamespaceMap($this->kernelBundles, $this->bundles);
138+
list($paths, $excludedPaths) = $this->loadBundleNamespaceMap($this->kernelBundles, $this->bundles);
139+
$paths = array_merge($paths, $this->loadResourceNamespaceMap($this->rootDir, $this->resources));
121140

122141
return $this->parseNamespaceMap($this->finder, $this->reader, $paths, $excludedPaths);
123142
}
@@ -132,7 +151,7 @@ public function load()
132151
*
133152
* @return array Return an array containing paths and ignore paths
134153
*/
135-
public function loadNamespaceMap(array $kernelBundles, array $bundles)
154+
public function loadBundleNamespaceMap(array $kernelBundles, array $bundles)
136155
{
137156
$paths = array();
138157
$excludedPaths = array();
@@ -177,6 +196,19 @@ public function loadNamespaceMap(array $kernelBundles, array $bundles)
177196
);
178197
}
179198

199+
/**
200+
* Get resource paths
201+
* @param string $rootDir
202+
* @param array $resources
203+
* @return array
204+
*/
205+
public function loadResourceNamespaceMap($rootDir, array $resources)
206+
{
207+
return array_map(function($resource) use ($rootDir) {
208+
return $rootDir . '/' . trim($resource, '/') . '/';
209+
}, $resources);
210+
}
211+
180212
/**
181213
* Perform a parsing inside all namespace map
182214
*

Tests/Functional/AppKernel.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,15 @@
1111
* @author Marc Morera <[email protected]>
1212
*/
1313

14+
namespace Mmoreram\GearmanBundle\Tests\Functional;
15+
16+
use Doctrine\Bundle\DoctrineCacheBundle\DoctrineCacheBundle;
17+
use Mmoreram\GearmanBundle\GearmanBundle;
18+
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
1419
use Symfony\Component\Config\Loader\LoaderInterface;
1520
use Symfony\Component\HttpKernel\Kernel;
1621

22+
1723
/**
1824
* AppKernel for testing
1925
*/
@@ -25,9 +31,9 @@ class AppKernel extends Kernel
2531
public function registerBundles()
2632
{
2733
return array(
28-
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
29-
new Doctrine\Bundle\DoctrineCacheBundle\DoctrineCacheBundle(),
30-
new Mmoreram\GearmanBundle\GearmanBundle(),
34+
new FrameworkBundle(),
35+
new DoctrineCacheBundle(),
36+
new GearmanBundle(),
3137
);
3238
}
3339

0 commit comments

Comments
 (0)