Skip to content

Commit 6c7c746

Browse files
author
Nicolas Cabot
committed
added configuration options
1 parent c35d366 commit 6c7c746

File tree

7 files changed

+110
-69
lines changed

7 files changed

+110
-69
lines changed

DependencyInjection/Configuration.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,22 @@ public function getConfigTreeBuilder()
2222

2323
$rootNode
2424
->children()
25-
->scalarNode('api_key')->end()
25+
->scalarNode('api_key')->isRequired()->cannotBeEmpty()->end()
2626
->arrayNode('cache')
27+
->canBeDisabled()
2728
->children()
28-
->scalarNode('enabled')->end()
29-
->scalarNode('path')->end()
29+
->scalarNode('path')->defaultValue('%kernel.cache_dir%/tmdb')->end()
3030
->end()
3131
->end()
3232
->arrayNode('log')
33+
->canBeDisabled()
3334
->children()
34-
->scalarNode('enabled')->end()
35-
->scalarNode('path')->end()
35+
->scalarNode('path')->defaultValue('%kernel.logs_dir%/tmdb.log')->end()
3636
->end()
3737
->end()
38-
->end()
39-
;
38+
->arrayNode('repositories')->canBeDisabled()->end()
39+
->arrayNode('twig_extension')->canBeDisabled()->end()
40+
->end();
4041

4142
return $treeBuilder;
4243
}

DependencyInjection/WtfzTmdbExtension.php

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,30 +23,26 @@ public function load(array $configs, ContainerBuilder $container)
2323
$config = $this->processConfiguration($configuration, $configs);
2424

2525
$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
26-
$loader->load('tmdb.xml');
27-
28-
if (!isset($config['api_key'])) {
29-
throw new \InvalidArgumentException(
30-
'The "api_key" option must be set'
31-
);
32-
}
26+
$loader->load('services.xml');
3327

3428
$container->setParameter('wtfz_tmdb.api_key', $config['api_key']);
3529

36-
if (array_key_exists('cache', $config)) {
37-
$cacheEnabled = array_key_exists('enabled', $config['cache']) && $config['cache']['enabled'];
38-
$cachePath = array_key_exists('path', $config['cache']) ? $config['cache']['path'] : null;
30+
if ($config['cache']['enabled']) {
31+
$path = $container->getParameterBag()->resolveValue($config['cache']['path']);
32+
$container->getDefinition('wtfz_tmdb.client')->addMethodCall('setCaching', array(true, $path));
33+
}
3934

40-
$container->setParameter('wtfz_tmdb.cache.enabled', $cacheEnabled);
41-
$container->setParameter('wtfz_tmdb.cache.path', $cachePath);
35+
if ($config['log']['enabled']) {
36+
$path = $container->getParameterBag()->resolveValue($config['log']['path']);
37+
$container->getDefinition('wtfz_tmdb.client')->addMethodCall('setLogging', array(true, $path));
4238
}
4339

44-
if (array_key_exists('log', $config)) {
45-
$logEnabled = array_key_exists('enabled', $config['log']) && $config['log']['enabled'];
46-
$logPath = array_key_exists('path', $config['log']) ? $config['log']['path'] : null;
40+
if ($config['repositories']['enabled']) {
41+
$loader->load('repositories.xml');
42+
}
4743

48-
$container->setParameter('wtfz_tmdb.log.enabled', $logEnabled);
49-
$container->setParameter('wtfz_tmdb.log.path', $logPath);
44+
if ($config['twig_extension']['enabled']) {
45+
$loader->load('twig.xml');
5046
}
5147
}
5248
}

