-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAbstractUrlsParser.php
67 lines (58 loc) · 1.35 KB
/
AbstractUrlsParser.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
/**
* Base class for edx and coursera urls parser
*
* @author Tatiana Braginets
*/
require_once 'Parser.php';
require_once 'IllegalStateException.php';
abstract class AbstractUrlsParser implements Parser
{
protected $urls,$courseImages, $isParsed;
/**
* Tests if array is populated after parsing
*
* @return boolean
*/
public function isValid()
{
return $this->isParsed && $this->urls && sizeof($this->urls) > 0;
}
/**
*
* @return array of course urls, each entry is in format
* 'https://www.coursera.org/course/...'
* or 'https://www.edx.org/courses/...'
*/
public function getUrls()
{
$this->checkState();
return $this->urls;
}
/**
*
* @return string image url for a course
*/
public function getCourseImage($url)
{
$this->checkState();
return $this->courseImages[$url];
}
/**
* You cannot call the getters in this object until the values are populated,
* which happens when you call parse().
*
* @throws IllegalStateException
*/
protected function checkState()
{
if (!$this->isParsed) {
throw new IllegalStateException(sprintf(
"must call parse() before calling '%s::%s'"
, __CLASS__
, __METHOD__
));
}
}
}
?>