TrackManiaControl/core/Utils/CommandLineHelper.php

50 lines
1.0 KiB
PHP
Raw Normal View History

2014-05-01 20:15:47 +02:00
<?php
namespace ManiaControl\Utils;
2014-05-01 20:15:47 +02:00
use ManiaControl\General\UsageInformationAble;
use ManiaControl\General\UsageInformationTrait;
2014-05-01 20:15:47 +02:00
/**
* Command Line Helper Class
2014-05-02 17:40:47 +02:00
*
* @author ManiaControl Team <mail@maniacontrol.com>
2019-01-05 21:02:24 +01:00
* @copyright 2014-2019 ManiaControl Team
2014-05-02 17:40:47 +02:00
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
2014-05-01 20:15:47 +02:00
*/
class CommandLineHelper implements UsageInformationAble {
use UsageInformationTrait;
2014-05-01 20:15:47 +02:00
/**
2014-08-02 20:51:48 +02:00
* Get the command line parameter value with the given name
2014-05-02 17:40:47 +02:00
*
2014-05-01 20:15:47 +02:00
* @param string $paramName
2014-06-26 11:07:53 +02:00
* @return string
2014-05-01 20:15:47 +02:00
*/
public static function getParameter($paramName) {
$paramName = (string) $paramName;
2014-08-02 20:51:48 +02:00
$params = self::getAllParameters();
foreach ($params as $param) {
$parts = explode('=', $param, 2);
2014-05-01 20:15:47 +02:00
if (count($parts) < 2) {
continue;
}
if ($parts[0] !== $paramName) {
continue;
}
return $parts[1];
}
return null;
}
2014-08-02 20:51:48 +02:00
/**
* Get all command line parameters
*
* @return array
*/
public static function getAllParameters() {
global $argv;
return (array) $argv;
2014-08-02 20:51:48 +02:00
}
2014-05-01 20:15:47 +02:00
}