PHP code example of nelexa / crossplane
1. Go to this page and download the library: Download nelexa/crossplane library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
nelexa / crossplane example snippets
$crossplane = new \Nelexa\NginxParser\Crossplane();
$lexer = $crossplane->lexer(); // gets \Nelexa\NginxParser\Lexer instance
$builder = $crossplane->builder(); // gets \Nelexa\NginxParser\Builder instance
$parser = $crossplane->parser(); // gets \Nelexa\NginxParser\Parser instance
$analyzer = $crossplane->analyzer(); // gets \Nelexa\NginxParser\Analyzer instance
$formatter = $crossplane->formatter(); // gets \Nelexa\NginxParser\Formatter instance
$nginxConfigFile = '/etc/nginx/nginx.conf';
$crossplane = new \Nelexa\NginxParser\Crossplane();
$payload = $crossplane->parser()->parse($nginxConfigFile, $parseOptions = [
\Nelexa\NginxParser\Parser::OPTION_COMMENTS => true,
\Nelexa\NginxParser\Parser::OPTION_COMBINE => true,
// etc...
]);
$crossplane = new \Nelexa\NginxParser\Crossplane();
$config = $crossplane->builder()->build(
[[
'directive' => 'events',
'args' => [],
'block' => [[
'directive' => 'worker_connections',
'args' => ['1024'],
]],
]]
);
$crossplane = new \Nelexa\NginxParser\Crossplane();
$tokensIterator = $crossplane->lexer()->lex('/etc/nginx/nginx.conf');
$tokensArray = iterator_to_array($tokensIterator);
[
[
'user', // token
1, // line
false, // quote
],
[
'www-data',
1,
false,
],
[
';',
1,
false,
],
[
'worker_processes',
2,
false,
],
[
'auto',
2,
false,
],
[
';',
2,
false,
],
[
'pid',
3,
false,
],
[
'/run/nginx.pid',
3,
false,
],
[
';',
3,
false,
],
// etc
]
$crossplane->registerExtension(new class() implements \Nelexa\NginxParser\Ext\CrossplaneExtension {
public function registerExtension(\Nelexa\NginxParser\Crossplane $crossplane): void
{
$crossplane->lexer()->registerExternalLexer(/* args */);
$crossplane->builder()->registerExternalBuilder(/* args */);
}
public function lex(\Iterator $charIterator, string $directive): ?\Generator
{
}
public function build(array $stmt, string $padding, int $indent = 4, bool $tabs = false): string
{
}
});