@ 2017-07-11T22:20:35Z <?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.009 16.85 7.1.6 0.027 0.011 34.73 7.1.5 0.029 0.013 34.78 7.1.4 0.025 0.018 34.29 7.1.3 0.015 0.028 34.47 7.1.2 0.033 0.009 34.52 7.1.1 0.006 0.011 16.11 7.1.0 0.010 0.010 16.48 7.0.20 0.009 0.011 16.31 7.0.19 0.007 0.009 16.27 7.0.18 0.006 0.019 16.29 7.0.17 0.008 0.011 16.11 7.0.16 0.018 0.004 16.01 7.0.15 0.008 0.012 16.00 7.0.14 0.010 0.007 16.36 7.0.13 0.016 0.005 16.36 7.0.12 0.011 0.014 16.20 7.0.11 0.008 0.011 16.23 7.0.10 0.008 0.012 16.18 7.0.9 0.009 0.009 16.14 7.0.8 0.009 0.010 16.13 7.0.7 0.011 0.010 16.11 7.0.6 0.006 0.012 15.92 7.0.5 0.000 0.015 16.33 7.0.4 0.011 0.007 16.27 7.0.3 0.006 0.013 16.45 7.0.2 0.007 0.013 16.18 7.0.1 0.005 0.015 16.14 7.0.0 0.008 0.013 16.30
preferences:dark mode live preview
141.05 ms | 1394 KiB | 7 Q