Bristol SU Support Package
RegisteredAction.php
Go to the documentation of this file.
1 <?php
2 
4 
5 use BristolSU\Support\Action\Contracts\RegisteredAction as RegisteredActionContract;
8 
13 class RegisteredAction implements Arrayable, Jsonable, RegisteredActionContract
14 {
15 
21  private $name;
22 
28  private $description;
29 
35  private $className;
36 
43  public function setName(string $name): void
44  {
45  $this->name = $name;
46  }
47 
53  public function getName(): string
54  {
55  return $this->name;
56  }
57 
64  public function setDescription(string $description): void
65  {
66  $this->description = $description;
67  }
68 
74  public function getDescription(): string
75  {
76  return $this->description;
77  }
78 
85  public function setClassName(string $className): void
86  {
87  $this->className = $className;
88  }
89 
95  public function getClassName(): string
96  {
97  return $this->className;
98  }
99 
113  public static function fromArray(array $parameters): RegisteredActionContract
114  {
115  $registeredAction = new self;
116  $registeredAction->setName($parameters['name']);
117  $registeredAction->setDescription($parameters['description']);
118  $registeredAction->setClassName($parameters['class']);
119  return $registeredAction;
120  }
121 
127  public function toArray()
128  {
129  return [
130  'name' => $this->getName(),
131  'description' => $this->getDescription(),
132  'class' => $this->getClassName()
133  ];
134  }
135 
142  public function toJson($options = 0)
143  {
144  return json_encode($this->toArray(), $options);
145  }
146 
152  public function __toString()
153  {
154  return $this->toJson();
155  }
156 
157 }