1 | <?php |
||
33 | class UriSigner |
||
34 | { |
||
35 | /** |
||
36 | * The resolved secret. |
||
37 | * |
||
38 | * @var string |
||
39 | */ |
||
40 | private $secret; |
||
41 | |||
42 | /** |
||
43 | * The config to obtain the secret parameter from. |
||
44 | * |
||
45 | * @var TensideJsonConfig |
||
46 | */ |
||
47 | private $tensideConfig; |
||
48 | |||
49 | /** |
||
50 | * Constructor. |
||
51 | * |
||
52 | * @param TensideJsonConfig $tensideConfig The tenside config. |
||
53 | */ |
||
54 | public function __construct(TensideJsonConfig $tensideConfig) |
||
58 | |||
59 | /** |
||
60 | * Signs a URI. |
||
61 | * |
||
62 | * The given URI is signed by adding a _hash query string parameter |
||
63 | * which value depends on the URI and the secret. |
||
64 | * |
||
65 | * @param string $uri A URI to sign. |
||
66 | * |
||
67 | * @return string The signed URI |
||
68 | */ |
||
69 | public function sign($uri) |
||
82 | |||
83 | /** |
||
84 | * Checks that a URI contains the correct hash. |
||
85 | * |
||
86 | * The _hash query string parameter must be the last one |
||
87 | * (as it is generated that way by the sign() method, it should |
||
88 | * never be a problem). |
||
89 | * |
||
90 | * @param string $uri A signed URI. |
||
91 | * |
||
92 | * @return bool True if the URI is signed correctly, false otherwise |
||
93 | */ |
||
94 | public function check($uri) |
||
112 | |||
113 | /** |
||
114 | * Calculate the hash. |
||
115 | * |
||
116 | * @param string $uri The uri to calculate the hash for. |
||
117 | * |
||
118 | * @return string |
||
119 | */ |
||
120 | private function computeHash($uri) |
||
128 | |||
129 | /** |
||
130 | * Build the url. |
||
131 | * |
||
132 | * @param array $url The url values. |
||
133 | * |
||
134 | * @param array $params The url parameters. |
||
135 | * |
||
136 | * @return string |
||
137 | * |
||
138 | * @SuppressWarnings(PHPMD.CyclomaticComplexity) |
||
139 | * @SuppressWarnings(PHPMD.NPathComplexity) |
||
140 | */ |
||
141 | private function buildUrl(array $url, array $params = array()) |
||
158 | } |
||
159 |
This check looks for type mismatches where the missing type is
false
. This is usually indicative of an error condtion.Consider the follow example
This function either returns a new
DateTime
object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returnedfalse
before passing on the value to another function or method that may not be able to handle afalse
.