ProcessProposals.php 2.2 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Illuminate\Support\Facades\Storage;

class ProcessProposals extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'proposal:process';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Check for changes to proposals';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     */
    public function handle()
    {
        $amounts = [];
        $files = Storage::files('ffs-proposals');
        foreach ($files as $file) {
            if (strpos($file,'.md')) {
                $amount['name'] = $file;
44
                $amount['values'] = $this->getAmountFromText($file);
45
46
47
48
49
50
51
52
53
54
                $amounts[] = $amount;
            }
        }
        dd($amounts);
    }

    /**
     * Gets the ffs amount requested from a file
     *
     * @param string $filename
55
     * @return array
56
57
58
59
60
61
     * @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
     */
    public function getAmountFromText($filename = 'additional-gui-dev.md')
    {
        $input = Storage::get($filename);
        $lines = preg_split('/\r\n|\r|\n/', $input);
62
63
64
65
        $values = [];
        $flag = false;
        $isPayoutLine = false;

66
        foreach($lines as $line) {
67
68
69
70
71
72
73
            if ($line === '---') {
                if ($flag === true) {
                    break;
                }
                $flag = true;
                continue;
            }
74
            $details = explode(':', $line);
75
76
77
78
79
80
81
82
83
84
85
            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;
86
            }
87
            $values[$details[0]] = ltrim($details[1]);
88
        }
89
        return $values;
90
91
    }
}