owncdn / lib-nginx-config-processor
Nginx 配置文件处理器。
v0.3.0
2018-11-18 18:06 UTC
Requires
- php: >=7.0
This package is auto-updated.
Last update: 2024-09-19 10:49:53 UTC
README
https://packagist.org.cn/packages/owncdn/lib-nginx-config-processor
(c) 2014-2016 Roman Piták roman@pitak.net
(c) 2016-2017 Peter Cui kuailedeyv@126.com
(c) 2018 Matthew Glinski matt@mglinski.com
PHP Nginx 配置文件处理器(解析器,创建器)。
安装
最佳安装方式是使用 Composer 依赖管理器。
php composer.phar require owncloud/lib-nginx-config-processor
功能
格式化输出
<?php Scope::fromFile('m1.conf')->saveToFile('out.conf');
配置创建
<?php
Scope::create()
->addDirective(Directive::create('server')
->setChildScope(Scope::create()
->addDirective(Directive::create('listen', 8080))
->addDirective(Directive::create('server_name', 'example.net'))
->addDirective(Directive::create('root', 'C:/www/example_net'))
->addDirective(Directive::create('location', '^~ /var/', Scope::create()
->addDirective(Directive::create('deny', 'all'))
)->setCommentText('Deny access for location /var/')
)
)
)
->saveToFile('example.net');
文件 example.net
server {
listen 8080;
server_name example.net;
root C:/www/example_net;
location ^~ /var/ { # Deny access for location /var/
deny all;
}
}
注释处理
简单注释
<?php echo new Comment("This is a simple comment.");
输出
# This is a simple comment.
多行注释
<?php
echo new Comment("This \nis \r\na multi
line " . PHP_EOL . "comment.");
输出
# This
# is
# a multi
# line
# comment.
带有简单注释的指令
<?php echo Directive::create('deny', 'all')->setCommentText('Directive with a comment');
输出
deny all; # Directive with a comment
带有多行注释的指令
<?php echo Directive::create('deny', 'all')->setCommentText('Directive
with a multi line comment');
输出
# Directive
# with a multi line comment
deny all;