Fix examples
This commit is contained in:
parent
d420db9d09
commit
44efbeaf31
12
README.md
12
README.md
|
@ -14,24 +14,24 @@ use Sikofitt\GenerateMac\Mac;
|
|||
|
||||
$mac = new Mac(); // default is ':'
|
||||
// or
|
||||
$mac->setSeparator(':');
|
||||
$mac->setSeparator(Mac::SEPARATOR_COLON);
|
||||
$address = $mac->getAddress(); // ab:cd:ef:01:23:45
|
||||
|
||||
$mac = new Mac('-');
|
||||
$mac = new Mac(Mac::SEPARATOR_DASH);
|
||||
// or
|
||||
$mac->setSeparator('-');
|
||||
$mac->setSeparator(Mac::SEPARATOR_DASH);
|
||||
$address = $mac->getAddress(); // ab-cd-ef-01-23-45
|
||||
|
||||
$mac = new Mac('');
|
||||
$mac = new Mac(Mac::SEPARATOR_NONE);
|
||||
// or
|
||||
$mac->setSeparator('');
|
||||
$mac->setSeparator(Mac::SEPARATOR_NONE);
|
||||
$address = $mac->getAddress(); // abcdef012345
|
||||
```
|
||||
|
||||
If you don't care that it is unique you can remove the check for private mac prefixes.
|
||||
|
||||
```php
|
||||
$mac = new Mac(':', false);
|
||||
$mac = new Mac(Mac::SEPARATOR_COLON, false);
|
||||
// or
|
||||
$mac->setUnique(false);
|
||||
|
||||
|
|
|
@ -29,7 +29,6 @@ use Symfony\Component\Console\Input\{
|
|||
InputInterface,
|
||||
InputOption
|
||||
};
|
||||
use Symfony\Component\Console\Output\ConsoleOutput;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
|
||||
|
|
|
@ -21,6 +21,9 @@ namespace Sikofitt\GenerateMac;
|
|||
|
||||
class Mac
|
||||
{
|
||||
public const SEPARATOR_COLON = 0;
|
||||
public const SEPARATOR_DASH = 1;
|
||||
public const SEPARATOR_NONE = 2;
|
||||
/**
|
||||
* Private mac address prefixes that are used
|
||||
* internally or with virtual machines and containers.
|
||||
|
@ -58,10 +61,6 @@ class Mac
|
|||
'xexxxx',
|
||||
];
|
||||
|
||||
public const SEPARATOR_COLON = 0;
|
||||
public const SEPARATOR_DASH = 1;
|
||||
public const SEPARATOR_NONE = 2;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @var bool For testing that we get a prefix that is not used.
|
||||
|
@ -177,6 +176,24 @@ class Mac
|
|||
return $this->separator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to get the separator in string format
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getSeparatorAsString(): string
|
||||
{
|
||||
switch ($this->getSeparator()) {
|
||||
default:
|
||||
case self::SEPARATOR_COLON:
|
||||
return ':';
|
||||
case self::SEPARATOR_DASH:
|
||||
return '-';
|
||||
case self::SEPARATOR_NONE:
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test to see if we have a unique prefix.
|
||||
*
|
||||
|
@ -219,19 +236,6 @@ class Mac
|
|||
return \current($prefixes);
|
||||
}
|
||||
|
||||
private function getSeparatorAsString(): string
|
||||
{
|
||||
switch($this->getSeparator()) {
|
||||
default:
|
||||
case self::SEPARATOR_COLON:
|
||||
return ':';
|
||||
case self::SEPARATOR_DASH:
|
||||
return '-';
|
||||
case self::SEPARATOR_NONE:
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Inserts the chosen separator.
|
||||
*
|
||||
|
@ -241,7 +245,6 @@ class Mac
|
|||
*/
|
||||
private function insertSeparator(string $macAddress): string
|
||||
{
|
||||
|
||||
return implode($this->getSeparatorAsString(), str_split($macAddress, 2));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue