webhelper/parser

WebHelper 解析器接口

0.5.0 2016-09-18 10:59 UTC

This package is auto-updated.

Last update: 2024-09-18 07:59:41 UTC


README

WebHelper(http://github.com/JamesRezo/WebHelper)的一部分,一个通用的 Httpd 配置助手。

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

安装

composer require webhelper/parser

基本用法

解析 Apache 配置文件

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());
}

或用 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...

已知问题

  • 不支持旧 macos9 文件格式。