Example #1
0
<?php

include_once './autoload.php';
try {
    $RestServer = new RestServer();
    $RestServer->setStatus(200);
    $id = $RestServer->getId();
    $resource = $RestServer->getResource();
    $verb = $RestServer->getVerb();
    $data = $RestServer->getServerData();
    if ('corps' === $resource) {
        $corps = new Corps();
        $results = null;
        if ($verb === 'GET') {
            if ($id === NULL) {
                $results = $corps->getAll();
            } else {
                $results = $corps->get($id);
            }
        }
        if ($verb === 'PUT') {
            if ($id === NULL) {
                throw new InvalidArgumentException('Corporation ID ' . $id . ' was not found');
            } else {
                $results = $corps->put($data, $id);
                $RestServer->setMessage($id . ' updated');
            }
        }
        if ($verb === 'POST') {
            if ($corps->post($data)) {
                $RestServer->setMessage('Corporation  Added');
Example #2
0
<?php

include_once './bootstrap.php';
$restServer = new RestServer();
try {
    $restServer->setStatus(200);
    $resource = $restServer->getResource();
    $verb = $restServer->getVerb();
    $id = $restServer->getId();
    $serverData = $restServer->getServerData();
    $config = array('DB_DNS' => 'mysql:host=localhost;port=3306;dbname=PHPAdvClassFall2015', 'DB_USER' => 'root', 'DB_PASSWORD' => '');
    $db = new PDO($config['DB_DNS'], $config['DB_USER'], $config['DB_PASSWORD']);
    $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
    if ('address' === $resource) {
        $resourceData = new AddressResoruce();
        if ('GET' === $verb) {
            if (NULL === $id) {
                $restServer->setData($resourceData->getAll());
            } else {
                $restServer->setData($resourceData->get($id));
            }
        }
        if ('POST' === $verb) {
            if ($resourceData->post($serverData)) {
                $restServer->setMessage('Address Added');
                $restServer->setStatus(201);
            } else {
                throw new Exception('Address could not be added');
            }
        }
        if ('PUT' === $verb) {