PHP code example of davidbadura / orangedb

1. Go to this page and download the library: Download davidbadura/orangedb 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/ */

    

davidbadura / orangedb example snippets




use DavidBadura\OrangeDb\Annotation as OD;

/**
 * @OD\Document("character")
 */
class Character {
    
    /**
     * @OD\Type("string")
     */
    private $name;
    
    /**
     * @OD\Type("integer")
     */
    private $age;
    
    /**
     * @OD\ReferenceMany("Character")
     */
    private $children;
    
    public function getName(): string 
    {
        return $this->name;
    }
    
    public function getAge(): int 
    {
        return $this->age;
    }
    
    public function getChildren(): array 
    {
        return $this->children;
    }
}



use DavidBadura\OrangeDb\DocumentManager;
use DavidBadura\OrangeDb\Adapter\YamlAdapter;

$manager = new DocumentManager(new YamlAdapter(__DIR__.'/data'), __DIR__.'/var/cache/orangedb');

$character = $manager->find(Character::class, 'sarah');

echo $character->getName(); // Sarah Connor
echo $character->getAge(); // 32

echo count($character->getChildren()); // 1
echo $character->getChildren()[0]->getName(); //John Connor