From e82b9b4d98c93eb6d08eee24bb11dfebf5941c72 Mon Sep 17 00:00:00 2001 From: Willem van der Jagt Date: Wed, 2 Jul 2014 22:21:12 -0400 Subject: [PATCH] Fix case where command namespace contains Command Fixes the case where a command has a namespace that contains the string 'Command'. For example: Acme/Commanding/LaunchMissileCommand where only the last instance of 'Command' should be replaced with 'CommandHandler' and 'Validator'. --- src/Laracasts/Commander/BasicCommandTranslator.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Laracasts/Commander/BasicCommandTranslator.php b/src/Laracasts/Commander/BasicCommandTranslator.php index fd41004..58a169e 100644 --- a/src/Laracasts/Commander/BasicCommandTranslator.php +++ b/src/Laracasts/Commander/BasicCommandTranslator.php @@ -11,7 +11,8 @@ class BasicCommandTranslator implements CommandTranslator { */ public function toCommandHandler($command) { - $handler = str_replace('Command', 'CommandHandler', get_class($command)); + $commandClass = get_class($command); + $handler = substr_replace($commandClass, 'CommandHandler', strrpos($commandClass, 'Command')); if ( ! class_exists($handler)) { @@ -31,7 +32,8 @@ public function toCommandHandler($command) */ public function toValidator($command) { - return str_replace('Command', 'Validator', get_class($command)); + $commandClass = get_class($command); + return substr_replace($commandClass, 'Validator', strrpos($commandClass, 'Command')); } } \ No newline at end of file