Skip to content

Commit f4434ed

Browse files
committed
Merge pull request #68 from aequasi/master
Adding a CustomProvider
2 parents 8881387 + d7926b1 commit f4434ed

9 files changed

Lines changed: 367 additions & 5 deletions

File tree

.travis.yml

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
language: php
22

33
php:
4-
- 5.5
5-
- 5.4
4+
- 5.5
5+
- 5.4
6+
- 5.6
7+
- 7.0
8+
- hhvm
69

710
env:
811
- SYMFONY_VERSION=2.3.*
912
- SYMFONY_VERSION=2.4.*
1013
- SYMFONY_VERSION=2.5.*
14+
- SYMFONY_VERSION=2.6.*
1115

12-
before_script:
13-
- composer self-update
16+
install:
17+
- travis_retry composer self-update
1418
- composer require symfony/framework-bundle:${SYMFONY_VERSION} --no-update
15-
- composer install --dev --prefer-source
19+
- travis_retry composer install --prefer-source
1620

1721
script: phpunit --coverage-text --coverage-clover=coverage.clover
1822

@@ -22,3 +26,14 @@ after_script:
2226

2327
notifications:
2428
webhooks: http://ue.hipchat.com/hubot/travis?room=Underground Elephant
29+
30+
matrix:
31+
allow_failures:
32+
- php: hhvm
33+
- php: 7.0
34+
35+
sudo: false
36+
37+
cache:
38+
directories:
39+
- $HOME/.composer/cache

docs/configuration.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ For specific instructions on how to configure each provider, please view their d
2424
aws-provider
2525
iron-mq-provider
2626
sync-provider
27+
custom-provider
2728

2829
Caching
2930
-------
@@ -122,6 +123,9 @@ A working configuration would look like the following
122123
project_id: YOUR_IRONMQ_PROJECT_ID_HERE
123124
in_band:
124125
driver: sync
126+
custom_provider:
127+
driver: custom
128+
service: YOUR_CUSTOM_SERVICE_ID
125129
queues:
126130
my_queue_key:
127131
provider: ironmq #or aws or in_band or another_aws_provider

docs/custom-provider.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
Custom Provider
2+
-------------
3+
4+
The custom provider allows you to use your own provider. When using this provider, your implementation must implement
5+
``Uecode\Bundle\QPushBundle\Provider\ProviderInterface``
6+
7+
Configuration
8+
^^^^^^^^^^^^^
9+
10+
To designate a queue as custom, set the ``driver`` of its provider to ``custom``, and the ``service`` to your service id.
11+
12+
.. code-block:: yaml
13+
14+
#app/config_dev.yml
15+
16+
uecode_qpush:
17+
providers:
18+
custom_provider:
19+
driver: custom
20+
service: YOUR_CUSTOM_SERVICE_ID
21+
queues:
22+
my_queue_name:
23+
provider: custom_provider

src/DependencyInjection/Configuration.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ private function getProvidersNode()
6060
'aws' => ['key', 'secret'],
6161
'ironmq' => ['token', 'project_id'],
6262
'sync' => [],
63+
'custom' => ['service']
6364
];
6465

