public function getReadStream2($entity, ResourceStreamInfo $resourceStreamInfo, $eTag, $checkETagForEquality, $operationContext)
 {
     if (!is_null($checkETagForEquality)) {
         throw new ODataException('This service does not support the ETag header for a media resource', 400);
     }
     if (!$entity instanceof Employee) {
         throw new ODataException('Internal Server Error.', 500);
     }
     //echo getcwd(); exit;
     $filePath = 'D:\\Projects\\ODataPHPProducer Yash\\Tests\\Resources\\NorthWind3\\images\\Employee_' . $entity->EmployeeID . '_' . $resourceStreamInfo->getName() . '.png';
     if (file_exists($filePath)) {
         $handle = fopen($filePath, 'r');
         $stream = fread($handle, filesize($filePath));
         fclose($handle);
         return $stream;
     } else {
         throw new ODataException('The image file could not be found', 500);
     }
 }
예제 #2
0
 /**
  * Add a named stream belongs to this resource type instance
  *
  * @param ResourceStreamInfo $namedStream ResourceStreamInfo instance describing
  *                                        the named stream to add.
  *
  * @return void
  *
  * @throws InvalidOperationException
  */
 public function addNamedStream(ResourceStreamInfo $namedStream)
 {
     if ($this->_resourceTypeKind != ResourceTypeKind::ENTITY) {
         throw new InvalidOperationException(Messages::resourceTypeNamedStreamsOnlyApplyToEntityType());
     }
     $name = $namedStream->getName();
     foreach (array_keys($this->_namedStreamsDeclaredOnThisType) as $namedStreamName) {
         if (strcasecmp($namedStreamName, $name) == 0) {
             throw new InvalidOperationException(Messages::resourceTypeNamedStreamWithSameNameAlreadyExists($name, $this->_name));
         }
     }
     $this->_namedStreamsDeclaredOnThisType[$name] = $namedStream;
     // Set $this->_allNamedStreams to null, the first call to getAllNamedStreams
     // will initilaize $this->_allNamedStreams, further call to
     // getAllNamedStreams will not reinitialize _allNamedStreams
     // so if addNamedStream is called after calling getAllNamedStreams then the
     // property just added will not be reflected in $this->_allNamedStreams
     unset($this->_allNamedStreams);
     $this->_allNamedStreams = array();
 }
 /**
  * This method is invoked by the data services framework to retrieve the named stream
  * associated with the entity instance specified by the entity parameter.
  *
  * @param object              $entity               The stream returned should be the default
  *                                                  stream associated with this entity instance.
  * @param ResourceStreamInfo  $resourceStreamInfo   The ResourceStreamInfo instance that describes
  *                                                  the named stream.
  * @param string              $eTag                 The etag value sent by the client (as the
  *                                                  value of an If[-None-]Match header) as part
  *                                                  of the HTTP request, This parameter will be
  *                                                  null if no If[-None-]Match header was present.
  * @param boolean             $checkETagForEquality True if an value of the etag parameter was sent
  *                                                  to the server as the value of an If-Match HTTP
  *                                                  request header, False if an value of the etag
  *                                                  parameter was sent to the server as the the value
  *                                                  of an If-None-Match HTTP request header null if
  *                                                  the HTTP request for the stream was not a
  *                                                  conditional request.
  * @param WebOperationContext $operationContext     A reference to the context for the current operation.
  *
  * @return mixed A valid stream the data service use to query/read a named stream which is
  * associated with the $entity. Null may be returned from this method if the requested named
  * stream has not been created since the creation of $entity. The data service will respond 
  * with 204 if this method returns null.
  *
  * @throws ODataException if a valid stream or null cannot be returned for the given arguments.
  */
 public function getReadStream2($entity, ResourceStreamInfo $resourceStreamInfo, $eTag, $checkETagForEquality, $operationContext)
 {
     /**
             if (!is_null($checkETagForEquality)) {
                 throw new ODataException(
                     'This service does not support the ETag header for a media resource', 
                     400
                 );
             }
             **/
     if (!$entity instanceof Employee) {
         throw new ODataException('Internal Server Error.', 500);
     }
     $filePath = self::IMAGE_PATH_ROOT . 'Employee_' . $entity->EmployeeID . '_' . $resourceStreamInfo->getName() . '.png';
     if (file_exists($filePath)) {
         $handle = fopen($filePath, 'r');
         $stream = fread($handle, filesize($filePath));
         fclose($handle);
         return $stream;
     } else {
         throw new ODataException('The image file could not be found', 500);
     }
 }