本文整理汇总了PHP中Rest::getApiSpecs方法的典型用法代码示例。如果您正苦于以下问题:PHP Rest::getApiSpecs方法的具体用法?PHP Rest::getApiSpecs怎么用?PHP Rest::getApiSpecs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Rest
的用法示例。
在下文中一共展示了Rest::getApiSpecs方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validate
/**
* First pass of the spec: parse and stop execution on errors
* @todo: introduce ValidationException
*
* @param SpecRest $restSpec
* @return void
*/
public function validate(Rest $restSpec)
{
$apiSpec = $restSpec->getApiSpecs();
if (empty($apiSpec)) {
throw new \RuntimeException('No API spec provided');
}
foreach ($apiSpec as $apiSpec) {
foreach ($apiSpec->getUrlSpecs() as $urlSpec) {
$useCases = $urlSpec->getUseCases();
if (!$useCases) {
throw new \RuntimeException('You have to specify use cases inside the URL specificetion');
}
foreach ($useCases as $urlUseCaseSpec) {
if (!$urlUseCaseSpec->getRequest()) {
throw new \RuntimeException('You have to add request specification using givenRequest() function');
}
if (!$urlUseCaseSpec->getExpectedResponseSpec()) {
throw new \RuntimeException('You have to specify expected response using expectResponse() function');
}
if ($urlUseCaseSpec->isATemplate() && !$urlUseCaseSpec->getExampleParameters()) {
throw new \RuntimeException('To use an URL template you have to provide example parameters to call the URL with.');
}
if ($exampleParams = $urlUseCaseSpec->getExampleParameters()) {
foreach ($exampleParams as $name => $value) {
$placeholder = $urlUseCaseSpec->buildParameterPlaceholder($name);
if (strpos($urlUseCaseSpec->getUrl(), $placeholder) === false) {
throw new \RuntimeException(sprintf('You specified example parameter, but the placeholder "%s" for it is missing in your URL', $placeholder));
}
}
}
}
}
}
}