protected function CssW3Form::testFiles in Advanced CSS/JS Aggregation 8.2
Same name and namespace in other branches
- 8.4 advagg_validator/src/Form/CssW3Form.php \Drupal\advagg_validator\Form\CssW3Form::testFiles()
- 8.3 advagg_validator/src/Form/CssW3Form.php \Drupal\advagg_validator\Form\CssW3Form::testFiles()
Perform server side test(s) on all given files.
Parameters
array $files: An array of files to be tested.
array $options: (optional) An array of options to use in the test.
Return value
array An array of files with the result.
Overrides BaseValidatorForm::testFiles
2 calls to CssW3Form::testFiles()
- CssW3Form::submitCheckAll in advagg_validator/
src/ Form/ CssW3Form.php - CssW3Form::submitCheckDirectory in advagg_validator/
src/ Form/ CssW3Form.php
File
- advagg_validator/
src/ Form/ CssW3Form.php, line 150
Class
- CssW3Form
- Configure form for W3C validation of CSS files.
Namespace
Drupal\advagg_validator\FormCode
protected function testFiles(array $files, array $options = []) {
$output = [];
$file_info = $this->advaggFiles
->getMultiple($files);
foreach ($files as $filename) {
// Skip missing files.
if (!file_exists($filename)) {
continue;
}
$file_contents = file_get_contents($filename);
$lines = file($filename);
$content_hash = Crypt::hashBase64($file_contents);
// If saved file information not current update filestore.
if ($file_info[$filename]['content_hash'] != $content_hash) {
$this->advagg_files
->scanFile($filename, $file_info[$filename], $file_contents);
}
// If saved validation results available use them rather than re-run.
if (isset($file_info[$filename]['validation']['w3'])) {
$output[$filename]['jigsaw.w3.org'] = $file_info[$filename]['validation']['w3'];
continue;
}
// Run jigsaw.w3.org validator.
$output[$filename]['jigsaw.w3.org'] = $this
->testW3C($filename, $options);
// Get extra context for errors.
if (!empty($output[$filename]['jigsaw.w3.org']['errors'])) {
foreach ($output[$filename]['jigsaw.w3.org']['errors'] as &$value) {
if (isset($value['line'])) {
$value['linedata'] = $lines[$value['line'] - 1];
if (strlen($value['linedata']) > 512) {
unset($value['linedata']);
}
}
}
unset($value);
}
if (!empty($output[$filename]['jigsaw.w3.org']['warnings'])) {
foreach ($output[$filename]['jigsaw.w3.org']['warnings'] as &$value) {
if (isset($value['line'])) {
$value['linedata'] = $lines[$value['line'] - 1];
if (strlen($value['linedata']) > 512) {
unset($value['linedata']);
}
}
}
unset($value);
}
// Save data.
$file_info[$filename]['validation']['w3'] = $output[$filename]['jigsaw.w3.org'];
$this->advaggFiles
->set($filename, $file_info[$filename]);
}
return $output;
}