vrajroham /
laravel-bitpay
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Vrajroham\LaravelBitpay\Traits; |
||
| 4 | |||
| 5 | use Vrajroham\LaravelBitpay\Exceptions\InvalidConfigurationException; |
||
| 6 | |||
| 7 | trait CreateKeypairTrait |
||
| 8 | { |
||
| 9 | public function validateAndLoadConfig() |
||
| 10 | { |
||
| 11 | $config = config('laravel-bitpay'); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 12 | |||
| 13 | if ('livenet' != $config['network'] && 'testnet' != $config['network']) { |
||
| 14 | throw InvalidConfigurationException::invalidNetworkName(); |
||
| 15 | } |
||
| 16 | |||
| 17 | if (!class_exists($config['key_storage'])) { |
||
| 18 | throw InvalidConfigurationException::invalidStorageClass(); |
||
| 19 | } |
||
| 20 | |||
| 21 | if ('' === trim($config['key_storage_password'])) { |
||
| 22 | throw InvalidConfigurationException::invalidOrEmptyPassword(); |
||
| 23 | } |
||
| 24 | |||
| 25 | $this->config = $config; |
||
|
0 ignored issues
–
show
|
|||
| 26 | } |
||
| 27 | |||
| 28 | protected function writeNewEnvironmentFileWith() |
||
| 29 | { |
||
| 30 | file_put_contents($this->laravel->environmentFilePath(), preg_replace( |
||
| 31 | $this->keyReplacementPattern(), |
||
| 32 | 'BITPAY_TOKEN='.$this->token, |
||
| 33 | file_get_contents($this->laravel->environmentFilePath()) |
||
| 34 | )); |
||
| 35 | } |
||
| 36 | |||
| 37 | protected function keyReplacementPattern() |
||
| 38 | { |
||
| 39 | $escaped = preg_quote('='.$this->laravel['config']['laravel-bitpay.token'], '/'); |
||
| 40 | |||
| 41 | return "/^BITPAY_TOKEN{$escaped}/m"; |
||
| 42 | } |
||
| 43 | } |
||
| 44 |