Commit d96509b7 authored by xiphon's avatar xiphon
Browse files

use symfony/yaml to parse proposal description and variables

parent 0adc618e
...@@ -5,6 +5,7 @@ namespace App\Console\Commands; ...@@ -5,6 +5,7 @@ namespace App\Console\Commands;
use App\Project; use App\Project;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\Storage;
use Yaml;
class ProcessProposals extends Command class ProcessProposals extends Command
{ {
...@@ -70,35 +71,10 @@ class ProcessProposals extends Command ...@@ -70,35 +71,10 @@ class ProcessProposals extends Command
*/ */
public function getAmountFromText($filename = 'additional-gui-dev.md') public function getAmountFromText($filename = 'additional-gui-dev.md')
{ {
$input = Storage::get($filename); $contents = preg_split('/\r?\n?---\r?\n/m', Storage::get($filename));
$lines = preg_split('/\r\n|\r|\n/', $input); if (sizeof($contents) < 3) {
$values = []; throw new \Exception("Failed to parse proposal, can't find YAML description surrounded by '---' lines");
$flag = false;
$isPayoutLine = false;
foreach($lines as $line) {
if ($line === '---') {
if ($flag === true) {
break;
}
$flag = true;
continue;
}
$details = explode(':', $line);
if (count($details) < 2) {
continue;
}
if ($details[0] === 'payouts') {
$isPayoutLine = true;
continue;
}
if ($isPayoutLine) {
$name = trim(str_replace('-','', $details[0]));
$values['payouts'][][$name] = ltrim($details[1]);
continue;
}
$values[$details[0]] = ltrim($details[1]);
} }
return $values; return Yaml::parse($contents[1]);
} }
} }
...@@ -208,6 +208,7 @@ return [ ...@@ -208,6 +208,7 @@ return [
'URL' => Illuminate\Support\Facades\URL::class, 'URL' => Illuminate\Support\Facades\URL::class,
'Validator' => Illuminate\Support\Facades\Validator::class, 'Validator' => Illuminate\Support\Facades\Validator::class,
'View' => Illuminate\Support\Facades\View::class, 'View' => Illuminate\Support\Facades\View::class,
'Yaml' => 'Symfony\Component\Yaml\Yaml',
], ],
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment