-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChecker.php
34 lines (29 loc) · 903 Bytes
/
Checker.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php
declare(strict_types=1);
/*
* The MIT License (MIT)
*
* Copyright (c) 2014-2019 Spomky-Labs
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
namespace OAuth2Framework\Component\Scope;
use function Safe\sprintf;
use function Safe\preg_match;
class Checker
{
public static function checkUsedOnce(string $scope, string $scopes): void
{
$scopes = explode(' ', $scopes);
if (1 < \count(array_keys($scopes, $scope, true))) {
throw new \InvalidArgumentException(sprintf('Scope "%s" appears more than once.', $scope));
}
}
public static function checkCharset(string $scope): void
{
if (1 !== preg_match('/^[\x20\x23-\x5B\x5D-\x7E]+$/', $scope)) {
throw new \InvalidArgumentException('Scope contains illegal characters.');
}
}
}