-
Notifications
You must be signed in to change notification settings - Fork 21
/
GetoptFactory.php
70 lines (65 loc) · 1.29 KB
/
GetoptFactory.php
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
/**
*
* This file is part of Aura for PHP.
*
* @package Aura.Cli
*
* @license http://opensource.org/licenses/bsd-license.php BSD
*
*/
namespace Aura\Cli\Context;
use Aura\Cli\Context\Getopt;
/**
*
* A factory to create Getopt objects.
*
* @package Aura.Cli
*
*/
class GetoptFactory
{
/**
*
* A getopt parser.
*
* @var GetoptParser
*
*/
protected $getopt_parser;
/**
*
* Constructor.
*
* @param GetoptParser $getopt_parser A getopt parser.
*
*/
public function __construct(GetoptParser $getopt_parser)
{
$this->getopt_parser = $getopt_parser;
}
public function getGetoptParser()
{
return $this->getopt_parser;
}
/**
*
* Returns a new Getopt instance.
*
* @param array $input The command line input array, as from $argv.
*
* @param array $options An options defintion array.
*
* @return Getopt
*
*/
public function newInstance(array $input, array $options)
{
$this->getopt_parser->setOptions($options);
$this->getopt_parser->parseInput($input);
return new Getopt(
$this->getopt_parser->getValues(),
$this->getopt_parser->getErrors()
);
}
}