Skip to content

Commit 373780c

Browse files
committed
Merge pull request #2 from StoreFactory/feature/fixed-bundle-structure
Fixed bundle structure
2 parents 98fbcc4 + 25bce63 commit 373780c

File tree

10 files changed

+99
-224
lines changed

10 files changed

+99
-224
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
/**
4+
* ZohoSubscription Bundle
5+
*
6+
* @author Tristan Bessoussa <tristan.bessoussa@gmail.com>
7+
*/
8+
9+
namespace StoreFactory\ZohoSubscriptionBundle\CompilerPass;
10+
11+
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
12+
use Symfony\Component\DependencyInjection\ContainerBuilder;
13+
use Symfony\Component\DependencyInjection\Reference;
14+
15+
class DynamicServiceCacheCompilerPass implements CompilerPassInterface
16+
{
17+
/**
18+
* {@inheritdoc}
19+
*/
20+
public function process(ContainerBuilder $container)
21+
{
22+
if ($container->getParameter('my_poseo.api.cache_service_id') !== null) {
23+
$container
24+
->getDefinition('zoho.api.manager')
25+
->addArgument(new Reference($container->getParameter('zoho_subscription.cache.service')))
26+
;
27+
}
28+
}
29+
}

DependencyInjection/Configuration.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,38 @@ public function getConfigTreeBuilder()
2020
$treeBuilder = new TreeBuilder();
2121
$rootNode = $treeBuilder->root('zoho_subscription');
2222

23+
$rootNode
24+
->children()
25+
->arrayNode('api')
26+
->children()
27+
->scalarNode('key')
28+
->isRequired()
29+
->info('The service is not free. You must provide an API Key which can be found on : https://www.zoho.com/subscriptions/')
30+
->end()
31+
->scalarNode('organisation_id')
32+
->isRequired()
33+
->info('Organization ID from Zoho Subscription')
34+
->end()
35+
->end()
36+
->childrenNode('cache')
37+
->children()
38+
->booleanNode('enabled')
39+
->info('If cache is active or not')
40+
->defaultValue(false)
41+
->end()
42+
->scalarNode('service')
43+
->info('Defines the service id of the cache that will be used')
44+
->defaultValue(null)
45+
->end()
46+
->integerNode('ttl')
47+
->info('Defines the TTL of the cache')
48+
->defaultValue(null)
49+
->end()
50+
->end()
51+
->end()
52+
->end()
53+
;
54+
2355
return $treeBuilder;
2456
}
2557
}

DependencyInjection/ZohoSubscriptionExtension.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,12 @@ public function load(array $configs, ContainerBuilder $container)
2323
$config = $this->processConfiguration($configuration, $configs);
2424
$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
2525

26+
$loader->load('services.xml');
27+
28+
$container->setParameter('zoho_subscription.api_key', $config['api']['key']);
29+
$container->setParameter('zoho_subscription.org_id', $config['api']['organisation_id']);
30+
$container->setParameter('zoho_subscription.cache.service', $config['cache']['service']);
31+
$container->setParameter('zoho_subscription.cache.enabled', $config['cache']['enabled']);
32+
$container->setParameter('zoho_subscription.cache.ttl', $config['cache']['ttl']);
2633
}
2734
}

Manager/AddonManager.php

Lines changed: 0 additions & 53 deletions
This file was deleted.

Manager/DefaultManager.php

Lines changed: 0 additions & 33 deletions
This file was deleted.

Manager/PlanManager.php

Lines changed: 0 additions & 69 deletions
This file was deleted.

Manager/ZohoSubscriptionManager.php

Lines changed: 0 additions & 60 deletions
This file was deleted.

Resources/config/services.xml

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,18 @@
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
44
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
55
<services>
6-
<service id="zoho.subscription_manager" class="StoreFactory\ZohoSubscriptionBundle\Manager\ZohoSubscriptionManager">
7-
<argument type="service" id="zoho_subscription.plan"></argument>
8-
<argument type="service" id="zoho_subscription.addon"></argument>
9-
<argument type="service" id="snc_redis.default"></argument>
6+
7+
<service id="zoho.api.manager" class="Zoho\Subscription\Client\Client" abstract="true">
8+
<argument>%zoho_subscription.api_key%</argument>
9+
<argument>%zoho_subscription.org_id%</argument>
1010
<argument>%zoho_cache_enabled%</argument>
11-
<argument>%zoho_cache_ttl%</argument>
12-
<argument>%zoho_token%</argument>
13-
<argument>%zoho_organization_id%</argument>
11+
<argument />
12+
<argument>%zoho_subscription.cache.ttl%</argument>
1413
</service>
14+
15+
<service id="zoho.api.addon" class="Zoho\Subscription\Api\Addon" parent="zoho.api.manager"></service>
16+
<service id="zoho.api.plan" class="Zoho\Subscription\Api\Plan" parent="zoho.api.manager"></service>
17+
18+
1519
</services>
1620
</container>

ZohoSubscriptionBundle.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,19 @@
77
* @author Tristan Bessoussa <tristan.bessoussa@gmail.com>
88
*/
99

10+
use Symfony\Component\DependencyInjection\ContainerBuilder;
1011
use Symfony\Component\HttpKernel\Bundle\Bundle;
1112

13+
use StoreFactory\ZohoSubscriptionBundle\CompilerPass\DynamicServiceCacheCompilerPass;
14+
1215
class ZohoSubscriptionBundle extends Bundle
1316
{
14-
17+
/**
18+
* {@inheritdoc}
19+
*/
20+
public function build(ContainerBuilder $container)
21+
{
22+
parent::build($container);
23+
$container->addCompilerPass(new DynamicServiceCacheCompilerPass());
24+
}
1525
}

composer.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,17 @@
66
"StoreFactory\\ZohoSubscriptionBundle\\": ""
77
}
88
},
9+
"authors": [
10+
{
11+
"name": "Tristan Bessoussa",
12+
"email": "tristan.bessoussa@gmail.com"
13+
}
14+
],
915
"description": "Zoho Subscription Bundle uses the zoho-subscription-api PHP client library",
1016
"require": {
11-
"storefactory/zoho-subscription-api": "^1.0"
17+
"php": ">=5.4.0",
18+
"symfony/framework-bundle": "^2.2",
19+
"storefactory/zoho-subscription-api": "dev-master"
1220
},
1321
"minimum-stability": "stable"
1422
}

0 commit comments

Comments
 (0)