コード例 #1
0
<?php

/* Reputation data of a particular person */
$app->get('/character/{id}/', function ($id) use($app) {
    $dbEngine = $app['config']['dbEngine'];
    $dbClass = '\\Mikron\\RpgSystem\\Infrastructure\\Storage\\' . $app['config']['databaseReference'][$dbEngine] . 'StorageEngine';
    $connection = new $dbClass($app['config'][$dbEngine]);
    $factory = new \Mikron\RpgSystem\Infrastructure\Factory\Character();
    $person = $factory->retrieveCharacterFromDb($connection, $id);
    $output = new \Mikron\RpgSystem\Domain\Service\Output("Character data", "", [$person->getName()]);
    return $app->json($output->getArrayForJson());
});
コード例 #2
0
<?php

/* List of all characters available for display */
$app->get('/characters/', function () use($app) {
    $dbEngine = $app['config']['dbEngine'];
    $dbClass = '\\Mikron\\RpgSystem\\Infrastructure\\Storage\\' . $app['config']['databaseReference'][$dbEngine] . 'StorageEngine';
    $connection = new $dbClass($app['config'][$dbEngine]);
    $factory = new \Mikron\RpgSystem\Infrastructure\Factory\Character();
    $characterObjects = $factory->retrieveAllFromDb($connection);
    $characterList = [];
    foreach ($characterObjects as $character) {
        $characterList[] = $character->getName();
    }
    $output = new \Mikron\RpgSystem\Domain\Service\Output("List", "This is a complete list of character available for your peruse. If the character you are looking for is not" . " here, please ensure you have correct access rights.", $characterList);
    return $app->json($output->getArrayForJson());
});