Skip to content

Commit b4530a6

Browse files
committed
CreateCommand: remove dependency on nette/utils
[closes #106][closes #114]
1 parent cc44190 commit b4530a6

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/Bridges/SymfonyConsole/CreateCommand.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\Component\Console\Input\InputInterface;
1717
use Symfony\Component\Console\Input\InputOption;
1818
use Symfony\Component\Console\Output\OutputInterface;
19+
use Symfony\Component\String\Slugger\AsciiSlugger;
1920

2021

2122
class CreateCommand extends BaseCommand
@@ -118,7 +119,7 @@ protected function getGroup($type)
118119

119120
$matchedGroups = [];
120121
foreach ($this->config->getGroups() as $group) {
121-
if (Strings::match($group->name, $groupNamePattern)) {
122+
if (preg_match($groupNamePattern, $group->name)) {
122123
$matchedGroups[] = $group;
123124
}
124125
}
@@ -148,7 +149,21 @@ protected function getGroup($type)
148149
*/
149150
protected function getFileName($label, $extension)
150151
{
151-
return date('Y-m-d-His-') . Strings::webalize($label, '.') . '.' . $extension;
152+
if (preg_match('#^[a-z0-9.-]++$#i', $label)) {
153+
$slug = strtolower($label);
154+
155+
} elseif (class_exists('Nette\Utils\Strings')) {
156+
$slug = Strings::webalize($label, '.');
157+
158+
} elseif (class_exists('Symfony\Component\String\Slugger\AsciiSlugger')) {
159+
$slugger = new AsciiSlugger('en');
160+
$slug = $slugger->slug($label)->toString();
161+
162+
} else {
163+
throw new Nextras\Migrations\LogicException("Provided label '$label' contains invalid characters.");
164+
}
165+
166+
return date('Y-m-d-His-') . $slug . '.' . $extension;
152167
}
153168

154169

0 commit comments

Comments
 (0)