diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index b502775..144e7cd 100755 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -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; } diff --git a/DependencyInjection/WtfzTmdbExtension.php b/DependencyInjection/WtfzTmdbExtension.php index 6de2ce2..abb5f00 100755 --- a/DependencyInjection/WtfzTmdbExtension.php +++ b/DependencyInjection/WtfzTmdbExtension.php @@ -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'); } } } diff --git a/README.md b/README.md index c1ead80..3a50312 100755 --- a/README.md +++ b/README.md @@ -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. @@ -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 @@ -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. @@ -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).** \ No newline at end of file +**For all all other interactions take a look at [wtfzdotnet/php-tmdb-api](https://github.com/wtfzdotnet/php-tmdb-api).** diff --git a/Resources/config/tmdb.xml b/Resources/config/repositories.xml similarity index 80% rename from Resources/config/tmdb.xml rename to Resources/config/repositories.xml index 7a2e90a..ba3af96 100755 --- a/Resources/config/tmdb.xml +++ b/Resources/config/repositories.xml @@ -5,18 +5,6 @@ xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> - - - - - - - Tmdb\Client - Tmdb\ApiToken - Tmdb\RequestToken - Tmdb\SessionToken - - Tmdb\Repository\AuthenticationRepository Tmdb\Repository\AccountRepository Tmdb\Repository\CertificationRepository @@ -42,24 +30,6 @@ - - - - %wtfz_tmdb.cache.enabled% - %wtfz_tmdb.cache.path% - - - - %wtfz_tmdb.log.enabled% - %wtfz_tmdb.log.path% - - - - - %wtfz_tmdb.api_key% - - - @@ -139,11 +109,6 @@ - - - - - - + diff --git a/Resources/config/services.xml b/Resources/config/services.xml new file mode 100755 index 0000000..98f81b6 --- /dev/null +++ b/Resources/config/services.xml @@ -0,0 +1,26 @@ + + + + + + + + + Tmdb\Client + Tmdb\ApiToken + Tmdb\RequestToken + Tmdb\SessionToken + + + + + + + + %wtfz_tmdb.api_key% + + + + diff --git a/Resources/config/twig.xml b/Resources/config/twig.xml new file mode 100755 index 0000000..ed9751f --- /dev/null +++ b/Resources/config/twig.xml @@ -0,0 +1,18 @@ + + + + + + Wtfz\TmdbBundle\Twig\WtfzTmdbExtension + + + + + + + + + + diff --git a/composer.json b/composer.json index 01719c2..0816488 100755 --- a/composer.json +++ b/composer.json @@ -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": "" }