2017 © Pedro Peláez
 

library nginxparser

A class for parsing nginx config files in PHP

image

jorisros/nginxparser

A class for parsing nginx config files in PHP

  • Sunday, September 25, 2016
  • by jorisros
  • Repository
  • 1 Watchers
  • 1 Stars
  • 15 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 3 Open issues
  • 2 Versions
  • 7 % Grown

The README.md

Build Status, (*1)

NginxParser

Read and create Nginx config files in php, (*2)

Requirements

  • PHP >= 7.4
  • Nginx installed (for the validate function)

Composer

Use composer to to add the classes to your project, (*3)

composer require jorisros/nginxparser

Run tests

Run in the main directory the following command, (*4)

./vendor/bin/phpunit tests

Examples

Examples to use the class, (*5)

Simple config file, (*6)

<?php

require __DIR__ . '/vendor/autoload.php';

use JorisRos\NginxParser\NginxParser;
use JorisRos\NginxParser\NginxElement;

$config = new NginxParser('server');

$location = new NginxParser('location','/');
$location->setRoot('/usr/share/nginx/html')
         ->setIndex(array('index.html', 'index.htm'));

$config ->setPort(80)
        ->setServerName(array('localhost','local','serveralias'))
        ->setAccessLog('/var/log/nginx/log/host.access.log')
        ->setLocation($location);

if($config->validate())
{
    $strFile = $config->build();
    file_put_contents('server.conf', $strFile);
}else{
    foreach ($config->getValidatorErrors() as $error) {
        # code...
    }
}

It will result in, (*7)

server {
    port        80;
    server_name     localhost;
    server_alias        local serveralias;
    access_log      /var/log/nginx/log/host.access.log;

    location / {
        root        /usr/share/nginx/html;
        index       index.html index.htm;
    }

}

Read existing config file, (*8)

<?php

require __DIR__ . '/vendor/autoload.php';

use JorisRos\NginxParser\NginxParser;
use JorisRos\NginxParser\NginxElement;

$d = new NginxParser();
$objects = $d->readFromFile('Resources/nginx-config/nginx.conf');

//var_dump($objects);

foreach($objects as $object)
{
    print($object->build());
}

Bitdeli Badge, (*9)

The Versions

25/09 2016

dev-master

9999999-dev

A class for parsing nginx config files in PHP

  Sources   Download

MIT

The Requires

  • php >=5.3.1

 

by Joris Ros

25/09 2016

1.1

1.1.0.0

A class for parsing nginx config files in PHP

  Sources   Download

MIT

The Requires

  • php >=5.3.1

 

by Joris Ros