vendor/codeages/biz-framework/src/Command/EnvWriteCommand.php

(开头部分) 1KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

<?php

namespace Codeages\Biz\Framework\Command;

use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Command\Command;

class EnvWriteCommand extends Command
{
    protected function configure()
    {
        $this
            ->setName('env:write')
            ->setDescription('Write environment variable to file.')
            ->addArgument('file', InputArgument::REQUIRED, 'The environment file.')
            ->addArgument('key', InputArgument::REQUIRED, 'The key of environment variable.')
            ->addArgument('value', InputArgument::REQUIRED, 'The value of environment variable.')
        ;
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $file = $input->getArgument('file');
        $key = $input->getArgument('key');
        $value = $input->getArgument('value');
        if ('true' == $value) {
            $value = true;
        } elseif ('false' == $value) {
            $value = false;
        }

        if (!file_exists($file)) {
            throw new \InvalidArgumentException('Environment file is not exist.');
        }

        $env = require $file;

        if (!is_array($env)) {
            throw new \RuntimeException('Environment file must return array.');
        }

        $env[$key] = $value;
        $env = var_export($env, true);

        file_put_contents($file, "<?php\nreturn ".$env.';');
    }
}

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。