6566
$node
@@ -74,6 +75,7 @@ private function getProvidersNode()
7475
// IronMQ
7576
->scalarNode('token')->end()
7677
->scalarNode('project_id')->end()
78+
->scalarNode('service')->end()
7779
->enumNode('host')
7880
->defaultValue('mq-aws-us-east-1')
7981
->values([

src/DependencyInjection/UecodeQPushExtension.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ public function load(array $configs, ContainerBuilder $container)
8181
$class = $container->getParameter('uecode_qpush.provider.sync');
8282
$client = $this->createSyncClient();
8383
break;
84+
case 'custom':
85+
$class = $container->getParameter('uecode_qpush.provider.custom');
86+
$client = $this->createCustomClient($config['providers'][$provider]['service']);
87+
break;
8488
}
8589

8690
$definition = new Definition(
@@ -196,6 +200,16 @@ private function createSyncClient()
196200
return new Reference('event_dispatcher');
197201
}
198202

203+
/**
204+
* @param string $serviceId
205+
*
206+
* @return Reference
207+
*/
208+
private function createCustomClient($serviceId)
209+
{
210+
return new Reference($serviceId);
211+
}
212+
199213
/**
200214
* Returns the Extension Alias
201215
*

src/Provider/CustomProvider.php

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
<?php
2+
3+
/**
4+
* Copyright 2014 Underground Elephant
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*
18+
* @package qpush-bundle
19+
* @copyright Underground Elephant 2014
20+
* @license Apache License, Version 2.0
21+
*/
22+
23+
namespace Uecode\Bundle\QPushBundle\Provider;
24+
25+
use Doctrine\Common\Cache\Cache;
26+
use Symfony\Bridge\Monolog\Logger;
27+
28+
/**
29+
* @author Keith Kirk <kkirk@undergroundelephant.com>
30+
*/
31+
class CustomProvider extends AbstractProvider
32+
{
33+
/**
34+
* @type ProviderInterface
35+
*/
36+
private $client;
37+
38+
/**
39+
* @param string $name
40+
* @param array $options
41+
* @param mixed $client
42+
* @param Cache $cache
43+
* @param Logger $logger
44+
*/
45+
public function __construct($name, array $options, $client, Cache $cache, Logger $logger)
46+
{
47+
$this->name = $name;
48+
$this->options = $options;
49+
$this->cache = $cache;
50+
$this->logger = $logger;
51+
52+
$this->setClient($client);
53+
}
54+
55+
/**
56+
* @param ProviderInterface $client
57+
*
58+
* @return CustomProvider
59+
*/
60+
public function setClient(ProviderInterface $client)
61+
{
62+
$this->client = $client;
63+
64+
return $this;
65+
}
66+
67+
public function getProvider()
68+
{
69+
return 'Custom';
70+
}
71+
72+
/**
73+
* Builds the configured queues
74+
*
75+
* If a Queue name is passed and configured, this method will build only that
76+
* Queue.
77+
*
78+
* All Create methods are idempotent, if the resource exists, the current ARN
79+
* will be returned
80+
*
81+
*/
82+
public function create()
83+
{
84+
return $this->client->create();
85+
}
86+
87+
/**
88+
* @return Boolean
89+
*/
90+
public function destroy()
91+
{
92+
return $this->client->destroy();
93+
}
94+
95+
/**
96+
* {@inheritDoc}
97+
*
98+
* This method will either use a SNS Topic to publish a queued message or
99+
* straight to SQS depending on the application configuration.
100+
*
101+
* @return string
102+
*/
103+
public function publish(array $message, array $options = [])
104+
{
105+
return $this->client->publish($message, $options);
106+
}
107+
108+
/**
109+
* {@inheritDoc}
110+
*/
111+
public function receive(array $options = [])
112+
{
113+
return $this->client->receive($options);
114+
}
115+
116+
/**
117+
* {@inheritDoc}
118+
*
119+
* @return bool
120+
*/
121+
public function delete($id)
122+
{
123+
return $this->client->delete($id);
124+
}
125+
}

src/Resources/config/parameters.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ parameters:
44
uecode_qpush.provider.aws: Uecode\Bundle\QPushBundle\Provider\AwsProvider
55
uecode_qpush.provider.ironmq: Uecode\Bundle\QPushBundle\Provider\IronMqProvider
66
uecode_qpush.provider.sync: Uecode\Bundle\QPushBundle\Provider\SyncProvider
7+
uecode_qpush.provider.custom: Uecode\Bundle\QPushBundle\Provider\CustomProvider
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
3+
/**
4+
* Copyright 2014 Underground Elephant
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*
18+
* @package qpush-bundle
19+
* @copyright Underground Elephant 2014
20+
* @license Apache License, Version 2.0
21+
*/
22+
23+
namespace Uecode\Bundle\QPushBundle\Tests\MockClient;
24+
25+
use Doctrine\Common\Cache\Cache;
26+
use Symfony\Bridge\Monolog\Logger;
27+
use Uecode\Bundle\QPushBundle\Provider\AbstractProvider;
28+
29+
/**
30+
* @codeCoverageIgnore
31+
*
32+
* @author Keith Kirk <kkirk@undergroundelephant.com>
33+
*/
34+
class CustomMockClient extends AbstractProvider
35+
{
36+
/**
37+
* Constructor for Provider classes
38+
*
39+
* @param string $name Name of the Queue the provider is for
40+
* @param array $options An array of configuration options for the Queue
41+
* @param mixed $client A Queue Client for the provider
42+
* @param Cache $cache An instance of Doctrine\Common\Cache\Cache
43+
* @param Logger $logger An instance of Symfony\Bridge\Mongolog\Logger
44+
*/
45+
public function __construct($name, array $options, $client, Cache $cache, Logger $logger)
46+
{
47+
}
48+
49+
public function getProvider()
50+
{
51+
}
52+
53+
public function create()
54+
{
55+
}
56+
57+
public function publish(array $message, array $options = [])
58+
{
59+
}
60+
61+
public function receive(array $options = [])
62+
{
63+
}
64+
65+
public function delete($id)
66+
{
67+
}
68+
69+
public function destroy()
70+
{
71+
}
72+
}

0 commit comments

Comments
 (0)