Skip to content

Commit

Permalink
Merge branch 'slashfan-default_configuration'
Browse files Browse the repository at this point in the history
  • Loading branch information
wtfzdotnet committed Aug 11, 2014
2 parents c35d366 + 75162be commit d358e6b
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 69 deletions.
15 changes: 8 additions & 7 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,22 @@ public function getConfigTreeBuilder()

$rootNode
->children()
->scalarNode('api_key')->end()
->scalarNode('api_key')->isRequired()->cannotBeEmpty()->end()
->arrayNode('cache')
->canBeEnabled()
->children()
->scalarNode('enabled')->end()
->scalarNode('path')->end()
->scalarNode('path')->defaultValue('%kernel.cache_dir%/tmdb')->end()
->end()
->end()
->arrayNode('log')
->canBeEnabled()
->children()
->scalarNode('enabled')->end()
->scalarNode('path')->end()
->scalarNode('path')->defaultValue('%kernel.logs_dir%/tmdb.log')->end()
->end()
->end()
->end()
;
->arrayNode('repositories')->canBeDisabled()->end()
->arrayNode('twig_extension')->canBeDisabled()->end()
->end();

return $treeBuilder;
}
Expand Down
30 changes: 13 additions & 17 deletions DependencyInjection/WtfzTmdbExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,30 +23,26 @@ public function load(array $configs, ContainerBuilder $container)
$config = $this->processConfiguration($configuration, $configs);

$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('tmdb.xml');

if (!isset($config['api_key'])) {
throw new \InvalidArgumentException(
'The "api_key" option must be set'
);
}
$loader->load('services.xml');

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

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

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

if (array_key_exists('log', $config)) {
$logEnabled = array_key_exists('enabled', $config['log']) && $config['log']['enabled'];
$logPath = array_key_exists('path', $config['log']) ? $config['log']['path'] : null;
if ($config['repositories']['enabled']) {
$loader->load('repositories.xml');
}

$container->setParameter('wtfz_tmdb.log.enabled', $logEnabled);
$container->setParameter('wtfz_tmdb.log.path', $logPath);
if ($config['twig_extension']['enabled']) {
$loader->load('twig.xml');
}
}
}
33 changes: 27 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ wtfz_tmdb:
That's all! Fire away!
__Want to make use of default caching?__
__Want to make use of default caching and/or logging?__
This caching system will adhere to the TMDB API max-age values, if you have different needs like long TTL's
you'd have to make your own implementation. We would be happy to intergrate more options, so please contribute.
Expand All @@ -24,11 +24,32 @@ wtfz_tmdb:
api_key: YOUR_API_KEY_HERE
cache:
enabled: true
path: "/tmp/php-tmdb-api"

#path: "%kernel.cache_dir%/tmdb"
log:
enabled: true
path: "/tmp/php-tmdb-api.log"
#path: "%kernel.logs_dir%/tmdb.log"
```

__Don't need the repositories?__

You can disable repositories :

```yaml
wtfz_tmdb:
api_key: YOUR_API_KEY_HERE
repositories:
enabled: false
```
__Don't need the twig extension?__
You can disable the twig extension :
```yaml
wtfz_tmdb:
api_key: YOUR_API_KEY_HERE
twig_extension:
enabled: false
```
Usage
Expand All @@ -46,7 +67,7 @@ Obtaining repositories
$movie = $this->get('wtfz_tmdb.movie_repository')->load(13);
```

