Skip to content

Commit

Permalink
Fix case where command namespace contains Command
Browse files Browse the repository at this point in the history
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'.
  • Loading branch information
wkjagt committed Jul 3, 2014
1 parent 1f65b8c commit e82b9b4
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/Laracasts/Commander/BasicCommandTranslator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand All @@ -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'));
}

}

0 comments on commit e82b9b4

Please sign in to comment.