From adfb4431fe982e5db1d43f9216dc6492d8cf5182 Mon Sep 17 00:00:00 2001 From: Johannes Schobel Date: Thu, 4 Jan 2018 14:29:43 +0100 Subject: [PATCH] GENERATOR: remove special chars from container and file name --- Generator/GeneratorCommand.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Generator/GeneratorCommand.php b/Generator/GeneratorCommand.php index e7991eaa2..c2f03702a 100644 --- a/Generator/GeneratorCommand.php +++ b/Generator/GeneratorCommand.php @@ -118,6 +118,11 @@ public function handle() $this->containerName = ucfirst($this->checkParameterOrAsk('container', 'Enter the name of the Container')); $this->fileName = $this->checkParameterOrAsk('file', 'Enter the name of the ' . $this->fileType . ' file', $this->getDefaultFileName()); + // now fix the container and file name + $this->containerName = $this->removeSpecialChars($this->containerName); + $this->fileName = $this->removeSpecialChars($this->fileName); + + // and we are ready to start $this->printStartedMessage($this->containerName, $this->fileName); // get user inputs @@ -330,4 +335,19 @@ protected function getDefaultFileExtension() return 'php'; } + /** + * Removes "special characters" from a string + * + * @param $str + * + * @return string + */ + private function removeSpecialChars($str) + { + // remove everything that is NOT a character or digit + $str = preg_replace('/[^A-Za-z0-9]/', '', $str); + + return $str; + } + }