An overview of all the repositories can be found in the services configuration [tmdb.xml](https://github.com/wtfzdotnet/WtfzTmdbBundle/blob/master/Resources/config/tmdb.xml).
An overview of all the repositories can be found in the services configuration [repositories.xml](https://github.com/wtfzdotnet/WtfzTmdbBundle/blob/master/Resources/config/repositories.xml).

There is also a Twig helper that makes use of the `Tmdb\Helper\ImageHelper` to output urls and html.

Expand All @@ -56,4 +77,4 @@ There is also a Twig helper that makes use of the `Tmdb\Helper\ImageHelper` to o
{{ movie.backdropImage|tmdb_image_html('original', null, 50)|raw }}
```

**For all all other interactions take a look at [wtfzdotnet/php-tmdb-api](https://github.com/wtfzdotnet/php-tmdb-api).**
**For all all other interactions take a look at [wtfzdotnet/php-tmdb-api](https://github.com/wtfzdotnet/php-tmdb-api).**
37 changes: 1 addition & 36 deletions Resources/config/tmdb.xml → Resources/config/repositories.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,6 @@
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">

<parameters>
<!-- Options parameters -->
<parameter key="wtfz_tmdb.api_key" />
<parameter key="wtfz_tmdb.cache.enabled" />
<parameter key="wtfz_tmdb.cache.path" />

<!-- Main classes -->
<parameter key="wtfz_tmdb.client.class">Tmdb\Client</parameter>
<parameter key="wtfz_tmdb.api_token.class">Tmdb\ApiToken</parameter>
<parameter key="wtfz_tmdb.request_token.class">Tmdb\RequestToken</parameter>
<parameter key="wtfz_tmdb.session_token.class">Tmdb\SessionToken</parameter>

<!-- Repository classes -->
<parameter key="wtfz_tmdb.authentication_repository.class">Tmdb\Repository\AuthenticationRepository</parameter>
<parameter key="wtfz_tmdb.account_repository.class">Tmdb\Repository\AccountRepository</parameter>
<parameter key="wtfz_tmdb.certification_repository.class">Tmdb\Repository\CertificationRepository</parameter>
Expand All @@ -42,24 +30,6 @@
</parameters>

<services>
<service id="wtfz_tmdb.client" class="%wtfz_tmdb.client.class%">
<argument type="service" id="wtfz_tmdb.api_token" />
<call method="setCaching">
<argument>%wtfz_tmdb.cache.enabled%</argument>
<argument>%wtfz_tmdb.cache.path%</argument>
</call>

<call method="setLogging">
<argument>%wtfz_tmdb.log.enabled%</argument>
<argument>%wtfz_tmdb.log.path%</argument>
</call>
</service>

<service id="wtfz_tmdb.api_token" class="%wtfz_tmdb.api_token.class%">
<argument>%wtfz_tmdb.api_key%</argument>
</service>

<!-- Repositories -->
<service id="wtfz_tmdb.certification_repository" class="%wtfz_tmdb.certification_repository.class%">
<argument type="service" id="wtfz_tmdb.client" />
</service>
Expand Down Expand Up @@ -139,11 +109,6 @@
<service id="wtfz_tmdb.tv_episode_repository" class="%wtfz_tmdb.tv_episode_repository.class%">
<argument type="service" id="wtfz_tmdb.client" />
</service>

<!-- Twig -->
<service id="wtfz_tmdb.twig.image_extension" class="Wtfz\TmdbBundle\Twig\WtfzTmdbExtension">
<argument type="service" id="wtfz_tmdb.client" />
<tag name="twig.extension" />
</service>
</services>

</container>
26 changes: 26 additions & 0 deletions Resources/config/services.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?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">

<parameters>
<!-- Options parameters -->
<parameter key="wtfz_tmdb.api_key" />
<!-- Main classes -->
<parameter key="wtfz_tmdb.client.class">Tmdb\Client</parameter>
<parameter key="wtfz_tmdb.api_token.class">Tmdb\ApiToken</parameter>
<parameter key="wtfz_tmdb.request_token.class">Tmdb\RequestToken</parameter>
<parameter key="wtfz_tmdb.session_token.class">Tmdb\SessionToken</parameter>
</parameters>

<services>
<service id="wtfz_tmdb.client" class="%wtfz_tmdb.client.class%">
<argument type="service" id="wtfz_tmdb.api_token" />
</service>
<service id="wtfz_tmdb.api_token" class="%wtfz_tmdb.api_token.class%" public="false">
<argument>%wtfz_tmdb.api_key%</argument>
</service>
</services>

</container>
18 changes: 18 additions & 0 deletions Resources/config/twig.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?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">

<parameters>
<parameter key="wtfz_tmdb.twig.image_extension.class">Wtfz\TmdbBundle\Twig\WtfzTmdbExtension</parameter>
</parameters>

<services>
<service id="wtfz_tmdb.twig.image_extension" class="%wtfz_tmdb.twig.image_extension.class%">
<argument type="service" id="wtfz_tmdb.client" />
<tag name="twig.extension" />
</service>
</services>

</container>
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
}
],
"require": {
"wtfzdotnet/php-tmdb-api": ">=1.1.0",
"doctrine/cache": ">=1.3.0",
"monolog/monolog": ">=1.7.0"
"symfony/symfony": "~2.3",
"doctrine/cache": "~1.3",
"monolog/monolog": "~1.7",
"wtfzdotnet/php-tmdb-api": "~1.1",
},
"autoload": {
"psr-0": { "Wtfz\\TmdbBundle": "" }
Expand Down

0 comments on commit d358e6b

Please sign in to comment.