From d40920320cc95dfc0fb66a1bc67b0faf58a302e2 Mon Sep 17 00:00:00 2001 From: Jan Tvrdik Date: Tue, 14 Jun 2022 19:25:37 +0200 Subject: [PATCH 1/2] Configuration: remove unused use statement --- src/Configurations/Configuration.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Configurations/Configuration.php b/src/Configurations/Configuration.php index b963644..e05d85f 100644 --- a/src/Configurations/Configuration.php +++ b/src/Configurations/Configuration.php @@ -9,7 +9,6 @@ namespace Nextras\Migrations\Configurations; -use Nette\Utils\Validators; use Nextras\Migrations\Entities\Group; use Nextras\Migrations\IConfiguration; use Nextras\Migrations\IExtensionHandler; From 2248f2dbd8f72ede2e3ff8bc6c6f4e8470c41846 Mon Sep 17 00:00:00 2001 From: Jan Tvrdik Date: Tue, 14 Jun 2022 19:27:30 +0200 Subject: [PATCH 2/2] 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; }