Newscoop\Service\Resource\ResourceRepository::getResourceFor PHP Method

getResourceFor() public method

The resource is located by using ResourceLocator (future).
public getResourceFor ( ResourceId $resourceId ) : mixed
$resourceId ResourceId The resource id used for obtaining the assigned resource, must not be null or empty.
return mixed The resource coresponding to the resource id.
    public function getResourceFor(ResourceId $resourceId)
    {
        Validation::notEmpty($resourceId, 'resourceId');
        //TODO: add implementation for visitors that can provide custom resources (ResourceLocator).
        if ($resourceId->getType() == ResourceId::TYPE_SERVICE) {
            $simpleClassName = $this->extractSimpleClassName($resourceId->getId());
            $properties = $this->getRepositoryProperties();
            $implClass = $properties['service.' . $simpleClassName];
            if (!isset($implClass)) {
                throw new \Exception("No default implementation set in the property file for '{$simpleClassName}'.");
            }
            // Instantiating the service
            $service = new $implClass($resourceId);
            $service = $this->configureService($service);
            return $this->cacheService($resourceId->getId(), $service);
        } else {
            if ($resourceId->getType() == ResourceId::TYPE_PROPERTIES) {
                $simpleClassName = $this->extractSimpleClassName($resourceId->getId());
                return $this->loadProperties($simpleClassName);
            }
        }
        throw new \Exception("Cannot locate the resource '.{$resourceId->getFullId}().' of type '.{$resourceId->getType}().'.");
    }