Skip to content

Commit

Permalink
Merge pull request #67 from johannesschobel/patch-01
Browse files Browse the repository at this point in the history
GENERATOR: remove special chars from container and file name
  • Loading branch information
johannesschobel authored Jan 4, 2018
2 parents 03473eb + adfb443 commit 1bdd5c1
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions Generator/GeneratorCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}

}

0 comments on commit 1bdd5c1

Please sign in to comment.