public function __construct($services) { foreach ($services as $service) { $oauthService = new OAuthService($service); $this->oAuthServices[$oauthService->getName()] = $oauthService; } }
/** * Parses the gadget's OAuth entries, the OAuth entry would look something like: * <OAuth> * <Service name="google"> * <Access url="https://www.google.com/accounts/OAuthGetAccessToken" method="GET" /> * <Request url="https://www.google.com/accounts/OAuthGetRequestToken?scope=http://www.google.com/m8/feeds/" method="GET" /> * <Authorization url="https://www.google.com/accounts/OAuthAuthorizeToken?oauth_callback=http://oauth.gmodules.com/gadgets/oauthcallback" /> * </Service> * </OAuth> * * And the resulting $gadgetSpec->oauth structure: * * Array ( * [access] => Array ( * [url] => https://www.google.com/accounts/OAuthGetAccessToken * [method] => GET * ) * [request] => Array ( * [url] => https://www.google.com/accounts/OAuthGetRequestToken?scope=http://www.google.com/m8/feeds/ * [method] => GET * ) * [authorization] => Array ( * [url] => https://www.google.com/accounts/OAuthAuthorizeToken?oauth_callback=http://oauth.gmodules.com/gadgets/oauthcallback * [method] => GET * ) * ) * * @param DOMElement $modulePrefs * @param GadgetSpec $gadget */ private function parseOAuth(DOMElement &$modulePrefs, GadgetSpec &$gadget) { if (($oauthNodes = $modulePrefs->getElementsByTagName('OAuth')) != null) { if ($oauthNodes->length > 1) { throw new GadgetSpecException("A gadget can only have one OAuth element (though multiple service entries are allowed in that one OAuth element)"); } $oauth = array(); if ($oauthNodes->length > 0) { $oauthNode = $oauthNodes->item(0); if (($serviceNodes = $oauthNode->getElementsByTagName('Service')) != null) { foreach ($serviceNodes as $service) { $oauthService = new OAuthService($service); $oauth[$oauthService->getName()] = $oauthService; } } $gadget->oauth = $oauth; } } }