PluginProbe
Extendify / 3.2.2
Extendify v3.2.2
3.2.2 3.2.1 3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 All 128 releases
extendify / app / Mcp / Grants.php

Grants.php in Extendify 3.2.2, at app/Mcp/Grants.php

67 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * What a connection is allowed to do.
5 */
6
7 namespace Extendify\Mcp;
8
9 defined('ABSPATH') || die('No direct access.');
10
11 /**
12 * The names a connection row stores.
13 */
14 class Grants
15 {
16 // phpcs:disable PSR12.Properties.ConstantVisibility.NotFound
17 const READ = 'read';
18
19 const WRITE = 'write';
20 // phpcs:enable PSR12.Properties.ConstantVisibility.NotFound
21
22 /**
23 * @return array
24 */
25 public static function names()
26 {
27 return [self::READ, self::WRITE];
28 }
29
30 /**
31 * A row storing no grants could only ever read.
32 *
33 * @param mixed $grants - Whatever the connection stored.
34 * @return array
35 */
36 public static function sanitize($grants)
37 {
38 $known = array_values(array_intersect(self::names(), is_array($grants) ? $grants : []));
39
40 return $known ?: [self::READ];
41 }
42
43 /**
44 * @param string $scope - The space-separated scope an OAuth client asked for.
45 * @return array
46 */
47 public static function fromScope($scope)
48 {
49 $asked = preg_split('/\s+/', trim((string) $scope));
50
51 return in_array(self::WRITE, $asked, true) ? self::names() : [self::READ];
52 }
53
54 /**
55 * @param array $grants - The connection's grants.
56 * @return string
57 */
58 public static function label(array $grants)
59 {
60 return in_array(self::WRITE, $grants, true)
61 /* translators: an access level, shown on a badge and on the approval page; a noun phrase, not a command. */
62 ? \__('Read and write', 'extendify-local')
63 /* translators: an access level, shown on a badge and on the approval page; a noun phrase, not a command. */
64 : \__('Read only', 'extendify-local');
65 }
66 }
67