Created
September 17, 2015 07:08
-
-
Save xemoe/95f549f3a3dc6960dbfc to your computer and use it in GitHub Desktop.
PHP Command template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$configuration = ['eth0' => ['ip_address' => '192.168.1.100', 'netmask' => '255.255.255.0', 'gateway_ip_address' => '192.168.1.1', 'interface' => 'eth0']]; | |
$template = [ | |
'template' => 'ip addr add %s dev %s', | |
'variables' => ['ip_address', 'interface'], | |
]; | |
function build($configuration, $template) | |
{ | |
extract($configuration); | |
return vsprintf($template['template'], compact($template['variables'])); | |
} | |
$expect = 'ip addr add 192.168.1.100 dev eth0'; | |
assert($expect == build($configuration['eth0'], $template)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment