DBDiff\Params\CLIGetter::getParams PHP Method

getParams() public method

public getParams ( )
    public function getParams()
    {
        $params = new \StdClass();
        $cliFactory = new CliFactory();
        $context = $cliFactory->newContext($GLOBALS);
        $stdio = $cliFactory->newStdio();
        $getopt = $context->getopt(['server1::', 'server2::', 'format::', 'template::', 'type::', 'include::', 'nocomments::', 'config::', 'output::', 'debug::']);
        $input = $getopt->get(1);
        if ($input) {
            $params->input = $this->parseInput($input);
        } else {
            throw new CLIException("Missing input");
        }
        if ($getopt->get('--server1')) {
            $params->server1 = $this->parseServer($getopt->get('--server1'));
        }
        if ($getopt->get('--server2')) {
            $params->server2 = $this->parseServer($getopt->get('--server2'));
        }
        if ($getopt->get('--format')) {
            $params->format = $getopt->get('--format');
        }
        if ($getopt->get('--template')) {
            $params->template = $getopt->get('--template');
        }
        if ($getopt->get('--type')) {
            $params->type = $getopt->get('--type');
        }
        if ($getopt->get('--include')) {
            $params->include = $getopt->get('--include');
        }
        if ($getopt->get('--nocomments')) {
            $params->nocomments = $getopt->get('--nocomments');
        }
        if ($getopt->get('--config')) {
            $params->config = $getopt->get('--config');
        }
        if ($getopt->get('--output')) {
            $params->output = $getopt->get('--output');
        }
        if ($getopt->get('--debug')) {
            $params->debug = $getopt->get('--debug');
        }
        return $params;
    }

Usage Example

Beispiel #1
0
 public static function get()
 {
     $params = new DefaultParams();
     $cli = new CLIGetter();
     $paramsCLI = $cli->getParams();
     if (!isset($paramsCLI->debug)) {
         error_reporting(E_ERROR);
     }
     $fs = new FSGetter($paramsCLI);
     $paramsFS = $fs->getParams();
     $params = self::merge($params, $paramsFS);
     $params = self::merge($params, $paramsCLI);
     if (empty($params->server1)) {
         throw new CLIException("A server is required");
     }
     return $params;
 }