Author: chabotc
Date: Mon Mar 16 11:03:14 2009
New Revision: 754873

URL: http://svn.apache.org/viewvc?rev=754873&view=rev
Log:
Update to SHINDIG-943 (add support for 0.9 limited invalidation), description 
from Pan Jie:

MakeRequest has 3 kinds of fetching remote content: 'SIGNED', 'OAUTH'
and 'NONE'. SIGNED and OAUTH contents are not cached. I refactored those
function and use BasicRemoteContent->fetch in MakeRequestHandler.
BasicRemoteContent->fetch will cache all remote content fetchings.

I want to make BasicRemoteContent the same as DefaultRequestPipeline in
Java. So all remote content request will be handled by BasicRemoteContent and
caching/invalidating seems much easier.

I added error_report(E_ALL | E_STRICT) for unittest which exposed
failures and I will fix those in next patches.


Modified:
    incubator/shindig/trunk/php/config/container.php
    incubator/shindig/trunk/php/src/common/Cache.php
    incubator/shindig/trunk/php/src/common/CacheStorage.php
    incubator/shindig/trunk/php/src/common/RemoteContent.php
    incubator/shindig/trunk/php/src/common/RemoteContentFetcher.php
    incubator/shindig/trunk/php/src/common/sample/BasicRemoteContent.php
    incubator/shindig/trunk/php/src/common/sample/CacheStorageMemcache.php
    incubator/shindig/trunk/php/src/gadgets/GadgetContext.php
    incubator/shindig/trunk/php/src/gadgets/MakeRequestHandler.php
    incubator/shindig/trunk/php/src/gadgets/ProxyBase.php
    incubator/shindig/trunk/php/src/gadgets/ProxyHandler.php
    incubator/shindig/trunk/php/src/gadgets/SigningFetcher.php
    incubator/shindig/trunk/php/src/gadgets/oauth/OAuthFetcher.php
    incubator/shindig/trunk/php/src/gadgets/oauth/OAuthFetcherFactory.php
    incubator/shindig/trunk/php/test/ShindigAllTests.php
    incubator/shindig/trunk/php/test/common/BasicRemoteContentTest.php
    incubator/shindig/trunk/php/test/common/CacheFileTest.php
    incubator/shindig/trunk/php/test/common/CacheMemcacheTest.php
    incubator/shindig/trunk/php/test/index.php

Modified: incubator/shindig/trunk/php/config/container.php
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/config/container.php?rev=754873&r1=754872&r2=754873&view=diff
==============================================================================
--- incubator/shindig/trunk/php/config/container.php (original)
+++ incubator/shindig/trunk/php/config/container.php Mon Mar 16 11:03:14 2009
@@ -117,12 +117,12 @@
   'security_token' => 'BasicSecurityToken',
   'oauth_lookup_service' => 'BasicOAuthLookupService',
 
-  // Caching back-end's to use. Shindig ships with CacheFile, CacheApc and 
CacheMemcache support
+  // 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
-  // On a production system you probably want to use CacheApc for features, 
and CacheMemcache for the data cache
-  'data_cache' => 'CacheFile',
-  'feature_cache' => 'CacheFile',
+  // On a production system you probably want to use CacheStorageApc for 
features, and CacheStorageMemcache for the data cache
+  'data_cache' => 'CacheStorageFile',
+  'feature_cache' => 'CacheStorageFile',
 
   // RESTful API data service classes to use
   // See http://code.google.com/p/partuza/source/browse/#svn/trunk/Shindig for 
a MySql powered example
@@ -141,7 +141,7 @@
   'cache_host' => 'localhost',
   'cache_port' => 11211,
   'cache_time' => 24 * 60 * 60,
-  // If you use CacheFile as caching backend, this is the directory where it 
stores the temporary files
+  // If you use CacheStorageFile as caching backend, this is the directory 
where it stores the temporary files
   'cache_root' => '/tmp/shindig',
 
   // connection timeout setting for all curl requests, set this time something 
low if you want errors reported

Modified: incubator/shindig/trunk/php/src/common/Cache.php
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/common/Cache.php?rev=754873&r1=754872&r2=754873&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/common/Cache.php (original)
+++ incubator/shindig/trunk/php/src/common/Cache.php Mon Mar 16 11:03:14 2009
@@ -33,22 +33,18 @@
    * @var RequestTime
    */
   private $time = null;
+  
+  /**
+   * @var CacheStorage
+   */
   private $storage = null;
 
