Skip to content

Instantly share code, notes, and snippets.

@errogaht
Created November 23, 2015 16:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save errogaht/c1a9da139eeaea8b03fc to your computer and use it in GitHub Desktop.
Save errogaht/c1a9da139eeaea8b03fc to your computer and use it in GitHub Desktop.
test.php
<?php
require_once("vendor/autoload.php");
$code = file_get_contents('settings.php');
$settings = [];
$parser = new PhpParser\Parser(new PhpParser\Lexer\Emulative);
try {
$stmts = $parser->parse($code);
foreach ($stmts as $item) {
if ($item->getType() === "Expr_Assign") {
if (!empty($item->expr)) {
if (!empty($item->expr->items)) {
if ($item->expr->items[0]->getType() === "Expr_ArrayItem") {
if ($item->expr->items[0]->key->value === "driver") {
foreach ($item->expr->items as $settingsItem) {
$settings[$settingsItem->key->value] = $settingsItem->value->value;
}
}
}
}
}
}
}
d($settings);
} catch (PhpParser\Error $e) {
echo 'Parse Error: ', $e->getMessage();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment