You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@shindig.apache.org by ch...@apache.org on 2009/07/08 16:12:20 UTC

svn commit: r792146 - in /incubator/shindig/trunk/php: config/ src/social/service/

Author: chabotc
Date: Wed Jul  8 14:12:20 2009
New Revision: 792146

URL: http://svn.apache.org/viewvc?rev=792146&view=rev
Log:
This patch changes the way the service classes are initiated and checked. If the configuration key for the service is empty it'll now automatically trigger a NOT_IMPLEMENTED response, this way poeple using shindig don't have to implement these them selves

Modified:
    incubator/shindig/trunk/php/config/container.php
    incubator/shindig/trunk/php/src/social/service/ActivityHandler.php
    incubator/shindig/trunk/php/src/social/service/AlbumHandler.php
    incubator/shindig/trunk/php/src/social/service/AppDataHandler.php
    incubator/shindig/trunk/php/src/social/service/DataRequestHandler.php
    incubator/shindig/trunk/php/src/social/service/InvalidateHandler.php
    incubator/shindig/trunk/php/src/social/service/MediaItemHandler.php
    incubator/shindig/trunk/php/src/social/service/MessagesHandler.php
    incubator/shindig/trunk/php/src/social/service/PersonHandler.php

Modified: incubator/shindig/trunk/php/config/container.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/config/container.php?rev=792146&r1=792145&r2=792146&view=diff
==============================================================================
--- incubator/shindig/trunk/php/config/container.php (original)
+++ incubator/shindig/trunk/php/config/container.php Wed Jul  8 14:12:20 2009
@@ -22,7 +22,9 @@
  * The default configuration settings
  *
  * Put any site specific configuration in a config/local.php file, this way
- * your configuration won't be lost when upgrading shindig.
+ * your configuration won't be lost when upgrading shindig. If your site don't
+ * support any services just use empty string as the service name. i.e.
+ *  'messages_service' => ''
  *
  * in local.php you only have to specificy the fields you want to overwrite
  * with other values, for example on a production system you would probably have:

Modified: incubator/shindig/trunk/php/src/social/service/ActivityHandler.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/social/service/ActivityHandler.php?rev=792146&r1=792145&r2=792146&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/social/service/ActivityHandler.php (original)
+++ incubator/shindig/trunk/php/src/social/service/ActivityHandler.php Wed Jul  8 14:12:20 2009
@@ -19,16 +19,15 @@
  */
 
 class ActivityHandler extends DataRequestHandler {
-  private $service;
-
+  
   private static $ACTIVITY_ID_PATH = "/activities/{userId}/{groupId}/appId/{activityId}";
 
   public function __construct() {
-    $service = Config::get('activity_service');
-    $this->service = new $service();
+    parent::__construct('activity_service');
   }
 
   public function handleDelete(RequestItem $requestItem) {
+    $this->checkService();
     $requestItem->applyUrlTemplate(self::$ACTIVITY_ID_PATH);
     $userIds = $requestItem->getUsers();
     $activityIds = $requestItem->getListParameter("activityId");
@@ -49,6 +48,7 @@
    * /activities/john.doe/@friends
    */
   public function handleGet(RequestItem $requestItem) {
+    $this->checkService();
     $requestItem->applyUrlTemplate(self::$ACTIVITY_ID_PATH);
     $userIds = $requestItem->getUsers();
     $optionalActivityIds = $requestItem->getListParameter("activityId");
@@ -77,6 +77,7 @@
    * - postBody is an activity object
    */
   public function handlePost(RequestItem $requestItem) {
+    $this->checkService();
     $requestItem->applyUrlTemplate(self::$ACTIVITY_ID_PATH);
     $userIds = $requestItem->getUsers();
     $activityIds = $requestItem->getListParameter("activityId");

Modified: incubator/shindig/trunk/php/src/social/service/AlbumHandler.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/social/service/AlbumHandler.php?rev=792146&r1=792145&r2=792146&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/social/service/AlbumHandler.php (original)
+++ incubator/shindig/trunk/php/src/social/service/AlbumHandler.php Wed Jul  8 14:12:20 2009
@@ -23,18 +23,9 @@
  */
 class AlbumHandler extends DataRequestHandler {
   private static $ALBUM_PATH = "/albums/{userId}/{groupId}/{albumId}";
-  private $service;
 
   public function __construct() {
-    try {
-      $service = Config::get('album_service');
-    } catch (ConfigException $e) {
-      // Do nothing. If album_service is not specified in the config file.
-      // All the requests to album handler will throw not implemented exception.
-    }
-    if ($service) {
-      $this->service = new $service();
-    }
+    parent::__construct('album_service');
   }
 
   /**
@@ -114,13 +105,4 @@
 
     return $this->service->updateAlbum($userIds[0], $groupId, $album, $requestItem->getToken());
   }
-
-  /**
-   * Checks whether the service is initialized.
-   */
-  private function checkService() {
-    if (!$this->service) {
-      throw new SocialSpiException("Not Implemented.", ResponseError::$NOT_IMPLEMENTED);
-    }
-  }
 }

Modified: incubator/shindig/trunk/php/src/social/service/AppDataHandler.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/social/service/AppDataHandler.php?rev=792146&r1=792145&r2=792146&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/social/service/AppDataHandler.php (original)
+++ incubator/shindig/trunk/php/src/social/service/AppDataHandler.php Wed Jul  8 14:12:20 2009
@@ -20,11 +20,9 @@
 
 class AppDataHandler extends DataRequestHandler {
   private static $APP_DATA_PATH = "/appdata/{userId}/{groupId}/appId";
-  private $service;
 
   public function __construct() {
-    $service = Config::get('app_data_service');
-    $this->service = new $service();
+    parent::__construct('app_data_service');
   }
 
   /**
@@ -37,6 +35,7 @@
    *
    */
   public function handleDelete(RequestItem $requestItem) {
+    $this->checkService();
     $requestItem->applyUrlTemplate(self::$APP_DATA_PATH);
     $userIds = $requestItem->getUsers();
     if (count($userIds) < 1) {
@@ -56,6 +55,7 @@
    * /appdata/john.doe/@self/app
    */
   public function handleGet(RequestItem $requestItem) {
+    $this->checkService();
     $requestItem->applyUrlTemplate(self::$APP_DATA_PATH);
     $userIds = $requestItem->getUsers();
     if (count($userIds) < 1) {
@@ -77,6 +77,7 @@
    * fields vars then all of the data will be overridden.
    */
   public function handlePost(RequestItem $requestItem) {
+    $this->checkService();
     $requestItem->applyUrlTemplate(self::$APP_DATA_PATH);
     $userIds = $requestItem->getUsers();
     if (count($userIds) < 1) {

Modified: incubator/shindig/trunk/php/src/social/service/DataRequestHandler.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/social/service/DataRequestHandler.php?rev=792146&r1=792145&r2=792146&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/social/service/DataRequestHandler.php (original)
+++ incubator/shindig/trunk/php/src/social/service/DataRequestHandler.php Wed Jul  8 14:12:20 2009
@@ -19,7 +19,21 @@
  */
 
 abstract class DataRequestHandler {
-
+  protected $service;
+  
+  public function __construct($serviceName) {
+    try {
+      $service = trim(Config::get($serviceName));
+      if (!empty($service)) {
+        $this->service = new $service();
+      }
+    } catch (ConfigException $e) {
+      // Do nothing. If service name is not specified in the config file.
+      // All the requests to the handler will throw not implemented exception.
+      // The handler function should invoke checkService method before serving. 
+    }
+  }
+  
   private static $GET_SYNONYMS = array("get");
   private static $CREATE_SYNONYMS = array("post", "create");
   private static $UPDATE_SYNONYMS = array("put", "update");
@@ -110,6 +124,15 @@
     rsort($version);
     return $version[0];
   }
+  
+  /**
+   * Checks whether the service is initialized.
+   */
+  protected function checkService() {
+    if (!$this->service) {
+      throw new SocialSpiException("Not Implemented.", ResponseError::$NOT_IMPLEMENTED);
+    }
+  }
 
   abstract public function handleDelete(RequestItem $requestItem);
 

Modified: incubator/shindig/trunk/php/src/social/service/InvalidateHandler.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/social/service/InvalidateHandler.php?rev=792146&r1=792145&r2=792146&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/social/service/InvalidateHandler.php (original)
+++ incubator/shindig/trunk/php/src/social/service/InvalidateHandler.php Wed Jul  8 14:12:20 2009
@@ -20,19 +20,21 @@
 
 class InvalidateHandler extends DataRequestHandler {
   
-  /**
-   * @var InvalidateService
-   */
-  private $invalidateService;
-  
   private static $INVALIDATE_PATH = "/cache/invalidate";
   
   private static $KEYS_PARAM = "invalidationKeys";
 
   public function __construct() {
-    $service = Config::get('invalidate_service');
-    $cache = Cache::createCache(Config::get('data_cache'), 'RemoteContent');
-    $this->invalidateService = new $service($cache);
+    try {
+      $service = trim(Config::get('invalidate_service'));
+      if (!empty($service)) {
+        $cache = Cache::createCache(Config::get('data_cache'), 'RemoteContent');
+        $this->service = new $service($cache);
+      }
+    } catch (ConfigException $e) {
+      // Do nothing. If invalidate service is not specified in the config file.
+      // All the requests to the handler will throw not implemented exception.
+    }
   }
 
   public function handleItem(RequestItem $requestItem) {
@@ -64,6 +66,7 @@
   }
 
   public function handleInvalidate(RequestItem $request) {
+    $this->checkService();
     if (!$request->getToken()->getAppId() && !$request->getToken()->getAppUrl()) {
       throw new SocialSpiException("Can't invalidate content without specifying application", ResponseError::$BAD_REQUEST);
     }
@@ -91,7 +94,7 @@
         $userIds[] = $key;
       }
     }
-    $this->invalidateService->invalidateApplicationResources($resources, $request->getToken());
-    $this->invalidateService->invalidateUserResources($userIds, $request->getToken());
+    $this->service->invalidateApplicationResources($resources, $request->getToken());
+    $this->service->invalidateUserResources($userIds, $request->getToken());
   }
 }

Modified: incubator/shindig/trunk/php/src/social/service/MediaItemHandler.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/social/service/MediaItemHandler.php?rev=792146&r1=792145&r2=792146&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/social/service/MediaItemHandler.php (original)
+++ incubator/shindig/trunk/php/src/social/service/MediaItemHandler.php Wed Jul  8 14:12:20 2009
@@ -22,15 +22,7 @@
   private static $MEDIA_ITEM_PATH = "/mediaitems/{userId}/{groupId}/{albumId}/{mediaItemId}";
   
   public function __construct() {
-    try {
-      $service = Config::get('media_item_service');
-    } catch (ConfigException $e) {
-      // Do nothing. If album_service is not specified in the config file.
-      // All the requests to album handler will throw not implemented exception.
-    }
-    if ($service) {
-      $this->service = new $service();
-    }
+    parent::__construct('media_item_service');
   }
   
   /**
@@ -119,10 +111,4 @@
     // The null param is the content data(image, video and audio binaries) uploaded by the user.
     return $this->service->updateMediaItem($userIds[0], $groupId, $mediaItem, null, $requestItem->getToken());
   }
-  
-  private function checkService() {
-    if (!$this->service) {
-      throw new SocialSpiException("Not Implemented.", ResponseError::$NOT_IMPLEMENTED);
-    }
-  }
 }

Modified: incubator/shindig/trunk/php/src/social/service/MessagesHandler.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/social/service/MessagesHandler.php?rev=792146&r1=792145&r2=792146&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/social/service/MessagesHandler.php (original)
+++ incubator/shindig/trunk/php/src/social/service/MessagesHandler.php Wed Jul  8 14:12:20 2009
@@ -21,17 +21,16 @@
 class MessagesHandler extends DataRequestHandler {
 
   private static $MESSAGES_PATH = "/messages/{userId}/msgCollId/{messageId}";
-  private $service;
 
   public function __construct() {
-    $service = Config::get('messages_service');
-    $this->service = new $service();
+    parent::__construct('messages_service');
   }
 
   /**
    * Deletes the message collection or the messages.
    */
   public function handleDelete(RequestItem $requestItem) {
+    $this->checkService();
     $requestItem->applyUrlTemplate(self::$MESSAGES_PATH);
 
     $userIds = $requestItem->getUsers();
@@ -56,6 +55,7 @@
    * /messages/john.doe/notification/1,2,3
    */
   public function handleGet(RequestItem $requestItem) {
+    $this->checkService();
     $requestItem->applyUrlTemplate(self::$MESSAGES_PATH);
 
     $userIds = $requestItem->getUsers();
@@ -84,6 +84,7 @@
    * /messages/john.doe/notification
    */
   public function handlePost(RequestItem $requestItem) {
+    $this->checkService();
     $requestItem->applyUrlTemplate(self::$MESSAGES_PATH);
 
     $userIds = $requestItem->getUsers();
@@ -127,6 +128,7 @@
    * Updates a message or a message collection.
    */
   public function handlePut(RequestItem $requestItem) {
+    $this->checkService();
     $requestItem->applyUrlTemplate(self::$MESSAGES_PATH);
 
     $userIds = $requestItem->getUsers();

Modified: incubator/shindig/trunk/php/src/social/service/PersonHandler.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/social/service/PersonHandler.php?rev=792146&r1=792145&r2=792146&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/social/service/PersonHandler.php (original)
+++ incubator/shindig/trunk/php/src/social/service/PersonHandler.php Wed Jul  8 14:12:20 2009
@@ -20,14 +20,11 @@
 
 class PersonHandler extends DataRequestHandler {
   
-  private $personService;
-  
   private static $PEOPLE_PATH = "/people/{userId}/{groupId}/{personId}";
   private static $DEFAULT_FIELDS = array('ID', 'NAME', 'GENDER', 'THUMBNAIL_URL');
 
   public function __construct() {
-    $service = Config::get('person_service');
-    $this->personService = new $service();
+    parent::__construct('person_service');
   }
 
   public function handleDelete(RequestItem $request) {
@@ -48,6 +45,7 @@
    * examples: /people/john.doe/@all /people/john.doe/@friends /people/john.doe/@self
    */
   public function handleGet(RequestItem $request) {
+    $this->checkService();
     $request->applyUrlTemplate(self::$PEOPLE_PATH);
     
     $groupId = $request->getGroup();
@@ -74,22 +72,22 @@
     if (count($userIds) == 1) {
       if (count($optionalPersonId) == 0) {
         if ($groupId->getType() == 'self') {
-          return $this->personService->getPerson($userIds[0], $groupId, $fields, $request->getToken());
+          return $this->service->getPerson($userIds[0], $groupId, $fields, $request->getToken());
         } else {
-          return $this->personService->getPeople($userIds, $groupId, $options, $fields, $request->getToken());
+          return $this->service->getPeople($userIds, $groupId, $options, $fields, $request->getToken());
         }
       } elseif (count($optionalPersonId) == 1) {
-        return $this->personService->getPerson($optionalPersonId[0], $groupId, $fields, $request->getToken());
+        return $this->service->getPerson($optionalPersonId[0], $groupId, $fields, $request->getToken());
       } else {
         $personIds = array();
         foreach ($optionalPersonId as $pid) {
           $personIds[] = new UserId('userId', $pid);
         }
         // Every other case is a collection response of optional person ids
-        return $this->personService->getPeople($personIds, new GroupId('self', null), $options, $fields, $request->getToken());
+        return $this->service->getPeople($personIds, new GroupId('self', null), $options, $fields, $request->getToken());
       }
     }
     // Every other case is a collection response.
-    return $this->personService->getPeople($userIds, $groupId, $options, $fields, $request->getToken());
+    return $this->service->getPeople($userIds, $groupId, $options, $fields, $request->getToken());
   }
 }