-  static public function createCache($type, $name, $time = null) {
-    return new Cache($type, $name, $time);
+  static public function createCache($cacheClass, $name, RequestTime $time = 
null) {
+    return new Cache($cacheClass, $name, $time);
   }
 
-  private function __construct($type, $name, $time) {
-    if ($type == 'CacheFile') {
-      $this->storage = new CacheStorageFile($name);
-    } else if ($type == 'CacheApc') {
-      $this->storage = new CacheStorageApc($name);
-    } else if ($type == 'CacheMemcache') {
-      $this->storage = new CacheStorageMemcache($name);
-    } else {
-      throw CacheException('undefined cache storage');
-    }
+  private function __construct($cacheClass, $name, RequestTime $time = null) {
+    $this->storage = new $cacheClass($name);
     if ($time == null) {
       $this->time = new RequestTime();
     } else {
@@ -77,7 +73,7 @@
     $data = $this->storage->fetch($key);
     if ($data) {
       $data = unserialize($data);
-      return array('found' => true, 'time' => $data['time'], 'ttl' => 
$data['ttl'], 'valid' => $data['valid'], 'data' => $data['data']);
+      return array_merge(array('found' => true), $data);
     }
     return array('found' => false);
   }

Modified: incubator/shindig/trunk/php/src/common/CacheStorage.php
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/common/CacheStorage.php?rev=754873&r1=754872&r2=754873&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/common/CacheStorage.php (original)
+++ incubator/shindig/trunk/php/src/common/CacheStorage.php Mon Mar 16 11:03:14 
2009
@@ -37,8 +37,8 @@
     do {
       usleep(100);
       $cnt ++;
-    } while ($cnt <= $tries && $this->isLocked());
-    if ($this->isLocked()) {
+    } while ($cnt <= $tries && $this->isLocked($key));
+    if ($this->isLocked($key)) {
       $this->unlock($key);
     }
   }

Modified: incubator/shindig/trunk/php/src/common/RemoteContent.php
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/common/RemoteContent.php?rev=754873&r1=754872&r2=754873&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/common/RemoteContent.php (original)
+++ incubator/shindig/trunk/php/src/common/RemoteContent.php Mon Mar 16 
11:03:14 2009
@@ -32,7 +32,7 @@
 
 abstract class RemoteContent {
 
-  abstract public function fetch(RemoteContentRequest $request, $context);
+  abstract public function fetch(RemoteContentRequest $request, GadgetContext 
$context);
 
   abstract public function multiFetch(Array $requests, Array $contexts);
   

Modified: incubator/shindig/trunk/php/src/common/RemoteContentFetcher.php
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/common/RemoteContentFetcher.php?rev=754873&r1=754872&r2=754873&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/common/RemoteContentFetcher.php (original)
+++ incubator/shindig/trunk/php/src/common/RemoteContentFetcher.php Mon Mar 16 
11:03:14 2009
@@ -20,18 +20,7 @@
 
 
 abstract class RemoteContentFetcher {
-
-  protected $fetcher;
-
-  protected function setNextFetcher($fetcher = null) {
-    $this->fetcher = $fetcher;
-  }
-
   abstract public function fetchRequest(RemoteContentRequest $request);
 
   abstract public function multiFetchRequest(Array $requests);
-
-  public function getNextFetcher() {
-    return $this->fetcher;
-  }
 }
\ No newline at end of file

Modified: incubator/shindig/trunk/php/src/common/sample/BasicRemoteContent.php
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/common/sample/BasicRemoteContent.php?rev=754873&r1=754872&r2=754873&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/common/sample/BasicRemoteContent.php 
(original)
+++ incubator/shindig/trunk/php/src/common/sample/BasicRemoteContent.php Mon 
Mar 16 11:03:14 2009
@@ -19,33 +19,45 @@
  */
 
 class BasicRemoteContent extends RemoteContent {
-  private $remoteContentFetcher = null;
-
-  public function __construct($fetcher = null) {
-    if (!$fetcher) {
-      $this->remoteContentFetcher = new BasicRemoteContentFetcher();
-    } else {
-      $this->remoteContentFetcher = $fetcher;
-    }
+  /**
+   * @var BesicRemoteContentFetcher
+   */
+  private $basicFetcher = null;
+  
+  /**
+   * @var SigningFetcherFactory
+   */
+  private $signingFetcherFactory = null;
+  
+  /**
+   * @var SecurityTokenDecoder
+   */
+  private $signer = null;
+
+  public function __construct(RemoteContentFetcher $basicFetcher = null, 
$signingFetcherFactory = null, $signer = null) {
+    $this->basicFetcher = $basicFetcher ? $basicFetcher : new 
BasicRemoteContentFetcher();
+    $this->signingFetcherFactory = $signingFetcherFactory;
+    $this->signer = $signer;
   }
 
-  public function setRemoteContentFetcher($fetcher) {
-    $this->remoteContentFetcher = $fetcher;
+  public function setBasicFetcher(RemoteContentFetcher $basicFetcher) {
+    $this->basicFetcher = $basicFetcher;
   }
 
-  public function fetch(RemoteContentRequest $request, $context) {
+  public function fetch(RemoteContentRequest $request, GadgetContext $context) 
{
     $cache = Cache::createCache(Config::get('data_cache'), 'RemoteContent');
     if (!$context->getIgnoreCache() && ! $request->isPost() && ($cachedRequest 
= $cache->get($request->toHash())) !== false) {
       $request = $cachedRequest;
     } else {
-      $request = $this->remoteContentFetcher->fetchRequest($request);
+      $originalRequest = clone $request;
+      $request = $this->divertFetch($request, $context);
       if ($request->getHttpCode() != 200 && !$context->getIgnoreCache() && 
!$request->isPost()) {
         $cachedRequest = $cache->expiredGet($request->toHash());
         if ($cachedRequest['found'] == true) {
           return $cachedRequest['data'];
         }
       }
-      $this->setRequestCache($request, $cache, $context);
+      $this->setRequestCache($originalRequest, $request, $cache, $context);
     }
     return $request;
   }
@@ -63,19 +75,25 @@
       if (!$context->getIgnoreCache() && ! $request->isPost() && 
($cachedRequest = $cache->get($request->toHash())) !== false) {
         $rets[] = $cachedRequest;
       } else {
+        $originalRequest = clone $request;
         $requestsToProc[] = $request;
+        $originalRequestArray[] = $originalRequest;
       }
     }
-    $newRets = $this->remoteContentFetcher->multiFetchRequest($requestsToProc);
-    foreach ($newRets as $request) {
-      if ($request->getHttpCode() != 200 && !$context->getIgnoreCache() && 
!$request->isPost()) {
-        $cachedRequest = $cache->expiredGet($request->toHash());
-        if ($cachedRequest['found'] == true) {
-          $rets[] = $cachedRequest['data'];
+    
+    if ($requestsToProc) {
+      $newRets = $this->basicFetcher->multiFetchRequest($requestsToProc);
+      foreach ($newRets as $request) {
+        list(, $originalRequest) = each($originalRequestArray);
+        if ($request->getHttpCode() != 200 && !$context->getIgnoreCache() && 
!$request->isPost()) {
+          $cachedRequest = $cache->expiredGet($request->toHash());
+          if ($cachedRequest['found'] == true) {
+            $rets[] = $cachedRequest['data'];
+          }
+        } else {
+          $this->setRequestCache($originalRequest, $request, $cache, $context);
+          $rets[] = $request;
         }
-      } else {
-        $this->setRequestCache($request, $cache, $context);
-        $rets[] = $request;
       }
     }
     return $rets;
@@ -86,7 +104,7 @@
     $cache->invalidate($request->toHash());
   }
 
-  private function setRequestCache(RemoteContentRequest $request, Cache 
$cache, GadgetContext $context) {
+  private function setRequestCache(RemoteContentRequest $originalRequest, 
RemoteContentRequest $request, Cache $cache, GadgetContext $context) {
     if (! $request->isPost() && ! $context->getIgnoreCache()) {
       $ttl = Config::get('cache_time');
       if ($request->getHttpCode() == '200') {
@@ -116,7 +134,31 @@
       } else {
         $ttl = 5 * 60; // cache errors for 5 minutes, takes the denial of 
service attack type behaviour out of having an error :)
       }
-      $cache->set($request->toHash(), $request, $ttl);
+      $cache->set($originalRequest->toHash(), $request, $ttl);
+    }
+  }
+  
+  private function divertFetch(RemoteContentRequest $request, GadgetContext 
$context) {
+    $authz = isset($_GET['authz']) ? $_GET['authz'] : (isset($_POST['authz']) 
? $_POST['authz'] : '');
+    switch (strtoupper($authz)) {
+      case 'SIGNED':
+        $token = $context->extractAndValidateToken($this->signer);
+        $fetcher = 
$this->signingFetcherFactory->getSigningFetcher($this->basicFetcher, $token);
+        $url = $request->getUrl();
+        $method = $request->isPost() ? 'POST' : 'GET'; 
+        return $fetcher->fetch($url, $method);
+      case 'OAUTH':
+        $params = new OAuthRequestParams();
+        $token = $context->extractAndValidateToken($this->signer);
+        $fetcher = 
$this->signingFetcherFactory->getSigningFetcher($this->basicFetcher, $token);
+        $oAuthFetcherFactory = new OAuthFetcherFactory($fetcher);
+        $oauthFetcher = $oAuthFetcherFactory->getOAuthFetcher($fetcher, 
$token, $params);
+        $url = $request->getUrl();
+        $request = new RemoteContentRequest($url);
+        $request->createRemoteContentRequestWithUri($url);
+        return $oauthFetcher->fetch($request);
+      default:
+        return $this->basicFetcher->fetchRequest($request);
     }
   }
 }

Modified: incubator/shindig/trunk/php/src/common/sample/CacheStorageMemcache.php
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/common/sample/CacheStorageMemcache.php?rev=754873&r1=754872&r2=754873&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/common/sample/CacheStorageMemcache.php 
(original)
+++ incubator/shindig/trunk/php/src/common/sample/CacheStorageMemcache.php Mon 
Mar 16 11:03:14 2009
@@ -19,6 +19,9 @@
  */
 
 class CacheStorageMemcache extends CacheStorage {
+  /**
+   * @var Memcache
+   */
   private static $memcache = null;
 
   private $prefix = null;

Modified: incubator/shindig/trunk/php/src/gadgets/GadgetContext.php
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/GadgetContext.php?rev=754873&r1=754872&r2=754873&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/GadgetContext.php (original)
+++ incubator/shindig/trunk/php/src/gadgets/GadgetContext.php Mon Mar 16 
11:03:14 2009
@@ -262,7 +262,7 @@
    * Extracts the 'st' token from the GET or POST params and calls the
    * signer to validate the token
    *
-   * @param GadgetSigner $signer the signer to use (configured in config.php)
+   * @param SecurityTokenDecoder $signer the signer to use (configured in 
config.php)
    * @return string the token to use in the signed url
    */
   public function extractAndValidateToken($signer) {

Modified: incubator/shindig/trunk/php/src/gadgets/MakeRequestHandler.php
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/MakeRequestHandler.php?rev=754873&r1=754872&r2=754873&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/MakeRequestHandler.php (original)
+++ incubator/shindig/trunk/php/src/gadgets/MakeRequestHandler.php Mon Mar 16 
11:03:14 2009
@@ -25,11 +25,14 @@
  * Handles the gadget.io.makeRequest requests
  */
 class MakeRequestHandler extends ProxyBase {
-  public $signingFetcher;
-
-  public function __construct($context, $signingFetcher) {
+  /**
+   * @var SingingFetcherFactory
+   */
+  private $signingFetcherFactory;
+  
+  public function __construct($context, $signingFetcherFactory) {
     $this->context = $context;
-    $this->signingFetcher = $signingFetcher;
+    $this->signingFetcherFactory = $signingFetcherFactory;
   }
 
   /**
@@ -78,26 +81,14 @@
    *
    * @param string $url
    * @param string $method
-   * @param SingingFetcher $signer
+   * @param SecurityTokenDecoder $signer
    * @return RemoteContentRequest
    */
   private function fetchContentDivert($url, $method, $signer) {
-    $authz = isset($_GET['authz']) ? $_GET['authz'] : (isset($_POST['authz']) 
? $_POST['authz'] : '');
-    $token = $this->context->extractAndValidateToken($signer);
-    switch (strtoupper($authz)) {
-      case 'SIGNED':
-        $fetcher = $this->signingFetcher->getSigningFetcher(new 
BasicRemoteContentFetcher(), $token);
-        return $fetcher->fetch($url, $method);
-      case 'OAUTH':
-        $params = new OAuthRequestParams();
-        $fetcher = $this->signingFetcher->getSigningFetcher(new 
BasicRemoteContentFetcher(), $token);
-        $oAuthFetcherFactory = new OAuthFetcherFactory($fetcher);
-        $this->oauthFetcher = $oAuthFetcherFactory->getOAuthFetcher($fetcher, 
$token, $params);
-        $request = new RemoteContentRequest($url);
-        $request->createRemoteContentRequestWithUri($url);
-        return $this->oauthFetcher->fetch($request);
-    }
-    return $this->fetchContent($url, $method);
+    $basicFetcher = new BasicRemoteContentFetcher();
+    $basicRemoteContent = new BasicRemoteContent($basicFetcher, 
$this->signingFetcherFactory, $signer);
+    $request = $this->buildRequest($url, $method);
+    return $basicRemoteContent->fetch($request, $this->context);
   }
 
   /**

Modified: incubator/shindig/trunk/php/src/gadgets/ProxyBase.php
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/ProxyBase.php?rev=754873&r1=754872&r2=754873&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/ProxyBase.php (original)
+++ incubator/shindig/trunk/php/src/gadgets/ProxyBase.php Mon Mar 16 11:03:14 
2009
@@ -22,7 +22,11 @@
  * This class contains the shared methods between the Proxy and makeRequest 
handlers
  */
 class ProxyBase {
+  /**
+   * @var GadgetContext
+   */
   public $context;
+  
   protected $disallowedHeaders = array('User-Agent', 'Keep-Alive', 'Host', 
'Accept-Encoding', 'Set-Cookie', 'Content-Length', 'Content-Encoding', 'ETag', 
'Last-Modified', 'Accept-Ranges', 'Vary', 'Expires', 'Date', 'Pragma', 
'Cache-Control', 'Transfer-Encoding', 'If-Modified-Since');
 
   public function __construct($context) {
@@ -35,7 +39,7 @@
    * @param string $url the url to fetch
    * @return the filled in request (RemoteContentRequest)
    */
-  protected function fetchContent($url, $method = 'GET') {
+  protected function buildRequest($url, $method = 'GET') {
     // Check the protocol requested - curl doesn't really support file://
     // requests but the 'error' should be handled properly
     $protocolSplit = explode('://', $url, 2);
@@ -71,10 +75,8 @@
       // even if postData is an empty string, it will still post (since 
RemoteContentRquest checks if its false)
       // so the request to POST is still honored
       $request = new RemoteContentRequest($url, null, $postData);
-      $request = $this->context->getHttpFetcher()->fetch($request, 
$this->context);
     } else {
       $request = new RemoteContentRequest($url);
-      $request = $this->context->getHttpFetcher()->fetch($request, 
$this->context);
     }
     return $request;
   }

Modified: incubator/shindig/trunk/php/src/gadgets/ProxyHandler.php
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/ProxyHandler.php?rev=754873&r1=754872&r2=754873&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/ProxyHandler.php (original)
+++ incubator/shindig/trunk/php/src/gadgets/ProxyHandler.php Mon Mar 16 
11:03:14 2009
@@ -34,7 +34,8 @@
    */
   public function fetch($url) {
     $url = $this->validateUrl($url);
-    $result = $this->fetchContent($url, 'GET');
+    $request = $this->buildRequest($url, 'GET');
+    $result = $this->context->getHttpFetcher()->fetch($request, 
$this->context);
     $httpCode = (int)$result->getHttpCode();
     $isShockwaveFlash = false;
     foreach ($result->getResponseHeaders() as $key => $val) {

Modified: incubator/shindig/trunk/php/src/gadgets/SigningFetcher.php
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/SigningFetcher.php?rev=754873&r1=754872&r2=754873&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/SigningFetcher.php (original)
+++ incubator/shindig/trunk/php/src/gadgets/SigningFetcher.php Mon Mar 16 
11:03:14 2009
@@ -51,6 +51,11 @@
    * The name of the key, included in the fetch to help with key rotation.
    */
   protected $keyName;
+  
+  /**
+   * @var RemoteContentFetcher
+   */
+  private $fetcher;
 
   /**
    * Constructor based on signing with the given PrivateKey object.
@@ -59,8 +64,8 @@
    * @param keyName name of the key to include in the request
    * @param privateKey the key to use for the signing
    */
-  public static function makeFromPrivateKey($next, $authToken, $keyName, 
$privateKey) {
-    return new SigningFetcher($next, $authToken, $keyName, $privateKey);
+  public static function makeFromPrivateKey($fetcher, $authToken, $keyName, 
$privateKey) {
+    return new SigningFetcher($fetcher, $authToken, $keyName, $privateKey);
   }
 
   /**
@@ -70,8 +75,8 @@
    * @param keyName name of the key to include in the request
    * @param privateKey base64 encoded private key
    */
-  public static function makeFromB64PrivateKey($next, $authToken, $keyName, 
$privateKey) {
-    return new SigningFetcher($next, $authToken, $keyName, $privateKey);
+  public static function makeFromB64PrivateKey($fetcher, $authToken, $keyName, 
$privateKey) {
+    return new SigningFetcher($fetcher, $authToken, $keyName, $privateKey);
   }
 
   /**
@@ -81,28 +86,28 @@
    * @param keyName name of the key to include in the request
    * @param privateKey DER encoded private key
    */
-  public static function makeFromPrivateKeyBytes($next, $authToken, $keyName, 
$privateKey) {
-    return new SigningFetcher($next, $authToken, $keyName, $privateKey);
+  public static function makeFromPrivateKeyBytes($fetcher, $authToken, 
$keyName, $privateKey) {
+    return new SigningFetcher($fetcher, $authToken, $keyName, $privateKey);
   }
 
-  protected function __construct($next, $authToken, $keyName, 
$privateKeyObject) {
-    parent::setNextFetcher($next);
+  protected function __construct($fetcher, $authToken, $keyName, 
$privateKeyObject) {
+    $this->fetcher = $fetcher;
     $this->authToken = $authToken;
     $this->keyName = $keyName;
     $this->privateKeyObject = $privateKeyObject;
   }
 
   public function fetchRequest(RemoteContentRequest $request) {
-    return $this->getNextFetcher()->fetchRequest($request);
+    return $this->fetcher->fetchRequest($request);
   }
 
   public function fetch($url, $method) {
     $signed = $this->signRequest($url, $method);
-    return $this->getNextFetcher()->fetchRequest($signed);
+    return $this->fetcher->fetchRequest($signed);
   }
 
   public function multiFetchRequest(Array $requests) {
-    return $this->getNextFetcher()->multiFetchRequest($requests);
+    return $this->fetcher->multiFetchRequest($requests);
   }
 
   public function signRequest($url, $method) {

Modified: incubator/shindig/trunk/php/src/gadgets/oauth/OAuthFetcher.php
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/oauth/OAuthFetcher.php?rev=754873&r1=754872&r2=754873&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/oauth/OAuthFetcher.php (original)
+++ incubator/shindig/trunk/php/src/gadgets/oauth/OAuthFetcher.php Mon Mar 16 
11:03:14 2009
@@ -28,7 +28,7 @@
  * requires OAuth signing.
  */
 class OAuthFetcher extends RemoteContentFetcher {
-  
+
   // We store some blobs of data on the client for later reuse; the blobs
   // contain key/value pairs, and these are the key names.
   private static $REQ_TOKEN_KEY = "r";
@@ -36,7 +36,7 @@
   private static $ACCESS_TOKEN_KEY = "a";
   private static $ACCESS_TOKEN_SECRET_KEY = "as";
   private static $OWNER_KEY = "o";
-  
+
   // names for the JSON values we return to the client
   public static $CLIENT_STATE = "oauthState";
   public static $APPROVAL_URL = "oauthApprovalUrl";
@@ -44,76 +44,76 @@
   public static $ERROR_TEXT = "oauthErrorText";
   // names of additional OAuth parameters we include in outgoing requests
   public static $XOAUTH_APP_URL = "xoauth_app_url";
-  
+
   /**
    * Maximum age for our client state; if this is exceeded we start over. One
    * hour is a fairly arbitrary time limit here.
    */
   private static $CLIENT_STATE_MAX_AGE_SECS = 3600;
-  
+
   /**
    * The gadget security token, with info about owner/viewer/gadget.
    */
   protected $authToken;
-  
+
   /**
    * Parameters from makeRequest
    */
   protected $requestParams;
-  
+
   /**
    * Reference to our persistent store for OAuth metadata.
    */
   protected $tokenStore;
-  
+
   /**
    * The accessor we use for signing messages. This also holds metadata about
    * the service provider, such as their URLs and the keys we use to access
    * those URLs.
    */
   private $accessorInfo;
-  
+
   /**
    * We use this to encrypt and sign the state we cache on the client.
    */
   private $oauthCrypter;
-  
+
   /**
    * State the client sent with their request.
    */
   private $origClientState = array();
-  
+
   /**
    * The request the client really wants to make.
    */
   private $realRequest;
-  
+
   /**
    * State to cache on the client.
    */
   private $newClientState;
-  
+
   /**
    * Authorization URL for the client
    */
   private $aznUrl;
-  
+
   /**
    * Error code for the client
    */
   private $error;
-  
+
   /**
    * Error text for the client
    */
   private $errorText;
-  
+
   /**
    * Whether or not we're supposed to ignore the spec cache when referring
    * to the gadget spec for information (e.g. OAuth URLs).
    */
   private $bypassSpecCache;
-  
+
   private $responseMetadata = array();
 
   /**
@@ -124,8 +124,8 @@
    * @param params OAuth fetch parameters sent from makeRequest
    * @param tokenStore storage for long lived tokens.
    */
-  public function __construct($tokenStore, $oauthCrypter, $nextFetcher, 
$authToken, OAuthRequestParams $params) {
-    parent::setNextFetcher($nextFetcher);
+  public function __construct($tokenStore, $oauthCrypter, $fetcher, 
$authToken, OAuthRequestParams $params) {
+    $this->fetcher = $fetcher;
     $this->oauthCrypter = $oauthCrypter;
     $this->authToken = $authToken;
     $this->bypassSpecCache = $params->getBypassSpecCache();
@@ -139,7 +139,7 @@
       try {
         $this->origClientState = $this->oauthCrypter->unwrap($origClientState, 
self::$CLIENT_STATE_MAX_AGE_SECS);
       } catch (BlobCrypterException $e) {// Probably too old, pretend we never 
saw it at all.
-}
+      }
     }
     if ($this->origClientState == null) {
       $this->origClientState = array();
@@ -312,9 +312,9 @@
   }
 
   /*
-        * @deprecated (All outgoing messages must send additional params
-        * like XOAUTH_APP_URL, so use newRequestMessageParams instead)
-        */
+   * @deprecated (All outgoing messages must send additional params
+   * like XOAUTH_APP_URL, so use newRequestMessageParams instead)
+   */
   private function newRequestMessageUrlOnly($url) {
     $params = array();
     return $this->newRequestMessageParams($url, $params);
@@ -365,7 +365,7 @@
         $authHeader = $this->getAuthorizationHeader($oauthParams);
         $newHeaders["Authorization"] = $authHeader;
         break;
-      
+
       case OAuthStoreVars::$OAuthParamLocation['POST_BODY']:
         if (! OAuthUtil::isFormEncoded($contentType)) {
           throw new GadgetException("Invalid param: OAuth param location can 
only " . "be post_body if post body if of type x-www-form-urlencoded");
@@ -376,7 +376,7 @@
           $postBody = $postBody . "&" . 
OAuthUtil::getPostBodyString($oauthParams);
         }
         break;
-      
+
       case OAuthStoreVars::$OAuthParamLocation['URI_QUERY']:
         $url = OAuthUtil::addParameters($url, $oauthParams);
         break;
@@ -392,7 +392,7 @@
    */
   private function sendOAuthMessage(OAuthRequest $request) {
     $rcr = 
$this->createRemoteContentRequest($this->filterOAuthParams($request), 
$request->get_normalized_http_method(), $request->get_url(), null, 
RemoteContentRequest::$DEFAULT_CONTENT_TYPE, null, 
RemoteContentRequest::getDefaultOptions());
-    $content = $this->getNextFetcher()->fetchRequest($rcr);
+    $content = $this->fetcher->fetchRequest($rcr);
     $reply = OAuthRequest::from_request();
     $params = OAuthUtil::decodeForm($content->getResponseContent());
     $reply->set_parameters($params);
@@ -502,7 +502,7 @@
       // Build and sign the message.
       $oauthRequest = $this->newRequestMessageMethod($method, 
$this->realRequest->getUrl(), $msgParams);
       $rcr = 
$this->createRemoteContentRequest($this->filterOAuthParams($oauthRequest), 
$this->realRequest->getMethod(), $this->realRequest->getUrl(), 
$this->realRequest->getHeaders(), $this->realRequest->getContentType(), 
$this->realRequest->getPostBody(), $this->realRequest->getOptions());
-      $content = $this->getNextFetcher()->fetchRequest($rcr);
+      $content = $this->fetcher->fetchRequest($rcr);
       //TODO is there a better way to detect an SP error?
       $statusCode = $content->getHttpCode();
       if ($statusCode >= 400 && $statusCode < 500) {
@@ -584,6 +584,6 @@
     }
   }
 
-  public function multiFetchRequest(Array $requests) {  // Do nothing  
+  public function multiFetchRequest(Array $requests) {  // Do nothing
   }
 }

Modified: incubator/shindig/trunk/php/src/gadgets/oauth/OAuthFetcherFactory.php
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/oauth/OAuthFetcherFactory.php?rev=754873&r1=754872&r2=754873&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/oauth/OAuthFetcherFactory.php 
(original)
+++ incubator/shindig/trunk/php/src/gadgets/oauth/OAuthFetcherFactory.php Mon 
Mar 16 11:03:14 2009
@@ -67,16 +67,15 @@
 
   /**
    * Produces an OAuthFetcher that will sign requests and delegate actual
-   * network retrieval to the {...@code nextFetcher}
+   * network retrieval to the {...@code fetcher}
    *
-   * @param nextFetcher The fetcher that will fetch real content
+   * @param fetcher The fetcher that will fetch real content
    * @param token The gadget token used to identity the user and gadget
    * @param params The parsed parameters the gadget requested
    * @return The oauth fetcher.
    * @throws GadgetException
    */
-  public function getOAuthFetcher($nextFetcher, $token, $params) {
-    $fetcher = new OAuthFetcher($this->tokenStore, $this->oauthCrypter, 
$nextFetcher, $token, $params);
-    return $fetcher;
+  public function getOAuthFetcher($fetcher, $token, $params) {
+    return new OAuthFetcher($this->tokenStore, $this->oauthCrypter, $fetcher, 
$token, $params);
   }
 }

Modified: incubator/shindig/trunk/php/test/ShindigAllTests.php
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/test/ShindigAllTests.php?rev=754873&r1=754872&r2=754873&view=diff
==============================================================================
--- incubator/shindig/trunk/php/test/ShindigAllTests.php (original)
+++ incubator/shindig/trunk/php/test/ShindigAllTests.php Mon Mar 16 11:03:14 
2009
@@ -46,7 +46,7 @@
 }
 
 set_include_path(get_include_path() . PATH_SEPARATOR . realpath('./php') . 
PATH_SEPARATOR . realpath('./php/external'));
-ini_set('error_reporting', E_COMPILE_ERROR | E_ERROR | E_CORE_ERROR);
+error_reporting(E_ALL | E_STRICT);
 require_once 'src/common/Config.php';
 require_once 'test/TestContext.php';
 

Modified: incubator/shindig/trunk/php/test/common/BasicRemoteContentTest.php
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/test/common/BasicRemoteContentTest.php?rev=754873&r1=754872&r2=754873&view=diff
==============================================================================
--- incubator/shindig/trunk/php/test/common/BasicRemoteContentTest.php 
(original)
+++ incubator/shindig/trunk/php/test/common/BasicRemoteContentTest.php Mon Mar 
16 11:03:14 2009
@@ -122,6 +122,14 @@
     $this->fetcher = null;
     parent::tearDown();
   }
+  
+  /**
+   * Tests BasicRemoteContent->__construct()
+   */
+  public function testConstruct() {
+    $basic = new BasicRemoteContent(new BasicRemoteContentFetcher(), null, 
false);
+    $signing = new BasicRemoteContent(new BasicRemoteContentFetcher(), new 
SigningFetcherFactory(), new BasicSecurityTokenDecoder());
+  }
 
   /**
    * Tests BasicRemoteContent->fetch()
@@ -292,7 +300,7 @@
    */
   public function testFeedFetch() {
     $fetcher = new BasicRemoteContentFetcher();
-    $this->basicRemoteContent->setRemoteContentFetcher($fetcher);
+    $this->basicRemoteContent->setBasicFetcher($fetcher);
     $request = new 
RemoteContentRequest('http://adwordsapi.blogspot.com/atom.xml');
     $context = new TestContext();
     $ret = $this->basicRemoteContent->fetch($request, $context);

Modified: incubator/shindig/trunk/php/test/common/CacheFileTest.php
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/test/common/CacheFileTest.php?rev=754873&r1=754872&r2=754873&view=diff
==============================================================================
--- incubator/shindig/trunk/php/test/common/CacheFileTest.php (original)
+++ incubator/shindig/trunk/php/test/common/CacheFileTest.php Mon Mar 16 
11:03:14 2009
@@ -53,7 +53,7 @@
   protected function setUp() {
     parent::setUp();
     $this->time = new MockRequestTime();
-    $this->cache = Cache::createCache('CacheFile', 'TestCache', $this->time);
+    $this->cache = Cache::createCache('CacheStorageFile', 'TestCache', 
$this->time);
   }
 
   /**
@@ -66,6 +66,13 @@
   }
 
   /**
+   * Tests Cache::createCache()
+   */
+  public function testCreateCache() {
+    $cache = Cache::createCache('CacheStorageFile', 'TestCache');
+  }
+  
+  /**
    * Tests cache->delete()
    */
   public function testDelete() {

Modified: incubator/shindig/trunk/php/test/common/CacheMemcacheTest.php
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/test/common/CacheMemcacheTest.php?rev=754873&r1=754872&r2=754873&view=diff
==============================================================================
--- incubator/shindig/trunk/php/test/common/CacheMemcacheTest.php (original)
+++ incubator/shindig/trunk/php/test/common/CacheMemcacheTest.php Mon Mar 16 
11:03:14 2009
@@ -42,7 +42,7 @@
   protected function setUp() {
     parent::setUp();
     $this->time = new MockRequestTime();
-    $this->cache = Cache::createCache('CacheMemcache', 'TestCache',
+    $this->cache = Cache::createCache('CacheStorageMemcache', 'TestCache',
                                       $this->time);
   }
 

Modified: incubator/shindig/trunk/php/test/index.php
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/test/index.php?rev=754873&r1=754872&r2=754873&view=diff
==============================================================================
--- incubator/shindig/trunk/php/test/index.php (original)
+++ incubator/shindig/trunk/php/test/index.php Mon Mar 16 11:03:14 2009
@@ -18,8 +18,9 @@
  * under the License.
  */
 
+...@date_default_timezone_set(@date_default_timezone_get());
 set_include_path(realpath("../") . PATH_SEPARATOR . realpath("../external/"));
-ini_set('error_reporting', E_COMPILE_ERROR | E_ERROR | E_CORE_ERROR);
+error_reporting(E_ALL | E_STRICT);
 
 require_once "PHPUnit/Framework/TestSuite.php";
 require_once "PHPUnit/TextUI/TestRunner.php";
@@ -70,13 +71,19 @@
   }
 }
 
+ob_start();    
 echo "<html><body><pre>";
 AllTests::main();
 echo "</pre></body></html>";
+$output = ob_get_clean();
 
 // make sure the result page isn't cached, some of the tests set caching 
headers which is bad here
+header('Content-Type: text/html', true);
 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT", true);
 header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT', true);
 header('Cache-Control: no-store, no-cache, must-revalidate', true);
 header('Cache-Control: pre-check=0, post-check=0, max-age=0', true);
 header("Pragma: no-cache", true);
+
+echo $output;
+


Reply via email to