示例#1
0
 /**
  * @inheritDoc
  */
 public function extract(Property $object)
 {
     if (!$object->isComplete()) {
         throw new DomainException(sprintf('Property from resource provided to %s was incomplete; must contain a URL or a route', __METHOD__));
     }
     if ($object->hasValue()) {
         $value = $object->getValue();
         if ($value instanceof PropertyCollection) {
             $extractor = new PropertyCollectionExtractor($this);
             $value = $extractor->extract($value);
         }
         return $value;
     }
     if ($object->hasUrl()) {
         return $object->getUrl();
     }
     $reuseMatchedParams = true;
     $options = $object->getRouteOptions();
     if (isset($options['reuse_matched_params'])) {
         $reuseMatchedParams = (bool) $options['reuse_matched_params'];
         unset($options['reuse_matched_params']);
     }
     $path = call_user_func($this->urlHelper, $object->getRoute(), $object->getRouteParams(), $options, $reuseMatchedParams);
     if (substr($path, 0, 4) == 'http') {
         return $path;
     }
     return $this->getServerUrl() . $path;
 }
示例#2
0
 /**
  * Generate HAL properties from a PropertyCollection
  *
  * @param  PropertyCollection $collection
  * @return array
  */
 public function fromPropertyCollection(PropertyCollection $collection)
 {
     return $this->propertyCollectionExtractor->extract($collection);
 }