You are here

private function DebuggingReviewForm::parsePhpModules in Lightweight Directory Access Protocol (LDAP) 8.3

Generates an array of values from phpinfo().

Return value

array Module list.

File

ldap_help/src/Form/DebuggingReviewForm.php, line 173

Class

DebuggingReviewForm
Form to allow for debugging review.

Namespace

Drupal\ldap_help\Form

Code

private function parsePhpModules() {
  ob_start();
  phpinfo();
  $s = ob_get_contents();
  ob_end_clean();
  $s = strip_tags($s, '<h2><th><td>');
  $s = preg_replace('/<th[^>]*>([^<]+)<\\/th>/', "<info>\\1</info>", $s);
  $s = preg_replace('/<td[^>]*>([^<]+)<\\/td>/', "<info>\\1</info>", $s);
  $vtmp = preg_split('/(<h2>[^<]+<\\/h2>)/', $s, -1, PREG_SPLIT_DELIM_CAPTURE);
  $vmodules = [];
  for ($i = 1; $i < count($vtmp); $i++) {
    if (preg_match('/<h2>([^<]+)<\\/h2>/', $vtmp[$i], $vmat)) {
      $vname = trim($vmat[1]);
      $vtmp2 = explode("\n", $vtmp[$i + 1]);
      foreach ($vtmp2 as $vone) {
        $vpat = '<info>([^<]+)<\\/info>';
        $vpat3 = "/{$vpat}\\s*{$vpat}\\s*{$vpat}/";
        $vpat2 = "/{$vpat}\\s*{$vpat}/";

        // 3cols.
        if (preg_match($vpat3, $vone, $vmat)) {
          $vmodules[$vname][trim($vmat[1])] = [
            trim($vmat[2]),
            trim($vmat[3]),
          ];
        }
        elseif (preg_match($vpat2, $vone, $vmat)) {
          $vmodules[$vname][trim($vmat[1])] = trim($vmat[2]);
        }
      }
    }
  }
  return $vmodules;
}