Skip to content

Instantly share code, notes, and snippets.

@xemoe
Created September 17, 2015 07:08
Show Gist options
  • Save xemoe/95f549f3a3dc6960dbfc to your computer and use it in GitHub Desktop.
Save xemoe/95f549f3a3dc6960dbfc to your computer and use it in GitHub Desktop.
PHP Command template
<?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