Returns the names of registered templates in the given domain.
public getNamesForDomain ( string $domain ) : array | ||
$domain | string | Return template names for this domain |
return | array | Array of template name strings |
public function initialize(ConsoleCommandEvent $event) { $command = $event->getCommand(); if ($command instanceof TemplateFeature) { $input = $event->getInput(); $template = $input->getOption('template'); if ($template) { $validTemplates = $this->templateHelper->getNamesForDomain($command->getTemplateDomain()); if (!in_array($template, $validTemplates, true)) { throw new \InvalidArgumentException(sprintf('The specified template "%s" does not exist, try one of: ' . PHP_EOL . ' - %s', $template, implode(PHP_EOL . ' - ', $validTemplates))); } } } }
/** * @test * @dataProvider provideGetNamesForDomain */ public function gets_names_for_domain($templateRegistrations, $domain, $expectedNames, $exception = false) { foreach ($templateRegistrations as $templateRegistration) { $template = $this->prophesize('Gush\\Template\\TemplateInterface'); $template->getName()->willReturn($templateRegistration); $this->helper->registerTemplate($template->reveal()); } if ($exception) { $this->setExpectedException('InvalidArgumentException', 'Unknown template domain'); } $res = $this->helper->getNamesForDomain($domain); $this->assertEquals($expectedNames, $res); }