Horde_Test::_requiredFileCheck PHP Method

_requiredFileCheck() protected method

Check the list of required files
protected _requiredFileCheck ( array $filelist, string $php, boolean $is_local = false ) : string
$filelist array List of files to check.
$php string PHP CLI location.
$is_local boolean Is filelist a "local" file?
return string The HTML output.
    protected function _requiredFileCheck($filelist, $php, $is_local = false)
    {
        $filedir = $GLOBALS['registry']->get('fileroot');
        $output = $tmp = '';
        foreach ($filelist as $key => $val) {
            $entry = array($key);
            $file = $filedir . '/' . $key;
            $entry2 = null;
            if (file_exists($file)) {
                if (is_readable($file)) {
                    if (is_null($php)) {
                        $entry[] = $this->_status(true);
                        $check_local = true;
                    } else {
                        exec(escapeshellcmd($php) . ' -l ' . escapeshellarg($file), $tmp, $error);
                        if ($error === 255) {
                            $entry[] = $this->_status(false);
                            $entry[] = 'The file <code>' . htmlspecialchars($key) . '</code> has PHP syntax errors:' . "\n<pre>" . htmlspecialchars(trim(implode("\n", $tmp))) . '</pre>';
                        } else {
                            ob_start();
                            include $file;
                            $parse_contents = trim(ob_get_clean());
                            if (strlen($parse_contents)) {
                                $entry[] = $this->_status(false);
                                $contents = file_get_contents($file);
                                if (preg_match("/<?php\\s+/", $contents)) {
                                    $entry[] = 'The file <code>' . htmlspecialchars($key) . '</code> is outputting a non-empty string when parsed. Configuration files should not output anything. Output string:' . "\n<pre>" . htmlspecialchars($parse_contents) . '</pre>';
                                } else {
                                    $entry[] = 'The file <code>' . htmlspecialchars($key) . '</code> appears to be missing the \'&lt;?php\' opening tag.';
                                }
                            } else {
                                $entry[] = $this->_status(true);
                                $check_local = true;
                            }
                        }
                    }
                    if ($check_local && !$is_local) {
                        $local_file = preg_replace("/\\.php\$/", '.local.php', $key);
                        if (file_exists($filedir . '/' . $local_file)) {
                            $entry2 = $this->_requiredFileCheck(array($local_file => null), $php, true);
                        }
                    }
                } else {
                    $entry[] = $this->_status(false);
                    $entry[] = 'The file <code>' . htmlspecialchars($key) . '</code> is not readable by the web user.';
                }
            } else {
                $entry[] = $this->_status(false);
                $entry[] = empty($val) ? 'The file <code>' . htmlspecialchars($key) . '</code> appears to be missing.' : $val;
            }
            $output .= $this->_outputLine($entry);
            if (!is_null($entry2)) {
                $output .= $entry2;
            }
        }
        return $output;
    }