Skip to content

Commit

Permalink
Merge b47ecc8 into 82756d6
Browse files Browse the repository at this point in the history
  • Loading branch information
holtkamp committed Jan 3, 2017
2 parents 82756d6 + b47ecc8 commit 2f3e527
Showing 1 changed file with 41 additions and 5 deletions.
46 changes: 41 additions & 5 deletions src/Routing/ClassBasedRoutingKeyResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,48 @@

class ClassBasedRoutingKeyResolver implements RoutingKeyResolver
{
/**
* @var string
*/
private $prefix;

/**
* @var string
*/
private $separator;

/**
* @var string
*/
private $suffix;

/**
* @param string $separator
* @param string $prefix
* @param string $suffix
*/
public function __construct($separator = '.', $prefix = null, $suffix = null)
{
$this->separator = $separator;
if ($prefix !== null) {
$this->prefix = $prefix;
}
if ($suffix !== null) {
$this->suffix = $suffix;
}
}

public function resolveRoutingKeyFor($message)
{
return str_replace(
'\\',
'.',
get_class($message)
);
$components = explode('\\', is_object($message) ? get_class($message) : $message);

if(isset($this->prefix)){
array_unshift($components, $this->prefix);
}
if(isset($this->suffix)){
$components[] = $this->suffix;
}

return implode($this->separator, $components);
}
}

0 comments on commit 2f3e527

Please sign in to comment.