webhelper/parser

WebHelper Parser Interface

0.5.0 2016-09-18 10:59 UTC

This package is auto-updated.

Last update: 2024-11-18 08:23:32 UTC


README

Part of WebHelper, a Generic Httpd Configuration Helper.

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

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.