You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@shindig.apache.org by li...@apache.org on 2010/08/09 14:29:59 UTC

svn commit: r983612 - in /shindig/trunk/php: config/ src/common/ src/common/sample/ src/gadgets/ src/gadgets/sample/ src/gadgets/servlet/ src/social/service/

Author: lindner
Date: Mon Aug  9 12:29:58 2010
New Revision: 983612

URL: http://svn.apache.org/viewvc?rev=983612&view=rev
Log:
SHINDIG-1399 | Patch from Bastian Hofmann | Improved extensibility for PHP Shindig

Modified:
    shindig/trunk/php/config/container.php
    shindig/trunk/php/src/common/RemoteContentRequest.php
    shindig/trunk/php/src/common/sample/BasicBlobCrypter.php
    shindig/trunk/php/src/common/sample/BasicSecurityToken.php
    shindig/trunk/php/src/gadgets/GadgetContext.php
    shindig/trunk/php/src/gadgets/GadgetFactory.php
    shindig/trunk/php/src/gadgets/GadgetSpecParser.php
    shindig/trunk/php/src/gadgets/MetadataHandler.php
    shindig/trunk/php/src/gadgets/ProxyHandler.php
    shindig/trunk/php/src/gadgets/Substitutions.php
    shindig/trunk/php/src/gadgets/sample/BasicGadgetSpecFactory.php
    shindig/trunk/php/src/gadgets/servlet/GadgetRenderingServlet.php
    shindig/trunk/php/src/gadgets/servlet/JsServlet.php
    shindig/trunk/php/src/gadgets/servlet/MakeRequestServlet.php
    shindig/trunk/php/src/gadgets/servlet/ProxyServlet.php
    shindig/trunk/php/src/social/service/DataRequestHandler.php
    shindig/trunk/php/src/social/service/HttpHandler.php
    shindig/trunk/php/src/social/service/PersonHandler.php

Modified: shindig/trunk/php/config/container.php
URL: http://svn.apache.org/viewvc/shindig/trunk/php/config/container.php?rev=983612&r1=983611&r2=983612&view=diff
==============================================================================
--- shindig/trunk/php/config/container.php (original)
+++ shindig/trunk/php/config/container.php Mon Aug  9 12:29:58 2010
@@ -146,6 +146,14 @@ $shindigConfig = array(
   // The OAuth Store is used to store the (gadgets/)oauth proxy credentials it obtained on behalf of the user/gadget combo
   'oauth_store' => 'BasicOAuthStore',
 
+  'gadget_class' => 'Gadget',
+  'gadget_context_class' => 'GadgetContext',
+  'gadget_factory_class' => 'GadgetFactory',
+  'gadget_spec_parser' => 'GadgetSpecParser',
+  'gadget_spec_class' => 'GadgetSpec',
+  'substitution_class' => 'Substitutions',
+  'proxy_handler' => 'ProxyHandler',
+  
   // Caching back-end's to use. Shindig ships with CacheStorageFile, CacheStorageApc and CacheStorageMemcache support
   // The data cache is primarily used for remote content (proxied files, gadget spec, etc)
   // and the feature_cache is used to cache the parsed features xml structure and javascript

Modified: shindig/trunk/php/src/common/RemoteContentRequest.php
URL: http://svn.apache.org/viewvc/shindig/trunk/php/src/common/RemoteContentRequest.php?rev=983612&r1=983611&r2=983612&view=diff
==============================================================================
--- shindig/trunk/php/src/common/RemoteContentRequest.php (original)
+++ shindig/trunk/php/src/common/RemoteContentRequest.php Mon Aug  9 12:29:58 2010
@@ -382,6 +382,33 @@ class RemoteContentRequest {
   }
 }
 
