RepoDb
in package
implements
RepoInterface
Uses
RepoTrait
Provides a read only access to the repository on the relational database level.
Tags
Table of Contents
Interfaces
Constants
- RES_STATE_ACTIVE = 'active'
Properties
- $resourceClass : string
- A class used to instantiate objects representing repository resources.
- $auth : AuthInterface|null
- $baseUrl : string
- Repository REST API base URL
- $headers : object
- An object providing mappings of repository REST API parameters to HTTP headers used by a given repository instance.
- $nonRelationProperties : array<string|int, string>
- $pdo : PDO
- $queryLog : AbstractLogger|null
- $schema : Schema
- An object providing mappings of repository concepts to RDF properties used to denote them by a given repository instance.
Methods
- __construct() : mixed
- factory() : RepoDb
- Creates a repository object instance from a given configuration file.
- getBaseUrl() : string
- Returns the repository REST API base URL.
- getGraphBySearchTerms() : Dataset
- Returns RDF metadata graph of the search results.
- getGraphBySqlQuery() : Dataset
- Returns RDF metadata graph of the search results.
- getHeaderName() : string
- Returns an HTTP header name to be used to pass a given information in the repository request.
- getMetadataAuthQuery() : QueryPart
- getPdoStatementBySearchTerms() : PDOStatement
- getPdoStatementBySqlQuery() : PDOStatement
- getResourceById() : RepoResourceInterface
- Tries to find a repository resource with a given id.
- getResourceByIds() : RepoResourceDb
- Tries to find a single repository resource matching provided identifiers.
- getResourcesBySearchTerms() : Generator<string|int, RepoResourceInterface>
- Returns repository resources matching all provided search terms.
- getResourcesBySqlQuery() : Generator<string|int, RepoResourceInterface>
- Performs a search
- getSchema() : Schema
- Returns the `Schema` object defining repository entities to RDF property mappings.
- getSmartSearch() : SmartSearch
- parsePdoStatement() : Dataset
- Parses SQL query results containing resources metadata into an RDF graph.
- runQuery() : PDOStatement
- setQueryLog() : void
- Sets a search queries logger
- extractResourcesFromGraph() : Generator<string|int, RepoResourceInterface>
- Extracts collection of RepoResource objects from the EasyRdf graph being parsed from a search response.
- getFtsQuery() : array<string|int, QueryPart>
- Prepares an SQL query adding a full text search query results as metadata graph edges.
- getOrderByQuery() : array<string|int, QueryPart>
- getPagingQuery() : QueryPart
- logQuery() : void
- parseMetadataReadMode() : array<string|int, int>
- sortMatchingResources() : void
Constants
RES_STATE_ACTIVE
public
mixed
RES_STATE_ACTIVE
= 'active'
Properties
$resourceClass
A class used to instantiate objects representing repository resources.
public
static string
$resourceClass
= \acdhOeaw\arche\lib\RepoResourceDb::class
To be used by external libraries extending the RepoResource class funcionality provided by this library.
$auth
private
AuthInterface|null
$auth
$baseUrl
Repository REST API base URL
private
string
$baseUrl
$headers
An object providing mappings of repository REST API parameters to HTTP headers used by a given repository instance.
private
object
$headers
$nonRelationProperties
private
array<string|int, string>
$nonRelationProperties
$pdo
private
PDO
$pdo
$queryLog
private
AbstractLogger|null
$queryLog
$schema
An object providing mappings of repository concepts to RDF properties used to denote them by a given repository instance.
private
Schema
$schema
Methods
__construct()
public
__construct(string $baseUrl, Schema $schema, Schema $headers, PDO $pdo[, array<string|int, string> $nonRelationProperties = [] ][, AuthInterface $auth = null ]) : mixed
Parameters
- $baseUrl : string
- $schema : Schema
- $headers : Schema
- $pdo : PDO
- $nonRelationProperties : array<string|int, string> = []
- $auth : AuthInterface = null
factory()
Creates a repository object instance from a given configuration file.
public
static factory(string $configFile[, string $dbSettings = 'guest' ]) : RepoDb
Automatically parses required config properties and passes them to the RepoDb object constructor.
At the moment it doesn't support authorization provider instantiating.
Parameters
- $configFile : string
-
a path to the YAML config file
- $dbSettings : string = 'guest'
-
database connection variant to read from the config
Return values
RepoDbgetBaseUrl()
Returns the repository REST API base URL.
public
getBaseUrl() : string
Return values
stringgetGraphBySearchTerms()
Returns RDF metadata graph of the search results.
public
getGraphBySearchTerms(array<string|int, SearchTerm> $searchTerms, SearchConfig $config) : Dataset
Parameters
- $searchTerms : array<string|int, SearchTerm>
- $config : SearchConfig
Return values
DatasetgetGraphBySqlQuery()
Returns RDF metadata graph of the search results.
public
getGraphBySqlQuery(string $query, array<string|int, mixed> $parameters, SearchConfig $config) : Dataset
Parameters
- $query : string
- $parameters : array<string|int, mixed>
- $config : SearchConfig
Return values
DatasetgetHeaderName()
Returns an HTTP header name to be used to pass a given information in the repository request.
public
getHeaderName(string $purpose) : string
Parameters
- $purpose : string
Return values
stringgetMetadataAuthQuery()
public
getMetadataAuthQuery() : QueryPart
Return values
QueryPartgetPdoStatementBySearchTerms()
public
getPdoStatementBySearchTerms(array<string|int, SearchTerm> $searchTerms, SearchConfig $config) : PDOStatement
Parameters
- $searchTerms : array<string|int, SearchTerm>
- $config : SearchConfig
Return values
PDOStatementgetPdoStatementBySqlQuery()
public
getPdoStatementBySqlQuery(string $query, array<string|int, mixed> $parameters, SearchConfig $config) : PDOStatement
Parameters
- $query : string
- $parameters : array<string|int, mixed>
- $config : SearchConfig
Tags
Return values
PDOStatementgetResourceById()
Tries to find a repository resource with a given id.
public
getResourceById(string $id[, SearchConfig|null $config = null ]) : RepoResourceInterface
Throws an error on failure.
Parameters
- $id : string
- $config : SearchConfig|null = null
Return values
RepoResourceInterfacegetResourceByIds()
Tries to find a single repository resource matching provided identifiers.
public
getResourceByIds(array<string|int, string> $ids[, SearchConfig|null $config = null ]) : RepoResourceDb
A resource matches the search if at lest one id matches the provided list. Resource is not required to have all provided ids.
If more then one resources matches the search or there is no resource matching the search, an error is thrown.
Parameters
- $ids : array<string|int, string>
-
an array of identifiers (being strings)
- $config : SearchConfig|null = null
Tags
Return values
RepoResourceDbgetResourcesBySearchTerms()
Returns repository resources matching all provided search terms.
public
getResourcesBySearchTerms(array<string|int, SearchTerm> $searchTerms, SearchConfig $config) : Generator<string|int, RepoResourceInterface>
Parameters
- $searchTerms : array<string|int, SearchTerm>
- $config : SearchConfig
Return values
Generator<string|int, RepoResourceInterface>getResourcesBySqlQuery()
Performs a search
public
getResourcesBySqlQuery(string $query, array<string|int, mixed> $parameters, SearchConfig $config) : Generator<string|int, RepoResourceInterface>
Parameters
- $query : string
- $parameters : array<string|int, mixed>
- $config : SearchConfig
Return values
Generator<string|int, RepoResourceInterface>getSchema()
Returns the `Schema` object defining repository entities to RDF property mappings.
public
getSchema() : Schema
Return values
SchemagetSmartSearch()
public
getSmartSearch() : SmartSearch
Return values
SmartSearchparsePdoStatement()
Parses SQL query results containing resources metadata into an RDF graph.
public
parsePdoStatement(PDOStatement $query) : Dataset
Parameters
- $query : PDOStatement
Return values
DatasetrunQuery()
public
runQuery(string $query, array<string|int, mixed> $param) : PDOStatement
Parameters
- $query : string
- $param : array<string|int, mixed>
Return values
PDOStatementsetQueryLog()
Sets a search queries logger
public
setQueryLog(AbstractLogger $log) : void
Parameters
- $log : AbstractLogger
extractResourcesFromGraph()
Extracts collection of RepoResource objects from the EasyRdf graph being parsed from a search response.
private
extractResourcesFromGraph(Dataset $graph, SearchConfig $config) : Generator<string|int, RepoResourceInterface>
Parameters
- $graph : Dataset
-
graph returned by the parseSearchResponse() method
- $config : SearchConfig
-
search configuration object
Return values
Generator<string|int, RepoResourceInterface>getFtsQuery()
Prepares an SQL query adding a full text search query results as metadata graph edges.
private
getFtsQuery(SearchConfig $cfg) : array<string|int, QueryPart>
Parameters
- $cfg : SearchConfig
Return values
array<string|int, QueryPart>getOrderByQuery()
private
getOrderByQuery(SearchConfig $config) : array<string|int, QueryPart>
Parameters
- $config : SearchConfig
Return values
array<string|int, QueryPart>getPagingQuery()
private
getPagingQuery(SearchConfig $config) : QueryPart
Parameters
- $config : SearchConfig
Return values
QueryPartlogQuery()
private
logQuery(string $query, array<string|int, mixed> $param) : void
Parameters
- $query : string
- $param : array<string|int, mixed>
parseMetadataReadMode()
private
parseMetadataReadMode(string $mode, string|null $parent) : array<string|int, int>
Parameters
- $mode : string
- $parent : string|null
Return values
array<string|int, int>sortMatchingResources()
private
sortMatchingResources(array<string|int, DatasetNodeInterface> &$resources, NamedNode $searchOrderProp) : void
Parameters
- $resources : array<string|int, DatasetNodeInterface>
- $searchOrderProp : NamedNode