1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Njasm\Soundcloud\Resource; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* SoundCloud API wrapper in PHP |
7
|
|
|
* |
8
|
|
|
* @author Nelson J Morais <[email protected]> |
9
|
|
|
* @copyright 2014 Nelson J Morais <[email protected]> |
10
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT |
11
|
|
|
* @link http://github.com/njasm/soundcloud |
12
|
|
|
* @package Njasm\Soundcloud |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
class Resource implements ResourceInterface |
16
|
|
|
{ |
17
|
|
|
private $path; |
18
|
|
|
private $params = array(); |
19
|
|
|
private $verb; |
20
|
|
|
private $availableVerbs = array('get', 'post', 'put', 'delete', 'patch', 'options'); |
21
|
|
|
|
22
|
27 |
|
public function __construct($verb = null, $path = null, array $params = array()) |
23
|
|
|
{ |
24
|
27 |
|
$this->isValidVerb($verb); |
25
|
26 |
|
$this->verb = $verb; |
26
|
26 |
|
$this->params = $params; |
27
|
|
|
|
28
|
26 |
|
if ($this->isValidPath($path) === false) { |
29
|
1 |
|
throw new \RuntimeException( |
30
|
1 |
|
"Path cannot be other then a string type and should start with a '/' (Slash)." |
31
|
|
|
); |
32
|
|
|
} |
33
|
|
|
|
34
|
25 |
|
$this->path = $path; |
35
|
25 |
|
} |
36
|
|
|
|
37
|
6 |
|
public function setParams(array $params = array()) |
38
|
|
|
{ |
39
|
6 |
|
$this->params = array_merge($this->params, $params); |
40
|
6 |
|
} |
41
|
|
|
|
42
|
14 |
|
public function getParams() |
43
|
|
|
{ |
44
|
14 |
|
return $this->params; |
45
|
|
|
} |
46
|
|
|
|
47
|
13 |
|
public function getPath() |
48
|
|
|
{ |
49
|
13 |
|
return $this->path; |
50
|
|
|
} |
51
|
|
|
|
52
|
17 |
|
public function getVerb() |
53
|
|
|
{ |
54
|
17 |
|
return $this->verb; |
55
|
|
|
} |
56
|
|
|
|
57
|
27 |
|
private function isValidVerb($verb) |
58
|
|
|
{ |
59
|
27 |
|
if (in_array(strtolower($verb), $this->availableVerbs) === false) { |
60
|
1 |
|
throw new \OutOfBoundsException("Resource of type: $verb, not available!"); |
61
|
|
|
} |
62
|
26 |
|
} |
63
|
|
|
|
64
|
26 |
|
private function isValidPath($path) |
65
|
|
|
{ |
66
|
26 |
|
return is_string($path) === true && substr($path, 0, 1) === "/"; |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|