1. Go to this page and download the library: Download thedava/dod-lite library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
thedava / dod-lite example snippets
# \DodLite\DocumentManagerFactory methods
public static function createLocalFile(string $folderPath): DocumentManager
public static function createCachedLocalFile(string $folderPath): DocumentManager
public static function createIndexedLocalFile(string $folderPath): DocumentManager
public static function createIndexCachedLocalFile(string $folderPath): DocumentManager
// Create a new DocumentManager
$documentManager = \DodLite\DocumentManagerFactory::createLocalFile('/tmp');
// Get/Create collection "docs"
$collection = $documentManager->getCollection('docs');
// Create a new document
$document = $collection->createDocument('README', [
'file' => 'README.md',
'headline' => 'Document-oriented Database Lite',
'description' => 'A simple file based document-oriented pseudo database.',
]);
// Persist document
$collection->writeDocument($document);
// Create another document and persist it immediately
$document = $collection->createDocument('Exceptions', [
'file' => '05-Exceptions.md',
'headline' => 'Exceptions',
'description' => 'DodLite employs a consistent error handling system',
], write: true);
// Write data directly without a document
$collection->writeData('Adapters', [
'file' => '04-Adapters.md',
'headline' => 'Adapters',
'description' => 'DodLite uses adapters to store data',
]);
// Create a document manually and persist it
$document = new \DodLite\Documents\Document('Concepts', [
'file' => '03-Concepts.md',
'headline' => 'Concepts',
'description' => 'Basic principles',
]);
$collection->writeDocument($document);
// Retrieve document
$document = $collection->getDocument('Concepts');
// Update content manually
$content = $document->getContent();
$content['description'] = 'DodLite uses collections and documents to store data';
$document->setContent($content);
// Update content via helper method (array_replace_recursive)
$document->updateContent([
'headline' => 'Concepts and Basic principles',
]);
// Persist document
$collection->writeDocument($document);
// Get document
$document = $collection->getDocument('Adapters');
var_dump($document->getContent()); // { 'file' => '04-Adapters.md', ... }
// Get the first document that matches a filter
$document = $collection->getDocumentByFilter(
new \DodLite\Filter\CallbackFilter(fn(Document $document) => $document->getContent()['file'] === '05-Exceptions.md')
);
// Get all documents
$documents = $collection->getAllDocuments();
foreach ($documents as $id => $document) {
var_dump($document->getContent());
}
// Get all documents filtered
$documents = $collection->getAllDocumentsByFilter(
new \DodLite\Filter\CallbackFilter(fn(Document $document) => str_ends_with($document->getContent()['file'], '.md'))
);
foreach ($documents as $id => $document) {
var_dump($document->getContent());
}
// Check if README exists
var_dump($collection->hasDocumentById('README')); // true
// Delete document directly by id
$collection->deleteDocumentById('Adapters');
// Delete a document object
$document = $collection->getDocument('Exceptions');
$collection->deleteDocument($document);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.