示例#1
0
 /** 
  * To instanciate correct writer from content type.
  *  
  * @param string $contentType  Writer Type 
  * (Atom, json etc..) which implements IOdataWriter interface.
  * @param array  $writerParams Parameters to writer
  * 
  * @return Returns an instance of writer specialized for 
  */
 public static function getWriter($contentType, $writerParams)
 {
     if (!array_key_exists(WRITERS, $contentType)) {
         if ($contetType == 'atom') {
             self::$WRITERS[$contetType] = new AtomODataWriter($writerParams);
         } else {
             if ($contetType == 'json') {
                 self::$WRITERS[$contetType] = new JSONODataWriter($writerParams);
             } else {
                 ODataException::CreateInternalServerError('unsupported type');
             }
         }
         return $self::$writers[$contentType];
     }
 }
示例#2
0
 /**
  * Read and validates the configuration for the given service.
  * 
  * @param string $serviceName  requested service name
  * @param string &$serviceInfo service info
  * @param string $configFile   config filename for all the services
  * 
  * @return void
  * 
  * @throws ODataException If configuration file 
  * does not exists or malformed.
  */
 public static function validateAndGetsServiceInfo($serviceName, &$serviceInfo, $configFile = '../../../services/service.config.xml')
 {
     $xml = simplexml_load_file(dirname(__FILE__) . "/" . $configFile, null, LIBXML_NOCDATA);
     if (!$xml) {
         ODataException::createInternalServerError('service.config file is not in proper XML format');
     }
     if (count($xml->children()) != 1) {
         ODataException::createInternalServerError("Config file has more than one root entries");
     }
     $pathResult = $xml->xpath("/configuration/services/service[@name=\"{$serviceName}\"]");
     if (empty($pathResult)) {
         ODataException::createBadRequestError("No configuration info found for {$serviceName}");
     }
     $pathResult = $xml->xpath("/configuration/services/service[@name=\"{$serviceName}\"]/path");
     if (empty($pathResult)) {
         ODataException::createInternalServerError("One of the mendatory configuration info were missing in the config file");
     } else {
         $serviceInfo['SERVICE_PATH'] = strval($pathResult[0]);
         if (empty($serviceInfo['SERVICE_PATH'])) {
             ODataException::createInternalServerError("One of the mendatory configuration info were missing in the config file or config file is mail formed");
         }
     }
     unset($pathResult);
     $pathResult = $xml->xpath("/configuration/services/service[@name=\"{$serviceName}\"]/classname");
     if (empty($pathResult)) {
         ODataException::createInternalServerError("One of the mendatory configuration info were missing in the config file");
     } else {
         $serviceInfo['SERVICE_CLASS'] = strval($pathResult[0]);
         if (empty($serviceInfo['SERVICE_CLASS'])) {
             ODataException::createInternalServerError("One of the mendatory configuration info were missing in the config file or config file is mail formed");
         }
     }
     unset($pathResult);
     $pathResult = $xml->xpath("/configuration/services/service[@name=\"{$serviceName}\"]/baseURL");
     if (empty($pathResult)) {
         ODataException::createInternalServerError("One of the mendatory configuration info were missing in the config file");
     } else {
         $serviceInfo['SERVICE_BASEURL'] = strval($pathResult[0]);
         if (empty($serviceInfo['SERVICE_BASEURL'])) {
             ODataException::createInternalServerError("One of the mendatory configuration info were missing in the config file or config file is mail formed");
         }
     }
 }
 /**
  * Build value of $skiptoken from the given object which will be the 
  * last object in the page.
  * 
  * @param mixed $lastObject entity instance from which skiptoken needs 
  *                          to be built.
  * 
  * @return string
  * 
  * @throws ODataException If reflection exception occurs while accessing 
  *                        property.
  */
 public function buildSkipTokenValue($lastObject)
 {
     $nextPageLink = null;
     foreach ($this->getOrderByPathSegments() as $orderByPathSegment) {
         $index = 0;
         $currentObject = $lastObject;
         $subPathSegments = $orderByPathSegment->getSubPathSegments();
         $subPathCount = count($subPathSegments);
         foreach ($subPathSegments as &$subPathSegment) {
             $isLastSegment = $index == $subPathCount - 1;
             try {
                 $dummyProperty = new \ReflectionProperty($currentObject, $subPathSegment->getName());
                 $currentObject = $dummyProperty->getValue($currentObject);
                 if (is_null($currentObject)) {
                     $nextPageLink .= 'null, ';
                     break;
                 } else {
                     if ($isLastSegment) {
                         $type = $subPathSegment->getInstanceType();
                         // assert($type implements IType)
                         // If this is a string then do utf8_encode to convert
                         // utf8 decoded characters to
                         // corrospoding utf8 char (e.g. � to í), then do a
                         // urlencode to convert í to %C3%AD
                         // urlencode is needed for datetime and guid too
                         // if ($type instanceof String || $type instanceof DateTime
                         //     || $type instanceof Guid) {
                         //    if ($type instanceof String) {
                         //        $currentObject = utf8_encode($currentObject);
                         //    }
                         //    $currentObject = urlencode($currentObject);
                         //}
                         // call IType::convertToOData to attach reuqired suffix
                         // and prepfix.
                         // e.g. $valueM, $valueF, datetime'$value', guid'$value',
                         // '$value' etc..
                         // Also we can think about moving above urlencode to this
                         // function
                         $value = $type->convertToOData($currentObject);
                         $nextPageLink .= $value . ', ';
                     }
                 }
             } catch (\ReflectionException $reflectionException) {
                 throw ODataException::createInternalServerError(Messages::internalSkipTokenInfoFailedToAccessOrInitializeProperty($subPathSegment->getName()));
             }
             $index++;
         }
     }
     return rtrim($nextPageLink, ", ");
 }
示例#4
0
 public static function GetServiceInfo($propertyName, $serviceName = "Default")
 {
     if (empty(self::$_serviceInfo[$propertyName])) {
         self::OpenConfigFile();
         self::CheckServiceName($serviceName);
         $searchStr = "/configuration/services/service[@name=\"" . self::$_serviceName . "\"]/{$propertyName}";
         $pathResult = self::$configXML->xpath($searchStr);
         if (empty($pathResult)) {
             ODataException::createInternalServerError("{$propertyName} configuration info were missing in the config file");
         } else {
             self::$_serviceInfo[$propertyName] = strval($pathResult[0]);
             if (empty(self::$_serviceInfo[$propertyName])) {
                 ODataException::createInternalServerError("{$propertyName} configuration info were missing in the config file or config file is mail formed");
             }
         }
         unset($pathResult);
     }
     return self::$_serviceInfo[$propertyName];
 }