Drest\Mapping\RouteMetaData::getOriginLocation PHP Method

getOriginLocation() public method

Generate the location string from the provided object
public getOriginLocation ( object $object, string $url, EntityManager $em = null ) : string | false
$object object
$url string - the Url to be prepended to the location
$em Doctrine\ORM\EntityManager - Optionally pass the entity manager to assist in determining a GET origin location
return string | false
    public function getOriginLocation($object, $url, EntityManager $em = null)
    {
        $exposedObjectArray = ObjectToArray::execute($object);
        if (($route = $this->class_metadata->getOriginRoute($em)) !== null) {
            if (!is_null($em)) {
                $pattern = $route->getRoutePattern();
                $ormClassMetadata = $em->getClassMetadata($this->getClassMetaData()->getClassName());
                foreach ($ormClassMetadata->getIdentifierFieldNames() as $identifier) {
                    if (isset($exposedObjectArray[$identifier])) {
                        $pattern = str_replace(':' . $identifier, $exposedObjectArray[$identifier], $pattern);
                    }
                }
                return $url . '/' . ltrim($pattern, '/');
            }
        }
        return false;
    }