PhpBench\Formatter\FormatRegistry::register PHP Method

register() public method

Register a format class.
public register ( string $name, PhpBench\Formatter\FormatInterface $format )
$name string
$format PhpBench\Formatter\FormatInterface
    public function register($name, FormatInterface $format)
    {
        if (isset($this->formats[$name])) {
            throw new \InvalidArgumentException(sprintf('Formatter with name "%s" is already registered', $name));
        }
        $this->formats[$name] = $format;
    }

Usage Example

Example #1
0
 private function registerFormatter(Container $container)
 {
     $container->register('phpbench.formatter.registry', function (Container $container) {
         $registry = new FormatRegistry();
         $registry->register('printf', new PrintfFormat());
         $registry->register('balance', new BalanceFormat());
         $registry->register('number', new NumberFormat());
         $registry->register('truncate', new TruncateFormat());
         $registry->register('time', new TimeUnitFormat($container->get('benchmark.time_unit')));
         return $registry;
     });
     $container->register('phpbench.formatter', function (Container $container) {
         $formatter = new Formatter($container->get('phpbench.formatter.registry'));
         $formatter->classesFromFile(__DIR__ . '/config/class/main.json');
         return $formatter;
     });
 }
FormatRegistry