+
+/**
+ * transforms a possible relative url to a absolute url from the gadget xml root
+ * @param string $url
+ * @param string $gadgetUrl
+ * @return mixed url or false
+ */
+public static function transformRelativeUrl($url, $gadgetUrl)
+{
+  $parsedUri = parse_url($url);
+  if (empty($parsedUri['host'])) {
+    // relative path's in the locale spec uri
+    // check against valid chars so that we can make sure that the given
+    // relative url is valid and does not try to fetch files outside of
+    // gadget scope (e.g. /../../../usr/bin... )
+    $pattern = '%^(([a-zA-Z0-9\-_](?<!\.)){1,2}([a-zA-Z0-9\.\-_](?<!\.\.))*/?)+$%';
+    if (preg_match($pattern, $url)) {
+      $gadgetUrl = substr($gadgetUrl, 0, strrpos($gadgetUrl, '/') + 1);
+      $url = $gadgetUrl . str_replace('..', '', $url);
+    } else {
+      return false;
+    }
+  }
+  return $url;
+}
+
+
 /**
  * Bag of options for making a request.
  *

Modified: shindig/trunk/php/src/common/sample/BasicBlobCrypter.php
URL: http://svn.apache.org/viewvc/shindig/trunk/php/src/common/sample/BasicBlobCrypter.php?rev=983612&r1=983611&r2=983612&view=diff
==============================================================================
--- shindig/trunk/php/src/common/sample/BasicBlobCrypter.php (original)
+++ shindig/trunk/php/src/common/sample/BasicBlobCrypter.php Mon Aug  9 12:29:58 2010
@@ -30,8 +30,8 @@ class BasicBlobCrypter extends BlobCrypt
 
 
   // Labels for key derivation
-  private $CIPHER_KEY_LABEL = 0;
-  private $HMAC_KEY_LABEL = 1;
+  protected $CIPHER_KEY_LABEL = 0;
+  protected $HMAC_KEY_LABEL = 1;
 
   /** Key used for time stamp (in seconds) of data */
   public $TIMESTAMP_KEY = "t";
@@ -40,9 +40,9 @@ class BasicBlobCrypter extends BlobCrypt
   public $MASTER_KEY_MIN_LEN = 16;
 
   /** allow three minutes for clock skew */
-  private $CLOCK_SKEW_ALLOWANCE = 180;
+  protected $CLOCK_SKEW_ALLOWANCE = 180;
 
-  private $UTF8 = "UTF-8";
+  protected $UTF8 = "UTF-8";
 
   protected $cipherKey;
   protected $hmacKey;
@@ -69,7 +69,7 @@ class BasicBlobCrypter extends BlobCrypt
     return $b64;
   }
 
-  private function serializeAndTimestamp(Array $in) {
+  protected function serializeAndTimestamp(Array $in) {
     $encoded = "";
     foreach ($in as $key => $val) {
       $encoded .= urlencode($key) . "=" . urlencode($val) . "&";
@@ -119,9 +119,9 @@ class BasicBlobCrypter extends BlobCrypt
    *
    * Parses the security token
    */
-  private function parseToken($stringToken) {
+  protected function parseToken($stringToken) {
     $data = explode(":", $stringToken);
-	$url_number = count($data)-6;
+       $url_number = count($data)-6;
 
 	//get array elements conrresponding to broken url - http://host:port/gadget.xml -> ["http","//host","port/gadget.xml"]
 	$url_array = array_slice($data,4,$url_number) ;
@@ -130,13 +130,13 @@ class BasicBlobCrypter extends BlobCrypt
     return $data;
   }
 
-  private function deserialize($plain) {
+  protected function deserialize($plain) {
     $map = array();
     parse_str($plain, $map);
     return $map;
   }
 
-  private function checkTimestamp(Array $out, $maxAge) {
+  protected function checkTimestamp(Array $out, $maxAge) {
     $minTime = (int)$out[$this->TIMESTAMP_KEY] - $this->CLOCK_SKEW_ALLOWANCE;
     $maxTime = (int)$out[$this->TIMESTAMP_KEY] + $maxAge + $this->CLOCK_SKEW_ALLOWANCE;
     $now = time();

Modified: shindig/trunk/php/src/common/sample/BasicSecurityToken.php
URL: http://svn.apache.org/viewvc/shindig/trunk/php/src/common/sample/BasicSecurityToken.php?rev=983612&r1=983611&r2=983612&view=diff
==============================================================================
--- shindig/trunk/php/src/common/sample/BasicSecurityToken.php (original)
+++ shindig/trunk/php/src/common/sample/BasicSecurityToken.php Mon Aug  9 12:29:58 2010
@@ -24,10 +24,10 @@
  */
 class BasicSecurityToken extends SecurityToken {
   /** serialized form of the token */
-  private $token;
+  protected $token;
 
   /** data from the token */
-  private $tokenData;
+  protected $tokenData;
 
   /** tool to use for signing and encrypting the token */
   protected $crypter;
@@ -40,7 +40,7 @@ class BasicSecurityToken extends Securit
   private $MODULE_KEY = "m";
   private $CONTAINER_KEY = "c";
 
-  private $authenticationMode;
+  protected $authenticationMode;
 
   /**
    * {@inheritDoc}

Modified: shindig/trunk/php/src/gadgets/GadgetContext.php
URL: http://svn.apache.org/viewvc/shindig/trunk/php/src/gadgets/GadgetContext.php?rev=983612&r1=983611&r2=983612&view=diff
==============================================================================
--- shindig/trunk/php/src/gadgets/GadgetContext.php (original)
+++ shindig/trunk/php/src/gadgets/GadgetContext.php Mon Aug  9 12:29:58 2010
@@ -55,11 +55,11 @@ class GadgetContext {
     //NOTE All classes are initialized when called (aka lazy loading) because we don't need all of them in every situation
   }
 
-  private function getRefreshIntervalParam() {
+  protected function getRefreshIntervalParam() {
     return isset($_GET['refresh']) ? $_GET['refresh'] : Config::get('default_refresh_interval');
   }
 
-  private function getContainerParam() {
+  protected function getContainerParam() {
     $container = 'default';
     if (! empty($_GET['container'])) {
       $container = $_GET['container'];
@@ -74,16 +74,16 @@ class GadgetContext {
     return $container;
   }
 
-  private function getIgnoreCacheParam() {
+  protected function getIgnoreCacheParam() {
     // Support both the old Orkut style &bpc and new standard style &nocache= params
     return (isset($_GET['nocache']) && intval($_GET['nocache']) == 1) || (isset($_GET['bpc']) && intval($_GET['bpc']) == 1);
   }
 
-  private function getForcedJsLibsParam() {
+  protected function getForcedJsLibsParam() {
     return isset($_GET['libs']) ? trim($_GET['libs']) : null;
   }
 
-  private function getUrlParam() {
+  protected function getUrlParam() {
     if (! empty($_GET['url'])) {
       return $_GET['url'];
     } elseif (! empty($_POST['url'])) {
@@ -92,15 +92,15 @@ class GadgetContext {
     return null;
   }
 
-  private function getModuleIdParam() {
+  protected function getModuleIdParam() {
     return isset($_GET['mid']) && is_numeric($_GET['mid']) ? intval($_GET['mid']) : 0;
   }
 
-  private function getViewParam() {
+  protected function getViewParam() {
     return ! empty($_GET['view']) ? $_GET['view'] : self::DEFAULT_VIEW;
   }
 
-  private function instanceBlacklist() {
+  protected function instanceBlacklist() {
     $blackListClass = Config::get('blacklist_class');
     if (! empty($blackListClass)) {
       return new $blackListClass();
@@ -109,12 +109,12 @@ class GadgetContext {
     }
   }
 
-  private function instanceHttpFetcher() {
+  protected function instanceHttpFetcher() {
     $remoteContent = Config::get('remote_content');
     return new $remoteContent();
   }
 
-  private function instanceRegistry() {
+  protected function instanceRegistry() {
     // feature parsing is very resource intensive so by caching the result this saves upto 30% of the processing time
     $featureCache = Cache::createCache(Config::get('feature_cache'), 'FeatureCache');
     $key = md5(implode(',', Config::get('features_path')));
@@ -125,14 +125,14 @@ class GadgetContext {
     return $registry;
   }
 
-  private function instanceLocale() {
+  protected function instanceLocale() {
     // Get language and country params, try the GET params first, if their not set try the POST, else use 'all' as default
     $language = ! empty($_GET['lang']) ? $_GET['lang'] : (! empty($_POST['lang']) ? $_POST['lang'] : 'all');
     $country = ! empty($_GET['country']) ? $_GET['country'] : (! empty($_POST['country']) ? $_POST['country'] : 'all');
     return array('lang' => strtolower($language), 'country' => strtoupper($country));
   }
 
-  private function instanceContainerConfig() {
+  protected function instanceContainerConfig() {
     return new ContainerConfig(Config::get('container_path'));
   }
 

Modified: shindig/trunk/php/src/gadgets/GadgetFactory.php
URL: http://svn.apache.org/viewvc/shindig/trunk/php/src/gadgets/GadgetFactory.php?rev=983612&r1=983611&r2=983612&view=diff
==============================================================================
--- shindig/trunk/php/src/gadgets/GadgetFactory.php (original)
+++ shindig/trunk/php/src/gadgets/GadgetFactory.php Mon Aug  9 12:29:58 2010
@@ -28,8 +28,8 @@ class GadgetFactory {
   /**
    * @var GadgetContext
    */
-  private $context;
-  private $token;
+  protected $context;
+  protected $token;
 
   public function __construct(GadgetContext $context, $token) {
     $this->context = $context;
@@ -48,9 +48,11 @@ class GadgetFactory {
     }
     // Fetch the gadget's content and create a GadgetSpec
     $gadgetContent = $this->fetchGadget($gadgetUrl);
-    $gadgetSpecParser = new GadgetSpecParser();
-    $gadgetSpec = $gadgetSpecParser->parse($gadgetContent);
-    $gadget = new Gadget($gadgetSpec, $this->context);
+    $gadgetSpecParserClass = Config::get('gadget_spec_parser');
+    $gadgetSpecParser = new $gadgetSpecParserClass();
+    $gadgetSpec = $gadgetSpecParser->parse($gadgetContent, $this->context);
+    $gadgetClass = Config::get('gadget_class');
+    $gadget = new $gadgetClass($gadgetSpec, $this->context);
 
     // Process the gadget: fetching remote resources, processing & applying the correct translations, user prefs and feature resolving
     $this->fetchResources($gadget);
@@ -68,7 +70,7 @@ class GadgetFactory {
    *
    * @param Gadget $gadget
    */
-  private function parseFeatures(Gadget &$gadget) {
+  protected function parseFeatures(Gadget &$gadget) {
     $found = $missing = array();
     if (! $this->context->getRegistry()->resolveFeatures(
         array_merge($gadget->gadgetSpec->requiredFeatures, $gadget->gadgetSpec->optionalFeatures),
@@ -93,7 +95,7 @@ class GadgetFactory {
    * Applies the substitutions to the complex types (preloads, user prefs, etc). Simple
    * types (author, title, etc) are translated on the fly in the gadget's getFoo() functions
    */
-  private function applySubstitutions(Gadget &$gadget) {
+  protected function applySubstitutions(Gadget &$gadget) {
     // Apply the substitutions to the UserPrefs
     foreach ($gadget->gadgetSpec->userPrefs as $key => $pref) {
       $gadget->gadgetSpec->userPrefs[$key]['name'] = $gadget->substitutions->substitute($pref['name']);
@@ -118,8 +120,9 @@ class GadgetFactory {
   /**
    * Seeds the substitutions class with the user prefs, messages, bidi and module id
    */
-  private function addSubstitutions(Gadget &$gadget) {
-    $gadget->substitutions = new Substitutions();
+  protected function addSubstitutions(Gadget &$gadget) {
+    $substiutionClass = Config::get('substitution_class');
+    $gadget->substitutions = new $substiutionClass();
     if ($this->token) {
       $gadget->substitutions->addSubstitution('MODULE', "ID", $this->token->getModuleId());
     } else {
@@ -142,7 +145,7 @@ class GadgetFactory {
    *
    * @param Gadget $gadget
    */
-  private function parseUserPrefs(Gadget &$gadget) {
+  protected function parseUserPrefs(Gadget &$gadget) {
     foreach ($gadget->gadgetSpec->userPrefs as $key => $pref) {
       $queryKey = 'up_' . $pref['name'];
       $gadget->gadgetSpec->userPrefs[$key]['value'] = isset($_GET[$queryKey]) ? trim(urldecode($_GET[$queryKey])) : $pref['defaultValue'];
@@ -158,7 +161,7 @@ class GadgetFactory {
    *
    * @param Gadget $gadget
    */
-  private function mergeLocales(Gadget $gadget) {
+  protected function mergeLocales(Gadget $gadget) {
     if (count($gadget->gadgetSpec->locales)) {
       $contextLocale = $this->context->getLocale();
       $locales = $gadget->gadgetSpec->locales;
@@ -191,34 +194,24 @@ class GadgetFactory {
    * @param Gadget $gadget
    * @param GadgetContext $context
    */
-  private function fetchResources(Gadget &$gadget) {
+  protected function fetchResources(Gadget &$gadget) {
     $contextLocale = $this->context->getLocale();
     $unsignedRequests = $signedRequests = array();
-    foreach ($gadget->getLocales() as $key => $locale) {
+    foreach ($gadget->gadgetSpec->locales as $key => $locale) {
       // Only fetch the locales that match the current context's language and country
       if (($locale['country'] == 'all' && $locale['lang'] == 'all') || ($locale['lang'] == $contextLocale['lang'] && $locale['country'] == 'all') || ($locale['lang'] == $contextLocale['lang'] && $locale['country'] == $contextLocale['country'])) {
-         $parsedUri = parse_url($locale['messages']);
-         if (empty($parsedUri['host'])) {
-           // relative path's in the locale spec uri
-           // check against valid chars so that we can make sure that the given
-           // relative url is valid and does not try to fetch files outside of
-           // gadget scope (e.g. /../../../usr/bin... )
-           $pattern = '%^(([a-zA-Z0-9\-_](?<!\.)){1,2}([a-zA-Z0-9\.\-_](?<!\.\.))*/?)+$%';
-           if (preg_match($pattern, $locale['messages'])){
-             $gadgetUrl = $this->context->getUrl();
-             $gadgetUrl = substr($gadgetUrl, 0, strrpos($gadgetUrl, '/') + 1);
-             $locale['messages'] = $gadgetUrl . str_replace('..', '', $locale['messages']);
-           } else {
+        if (! empty($locale['messages'])) {
+          $transformedUrl = RemoteContentRequest::transformRelativeUrl($locale['messages'], $this->context->getUrl());
+          if (! $transformedUrl) {
              // remove any locales that are not applicable to this context
              unset($gadget->gadgetSpec->locales[$key]);
              continue;
+          } else {
+            $gadget->gadgetSpec->locales[$key]['messages'] = $transformedUrl;
            }
-         }
-
-        if (! empty($locale['messages'])) {
           // locale matches the current context, add it to the requests queue
-          $request = new RemoteContentRequest($locale['messages']);
-          $request->createRemoteContentRequestWithUri($locale['messages']);
+          $request = new RemoteContentRequest($gadget->gadgetSpec->locales[$key]['messages'] );
+          $request->createRemoteContentRequestWithUri($gadget->gadgetSpec->locales[$key]['messages'] );
           $request->getOptions()->ignoreCache = $this->context->getIgnoreCache();
           $unsignedRequests[] = $request;
         }
@@ -257,9 +250,15 @@ class GadgetFactory {
       }
       // Add template libraries to the request queue
       if ($gadget->gadgetSpec->templatesRequireLibraries) {
-        foreach ($gadget->gadgetSpec->templatesRequireLibraries as $libraryUrl) {
-        	$request = new RemoteContentRequest($libraryUrl);
-          $request->createRemoteContentRequestWithUri($libraryUrl);
+        foreach ($gadget->gadgetSpec->templatesRequireLibraries as $key => $libraryUrl) {
+               $request = new RemoteContentRequest($libraryUrl);
+          $transformedUrl = RemoteContentRequest::transformRelativeUrl($libraryUrl, $this->context->getUrl());
+          if (! $transformedUrl) {
+            continue;
+          } else {
+            $gadget->gadgetSpec->templatesRequireLibraries[$key] = $transformedUrl;
+          }
+          $request->createRemoteContentRequestWithUri($gadget->gadgetSpec->templatesRequireLibraries[$key]);
           $request->getOptions()->ignoreCache = $this->context->getIgnoreCache();
           $unsignedRequests[] = $request;
         }
@@ -276,6 +275,7 @@ class GadgetFactory {
             'rc' => $response->getHttpCode());
       }
     }
+
     // Perform the signed requests
     if (count($signedRequests)) {
       $signingFetcherFactory = new SigningFetcherFactory(Config::get("private_key_file"));
@@ -321,7 +321,7 @@ class GadgetFactory {
    * @param string $messageBundleData
    * @return array (MessageBundle)
    */
-  private function parseMessageBundle($messageBundleData) {
+  protected function parseMessageBundle($messageBundleData) {
     libxml_use_internal_errors(true);
     $doc = new DOMDocument();
     if (! $doc->loadXML($messageBundleData, LIBXML_NOCDATA)) {

Modified: shindig/trunk/php/src/gadgets/GadgetSpecParser.php
URL: http://svn.apache.org/viewvc/shindig/trunk/php/src/gadgets/GadgetSpecParser.php?rev=983612&r1=983611&r2=983612&view=diff
==============================================================================
--- shindig/trunk/php/src/gadgets/GadgetSpecParser.php (original)
+++ shindig/trunk/php/src/gadgets/GadgetSpecParser.php Mon Aug  9 12:29:58 2010
@@ -27,12 +27,14 @@ class GadgetSpecException extends Except
  */
 class GadgetSpecParser {
 
+  protected $context;
+
   /**
    * Parses the $xmlContent into a Gadget class
    *
    * @param string $xmlContent
    */
-  public function parse($xmlContent) {
+  public function parse($xmlContent, GadgetContext $context) {
     libxml_use_internal_errors(true);
     $doc = new DOMDocument();
     if (! $doc->loadXML($xmlContent, LIBXML_NOCDATA)) {
@@ -41,7 +43,8 @@ class GadgetSpecParser {
     //TODO: we could do a XSD schema validation here, but both the schema and most of the gadgets seem to have some form of schema
     // violatons, so it's not really practical yet (and slow)
     // $doc->schemaValidate('gadget.xsd');
-    $gadget = new GadgetSpec();
+    $gadgetSpecClass = Config::get('gadget_spec_class');
+    $gadget = new $gadgetSpecClass();
     $gadget->checksum = md5($xmlContent);
     $this->parseModulePrefs($doc, $gadget);
     $this->parseUserPrefs($doc, $gadget);

Modified: shindig/trunk/php/src/gadgets/MetadataHandler.php
URL: http://svn.apache.org/viewvc/shindig/trunk/php/src/gadgets/MetadataHandler.php?rev=983612&r1=983611&r2=983612&view=diff
==============================================================================
--- shindig/trunk/php/src/gadgets/MetadataHandler.php (original)
+++ shindig/trunk/php/src/gadgets/MetadataHandler.php Mon Aug  9 12:29:58 2010
@@ -28,7 +28,8 @@ class MetadataHandler {
         $gadgetModuleId = $gadget->moduleId;
         $context = new MetadataGadgetContext($requests->context, $gadgetUrl);
         $token = $this->getSecurityToken();
-        $gadgetServer = new GadgetFactory($context, $token);
+        $factoryClass = Config::get('gadget_factory_class');
+        $gadgetServer = new $factoryClass($context, $token);
         $gadget = $gadgetServer->createGadget($gadgetUrl);
         $response[] = $this->makeResponse($gadget, $gadgetModuleId, $gadgetUrl, $context);
       } catch (Exception $e) {

Modified: shindig/trunk/php/src/gadgets/ProxyHandler.php
URL: http://svn.apache.org/viewvc/shindig/trunk/php/src/gadgets/ProxyHandler.php?rev=983612&r1=983611&r2=983612&view=diff
==============================================================================
--- shindig/trunk/php/src/gadgets/ProxyHandler.php (original)
+++ shindig/trunk/php/src/gadgets/ProxyHandler.php Mon Aug  9 12:29:58 2010
@@ -137,7 +137,8 @@ class ProxyHandler extends ProxyBase {
     // make sure our context returns the gadget url and not the proxied document url
     $this->context->setUrl($gadgetUrl);
     // and create & return the gadget
-    $gadgetSpecFactory = new GadgetFactory($this->context, null);
+    $factoryClass = Config::get('gadget_factory_class');
+    $gadgetSpecFactory = new $factoryClass($this->context, null);
     $gadget = $gadgetSpecFactory->createGadget();
     return $gadget;
   }

Modified: shindig/trunk/php/src/gadgets/Substitutions.php
URL: http://svn.apache.org/viewvc/shindig/trunk/php/src/gadgets/Substitutions.php?rev=983612&r1=983611&r2=983612&view=diff
==============================================================================
--- shindig/trunk/php/src/gadgets/Substitutions.php (original)
+++ shindig/trunk/php/src/gadgets/Substitutions.php Mon Aug  9 12:29:58 2010
@@ -19,9 +19,9 @@
  */
 
 class Substitutions {
-  private $types = array('MESSAGE' => 'MSG', 'BIDI' => 'BIDI', 'USER_PREF' => 'UP', 'MODULE' => 'MODULE');
+  protected $types = array('MESSAGE' => 'MSG', 'BIDI' => 'BIDI', 'USER_PREF' => 'UP', 'MODULE' => 'MODULE');
   
-  private $substitutions = array();
+  protected $substitutions = array();
 
   public function __construct() {
     foreach ($this->types as $type) {

Modified: shindig/trunk/php/src/gadgets/sample/BasicGadgetSpecFactory.php
URL: http://svn.apache.org/viewvc/shindig/trunk/php/src/gadgets/sample/BasicGadgetSpecFactory.php?rev=983612&r1=983611&r2=983612&view=diff
==============================================================================
--- shindig/trunk/php/src/gadgets/sample/BasicGadgetSpecFactory.php (original)
+++ shindig/trunk/php/src/gadgets/sample/BasicGadgetSpecFactory.php Mon Aug  9 12:29:58 2010
@@ -23,8 +23,10 @@
  */
 class BasicGadgetSpecFactory {
   private $cache;
+  private $context;
 
   public function getGadgetSpec(GadgetContext $context) {
+    $this->context = $context;
     return $this->getGadgetSpecUri($context->getUrl(), $context->getIgnoreCache());
   }
 
@@ -44,10 +46,10 @@ class BasicGadgetSpecFactory {
     $remoteContentRequest->getOptions()->ignoreCache = $ignoreCache;
     $remoteContent = new BasicRemoteContent();
     $spec = $remoteContent->fetch($remoteContentRequest);
-    
-    $gadgetSpecParser = new GadgetSpecParser();
-    $gadgetSpec = $gadgetSpecParser->parse($spec->getResponseContent());
+
+    $gadgetSpecParserClass = Config::get('gadget_spec_parser');
+    $gadgetSpecParser = new $gadgetSpecParserClass();
+    $gadgetSpec = $gadgetSpecParser->parse($spec->getResponseContent(), $this->context);
     return $gadgetSpec;
   }
-
 }

Modified: shindig/trunk/php/src/gadgets/servlet/GadgetRenderingServlet.php
URL: http://svn.apache.org/viewvc/shindig/trunk/php/src/gadgets/servlet/GadgetRenderingServlet.php?rev=983612&r1=983611&r2=983612&view=diff
==============================================================================
--- shindig/trunk/php/src/gadgets/servlet/GadgetRenderingServlet.php (original)
+++ shindig/trunk/php/src/gadgets/servlet/GadgetRenderingServlet.php Mon Aug  9 12:29:58 2010
@@ -40,14 +40,15 @@ require_once 'src/gadgets/rewrite/Gadget
 require_once 'src/gadgets/rewrite/DomRewriter.php';
 
 class GadgetRenderingServlet extends HttpServlet {
-  private $context;
+  protected $context;
 
   public function doGet() {
     try {
       if (empty($_GET['url'])) {
         throw new GadgetException("Missing required parameter: url");
       }
-      $this->context = new GadgetContext('GADGET');
+      $contextClass = Config::get('gadget_context_class');
+      $this->context = new $contextClass('GADGET');
       $gadgetSigner = Config::get('security_token_signer');
       $gadgetSigner = new $gadgetSigner();
       try {
@@ -60,7 +61,8 @@ class GadgetRenderingServlet extends Htt
           $token = '';
         }
       }
-      $gadgetSpecFactory = new GadgetFactory($this->context, $token);
+      $factoryClass = Config::get('gadget_factory_class');
+      $gadgetSpecFactory = new $factoryClass($this->context, $token);
       $gadget = $gadgetSpecFactory->createGadget();
       $this->setCachingHeaders();
       $this->renderGadget($gadget);
@@ -69,7 +71,7 @@ class GadgetRenderingServlet extends Htt
     }
   }
 
-  private function renderGadget(Gadget $gadget) {
+  protected function renderGadget(Gadget $gadget) {
     $view = $gadget->getView($this->context->getView());
     if ($view['type'] == 'URL') {
       require_once "src/gadgets/render/GadgetUrlRenderer.php";
@@ -86,7 +88,7 @@ class GadgetRenderingServlet extends Htt
     $gadgetRenderer->renderGadget($gadget, $view);
   }
 
-  private function setCachingHeaders() {
+  protected function setCachingHeaders() {
     $this->setContentType("text/html; charset=UTF-8");
     if ($this->context->getIgnoreCache()) {
       // no cache was requested, set non-caching-headers
@@ -100,7 +102,7 @@ class GadgetRenderingServlet extends Htt
     }
   }
 
-  private function showError($e) {
+  protected function showError($e) {
     header("HTTP/1.0 400 Bad Request", true, 400);
     echo "<html><body>";
     echo "<h1>Error</h1>";

Modified: shindig/trunk/php/src/gadgets/servlet/JsServlet.php
URL: http://svn.apache.org/viewvc/shindig/trunk/php/src/gadgets/servlet/JsServlet.php?rev=983612&r1=983611&r2=983612&view=diff
==============================================================================
--- shindig/trunk/php/src/gadgets/servlet/JsServlet.php (original)
+++ shindig/trunk/php/src/gadgets/servlet/JsServlet.php Mon Aug  9 12:29:58 2010
@@ -54,7 +54,8 @@ class JsServlet extends HttpServlet {
     }
     $found = array();
     $missing = array();
-    $context = new GadgetContext('GADGET');
+    $contextClass = Config::get('gadget_context_class');
+    $context = new $contextClass('GADGET');
     $registry = new GadgetFeatureRegistry(Config::get('features_path'));
     if ($registry->resolveFeatures($needed, $found, $missing)) {
       $isGadgetContext = !isset($_GET["c"]) || $_GET['c'] == 0 ? true : false;

Modified: shindig/trunk/php/src/gadgets/servlet/MakeRequestServlet.php
URL: http://svn.apache.org/viewvc/shindig/trunk/php/src/gadgets/servlet/MakeRequestServlet.php?rev=983612&r1=983611&r2=983612&view=diff
==============================================================================
--- shindig/trunk/php/src/gadgets/servlet/MakeRequestServlet.php (original)
+++ shindig/trunk/php/src/gadgets/servlet/MakeRequestServlet.php Mon Aug  9 12:29:58 2010
@@ -34,7 +34,8 @@ class MakeRequestServlet extends HttpSer
   public function doGet() {
     try {
       $this->noHeaders = true;
-      $context = new GadgetContext('GADGET');
+      $contextClass = Config::get('gadget_context_class');
+      $context = new $contextClass('GADGET');
       $makeRequestParams = MakeRequestOptions::fromCurrentRequest();
       $makeRequestHandler = new MakeRequestHandler($context);
       $makeRequestHandler->fetchJson($makeRequestParams);

Modified: shindig/trunk/php/src/gadgets/servlet/ProxyServlet.php
URL: http://svn.apache.org/viewvc/shindig/trunk/php/src/gadgets/servlet/ProxyServlet.php?rev=983612&r1=983611&r2=983612&view=diff
==============================================================================
--- shindig/trunk/php/src/gadgets/servlet/ProxyServlet.php (original)
+++ shindig/trunk/php/src/gadgets/servlet/ProxyServlet.php Mon Aug  9 12:29:58 2010
@@ -33,14 +33,16 @@ class ProxyServlet extends HttpServlet {
     try {
       // Make sure the HttpServlet doesn't overwrite our headers
       $this->noHeaders = true;
-      $context = new GadgetContext('GADGET');
+      $contextClass = Config::get('gadget_context_class');
+      $context = new $contextClass('GADGET');
       $url = (isset($_GET['url']) ? $_GET['url'] : (isset($_POST['url']) ? $_POST['url'] : false));
       $url = urldecode($url);
       if (! $url) {
         header("HTTP/1.0 400 Bad Request", true);
         echo "<html><body><h1>400 - Missing url parameter</h1></body></html>";
       }
-      $proxyHandler = new ProxyHandler($context);
+      $proxyHandlerClass = Config::get('proxy_handler');
+      $proxyHandler = new $proxyHandlerClass($context);
       $proxyHandler->fetch($url);
     } catch (Exception $e) {
       // catch all exceptions and give a 500 server error

Modified: shindig/trunk/php/src/social/service/DataRequestHandler.php
URL: http://svn.apache.org/viewvc/shindig/trunk/php/src/social/service/DataRequestHandler.php?rev=983612&r1=983611&r2=983612&view=diff
==============================================================================
--- shindig/trunk/php/src/social/service/DataRequestHandler.php (original)
+++ shindig/trunk/php/src/social/service/DataRequestHandler.php Mon Aug  9 12:29:58 2010
@@ -92,7 +92,8 @@ abstract class DataRequestHandler {
    *  @param parameters url parameters to get request type(people/activity)
    */
   public function getSupportedFields($parameters) {
-    $context = new GadgetContext('GADGET');
+    $contextClass = Config::get('gadget_context_class');
+    $context = new $contextClass('GADGET');
     $container = $context->getContainer();
     $containerConfig = new ContainerConfig(Config::get('container_path'));
     $config = $containerConfig->getConfig($container, 'gadgets.features');

Modified: shindig/trunk/php/src/social/service/HttpHandler.php
URL: http://svn.apache.org/viewvc/shindig/trunk/php/src/social/service/HttpHandler.php?rev=983612&r1=983611&r2=983612&view=diff
==============================================================================
--- shindig/trunk/php/src/social/service/HttpHandler.php (original)
+++ shindig/trunk/php/src/social/service/HttpHandler.php Mon Aug  9 12:29:58 2010
@@ -49,7 +49,8 @@ class HttpHandler extends DataRequestHan
       // complain.  
       $options = MakeRequestOptions::fromRpcRequestItem($requestItem);
       $makeRequest = new MakeRequest();
-      $context = new GadgetContext('GADGET');
+      $contextClass = Config::get('gadget_context_class');
+      $context = new $contextClass('GADGET');
       $response = $makeRequest->fetch($context, $options);
 
       $result = array(

Modified: shindig/trunk/php/src/social/service/PersonHandler.php
URL: http://svn.apache.org/viewvc/shindig/trunk/php/src/social/service/PersonHandler.php?rev=983612&r1=983611&r2=983612&view=diff
==============================================================================
--- shindig/trunk/php/src/social/service/PersonHandler.php (original)
+++ shindig/trunk/php/src/social/service/PersonHandler.php Mon Aug  9 12:29:58 2010
@@ -20,11 +20,11 @@
 
 class PersonHandler extends DataRequestHandler {
 
-  private static $PEOPLE_PATH = "/people/{userId}/{groupId}/{personId}";
-  private static $DEFAULT_FIELDS = array('id', 'displayName', 'gender', 'thumbnailUrl');
+  protected static $PEOPLE_PATH = "/people/{userId}/{groupId}/{personId}";
+  protected static $DEFAULT_FIELDS = array('id', 'displayName', 'gender', 'thumbnailUrl');
 
-  private static $ANONYMOUS_ID_TYPE = array('viewer', 'me');
-  private static $ANONYMOUS_VIEWER = array(
+  protected static $ANONYMOUS_ID_TYPE = array('viewer', 'me');
+  protected static $ANONYMOUS_VIEWER = array(
       'isOwner' => false,
       'isViewer' => true,
       'name' => 'anonymous_user',