Elgg  Version 6.0
EntityCapabilitiesService.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg;
4 
12 
18  protected $entities = [];
19 
30  public function hasCapability(string $type, string $subtype, string $capability, bool $default = false): bool {
31  return elgg_extract($capability, elgg_extract($subtype, elgg_extract($type, $this->entities, []), [])) ?? $default;
32  }
33 
44  public function setCapability(string $type, string $subtype, string $capability, bool $value): void {
45  if (!isset($this->entities[$type])) {
46  $this->entities[$type] = [];
47  }
48 
49  if (!isset($this->entities[$type][$subtype])) {
50  $this->entities[$type][$subtype] = [];
51  }
52 
53  $this->entities[$type][$subtype][$capability] = $value;
54  }
55 
63  public function getTypesWithCapability(string $capability): array {
64  $result = [];
65 
66  foreach ($this->entities as $type => $subtypes) {
67  foreach ($subtypes as $subtype => $capabilities) {
68  if (elgg_extract($capability, $capabilities) !== true) {
69  continue;
70  }
71 
72  if (!isset($result[$type])) {
73  $result[$type] = [];
74  }
75 
76  $result[$type][] = $subtype;
77  }
78  }
79 
80  return $result;
81  }
82 }
$default
Definition: checkbox.php:30
c Accompany it with the information you received as to the offer to distribute corresponding source complete source code means all the source code for all modules it plus any associated interface definition plus the scripts used to control compilation and installation of the executable as a special the source code distributed need not include anything that is normally and so on of the operating system on which the executable unless that component itself accompanies the executable If distribution of executable or object code is made by offering access to copy from a designated then offering equivalent access to copy the source code from the same place counts as distribution of the source even though third parties are not compelled to copy the source along with the object code You may not or distribute the Program except as expressly provided under this License Any attempt otherwise to sublicense or distribute the Program is void
Definition: LICENSE.txt:215
$type
Definition: delete.php:21
$value
Definition: generic.php:51
getTypesWithCapability(string $capability)
Returns an array of type/subtypes with the requested capability enabled.
elgg_extract($key, $array, $default=null, bool $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
Definition: elgglib.php:254
hasCapability(string $type, string $subtype, string $capability, bool $default=false)
Checks if a capability is enabled for a specified type/subtype.
$subtype
Definition: delete.php:22
$subtypes
setCapability(string $type, string $subtype, string $capability, bool $value)
Sets the capability value for a specified type/subtype.