Exemplo n.º 1
0
            $url->setModelFirstPart($value);
        } elseif ($key % 2 != 0) {
            if (!empty($value) && !is_numeric($value)) {
                throw new InvalidArgumentException('Second Argument must be an integer !');
            } elseif ($key === 1 && is_numeric($value)) {
                $url->setIdFirstPart($value);
            } elseif (is_numeric($value)) {
                $url->setIdSecondPart($value);
            }
        } elseif ($key % 2 == 0) {
            if ($key === 2 && !is_numeric($value)) {
                $url->setModelSecondPart($value);
            }
        }
    }
} catch (InvalidArgumentException $e) {
    print $e->getMessage();
    exit;
}
/**
 * Define the used model by analyze the object URL
 * and his attributes. After include the controller to use.
 */
$model = constructRoute($url);
if (existController($model)) {
    include_once APPLICATION_PATH . '/controllers/' . $model . '.controller.php';
} elseif ($model === '') {
    include_once APPLICATION_PATH . '/controllers/default.controller.php';
} else {
    Rest::sendResponse(404);
}
Exemplo n.º 2
0
        }
        break;
    case 'delete':
        $picture_ = new Picture();
        $pictureMapper = new \PictureMapper();
        if ($pictureMapper->deletePicture()) {
            Rest::sendResponse(200);
        }
        break;
    case 'put':
        try {
            $picture_ = new Picture();
            $data_picture_ = $http->getRequestVars();
            $pictureObject = initObject($data_picture_, $picture_, true);
            if (!emptyObject($pictureObject)) {
                $pictureMapper = new \PictureMapper();
                if ($pictureMapper->updatePicture($pictureObject)) {
                    Rest::sendResponse(200);
                }
            } else {
                throw new InvalidArgumentException('Need arguments to UPDATE data !');
            }
        } catch (InvalidArgumentException $e) {
            print $e->getMessage();
            exit;
        }
        break;
    default:
        Rest::sendResponse(501);
        break;
}