UriNormalizer
in package
A simply utility class normalizing the URIs
Tags
Table of Contents
Properties
- $cache : CacheInterface
- $client : ClientInterface
- $dataFactory : DataFactoryInterface
- $idTmpl : PredicateTemplate
- $mappings : array<string|int, UriNormalizerRule>
- $obj : self
Methods
- __construct() : mixed
- fetch() : DatasetNode
- Fetches RDF metadata for a given URI.
- gFetch() : DatasetNode
- A static version of the fetch() method.
- gNormalize() : string
- A static version of the normalize() method.
- gNormalizeMeta() : void
- A static version of the normalizeMeta() method.
- gNormalizeNN() : NamedNodeInterface
- A static version of the normalizeNN() method.
- gResolve() : RequestInterface
- A static version of the resolve() method.
- init() : void
- Initializes a global singleton instance of the UriNormalizer.
- normalize() : string
- Returns a normalized URI as string.
- normalizeMeta() : void
- Performs id URI normalization on all id properties of a given metadata resource object.
- normalizeNN() : NamedNodeInterface
- Returns a normalized URI as a NamedNodeInterface object.
- resolve() : Request
- Resolves a given URI to a PSR-7 request fetching its RDF metadata.
- fetchUrl() : ResponseInterface
- setCache() : void
Properties
$cache
private
CacheInterface
$cache
$client
private
ClientInterface
$client
$dataFactory
private
DataFactoryInterface
$dataFactory
$idTmpl
private
PredicateTemplate
$idTmpl
$mappings
private
array<string|int, UriNormalizerRule>
$mappings
$obj
private
static self
$obj
Methods
__construct()
public
__construct([array<string|int, UriNormalizerRule|array<string, string>|stdClass>|null $mappings = null ][, NamedNodeInterface|string $idProp = '' ][, ClientInterface|null $client = null ][, CacheInterface|null $cache = null ][, DataFactoryInterface $dataFactory = null ]) : mixed
Parameters
- $mappings : array<string|int, UriNormalizerRule|array<string, string>|stdClass>|null = null
-
a set of normalization rules to be used. If they are not UriNormRule objects, an attempt to cast them is made with the
UriNormRule::factory()
. If null is passed, rules provided by the UriNormRules::getRules() class are used. - $idProp : NamedNodeInterface|string = ''
-
a default RDF property to be used by the
normalizeMeta()
method - $client : ClientInterface|null = null
-
a PSR-18 HTTP client to be used to resolve URIs. If not provided, a new instance of a
\GuzzleHttp\Client
is used. - $cache : CacheInterface|null = null
-
instance of a PSR-16 compatible cache object for caching normalize()/resolve()/normalize() results
- $dataFactory : DataFactoryInterface = null
-
factory class to be used to create RDF terms. If not provided, a quickRdf\DataFactory from the sweetrdf/quick-rdf library is used.
fetch()
Fetches RDF metadata for a given URI.
public
fetch(NamedNodeInterface|string $uri) : DatasetNode
Throws UriNormalizerException when the retrieval fails.
Parameters
- $uri : NamedNodeInterface|string
Tags
Return values
DatasetNodegFetch()
A static version of the fetch() method.
public
static gFetch(NamedNodeInterface|string $uri) : DatasetNode
Call UriNormalizer::init()
before first use.
Parameters
- $uri : NamedNodeInterface|string
Tags
Return values
DatasetNodegNormalize()
A static version of the normalize() method.
public
static gNormalize(NamedNodeInterface|string $uri[, bool $requireMatch = true ]) : string
Call UriNormalizer::init()
before first use.
Parameters
- $uri : NamedNodeInterface|string
- $requireMatch : bool = true
Tags
Return values
stringgNormalizeMeta()
A static version of the normalizeMeta() method.
public
static gNormalizeMeta(DatasetInterface $res[, NamedNodeInterface|string $idProp = '' ][, bool $requireMatch = true ]) : void
Call UriNormalizer::init()
before first use.
Parameters
- $res : DatasetInterface
-
metadata to be processed
- $idProp : NamedNodeInterface|string = ''
-
id property URI (if not provided, value passed to the
UriNormalizer::init()
is used) - $requireMatch : bool = true
-
should an exception be rised if the $uri matches no rule
Tags
gNormalizeNN()
A static version of the normalizeNN() method.
public
static gNormalizeNN(NamedNodeInterface|string $uri[, bool $requireMatch = true ]) : NamedNodeInterface
Call UriNormalizer::init()
before first use.
Parameters
- $uri : NamedNodeInterface|string
- $requireMatch : bool = true
Tags
Return values
NamedNodeInterfacegResolve()
A static version of the resolve() method.
public
static gResolve(NamedNodeInterface|string $uri) : RequestInterface
Call UriNormalizer::init()
before first use.
Parameters
- $uri : NamedNodeInterface|string
Tags
Return values
RequestInterfaceinit()
Initializes a global singleton instance of the UriNormalizer.
public
static init([array<string|int, UriNormalizerRule|array<string, string>|stdClass>|null $mappings = null ][, string $idProp = '' ][, ClientInterface|null $client = null ][, CacheInterface|null $cache = null ][, DataFactoryInterface $dataFactory = null ]) : void
Parameters
- $mappings : array<string|int, UriNormalizerRule|array<string, string>|stdClass>|null = null
-
a set of normalization rules to be used. If they are not UriNormalizerRule objects, an attempt to cast them is made with the
UriNormalizerRule::factory()
. If null is passed, rules provided by the UriNormRules::getRules() class are used. - $idProp : string = ''
-
a default RDF property to be used by the
normalizeMeta()
method - $client : ClientInterface|null = null
-
a PSR-18 HTTP client to be used to resolve URIs. If not provided, a new instance of a
\GuzzleHttp\Client
is used. - $cache : CacheInterface|null = null
-
instance of a PSR-16 compatible cache object for caching normalize()/resolve()/normalize() results
- $dataFactory : DataFactoryInterface = null
-
factory class to be used to create RDF terms. If not provided, a quickRdf\DataFactory from the sweetrdf/quick-rdf library is used.
Tags
normalize()
Returns a normalized URI as string.
public
normalize(NamedNodeInterface|string $uri[, bool $requireMatch = true ]) : string
Parameters
- $uri : NamedNodeInterface|string
-
URI to be normalized
- $requireMatch : bool = true
-
should an exception be rised if the $uri matches no rule
Tags
Return values
stringnormalizeMeta()
Performs id URI normalization on all id properties of a given metadata resource object.
public
normalizeMeta(DatasetInterface $res[, NamedNodeInterface|string $idProp = '' ][, bool $requireMatch = true ]) : void
The normalization is performed in-place, therefore the return type is void.
Parameters
- $res : DatasetInterface
-
metadata to be processed
- $idProp : NamedNodeInterface|string = ''
-
id property URI (if not provided, value passed to the object constructor is used)
- $requireMatch : bool = true
-
should an exception be rised if the $uri matches no rule
Tags
normalizeNN()
Returns a normalized URI as a NamedNodeInterface object.
public
normalizeNN(NamedNodeInterface|string $uri[, bool $requireMatch = true ]) : NamedNodeInterface
Parameters
- $uri : NamedNodeInterface|string
-
URI to be normalized
- $requireMatch : bool = true
-
should an exception be rised if the $uri matches no rule
Tags
Return values
NamedNodeInterfaceresolve()
Resolves a given URI to a PSR-7 request fetching its RDF metadata.
public
resolve(NamedNodeInterface|string $uri) : Request
Throws the UriNormalizerException if the resolving fails.
Parameters
- $uri : NamedNodeInterface|string
Tags
Return values
RequestfetchUrl()
private
fetchUrl(Request &$request) : ResponseInterface
Parameters
- $request : Request
Tags
Return values
ResponseInterfacesetCache()
private
setCache(string $key1, string $key2, mixed $value) : void
Parameters
- $key1 : string
- $key2 : string
- $value : mixed