WebHelper Parser Interface


Keywords
configuration, parser, web, server, apache, nginx, devops
License
MIT

Documentation

Web Server Configuration File Generic Parser

Part of WebHelper, a Generic Httpd Configuration Helper.

Build Status Scrutinizer Code Quality Code Coverage Code Climate SensioLabsInsight Dependency Status Latest Stable Version License

Installation

composer require webhelper/parser

Basic Usage

Parse an Apache configuration file:

use WebHelper\Parser\Factory;
use WebHelper\Parser\ParserException;
use WebHelper\Parser\InvalidConfigException;

$factory = new Factory()
$parser = $factory->createParser('apache');
$parser->getServer()->setPrefix('/usr');

try {
    $activeConfig = $parser
        ->setConfigFile('/private/etc/apache2/httpd.conf')
        ->getActiveConfig();

    echo $parser->getOriginalConfig();

    echo var_export($activeConfig, true).PHP_EOL;
} catch (ParserException $e) {
    //file not found
    var_dump($e->getMessage());
} catch (InvalidConfigException $e) {
    //empty config or syntax error
    var_dump($e->getMessage());
}

Or the same with Nginx

use WebHelper\Parser\Factory;

$factory = new Factory()
$parser = $factory->createParser('nginx');
$parser->getServer()->setPrefix('/usr/sbin/');

$activeConfig = $parser
        ->setConfigFile('/etc/nginx/nginx.conf')
        ->getActiveConfig();

// etc...

Known issues

  • Does not support old macos9 file format.