@ 2017-07-11T22:19:32Z <?php
class CommandFactory
{
private $commandMappings;
public function __construct(string $mappingFilename = 'default.json')
{
$mappingsJSON = file_get_content($mappingFilename);
$this->commandMappings = json_decode("{
'command' : {
'SYSTEMS' : {
'OS1' : {
'Version' : 'command string',
'Version2' : 'command string',
},
'OS2' : {
'Version' : 'command string',
'Version' : 'command string'
},
'COMMANDOPTIONS' : ['var1', 'var2', 'var3'],
},
'add-Firewall' : {
'SYSTEMS' : {
'Ubuntu' : {
'14' : 'command string',
'11' : 'command string',
},
'Redhat' : {
'13' : 'command string',
'11' : 'command string'
},
'COMMANDOPTIONS' : ['port',],
},
}", true);
}
public function getCommand(string $command, array $options): Command
{
$commandArray = $this->commandMappings[$command];
return new Command($commandArray, $options);
}
}
class Command
{
private $options;
private $mapping;
public function __construct($mappings, $options)
{
// check if options are are valid
// potentially map in options here?
}
public function view(string $os, $version): string
{
// validate $os and $version
$command = $this->mapping['SYSTEMS'][$os][$version]
$command = str_replace(array_keys($options), $options, $command);
return $command;
}
}
// usage
$factory = new CommandFactory();
$firewallCommand = $factory->getCommand('add-Firewall', array['port' => 23]);
echo $firewallCommand->view('Ubuntu', '11');
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).
Version System time (s) User time (s) Memory (MiB) 7.1.7 0.006 0.013 17.10 7.1.6 0.020 0.022 34.89 7.1.5 0.021 0.022 34.85 7.1.4 0.023 0.020 34.31 7.1.3 0.013 0.028 34.23 7.1.2 0.024 0.015 34.50 7.1.1 0.003 0.016 16.48 7.1.0 0.010 0.008 16.28 7.0.20 0.007 0.013 16.52 7.0.19 0.011 0.012 16.26 7.0.18 0.010 0.010 16.13 7.0.17 0.011 0.010 16.11 7.0.16 0.010 0.010 16.25 7.0.15 0.010 0.013 16.15 7.0.14 0.005 0.013 16.18 7.0.13 0.006 0.012 16.53 7.0.12 0.011 0.011 16.25 7.0.11 0.003 0.016 16.03 7.0.10 0.013 0.008 16.01 7.0.9 0.006 0.016 16.11 7.0.8 0.006 0.014 16.08 7.0.7 0.004 0.016 16.03 7.0.6 0.000 0.018 15.95 7.0.5 0.008 0.011 16.09 7.0.4 0.000 0.019 16.22 7.0.3 0.005 0.015 16.48 7.0.2 0.010 0.010 16.48 7.0.1 0.008 0.012 16.02 7.0.0 0.002 0.017 16.39
preferences:dark mode live preview
164.42 ms | 1394 KiB | 7 Q