$collections * @param list $actions */ public function __construct( public array $collections, public array $actions = [], ) { PermissionCodec::assertNsidOrWildcardList($collections, 'Repository permission collections'); if (\count($actions) !== \count(\array_unique($actions))) { throw new \InvalidArgumentException('Repository permission actions must be unique.'); } foreach ($actions as $action) { if (!\in_array($action, self::ACTIONS, TRUE)) { throw new \InvalidArgumentException('Repository permission actions must be create, update, or delete.'); } } } /** * Returns the permission resource identifier. */ public function resource(): string { return 'repo'; } /** * Returns the canonical OAuth scope. */ public function toScope(): string { $positional = \count($this->collections) === 1 ? $this->collections[0] : NULL; $parameters = []; if ($positional === NULL) { $parameters['collection'] = $this->collections; } if ($this->actions !== []) { $parameters['action'] = $this->actions; } return PermissionCodec::encode('repo', $positional, $parameters); } /** * Returns the Lexicon permission declaration. */ public function toLexiconPermission(): array { if ($this->collections === ['*']) { throw new \LogicException('Repository wildcards are not allowed inside permission sets.'); } $permission = [ 'type' => 'permission', 'resource' => 'repo', 'collection' => $this->collections, ]; if ($this->actions !== []) { $permission['action'] = $this->actions; } return $permission; } }