Skip to content

Commit

Permalink
Introduce setting option for GH API client
Browse files Browse the repository at this point in the history
  • Loading branch information
stloyd committed Sep 7, 2012
1 parent 8965c19 commit 5159afc
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 8 deletions.
5 changes: 5 additions & 0 deletions app/config/config_prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ imports:
framework:
esi: { enabled: true }

# KnpBundles Configuration
knp_bundles:
github_client:
limit: %knp_bundles.github.limit%

monolog:
handlers:
main:
Expand Down
1 change: 1 addition & 0 deletions app/config/parameters.yml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ parameters:

knp_bundles.github.client_id: your_client_id_here
knp_bundles.github.client_secret: your_client_secret_here
knp_bundles.github.limit: 5000

knp_bundles.sensio.client_id: your_client_id_here
knp_bundles.sensio.client_secret: your_client_secret_here
Expand Down
1 change: 1 addition & 0 deletions app/config/parameters.yml.test
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ parameters:

knp_bundles.github.client_id: b46912af13ee7cb7ecd3
knp_bundles.github.client_secret: 116f5427707fcc2a3f7c630dd356be61500b2e18
knp_bundles.github.limit: 5000

knp_bundles.sensio.client_id: 867d229fab429f69b99ac40fc52d0184b6ab83b5fc28b5daadc7f9282cfee1a5
knp_bundles.sensio.client_secret: b79a082b4b88b0e4d8b0832a6ea8db76e68bce338a19279d7d712c2792f8f789
Expand Down
4 changes: 2 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\Processor;

use Github\Client;

class KnpBundlesExtension extends Extension
{
public function load(array $configs, ContainerBuilder $container)
Expand All @@ -33,6 +35,21 @@ public function load(array $configs, ContainerBuilder $container)
$driver = strtolower($config['generate_badges']['driver']);

$container->setAlias('knp_bundles.imagine', new Alias('knp_bundles.imagine.'.$driver, false));

// setup GitHub API client settings
$githubHttpClient = $container->getDefinition('knp_bundles.github_http_client');
$githubHttpClient->addMethodCall('setOption', array('limit', $config['github_client']['limit']));

$githubClient = $container->getDefinition('knp_bundles.github_client');
$githubClient->addMethodCall('setHttpClient', array($githubHttpClient));
$githubClient->addMethodCall(
'authenticate',
array(
$container->getParameter('knp_bundles.github.client_id'),
$container->getParameter('knp_bundles.github.client_secret'),
Client::AUTH_URL_CLIENT_ID
)
);
}

private function getConfigTree()
Expand All @@ -42,16 +59,29 @@ private function getConfigTree()
$tb
->root('knp_bundles')
->children()
->scalarNode('git_bin')->defaultValue('/usr/bin/git')->cannotBeEmpty()->end()
->arrayNode('generate_badges')
->arrayNode('github_client')
->addDefaultsIfNotSet()
->children()
->scalarNode('driver')->defaultValue('gd')
->validate()
->ifNotInArray(array('gd', 'imagick', 'gmagick'))
->thenInvalid('Invalid imagine driver specified: %s')
->scalarNode('limit')
->defaultValue(5000)
->cannotBeEmpty()
->end()
->end()
->end()
->scalarNode('git_bin')
->defaultValue('/usr/bin/git')
->cannotBeEmpty()
->end()
->arrayNode('generate_badges')
->addDefaultsIfNotSet()
->children()
->scalarNode('driver')
->defaultValue('gd')
->validate()
->ifNotInArray(array('gd', 'imagick', 'gmagick'))
->thenInvalid('Invalid imagine driver specified: %s')
->end()
->end()
->end()
->end()
->end()
Expand Down
5 changes: 5 additions & 0 deletions src/Knp/Bundle/KnpBundlesBundle/Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ parameters:
knp_bundles.output.class: Symfony\Component\Console\Output\NullOutput
knp_bundles.travis.class: Knp\Bundle\KnpBundlesBundle\Travis\Travis
knp_bundles.github.client.class: Github\Client
knp_bundles.github.http_client.class: Github\HttpClient\HttpClient
knp_bundles.github.users.class: Knp\Bundle\KnpBundlesBundle\Github\User
knp_bundles.git_repository_manager.class: Knp\Bundle\KnpBundlesBundle\Git\RepoManager
knp_bundles.github.repository_api.class: Knp\Bundle\KnpBundlesBundle\Github\Repo
Expand Down Expand Up @@ -73,6 +74,10 @@ services:
public: false
class: %knp_bundles.github.client.class%

knp_bundles.github_http_client:
public: false
class: %knp_bundles.github.http_client.class%

knp_bundles.git_repository_manager:
class: %knp_bundles.git_repository_manager.class%
arguments:
Expand Down

0 comments on commit 5159afc

Please sign in to comment.