ApiPlatform\Core\Api\IriConverterInterface::getItemFromIri PHP Method

getItemFromIri() public method

Retrieves an item from its IRI.
public getItemFromIri ( string $iri, array $context = [] ) : object
$iri string
$context array
return object
    public function getItemFromIri(string $iri, array $context = []);

Usage Example

 /**
  * Gets the ID from an URI or a raw ID.
  *
  * @param string $value
  *
  * @return string
  */
 protected function getFilterValueFromUrl($value)
 {
     try {
         if ($item = $this->iriConverter->getItemFromIri($value)) {
             return $this->propertyAccessor->getValue($item, 'id');
         }
     } catch (\InvalidArgumentException $e) {
         // Do nothing, return the raw value
     }
     return $value;
 }