Skip to content

Commit

Permalink
more cleanup, begin adding back phpally integration
Browse files Browse the repository at this point in the history
  • Loading branch information
panbed committed Sep 30, 2024
1 parent 7516927 commit 24e796a
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 29 deletions.
16 changes: 1 addition & 15 deletions src/Services/AsyncEqualAccessReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@
// send asynchronous requests to a Lambda function's API gateway

class AsyncEqualAccessReport {


/** @var App\Service\HtmlService */
protected $htmlService;

private $client;

private $awsAccessKeyId;
Expand Down Expand Up @@ -137,24 +132,15 @@ public function postSingleAsync(ContentItem $contentItem) {
// POST document to Lambda and wait for fulfillment
$this->logToServer("Sending to single promise...");
$promise = $client->sendAsync($signedRequest);
// $promise->then(function($response) {
// $this->logToServer("Fulfilled!");
// $responseContents = $response->getBody()->getContents();
// $report = json_decode($responseContents, true);
// return $report;
// });

$response = $promise->wait();


if ($response) {
$this->logToServer("Fulfilled!");
$contents = $response->getBody()->getContents();
$this->logToServer(json_encode($contents));
$report = json_decode($contents, true);
}

// Return the single Equal Access report
// Return the Equal Access report
return $report;
}

Expand Down
15 changes: 5 additions & 10 deletions src/Services/EqualAccessService.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,12 @@
TODO:
- check for phpally-ignore on html snippets and ignore them
- think about how to migrate old database data to equal access
- find way to skip rules in aws perhaps(?)
*/

class EqualAccessService {

/** @var App\Service\HtmlService */
protected $htmlService;

// (maybe) force full rescan (hopefully not) and also check for phpally-ignore(?)

// probably should disable rules in equal access itself, this is temporary hopefully
private $skipRules = array(
"html_lang_exists",
Expand Down Expand Up @@ -71,7 +68,7 @@ public function xpathToSnippet($domXPath, $xpathQuery) {
}

public function checkforIgnoreClass($htmlSnippet) {
// Assume no phpAllyIgnore by defalt
// Assume no phpAllyIgnore by default
$phpAllyIgnore = false;

if ($htmlSnippet) {
Expand Down Expand Up @@ -109,13 +106,11 @@ public function generateReport($json, $document) {
$issueCounts[$udoitRule] = 1;
}

// UDOIT database has 'html' and 'preview_html',
// where 'preview_html' is the parent of the offending html
// $issueHtml = $this->xpathToSnippet($xpath, $xpathQuery);

// Check for null (aka no XPath result was found) and skip.
// Otherwise, create a new issue with the HTML from the XPath query.
if (!is_null($issueHtml)) {
// UDOIT database has 'html' and 'preview_html',
// where 'preview_html' is the parent of the offending html
$parentIssueHtml = $issueHtml->parentNode;

$issue = new PhpAllyIssue($udoitRule, $issueHtml, $parentIssueHtml, null);
Expand Down
6 changes: 3 additions & 3 deletions src/Services/LmsFetchService.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,11 @@ public function updateReport(Course $course, User $user): Report
// Performs PHPAlly scan on each Content Item.
private function scanContentItems(array $contentItems)
{

$scanner = $_ENV['ACCESSIBILITY_CHECKER'];
$equalAccessReports = null;

// Testing async post requests...
// If we're using Equal Access Lambda, send all the requests to Lambda for the
// reports at once and save them all into an array (which should be in the same order as the ContentItems)
if ($scanner == "equalaccess_lambda" && count($contentItems) > 0) {
$equalAccessReports = $this->asyncReport->postMultipleAsync($contentItems);
}
Expand All @@ -214,7 +214,7 @@ private function scanContentItems(array $contentItems)

try {
// Scan the content item with the scanner set in the environment.
$report = $this->scanner->scanContentItem($contentItem, $equalAccessReports[$index++]);
$report = $this->scanner->scanContentItem($contentItem, $equalAccessReports == null ? null : $equalAccessReports[$index++], $this->util);

if ($report) {
// TODO: Do something with report errors
Expand Down
14 changes: 13 additions & 1 deletion src/Services/ScannerService.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,21 @@
use App\Services\EqualAccessService;
use App\Services\AsyncEqualAccessReport;

use App\Services\HtmlService;
use App\Services\UtilityService;

use DOMDocument;

// Main scanner class, expects a phpAlly-styled JSON report from whichever scanner is run

class ScannerService {

// /** @var UtilityService $util */
// protected $util;

// /** @var HtmlService $htmlService */
// protected $htmlService;

public function logToServer(string $message) {
$options = [
'http' => [
Expand All @@ -27,14 +36,17 @@ public function logToServer(string $message) {
file_get_contents("http://host.docker.internal:3000/log", false, $context);
}

public function scanContentItem(ContentItem $contentItem, $scannerReport = null) {
public function scanContentItem(ContentItem $contentItem, $scannerReport = null, UtilityService $util) {
// Optional argument scannerReport is used when handling async Equal Access
// requests, so then all we have to do is just make those into a UDOIT report
$scanner = $_ENV['ACCESSIBILITY_CHECKER'];
$report = null;

if ($scanner == 'phpally') {
// TODO: implement flow for phpally scanning
$htmlService = new HtmlService();
$phpAlly = new PhpAllyService($htmlService, $util);
$report = $phpAlly->scanContentItem($contentItem);
}
else if ($scanner == 'equalaccess_local') {
// TODO: create a LocalAccessibilityService
Expand Down

0 comments on commit 24e796a

Please sign in to comment.