aboutsummaryrefslogtreecommitdiff
path: root/lib/classes/JsonApi/Routes/Wiki/HelperTrait.php
blob: 00bd43e1ecc7d9cdd02e4de8df6cfc484befffb4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<?php

namespace JsonApi\Routes\Wiki;

use JsonApi\Errors\BadRequestException;
use JsonApi\Errors\RecordNotFoundException;

trait HelperTrait
{
    protected static function findWikiPage($wikiPageId)
    {
        if (!preg_match('/^([^_]+)_(.+)$/', $wikiPageId, $matches)) {
            throw new BadRequestException();
        }

        if (!$wikiPage = \WikiPage::findLatestPage($matches[1], $matches[2])) {
            throw new RecordNotFoundException();
        }

        return $wikiPage;
    }
}