initial commit
This commit is contained in:
commit
0db3e92ee6
59 changed files with 3384 additions and 0 deletions
85
index.php
Normal file
85
index.php
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
<?php
|
||||
|
||||
use \VeruA\DomainObjects\{
|
||||
DomainObject,
|
||||
Owner,
|
||||
Client,
|
||||
Address,
|
||||
ValueObjects\Date,
|
||||
};
|
||||
use \VeruA\DomainObjects\Validation\{
|
||||
OwnerValidator,
|
||||
ClientValidator,
|
||||
ResultCollection,
|
||||
};
|
||||
|
||||
const BASE_PATH = __DIR__;
|
||||
require __DIR__ . '/vendor/autoload.php';
|
||||
|
||||
// owner
|
||||
$owner = new Owner([
|
||||
'id' => 1,
|
||||
'firstname' => 'Arthur',
|
||||
'lastname' => 'Dent',
|
||||
'gln' => 7653298712357,
|
||||
// 'gln' => 7653298712358, // GLN with valid checksum
|
||||
'email' => 'dear@example.com',
|
||||
'username' => 'ardente'
|
||||
]);
|
||||
|
||||
|
||||
// client
|
||||
$client = new Client([
|
||||
'id' => 1,
|
||||
'firstname' => '',
|
||||
// 'firstname' => 'Ford',
|
||||
'lastname' => 'Prefect',
|
||||
'ahv' => 1234,
|
||||
'birthday' => new Date('12.02.1842'),
|
||||
'address' => new Address([
|
||||
'id' => 1,
|
||||
'street' => '58 Orionis',
|
||||
'city' => 'Beteigeuze',
|
||||
'email' => null,
|
||||
]),
|
||||
]);
|
||||
|
||||
printDMO($owner);
|
||||
dumpValidationErrors($owner->validate(OwnerValidator::getInstance()));
|
||||
|
||||
printDMO($client);
|
||||
dumpValidationErrors($client->validate(ClientValidator::getInstance()));
|
||||
|
||||
|
||||
function printDMO(DomainObject $dmo, int $level = 1)
|
||||
{
|
||||
echo "<h$level>".get_class($dmo)."</h$level>\n";
|
||||
echo "<dl style=\"margin-left: {$level}em\">\n";
|
||||
foreach ($dmo as $field => $value)
|
||||
{
|
||||
// display missing if ValueObject->__toString() is empty
|
||||
if ((string)$value === '') $value = '<i>__ missing __</i>';
|
||||
|
||||
// output fieldname and value
|
||||
echo "<dt style=\"float: left\">$field:</dt><dd style=\"margin-left: 10em\">$value</dd>\n";
|
||||
|
||||
// recursive print DMOs .. will obviously not work on self reference ..
|
||||
if ($value instanceOf DomainObject)
|
||||
{
|
||||
$level++;
|
||||
printDMO($value, $level);
|
||||
$level--;
|
||||
}
|
||||
}
|
||||
echo "</dl>\n";
|
||||
}
|
||||
|
||||
function dumpValidationErrors(bool|ResultCollection $validationResult)
|
||||
{
|
||||
if ($validationResult !== true)
|
||||
{
|
||||
echo "<hr><strong>Validation Errors:</strong>\n<pre>";
|
||||
var_dump($validationResult);
|
||||
echo '</pre><hr>';
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue