depage-xmldb v2.3.1
XML documents in a relational database
Loading...
Searching...
No Matches
XmlDb Class Reference

Detailed Description

Definition at line 18 of file XmlDb.php.

Public Member Functions

 __construct ($tablePrefix, $pdo, $cache, $options=[])
 creates an instance of the xmlDb
 __get ($property)
 Get properties (basically read-only).
 docExists ($docIdOrName)
 gets the doc-id of a xml-document by name or id and checks if the document exists
 getDocuments ($name="", $type="")
 gets available documents in database
 getDoc ($docIdOrName)
 Get xmlDb\document.
 getDocByNodeId ($nodeId)
 Get xmlDb\document.
 getDocInfo ($docIdOrName)
 getDocInfo
 getDocXml ($docIdOrName, $addIdAttribute=true)
 gets a document as a DOMDocument
 getDocXmlXpath ($docIdOrName, $xpath, $addIdAttribute=true)
 gets the first node of a document that matches an xpath query
 getSubdocByXpath ($xpath, $addIdAttribute=true)
 gets document by xpath.
 getNodeIdsByXpath ($xpath, $docId=null)
 gets node_ids by xpath
 getIndexNodeData ($nodeIds)
 loads the document id and the attributes of the given nodes with a single query (used by the Indexer to resolve targeted attributes and the lang attribute without a round trip per node); non element nodes get an empty attribute map
 getIndexTextContent ($nodeIds)
 concatenates the descendant text nodes of the given nodes with a single query, in document order; that is the text content Document::getSubdocByNodeId assembles (processing instructions and comments never contribute to textContent and entity references are not emitted by getSubdocByNodeId either)
 createDoc ($doctype='Depage\XmlDb\XmlDoctypes\Base', $docName=null)
 CreateDoc.
 duplicateDoc ($docNameOrId, $newName=null)
 duplicateDoc
 removeDoc ($docId)
 updateSchema ()
 updateSchema
 clearTables ()
 Removes SQL tables.
 beginTransactionAltering ()
 opens a transaction that changes the documents
 beginTransactionNonAltering ()
 opens a transaction that only reads the documents
 endTransaction ()
 closes the innermost open transaction level
 rollBackTransaction ()
 rolls back to the start of the innermost open transaction level, keeping outer transaction levels (if any) intact.
 rollBack ()
 resets the transaction state completely and rolls back the database transaction; use to recover after a failure that left transactions open.

Data Fields

 $pdo
 $options

Protected Member Functions

 getNodeIdsByXpathDom ($xpath, $docs=[])
 beginPdoTransaction ()
 commitPdoTransaction ()
 rollBackPdoTransaction ()
 createSavepoint ($level)
 releaseSavepoint ($level)
 rollbackToSavepoint ($level)

Protected Attributes

 $cache
 $dbNs
 $tablePrefix = 'dp_'
 $tableDocs
 $tableXml
 $docIds = []
 $transactions = 0
 $alteringTransaction

Constructor & Destructor Documentation

◆ __construct()

__construct ( $tablePrefix,
$pdo,
$cache,
$options = [] )
Parameters
$tablePrefix(string) prefix of the tables of the library
$pdo(Depage\Db\Pdo) database connection
$cache(Depage\Cache\Cache) cache instance
$options(array) options of the instance, the option "userId" is used as the id of the user that changes the documents

Definition at line 43 of file XmlDb.php.

Member Function Documentation

◆ __get()

__get ( $property)
Parameters
$property
Returns
mixed

Definition at line 65 of file XmlDb.php.

◆ beginPdoTransaction()

beginPdoTransaction ( )
protected

Definition at line 737 of file XmlDb.php.

◆ beginTransactionAltering()

beginTransactionAltering ( )

the outermost level starts a database transaction, the inner levels use savepoints

Returns
int the level of the transaction

Definition at line 646 of file XmlDb.php.

◆ beginTransactionNonAltering()

beginTransactionNonAltering ( )

the outermost level starts a database transaction, the inner levels use savepoints

Returns
int the level of the transaction

Definition at line 660 of file XmlDb.php.

◆ clearTables()

clearTables ( )

Definition at line 630 of file XmlDb.php.

◆ commitPdoTransaction()

commitPdoTransaction ( )
protected

Definition at line 741 of file XmlDb.php.

◆ createDoc()

createDoc ( $doctype = 'Depage\XmlDb\XmlDoctypes\Base',
$docName = null )
Parameters
$doctype(string) class-name of doctype for new document
$docName(string) optional name of document
Returns
Document
Exceptions
xmlDbException

Definition at line 514 of file XmlDb.php.

◆ createSavepoint()

createSavepoint ( $level)
protected

Definition at line 756 of file XmlDb.php.

◆ docExists()

docExists ( $docIdOrName)
Parameters
$docIdOrName(mixed) id or name of the document
Returns
(int) id of the document or false when document does not exist

Implements XmlGetter.

Definition at line 79 of file XmlDb.php.

◆ duplicateDoc()

duplicateDoc ( $docNameOrId,
$newName = null )
Parameters
$docNameOrId(mixed)
$newName(string) optional name for new document
Returns
Document|bool

Definition at line 545 of file XmlDb.php.

◆ endTransaction()

