ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ComponentEntryRules.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
23use JsonSerializable;
24
31class ComponentEntryRules extends AbstractEntryPart implements JsonSerializable
32{
33 protected array $rules = array(
34 "usage" => array(),
35 "composition" => array(),
36 "interaction" => array(),
37 "wording" => array(),
38 "ordering" => array(),
39 "style" => array(),
40 "responsiveness" => array(),
41 "accessibility" => array()
42 );
43
44 public function __construct(array $rules = array())
45 {
47 $this->setRules($rules);
48 }
49
50 public function withRules(array $rules = array()): ComponentEntryRules
51 {
52 $clone = clone $this;
53 $clone->setRules($rules);
54 return $clone;
55 }
56
57 protected function setRules(array $rules): void
58 {
59 if (!$rules) {
60 return;
61 }
62
63 foreach ($rules as $rule_category => $category_rules) {
64 $this->assert()->isIndex($rule_category, $this->rules);
65 if ($category_rules && $category_rules != "") {
66 $this->assert()->isArray($category_rules);
67 foreach ($category_rules as $rule_id => $rule) {
68 $this->assert()->isString($rule);
69 $this->rules[$rule_category][$rule_id] = $rule;
70 }
71 }
72 }
73 }
74
75 public function getRules(): array
76 {
77 return $this->rules;
78 }
79
80 public function hasRules(): bool
81 {
82 foreach ($this->rules as $category_rules) {
83 if (sizeof($category_rules)) {
84 return true;
85 }
86 }
87 return false;
88 }
89
90 public function jsonSerialize(): array
91 {
92 return $this->getRules();
93 }
94}
Abstract Entry Part to share some common entry functionality.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc