From 2248f2dbd8f72ede2e3ff8bc6c6f4e8470c41846 Mon Sep 17 00:00:00 2001 From: Jan Tvrdik Date: Tue, 14 Jun 2022 19:27:30 +0200 Subject: [PATCH] CreateCommand: remove dependency on nette/utils [closes #106][closes #114] --- src/Bridges/SymfonyConsole/CreateCommand.php | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/Bridges/SymfonyConsole/CreateCommand.php b/src/Bridges/SymfonyConsole/CreateCommand.php index 7e09030..c9420f2 100644 --- a/src/Bridges/SymfonyConsole/CreateCommand.php +++ b/src/Bridges/SymfonyConsole/CreateCommand.php @@ -16,6 +16,7 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\String\Slugger\AsciiSlugger; class CreateCommand extends BaseCommand @@ -118,7 +119,7 @@ protected function getGroup($type) $matchedGroups = []; foreach ($this->config->getGroups() as $group) { - if (Strings::match($group->name, $groupNamePattern)) { + if (preg_match($groupNamePattern, $group->name)) { $matchedGroups[] = $group; } } @@ -148,7 +149,21 @@ protected function getGroup($type) */ protected function getFileName($label, $extension) { - return date('Y-m-d-His-') . Strings::webalize($label, '.') . '.' . $extension; + if (preg_match('#^[a-z0-9.-]++$#i', $label)) { + $slug = strtolower($label); + + } elseif (class_exists('Nette\Utils\Strings')) { + $slug = Strings::webalize($label, '.'); + + } elseif (class_exists('Symfony\Component\String\Slugger\AsciiSlugger')) { + $slugger = new AsciiSlugger('en'); + $slug = $slugger->slug($label)->toString(); + + } else { + throw new Nextras\Migrations\LogicException("Provided label '$label' contains invalid characters."); + } + + return date('Y-m-d-His-') . $slug . '.' . $extension; }