The Operator
class implements the RequestInterface
interface and represents a request model for an operator. It contains four constants ORANGE
, PLAY
, T_MOBILE
, and PLUS
which represent the values for the four different operators. It also has a private property $value
which holds the value of the operator and a constructor that sets the value of $value
upon instantiation. The class also has a toArray()
method that returns an associative array representation of the Operator
object.
This constant represents the Orange operator.
This constant represents the Play operator.
This constant represents the T-Mobile operator.
This constant represents the Plus operator.
The constructor takes in a single parameter $value
of type string. It validates if the string is one of the constants defined in the class and throws an InvalidArgumentException
if it is not. If the string is valid, it sets the value to the $value
property.
The toArray()
method returns an associative array representation of the Operator
object. The array has a single key operator
which holds the value of the $value
property.
$operator = new Operator(Operator::ORANGE);
$operatorArray = $operator->toArray();
print_r($operatorArray);
/*
Array
(
[operator] => orange
)
*/