Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F4134333
CLIBuilder.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
CLIBuilder.php
View Options
<?php
declare
(
strict_types
=
1
);
namespace
Phan
;
use
Phan\Daemon\ExitException
;
use
Phan\Exception\UsageException
;
/**
* Helper method to build instances of CLI.
*
* Constructing CLI instances will affect Phan's configuration and may terminate the program.
*/
class
CLIBuilder
{
/** @var associative-array<int|string,string|string[]|false> */
private
$opts
=
[];
/** @var list<string> */
private
$argv
=
[];
public
function
__construct
()
{
}
/**
* Set an option and return $this.
*
* @param string|list<string>|false $value
*/
public
function
setOption
(
string
$opt
,
$value
=
false
):
self
{
$this
->
opts
[
$opt
]
=
$value
;
if
(!
\is_array
(
$value
))
{
$value
=
[
$value
];
}
foreach
(
$value
as
$element
)
{
// Hardcode the option that there are no single-letter long options.
$opt_name
=
\strlen
(
$opt
)
>
1
?
"--$opt"
:
"-$opt"
;
$this
->
argv
[]
=
$opt_name
;
if
(
\is_int
(
$element
)
||
\is_string
(
$element
))
{
$this
->
argv
[]
=
(
string
)
$element
;
}
}
return
$this
;
}
/**
* Create and read command line arguments, configuring
* \Phan\Config as a side effect.
*
* @throws ExitException
* @throws UsageException
*/
public
function
build
():
CLI
{
return
CLI
::
fromRawValues
(
$this
->
opts
,
$this
->
argv
);
}
/**
* Return options in the same format as the getopt() call returns.
* @return associative-array<int|string,string|string[]|false>
*/
public
function
getOpts
():
array
{
return
$this
->
opts
;
}
/**
* Return an array of arguments that correspond to what would cause getopt() to return $this->getOpts().
* @return list<string>
*/
public
function
getArgv
():
array
{
return
$this
->
argv
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Wed, Aug 19, 12:35 (3 w, 2 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
54/3e/6c9203a1a32c96be1fe549c1f51d
Default Alt Text
CLIBuilder.php (1 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment