|
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
|
|
|
const ID = 'id'; |
|
17
|
|
|
const API = 'api'; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* API access object |
|
21
|
|
|
* @var CanvasPest |
|
22
|
|
|
*/ |
|
23
|
|
|
protected $api; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Construct a CanvasSearchDomain from `$params`, requires `id` and `api` |
|
27
|
|
|
* params, will extract `url` param from `api`, if necessary. |
|
28
|
|
|
* |
|
29
|
|
|
* @inheritdoc |
|
30
|
|
|
* |
|
31
|
|
|
* @param mixed[string] $params |
|
|
|
|
|
|
32
|
|
|
*/ |
|
33
|
|
|
public function __construct($params) |
|
34
|
|
|
{ |
|
35
|
|
|
static::requireParameter($params, self::ID); |
|
36
|
|
|
static::requireParameter($params, self::API, CanvasPest::class); |
|
37
|
|
|
|
|
38
|
|
|
static::defaultParameter( |
|
39
|
|
|
$params, |
|
40
|
|
|
'icon', |
|
41
|
|
|
'https://du11hjcvx0uqb.cloudfront.net/dist/images/favicon-e10d657a73.ico' |
|
42
|
|
|
); |
|
43
|
|
|
|
|
44
|
|
|
$this->setApi($params[self::API]); |
|
45
|
|
|
if (empty($params[self::URL])) { |
|
46
|
|
|
$params[self::URL] = preg_replace('%^(.*)/api/v\d+$%', '$1', $this->getApi()->base_url); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
parent::__construct($params); |
|
50
|
|
|
|
|
51
|
|
|
$this->setId($params[self::ID]); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Update the `$api` field |
|
56
|
|
|
* |
|
57
|
|
|
* @param CanvasPest $api |
|
58
|
|
|
* @throws Exception If `$api` is `NULL` |
|
59
|
|
|
*/ |
|
60
|
|
|
protected function setApi(CanvasPest $api) |
|
61
|
|
|
{ |
|
62
|
|
|
if ($api === null) { |
|
63
|
|
|
throw new Exception('Initialized CanvasPest object required'); |
|
64
|
|
|
} |
|
65
|
|
|
$this->api = $api; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Get the Canvas API field |
|
70
|
|
|
* |
|
71
|
|
|
* @return CanvasPest |
|
72
|
|
|
*/ |
|
73
|
|
|
protected function getApi() |
|
74
|
|
|
{ |
|
75
|
|
|
return $this->api; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* Update the ID of the Canvas object |
|
80
|
|
|
* |
|
81
|
|
|
* @used-by AbstractCanvasSearchDomain::__construct() |
|
82
|
|
|
* @param string|integer $id Canvas ID or SIS ID formatted as `sis_*_id:*` |
|
83
|
|
|
*/ |
|
84
|
|
|
protected function setId($id) |
|
85
|
|
|
{ |
|
86
|
|
|
if (!is_numeric($id) && |
|
87
|
|
|
!preg_match('/^sis_[a-z]+_id:\S+$/i', $id) |
|
88
|
|
|
) { |
|
89
|
|
|
throw new Exception('ID must be a Canvas ID or SIS ID, received:' . PHP_EOL . print_r($id, true)); |
|
90
|
|
|
} |
|
91
|
|
|
$this->id = $id; |
|
|
|
|
|
|
92
|
|
|
} |
|
93
|
|
|
} |
|
94
|
|
|
|
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.