{"action":"created","issue":{"url":"https://api.github.com/repos/guzzle/guzzle-silex-extension/issues/16","labels_url":"https://api.github.com/repos/guzzle/guzzle-silex-extension/issues/16/labels{/name}","comments_url":"https://api.github.com/repos/guzzle/guzzle-silex-extension/issues/16/comments","events_url":"https://api.github.com/repos/guzzle/guzzle-silex-extension/issues/16/events","html_url":"https://github.com/guzzle/guzzle-silex-extension/issues/16","id":11406561,"number":16,"title":"Add support for global plugins","user":{"login":"gunnarlium","id":207556,"avatar_url":"https://avatars.githubusercontent.com/u/207556?v=3","gravatar_id":"","url":"https://api.github.com/users/gunnarlium","html_url":"https://github.com/gunnarlium","followers_url":"https://api.github.com/users/gunnarlium/followers","following_url":"https://api.github.com/users/gunnarlium/following{/other_user}","gists_url":"https://api.github.com/users/gunnarlium/gists{/gist_id}","starred_url":"https://api.github.com/users/gunnarlium/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gunnarlium/subscriptions","organizations_url":"https://api.github.com/users/gunnarlium/orgs","repos_url":"https://api.github.com/users/gunnarlium/repos","events_url":"https://api.github.com/users/gunnarlium/events{/privacy}","received_events_url":"https://api.github.com/users/gunnarlium/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2013-02-26T12:44:46Z","updated_at":"2015-01-12T02:28:01Z","closed_at":"2015-01-12T02:28:01Z","body":"I would like to be able to define global plugins, which will be added to all services, similar to the \"generic\" client.\r\n\r\nWhen setting up Silex\\Application, I would like to do something like this:\r\n\r\n```PHP\r\n$app['guzzle.plugins'] = function () use ($app) {\r\n    $logAdapter = new MonologLogAdapter($app['logger']);\r\n    $logFormatter = new MessageFormatter('{code} {method} {url} in {total_time}s');\r\n    $logPlugin = new LogPlugin($logAdapter, $logFormatter);\r\n\r\n    return array($logPlugin);\r\n};\r\n```\r\n\r\nAnd then have logging enabled for all clients.\r\n\r\nI can make this work by adding a couple of lines to the GuzzleServiceProvider->register method:\r\n\r\n```PHP\r\n// Register a Guzzle ServiceBuilder\r\n$app['guzzle'] = $app->share(function () use ($app) {\r\n    if (!isset($app['guzzle.services'])) {\r\n        $builder = new ServiceBuilder(array());\r\n    } else {\r\n        $builder = ServiceBuilder::factory($app['guzzle.services']);\r\n    }\r\n\r\n    // I added this\r\n    foreach ($app['guzzle.plugins'] as $plugin) {\r\n        $builder->addGlobalPlugin($plugin);\r\n    }\r\n\r\n    return $builder;\r\n});\r\n\r\n```\r\n\r\nI'm quite new to Guzzle, so it might be that I'm missing some better way to define plugins for services. If this way makes sense, I can create a pull request with the changes and some docs."},"comment":{"url":"https://api.github.com/repos/guzzle/guzzle-silex-extension/issues/comments/69524354","html_url":"https://github.com/guzzle/guzzle-silex-extension/issues/16#issuecomment-69524354","issue_url":"https://api.github.com/repos/guzzle/guzzle-silex-extension/issues/16","id":69524354,"user":{"login":"mtdowling","id":190930,"avatar_url":"https://avatars.githubusercontent.com/u/190930?v=3","gravatar_id":"","url":"https://api.github.com/users/mtdowling","html_url":"https://github.com/mtdowling","followers_url":"https://api.github.com/users/mtdowling/followers","following_url":"https://api.github.com/users/mtdowling/following{/other_user}","gists_url":"https://api.github.com/users/mtdowling/gists{/gist_id}","starred_url":"https://api.github.com/users/mtdowling/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mtdowling/subscriptions","organizations_url":"https://api.github.com/users/mtdowling/orgs","repos_url":"https://api.github.com/users/mtdowling/repos","events_url":"https://api.github.com/users/mtdowling/events{/privacy}","received_events_url":"https://api.github.com/users/mtdowling/received_events","type":"User","site_admin":false},"created_at":"2015-01-12T02:28:01Z","updated_at":"2015-01-12T02:28:01Z","body":"This repo is no longer maintained."}}