-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtenonTest.class.php
73 lines (61 loc) · 1.92 KB
/
tenonTest.class.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
68
69
70
71
72
73
<?php
/**
* This class submits a request against the Tenon API for automatic
* accessibility testing.
*
* Essentially all this does is populate a variable, $tenonResponse, with the JSON response from Tenon
*
*/
class tenonTest
{
protected $url, $opts;
public $tenonResponse, $tCode;
/**
* Class constructor
*
* @param string $url the API url to post your request to
* @param array $opts options for the request
*/
public function __construct($url, $opts)
{
$this->url = $url;
$this->opts = $opts;
$this->tenonResponse = '';
}
/**
* Submits the HTML source for testing
*
* @param bool $printInfo whether or not to print the output from curl_getinfo (usually for debugging only)
*
* @return string the results, formatted as JSON
*/
public function submit($printInfo = false)
{
if (true == $printInfo) {
echo '<h2>Options Passed To TenonTest</h2><pre><br>';
var_dump($this->opts);
echo '</pre>';
}
//open connection
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $this->opts);
//execute post and get results
$result = curl_exec($ch);
if (true == $printInfo) {
echo 'ERROR INFO (if any): ' . curl_error($ch) . '<br>';
echo '<h2>Curl Info </h2><pre><br>';
print_r(curl_getinfo($ch));
echo '</pre>';
}
$this->tCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
//close connection
curl_close($ch);
//the test results
$this->tenonResponse = $result;
}
}