PHP code example of wmsamolet / object-map

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

    

wmsamolet / object-map example snippets




use Wmsamolet\ObjectMap\Domain\Repository\Memory\ObjectElementRepository;
use Wmsamolet\ObjectMap\Domain\Repository\Memory\ObjectLinkingRepository;
use Wmsamolet\ObjectMap\Domain\Service\ObjectMapService;

$objectMapService = new ObjectMapService(
    new ObjectElementRepository(),
    new ObjectLinkingRepository()
);

class TargetObject
{
}

class LinkedObject1
{
}

class LinkedObject2
{
}

// Add objects to map (adding information to the repository)
$objectMapService->addObjectToMap(TargetObject::class, 'Target object');
$objectMapService->addObjectToMap(LinkedObject1::class, 'Linked object #1');
$objectMapService->addObjectToMap(LinkedObject2::class, 'Linked object #2');

// Link objects to class TargetObject
$objectMapService->linkObjects(TargetObject::class, LinkedObject1::class);
$objectMapService->linkObjects(TargetObject::class, LinkedObject2::class);

// Get linked objects class name collection
$classNameCollection = $objectMapService->collectLinkedObjectsClassNames(
    TargetObject::class
);

// Get linked objects config collection ['class_name' => [...], ...]
$objectConfigCollection = $objectMapService->collectLinkedObjectsConfigs(
    TargetObject::class
);