Created
August 19, 2013 13:15
-
-
Save clops/6269005 to your computer and use it in GitHub Desktop.
This is how to configure a Service in Symfony 2 with dynamic parameters. No magic, but still awesome.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
//.. | |
//the following will return an Instance of InstagramAPI ... configured and ready to roll! | |
$this->get('instagram'); | |
//.. | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
//... | |
public function __construct($apiKey, $apiSecret, Request $request, Router $router) { | |
if(empty($apiKey)){ | |
throw new \Exception("Error: __construct() - Configuration data is missing."); | |
} | |
$this->setApiKey($apiKey); | |
$this->setApiSecret($apiSecret); | |
$this->setApiCallbackFromSymfonyData($request, $router); | |
} | |
//... | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
parameters: | |
client_id: xxxxx | |
client_secret: yyyyy | |
clops.instagram.api.class: Clops\InstagramBundle\InstagramAPI | |
services: | |
instagram: | |
scope: request | |
class: "%clops.instagram.api.class%" | |
arguments: ["%client_id%", "%client_secret%", @request, @router] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
try this: http://jmsyst.com/bundles/JMSDiExtraBundle/master/annotations ;) it's awsome to write