README.md

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,55 @@ wtfz_tmdb:
1414
1515
That's all! Fire away!
1616
17-
__Want to make use of default caching?__
17+
__Default caching and loggin capabilities?__
1818
1919
This caching system will adhere to the TMDB API max-age values, if you have different needs like long TTL's
2020
you'd have to make your own implementation. We would be happy to intergrate more options, so please contribute.
2121
22+
Default configuration looks like this :
23+
2224
```yaml
2325
wtfz_tmdb:
24-
api_key: YOUR_API_KEY_HERE
26+
...
2527
cache:
2628
enabled: true
27-
path: "/tmp/php-tmdb-api"
28-
29+
path: "%kernel.cache_dir%/tmdb"
2930
log:
3031
enabled: true
31-
path: "/tmp/php-tmdb-api.log"
32+
path: "%kernel.logs_dir%/tmdb.log"
33+
```
34+
35+
You can disable if you don't want to use it :
36+
37+
```yaml
38+
wtfz_tmdb:
39+
...
40+
cache:
41+
enabled: false
42+
log:
43+
enabled: false
44+
```
45+
46+
__Disable repositories?__
47+
48+
You can disable repositories if you don't use them :
49+
50+
```yaml
51+
wtfz_tmdb:
52+
...
53+
repositories:
54+
enabled: false
55+
```
56+
57+
__Disable twig extension?__
58+
59+
You can disable twig extension if you don't use it :
60+
61+
```yaml
62+
wtfz_tmdb:
63+
...
64+
twig_extension:
65+
enabled: false
3266
```
3367
3468
Usage
@@ -56,4 +90,4 @@ There is also a Twig helper that makes use of the `Tmdb\Helper\ImageHelper` to o
5690
{{ movie.backdropImage|tmdb_image_html('original', null, 50)|raw }}
5791
```
5892

59-
**For all all other interactions take a look at [wtfzdotnet/php-tmdb-api](https://github.com/wtfzdotnet/php-tmdb-api).**
93+
**For all all other interactions take a look at [wtfzdotnet/php-tmdb-api](https://github.com/wtfzdotnet/php-tmdb-api).**

Resources/config/tmdb.xml renamed to Resources/config/repositories.xml

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,6 @@
55
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
66

77
<parameters>
8-
<!-- Options parameters -->
9-
<parameter key="wtfz_tmdb.api_key" />
10-
<parameter key="wtfz_tmdb.cache.enabled" />
11-
<parameter key="wtfz_tmdb.cache.path" />
12-
13-
<!-- Main classes -->
14-
<parameter key="wtfz_tmdb.client.class">Tmdb\Client</parameter>
15-
<parameter key="wtfz_tmdb.api_token.class">Tmdb\ApiToken</parameter>
16-
<parameter key="wtfz_tmdb.request_token.class">Tmdb\RequestToken</parameter>
17-
<parameter key="wtfz_tmdb.session_token.class">Tmdb\SessionToken</parameter>
18-
19-
<!-- Repository classes -->
208
<parameter key="wtfz_tmdb.authentication_repository.class">Tmdb\Repository\AuthenticationRepository</parameter>
219
<parameter key="wtfz_tmdb.account_repository.class">Tmdb\Repository\AccountRepository</parameter>
2210
<parameter key="wtfz_tmdb.certification_repository.class">Tmdb\Repository\CertificationRepository</parameter>
@@ -42,24 +30,6 @@
4230
</parameters>
4331

4432
<services>
45-
<service id="wtfz_tmdb.client" class="%wtfz_tmdb.client.class%">
46-
<argument type="service" id="wtfz_tmdb.api_token" />
47-
<call method="setCaching">
48-
<argument>%wtfz_tmdb.cache.enabled%</argument>
49-
<argument>%wtfz_tmdb.cache.path%</argument>
50-
</call>
51-
52-
<call method="setLogging">
53-
<argument>%wtfz_tmdb.log.enabled%</argument>
54-
<argument>%wtfz_tmdb.log.path%</argument>
55-
</call>
56-
</service>
57-
58-
<service id="wtfz_tmdb.api_token" class="%wtfz_tmdb.api_token.class%">
59-
<argument>%wtfz_tmdb.api_key%</argument>
60-
</service>
61-
62-
<!-- Repositories -->
6333
<service id="wtfz_tmdb.certification_repository" class="%wtfz_tmdb.certification_repository.class%">
6434
<argument type="service" id="wtfz_tmdb.client" />
6535
</service>
@@ -139,11 +109,6 @@
139109
<service id="wtfz_tmdb.tv_episode_repository" class="%wtfz_tmdb.tv_episode_repository.class%">
140110
<argument type="service" id="wtfz_tmdb.client" />
141111
</service>
142-
143-
<!-- Twig -->
144-
<service id="wtfz_tmdb.twig.image_extension" class="Wtfz\TmdbBundle\Twig\WtfzTmdbExtension">
145-
<argument type="service" id="wtfz_tmdb.client" />
146-
<tag name="twig.extension" />
147-
</service>
148112
</services>
113+
149114
</container>

Resources/config/services.xml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" ?>
2+
3+
<container xmlns="http://symfony.com/schema/dic/services"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
6+
7+
<parameters>
8+
<!-- Options parameters -->
9+
<parameter key="wtfz_tmdb.api_key" />
10+
<!-- Main classes -->
11+
<parameter key="wtfz_tmdb.client.class">Tmdb\Client</parameter>
12+
<parameter key="wtfz_tmdb.api_token.class">Tmdb\ApiToken</parameter>
13+
<parameter key="wtfz_tmdb.request_token.class">Tmdb\RequestToken</parameter>
14+
<parameter key="wtfz_tmdb.session_token.class">Tmdb\SessionToken</parameter>
15+
</parameters>
16+
17+
<services>
18+
<service id="wtfz_tmdb.client" class="%wtfz_tmdb.client.class%">
19+
<argument type="service" id="wtfz_tmdb.api_token" />
20+
</service>
21+
<service id="wtfz_tmdb.api_token" class="%wtfz_tmdb.api_token.class%" public="false">
22+
<argument>%wtfz_tmdb.api_key%</argument>
23+
</service>
24+
</services>
25+
26+
</container>

Resources/config/twig.xml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" ?>
2+
3+
<container xmlns="http://symfony.com/schema/dic/services"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
6+
7+
<parameters>
8+
<parameter key="wtfz_tmdb.twig.image_extension.class">Wtfz\TmdbBundle\Twig\WtfzTmdbExtension</parameter>
9+
</parameters>
10+
11+
<services>
12+
<service id="wtfz_tmdb.twig.image_extension" class="%wtfz_tmdb.twig.image_extension.class%">
13+
<argument type="service" id="wtfz_tmdb.client" />
14+
<tag name="twig.extension" />
15+
</service>
16+
</services>
17+
18+
</container>

composer.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@
1313
}
1414
],
1515
"require": {
16-
"wtfzdotnet/php-tmdb-api": ">=1.1.0",
17-
"doctrine/cache": ">=1.3.0",
18-
"monolog/monolog": ">=1.7.0"
16+
"symfony/symfony": "~2.3",
17+
"doctrine/cache": "~1.3",
18+
"monolog/monolog": "~1.7",
19+
"wtfzdotnet/php-tmdb-api": "~1.1",
1920
},
2021
"autoload": {
2122
"psr-0": { "Wtfz\\TmdbBundle": "" }

0 commit comments

Comments
 (0)