Download the PHP package nelexa/crossplane without Composer
On this page you can find all versions of the php package nelexa/crossplane. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download nelexa/crossplane
More information about nelexa/crossplane
Files in nelexa/crossplane
Package crossplane
Short Description Reliable and fast NGINX configuration file parser and builder. This is a PHP port of the Nginx Python crossplane package.
License Apache-2.0
Informations about the package crossplane
php-crossplane
Reliable and fast NGINX configuration file parser and builder
:information_source: This is a PHP port of the Nginx Python crossplane package which can be found here.
- Install
- Use in PHP
- Parse config
- Build config from payload
- Lex config
- Register custom Lexer / Builder directives
- Command Line Interface
- crossplane parse
- Schema
- Example
- crossplane parse (advanced)
- crossplane build
- crossplane lex
- Example
- crossplane format
- crossplane minify
Install
Install in project
Global install
Use in PHP
Parse config
This will return the same payload as described in the crossplane parse section.
Build config from payload
This will return a single string that contains an entire NGINX config file.
Lex config
$crossplane->lexer()->lex()
generates 3-tuples.
Register custom Lexer / Builder directives
Command Line Interface
To invoke commands in the command line interface, use vendor/bin/crossplane
if you have installed the package locally in the project, and crossplane
if you have installed the package globally.
crossplane parse
This command will take a path to a main NGINX config file as input, then parse the entire config into the schema defined below, and dumps the entire thing as a JSON payload.
Privacy and Security
Since crossplane
is usually used to create payloads that are sent to
different servers, it's important to keep security in mind. For that
reason, the --ignore
option was added. It can be used to keep certain
sensitive directives out of the payload output entirely.
For example, we always use the equivalent of this flag in the NGINX Amplify Agent out of respect for our users' privacy:
--ignore=auth_basic_user_file,secure_link_secret,ssl_certificate_key,ssl_client_certificate,ssl_password_file,ssl_stapling_file,ssl_trusted_certificate
Schema
Response Object
Config Object
Directive Object
Error Object
Example
The main NGINX config file is at /etc/nginx/nginx.conf
:
And this config file is at /etc/nginx/conf.d/servers.conf
:
So then if you run this:
vendor/bin/crossplane parse --indent=4 /etc/nginx/nginx.conf
The prettified JSON output would look like this:
crossplane parse (advanced)
This tool uses two flags that can change how crossplane
handles
errors.
The first, --no-catch
, can be used if you'd prefer that crossplane
quit parsing after the first error it finds.
The second, --tb-onerror
, will add a "callback"
key to all error
objects in the JSON output, each containing a string representation of
the traceback that would have been raised by the parser if the exception
had not been caught. This can be useful for logging purposes.
crossplane build
This command will take a path to a file as input. The file should
contain a JSON representation of an NGINX config that has the structure
defined above. Saving and using the output from crossplane parse
to
rebuild your config files should not cause any differences in content
except for the formatting.
crossplane lex
This command takes an NGINX config file, splits it into tokens by removing whitespace and comments, and dumps the list of tokens as a JSON array.
Example
Passing in this NGINX config file at /etc/nginx/nginx.conf
:
By running:
vendor/bin/crossplane lex /etc/nginx/nginx.conf
Will result in this JSON output:
However, if you decide to use the --line-numbers
flag, your output
will look
like:
crossplane format
This is a quick and dirty tool that uses crossplane
parse internally to format an NGINX config file.
It serves the purpose of demonstrating what you can do with crossplane
's
parsing abilities. It is not meant to be a fully fleshed out, feature-rich
formatting tool. If that is what you are looking for, then you may want to
look writing your own using crossplane's PHP API.
crossplane minify
This is a simple and fun little tool that uses crossplane
lex internally to remove as much whitespace from an
NGINX config file as possible without affecting what it does. It can't
imagine it will have much of a use to most people, but it demonstrates
the kinds of things you can do with crossplane
's lexing abilities.
All versions of crossplane with dependencies
ext-json Version *
ext-mbstring Version *
symfony/console Version *
symfony/polyfill-php73 Version ^1.23
symfony/polyfill-php80 Version ^1.23