|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace smtech\StMarksSearch\Canvas; |
|
4
|
|
|
|
|
5
|
|
|
use Exception; |
|
6
|
|
|
use smtech\CanvasPest\CanvasPest; |
|
7
|
|
|
use smtech\StMarksSearch\AbstractSearchDomain; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Parent class for all Canvas search domains |
|
11
|
|
|
* |
|
12
|
|
|
* @author Seth Battis <[email protected]> |
|
13
|
|
|
*/ |
|
14
|
|
|
abstract class AbstractCanvasSearchDomain extends AbstractSearchDomain |
|
15
|
|
|
{ |
|
16
|
|
|
use RequireCanvasPestParameter; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Canvas ID or SIS ID of the Canvas object |
|
20
|
|
|
* @var string|integer |
|
21
|
|
|
*/ |
|
22
|
|
|
protected $id; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Construct a CanvasSearchDomain from `$params`, requires `id` and `api` |
|
26
|
|
|
* params, will extract `url` param from `api`, if necessary. |
|
27
|
|
|
* |
|
28
|
|
|
* @inheritdoc |
|
29
|
|
|
* |
|
30
|
|
|
* @param mixed[string] $params |
|
|
|
|
|
|
31
|
|
|
*/ |
|
32
|
|
|
public function __construct($params) |
|
33
|
|
|
{ |
|
34
|
|
|
$this->requireCanvasPestParameter($params); |
|
35
|
|
|
|
|
36
|
|
View Code Duplication |
if (empty($params['url'])) { |
|
|
|
|
|
|
37
|
|
|
$params['url'] = preg_replace('%^(.*)/api/v\d+$%', '$1', $this->getApi()->base_url); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
parent::__construct($params); |
|
41
|
|
|
|
|
42
|
|
|
assert(isset($params['id']), new Exception('`id` parameter required')); |
|
43
|
|
|
$this->setId($params['id']); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Update the ID of the Canvas object |
|
48
|
|
|
* |
|
49
|
|
|
* @used-by AbstractCanvasSearchDomain::__construct() |
|
50
|
|
|
* @param string|integer $id Canvas ID or SIS ID formatted as `sis_*_id:*` |
|
51
|
|
|
*/ |
|
52
|
|
|
protected function setId($id) |
|
53
|
|
|
{ |
|
54
|
|
|
assert( |
|
55
|
|
|
is_numeric($id) || |
|
56
|
|
|
preg_match('/^sis_[a-z]+_id:\S+$/i', $id), |
|
57
|
|
|
new Exception('ID must be a Canvas ID or SIS ID, received:' . PHP_EOL . print_r($id, true)) |
|
58
|
|
|
); |
|
59
|
|
|
$this->id = $id; |
|
|
|
|
|
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Get the Canvas object ID |
|
64
|
|
|
* |
|
65
|
|
|
* @return string|integer |
|
66
|
|
|
*/ |
|
67
|
|
|
public function getId() |
|
68
|
|
|
{ |
|
69
|
|
|
return $this->id; |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.