SAREhub/php_component_worker

View on GitHub
src/SAREhub/Component/Worker/Command/BasicCommand.php

Summary

Maintainability
A
0 mins
Test Coverage
<?php

namespace SAREhub\Component\Worker\Command;

/**
 * Implementation of command pattern
 */
class BasicCommand implements Command {
    
    private $correlationId;
    private $name;
    private $parameters;
    
    public function __construct($correlationId, $name, array $parameters = null) {
        $this->correlationId = $correlationId;
        $this->name = $name;
        $this->parameters = empty($parameters) ? [] : $parameters;
    }
    
    /**
     * @return string
     */
    public function getCorrelationId() {
        return $this->correlationId;
    }
    
    /**
     * @return string
     */
    public function getName() {
        return $this->name;
    }
    
    /**
     * @return array
     */
    public function getParameters() {
        return $this->parameters;
    }
    
    public function __toString() {
        return 'COMMAND:'.json_encode([
          'correlation_id' => $this->getCorrelationId(),
          'name' => $this->getName(),
          'parameters' => $this->getParameters()
        ]);
    }
}