endTransaction ( )

the outermost level commits the database transaction, an inner level releases its savepoint

Returns
bool true if the outermost transaction has changed the documents

Definition at line 680 of file XmlDb.php.

◆ getDoc()

getDoc ( $docIdOrName)
Parameters
$docIdOrName(mixed) id or name of the document
Returns
bool|document

Definition at line 176 of file XmlDb.php.

◆ getDocByNodeId()

getDocByNodeId ( $nodeId)
Parameters
$nodeId(int) db-id of a node of the document
Returns
bool|document

Definition at line 192 of file XmlDb.php.

◆ getDocInfo()

getDocInfo ( $docIdOrName)
Parameters
mixed$docIdOrName
Returns
void

Definition at line 219 of file XmlDb.php.

◆ getDocuments()

getDocuments ( $name = "",
$type = "" )
Parameters
$name(string) optional name of the documents to get
$type(string) optional class name of the doctype handler of the documents to get
Returns
$docs (array) the key is the name of the document, the value is the document db-id.

Definition at line 130 of file XmlDb.php.

◆ getDocXml()

getDocXml ( $docIdOrName,
$addIdAttribute = true )
Parameters
$docIdOrName(mixed) id or name of the document
$addIdAttribute(bool) whether to add the db:id attributes
Returns
bool|\DOMDocument

Implements XmlGetter.

Definition at line 235 of file XmlDb.php.

◆ getDocXmlXpath()

getDocXmlXpath ( $docIdOrName,
$xpath,
$addIdAttribute = true )
Parameters
$docIdOrName(mixed) id or name of the document
$xpath(string) xpath to target node
$addIdAttribute(bool) whether to add the db:id attributes
Returns
bool|\DOMDocument

Implements XmlGetter.

Definition at line 254 of file XmlDb.php.

◆ getIndexNodeData()

getIndexNodeData ( $nodeIds)
Parameters
$nodeIds(array) database ids of the nodes
Returns
array node id => [ 'doc_id' => int, 'attributes' => array ]

Definition at line 437 of file XmlDb.php.

◆ getIndexTextContent()

getIndexTextContent ( $nodeIds)
Parameters
$nodeIds(array) database ids of the nodes
Returns
array node id => text content (nodes without text are absent from the result)

Definition at line 476 of file XmlDb.php.

◆ getNodeIdsByXpath()

getNodeIdsByXpath ( $xpath,
$docId = null )
Attention
this supports only a small subset of xpath-queries. so recheck source before using.
Parameters
$this->docId(int) id of document
$xpath(string) xpath to target node
Returns
$nodeids (array) array of found node ids
Todo
implement full xpath specifications

Definition at line 298 of file XmlDb.php.

◆ getNodeIdsByXpathDom()

getNodeIdsByXpathDom ( $xpath,
$docs = [] )
protected

Definition at line 412 of file XmlDb.php.

◆ getSubdocByXpath()

getSubdocByXpath ( $xpath,
$addIdAttribute = true )

if xpath directs to more than one node, only the first node will be returned.

Parameters
$xpath(string) xpath to target node
$addIdAttribute(bool) whether to add db:id attribute or not
Returns
$doc (domxmlobject)

Definition at line 275 of file XmlDb.php.

◆ releaseSavepoint()

releaseSavepoint ( $level)
protected

Definition at line 762 of file XmlDb.php.

◆ removeDoc()

removeDoc ( $docId)
Parameters
$docIdOrName
Returns
bool

Definition at line 565 of file XmlDb.php.

◆ rollBack()

rollBack ( )
Returns
bool true if a database transaction was rolled back

Definition at line 729 of file XmlDb.php.

◆ rollBackPdoTransaction()

rollBackPdoTransaction ( )
protected

Definition at line 745 of file XmlDb.php.

◆ rollbackToSavepoint()

rollbackToSavepoint ( $level)
protected

Definition at line 768 of file XmlDb.php.

◆ rollBackTransaction()

rollBackTransaction ( )

call from the catch block of code that opened the transaction.

Returns
bool true if a transaction level was rolled back, false if no transaction was open

Definition at line 704 of file XmlDb.php.

◆ updateSchema()

updateSchema ( )
Parameters
mixed
Returns
void

Definition at line 602 of file XmlDb.php.

Field Documentation

◆ $alteringTransaction

$alteringTransaction
protected

Definition at line 31 of file XmlDb.php.

◆ $cache

$cache
protected

Definition at line 21 of file XmlDb.php.

◆ $dbNs

$dbNs
protected

Definition at line 22 of file XmlDb.php.

◆ $docIds

$docIds = []
protected

Definition at line 28 of file XmlDb.php.

◆ $options

$options

Definition at line 33 of file XmlDb.php.

◆ $pdo

$pdo

Definition at line 20 of file XmlDb.php.

◆ $tableDocs

$tableDocs
protected

Definition at line 25 of file XmlDb.php.

◆ $tablePrefix

$tablePrefix = 'dp_'
protected

Definition at line 24 of file XmlDb.php.

◆ $tableXml

$tableXml
protected

Definition at line 26 of file XmlDb.php.

◆ $transactions

$transactions = 0
protected

Definition at line 30 of file XmlDb.php.


The documentation for this class was generated from the following file: