misuzu/src/Perms/PermissionResultShared.php

25 lines
623 B
PHP
Raw Normal View History

2023-08-30 22:37:21 +00:00
<?php
namespace Misuzu\Perms;
use stdClass;
use InvalidArgumentException;
trait PermissionResultShared {
public function checkMany(array $perms): object {
if(empty($perms))
throw new InvalidArgumentException('$perms must not be empty.');
$result = new stdClass;
$calculated = $this->getCalculated();
foreach($perms as $name => $perm)
$result->{$name} = ($calculated & $perm) > 0;
return $result;
}
public function apply(callable $callable): IPermissionResult {
return new PermissionResult($callable($this->getCalculated()));
}
}