ylem /ˈiːlɛm/ noun
(in the Big Bang theory) the primordial matter of the universe, originally conceived as composed of neutrons at high temperature and density.
This is an implementation of the TMF632 Party Management API REST Specification in Laravel. Supporting Individual, Organization, & Organizational Unit relational hierarchies.
composer require poing/ylem
php artisan ylem:seed
Like the primordial substance from which all matter is formed, this is intended as the core application fabric for business and consumer interaction.
Topological ordering and directed acyclic graph functions are provided for Laravel Eloquent models by the gazsp/baum
package. baum/baum
is no longer maintained. While some key functions will be covered in this document, see the complete documentation for additional functions.
The use of the Dijkstras algorithm, to determine the shortest path, is not a necessary consideration of this project. Dijkstras algorithm functionally is not provided by the gazsp/baum
package anyway.
Package discovery for gazsp/baum
is handled by the extra section of this packages composer.json
file. Just to make it easier to use.
Recursive functions are important for cyclining through all elements in the tree. This is because the depth
of nodes and all decendants will be different. This is the advantage that DAG provides, you're not locked into a strict level of hierarchies.
.
├── alpha
│ └── bravo
│ └── charlie
└── one
└── two
└── three
└── four
└── five
└── six
└── seven
└── eight
└── nine
└── ten
└── eleven
└── twelve
Below is an example of recursive iteration using the Blade templating engine provided with Laravel. Recursive iteration can be acheived with PHP
and other languages too. Generating an unordered list output, similar to the tree shown above.
function getBlade() // Function or Route
{
$roots = \App\DirectedAcyclicGraph::roots()->get();
return view('roots', compact('roots'));
}
<!-- roots.blade.php -->
<ul>
@foreach ($roots as $item)
<li>{{ $item->someValue }}</li>
@include('nodes', array('items' => $item->getImmediateDescendants()))
@endforeach
</ul>
<!-- nodes.blade.php -->
</ul>
@foreach ($items as $item)
<li>{{ $item->someValue }}</li>
@include('nodes', array('items' => $item->getImmediateDescendants()))
@endforeach
</ul>
- Create a Laravel Project
laravel new project_name
-or-
composer create-project --prefer-dist laravel/laravel project_name
cd project_name
composer require poing/ylem
- Publish the Laravel package
php artisan vendor:publish --provider Ylem\\Providers\\YlemServiceProvider
php artisan migrate
- Seed the demo table This could take a while, builds
10
root nodes with random nested itmes.
php artisan db:seed --class=Ylem\\Database\\Seeds\\StubSeeder
- Open
/ylem
in a browser.
You will see the random data associated to Ylem\Models\Stub
. This is simply a test table, once seeded, it can be used to examine the relationships. Faker is used to create: Company Name, JOB TITLE, and People Name.
$faker->company
└── strtoupper($faker->jobTitle)
└── $faker->name
Here are some tinker
commands to check out:
$node = Ylem\Models\Stub::find(50);
$node->isRoot(); // Checks if root node
$node->getRoot(); // Gets the root node
$node->parent()->get(); // Gets parent node, if not root
$node->siblings()->get(); // Gets siblings, sharing the same parent
$node->children()->get(); // Gets any children for this node