@@ -32,25 +32,25 @@ |
||
32 | 32 | */ |
33 | 33 | class ForbiddenException extends \Exception { |
34 | 34 | |
35 | - /** @var bool */ |
|
36 | - private $retry; |
|
35 | + /** @var bool */ |
|
36 | + private $retry; |
|
37 | 37 | |
38 | - /** |
|
39 | - * @param string $message |
|
40 | - * @param bool $retry |
|
41 | - * @param \Exception|null $previous previous exception for cascading |
|
42 | - * @since 9.0.0 |
|
43 | - */ |
|
44 | - public function __construct($message, $retry, \Exception $previous = null) { |
|
45 | - parent::__construct($message, 0, $previous); |
|
46 | - $this->retry = $retry; |
|
47 | - } |
|
38 | + /** |
|
39 | + * @param string $message |
|
40 | + * @param bool $retry |
|
41 | + * @param \Exception|null $previous previous exception for cascading |
|
42 | + * @since 9.0.0 |
|
43 | + */ |
|
44 | + public function __construct($message, $retry, \Exception $previous = null) { |
|
45 | + parent::__construct($message, 0, $previous); |
|
46 | + $this->retry = $retry; |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * @return bool |
|
51 | - * @since 9.0.0 |
|
52 | - */ |
|
53 | - public function getRetry() { |
|
54 | - return (bool) $this->retry; |
|
55 | - } |
|
49 | + /** |
|
50 | + * @return bool |
|
51 | + * @since 9.0.0 |
|
52 | + */ |
|
53 | + public function getRetry() { |
|
54 | + return (bool) $this->retry; |
|
55 | + } |
|
56 | 56 | } |
@@ -27,15 +27,15 @@ |
||
27 | 27 | */ |
28 | 28 | class StorageTimeoutException extends StorageNotAvailableException { |
29 | 29 | |
30 | - /** |
|
31 | - * StorageTimeoutException constructor. |
|
32 | - * |
|
33 | - * @param string $message |
|
34 | - * @param \Exception|null $previous |
|
35 | - * @since 9.0.0 |
|
36 | - */ |
|
37 | - public function __construct($message = '', \Exception $previous = null) { |
|
38 | - $l = \OC::$server->getL10N('core'); |
|
39 | - parent::__construct($l->t('Storage connection timeout. %s', [$message]), self::STATUS_TIMEOUT, $previous); |
|
40 | - } |
|
30 | + /** |
|
31 | + * StorageTimeoutException constructor. |
|
32 | + * |
|
33 | + * @param string $message |
|
34 | + * @param \Exception|null $previous |
|
35 | + * @since 9.0.0 |
|
36 | + */ |
|
37 | + public function __construct($message = '', \Exception $previous = null) { |
|
38 | + $l = \OC::$server->getL10N('core'); |
|
39 | + parent::__construct($l->t('Storage connection timeout. %s', [$message]), self::STATUS_TIMEOUT, $previous); |
|
40 | + } |
|
41 | 41 | } |
@@ -27,15 +27,15 @@ |
||
27 | 27 | */ |
28 | 28 | class StorageConnectionException extends StorageNotAvailableException { |
29 | 29 | |
30 | - /** |
|
31 | - * StorageConnectionException constructor. |
|
32 | - * |
|
33 | - * @param string $message |
|
34 | - * @param \Exception|null $previous |
|
35 | - * @since 9.0.0 |
|
36 | - */ |
|
37 | - public function __construct($message = '', \Exception $previous = null) { |
|
38 | - $l = \OC::$server->getL10N('core'); |
|
39 | - parent::__construct($l->t('Storage connection error. %s', [$message]), self::STATUS_NETWORK_ERROR, $previous); |
|
40 | - } |
|
30 | + /** |
|
31 | + * StorageConnectionException constructor. |
|
32 | + * |
|
33 | + * @param string $message |
|
34 | + * @param \Exception|null $previous |
|
35 | + * @since 9.0.0 |
|
36 | + */ |
|
37 | + public function __construct($message = '', \Exception $previous = null) { |
|
38 | + $l = \OC::$server->getL10N('core'); |
|
39 | + parent::__construct($l->t('Storage connection error. %s', [$message]), self::STATUS_NETWORK_ERROR, $previous); |
|
40 | + } |
|
41 | 41 | } |
@@ -33,46 +33,46 @@ |
||
33 | 33 | |
34 | 34 | class ContactsMenuController extends Controller { |
35 | 35 | |
36 | - /** @var Manager */ |
|
37 | - private $manager; |
|
36 | + /** @var Manager */ |
|
37 | + private $manager; |
|
38 | 38 | |
39 | - /** @var IUserSession */ |
|
40 | - private $userSession; |
|
39 | + /** @var IUserSession */ |
|
40 | + private $userSession; |
|
41 | 41 | |
42 | - /** |
|
43 | - * @param IRequest $request |
|
44 | - * @param IUserSession $userSession |
|
45 | - * @param Manager $manager |
|
46 | - */ |
|
47 | - public function __construct(IRequest $request, IUserSession $userSession, Manager $manager) { |
|
48 | - parent::__construct('core', $request); |
|
49 | - $this->userSession = $userSession; |
|
50 | - $this->manager = $manager; |
|
51 | - } |
|
42 | + /** |
|
43 | + * @param IRequest $request |
|
44 | + * @param IUserSession $userSession |
|
45 | + * @param Manager $manager |
|
46 | + */ |
|
47 | + public function __construct(IRequest $request, IUserSession $userSession, Manager $manager) { |
|
48 | + parent::__construct('core', $request); |
|
49 | + $this->userSession = $userSession; |
|
50 | + $this->manager = $manager; |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * @NoAdminRequired |
|
55 | - * |
|
56 | - * @param string|null filter |
|
57 | - * @return \JsonSerializable[] |
|
58 | - */ |
|
59 | - public function index($filter = null) { |
|
60 | - return $this->manager->getEntries($this->userSession->getUser(), $filter); |
|
61 | - } |
|
53 | + /** |
|
54 | + * @NoAdminRequired |
|
55 | + * |
|
56 | + * @param string|null filter |
|
57 | + * @return \JsonSerializable[] |
|
58 | + */ |
|
59 | + public function index($filter = null) { |
|
60 | + return $this->manager->getEntries($this->userSession->getUser(), $filter); |
|
61 | + } |
|
62 | 62 | |
63 | - /** |
|
64 | - * @NoAdminRequired |
|
65 | - * |
|
66 | - * @param integer $shareType |
|
67 | - * @param string $shareWith |
|
68 | - * @return JSONResponse|\JsonSerializable |
|
69 | - */ |
|
70 | - public function findOne($shareType, $shareWith) { |
|
71 | - $contact = $this->manager->findOne($this->userSession->getUser(), $shareType, $shareWith); |
|
63 | + /** |
|
64 | + * @NoAdminRequired |
|
65 | + * |
|
66 | + * @param integer $shareType |
|
67 | + * @param string $shareWith |
|
68 | + * @return JSONResponse|\JsonSerializable |
|
69 | + */ |
|
70 | + public function findOne($shareType, $shareWith) { |
|
71 | + $contact = $this->manager->findOne($this->userSession->getUser(), $shareType, $shareWith); |
|
72 | 72 | |
73 | - if ($contact) { |
|
74 | - return $contact; |
|
75 | - } |
|
76 | - return new JSONResponse([], Http::STATUS_NOT_FOUND); |
|
77 | - } |
|
73 | + if ($contact) { |
|
74 | + return $contact; |
|
75 | + } |
|
76 | + return new JSONResponse([], Http::STATUS_NOT_FOUND); |
|
77 | + } |
|
78 | 78 | } |
@@ -21,7 +21,7 @@ |
||
21 | 21 | */ |
22 | 22 | |
23 | 23 | return [ |
24 | - 'routes' => [ |
|
25 | - ['name' => 'Notifications#view', 'url' => '/notifications/view/{id}', 'verb' => 'GET'], |
|
26 | - ] |
|
24 | + 'routes' => [ |
|
25 | + ['name' => 'Notifications#view', 'url' => '/notifications/view/{id}', 'verb' => 'GET'], |
|
26 | + ] |
|
27 | 27 | ]; |
@@ -32,42 +32,42 @@ |
||
32 | 32 | |
33 | 33 | class LegacyDAVACL extends DavAclPlugin { |
34 | 34 | |
35 | - /** |
|
36 | - * @inheritdoc |
|
37 | - */ |
|
38 | - public function getCurrentUserPrincipals() { |
|
39 | - $principalV2 = $this->getCurrentUserPrincipal(); |
|
35 | + /** |
|
36 | + * @inheritdoc |
|
37 | + */ |
|
38 | + public function getCurrentUserPrincipals() { |
|
39 | + $principalV2 = $this->getCurrentUserPrincipal(); |
|
40 | 40 | |
41 | - if (is_null($principalV2)) return []; |
|
41 | + if (is_null($principalV2)) return []; |
|
42 | 42 | |
43 | - $principalV1 = $this->convertPrincipal($principalV2, false); |
|
44 | - return array_merge( |
|
45 | - [ |
|
46 | - $principalV2, |
|
47 | - $principalV1 |
|
48 | - ], |
|
49 | - $this->getPrincipalMembership($principalV1) |
|
50 | - ); |
|
51 | - } |
|
43 | + $principalV1 = $this->convertPrincipal($principalV2, false); |
|
44 | + return array_merge( |
|
45 | + [ |
|
46 | + $principalV2, |
|
47 | + $principalV1 |
|
48 | + ], |
|
49 | + $this->getPrincipalMembership($principalV1) |
|
50 | + ); |
|
51 | + } |
|
52 | 52 | |
53 | - private function convertPrincipal($principal, $toV2) { |
|
54 | - list(, $name) = \Sabre\Uri\split($principal); |
|
55 | - if ($toV2) { |
|
56 | - return "principals/users/$name"; |
|
57 | - } |
|
58 | - return "principals/$name"; |
|
59 | - } |
|
53 | + private function convertPrincipal($principal, $toV2) { |
|
54 | + list(, $name) = \Sabre\Uri\split($principal); |
|
55 | + if ($toV2) { |
|
56 | + return "principals/users/$name"; |
|
57 | + } |
|
58 | + return "principals/$name"; |
|
59 | + } |
|
60 | 60 | |
61 | - public function propFind(PropFind $propFind, INode $node) { |
|
62 | - /* Overload current-user-principal */ |
|
63 | - $propFind->handle('{DAV:}current-user-principal', function () { |
|
64 | - if ($url = parent::getCurrentUserPrincipal()) { |
|
65 | - return new Principal(Principal::HREF, $url . '/'); |
|
66 | - } else { |
|
67 | - return new Principal(Principal::UNAUTHENTICATED); |
|
68 | - } |
|
69 | - }); |
|
61 | + public function propFind(PropFind $propFind, INode $node) { |
|
62 | + /* Overload current-user-principal */ |
|
63 | + $propFind->handle('{DAV:}current-user-principal', function () { |
|
64 | + if ($url = parent::getCurrentUserPrincipal()) { |
|
65 | + return new Principal(Principal::HREF, $url . '/'); |
|
66 | + } else { |
|
67 | + return new Principal(Principal::UNAUTHENTICATED); |
|
68 | + } |
|
69 | + }); |
|
70 | 70 | |
71 | - return parent::propFind($propFind, $node); |
|
72 | - } |
|
71 | + return parent::propFind($propFind, $node); |
|
72 | + } |
|
73 | 73 | } |
@@ -57,110 +57,110 @@ |
||
57 | 57 | */ |
58 | 58 | class Backend implements \JsonSerializable { |
59 | 59 | |
60 | - use VisibilityTrait; |
|
61 | - use FrontendDefinitionTrait; |
|
62 | - use PriorityTrait; |
|
63 | - use DependencyTrait; |
|
64 | - use StorageModifierTrait; |
|
65 | - use IdentifierTrait; |
|
66 | - |
|
67 | - /** @var string storage class */ |
|
68 | - private $storageClass; |
|
69 | - |
|
70 | - /** @var array 'scheme' => true, supported authentication schemes */ |
|
71 | - private $authSchemes = []; |
|
72 | - |
|
73 | - /** @var AuthMechanism|callable authentication mechanism fallback */ |
|
74 | - private $legacyAuthMechanism; |
|
75 | - |
|
76 | - /** |
|
77 | - * @return string |
|
78 | - */ |
|
79 | - public function getStorageClass() { |
|
80 | - return $this->storageClass; |
|
81 | - } |
|
82 | - |
|
83 | - /** |
|
84 | - * @param string $class |
|
85 | - * @return $this |
|
86 | - */ |
|
87 | - public function setStorageClass($class) { |
|
88 | - $this->storageClass = $class; |
|
89 | - return $this; |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * @return array |
|
94 | - */ |
|
95 | - public function getAuthSchemes() { |
|
96 | - if (empty($this->authSchemes)) { |
|
97 | - return [AuthMechanism::SCHEME_NULL => true]; |
|
98 | - } |
|
99 | - return $this->authSchemes; |
|
100 | - } |
|
101 | - |
|
102 | - /** |
|
103 | - * @param string $scheme |
|
104 | - * @return self |
|
105 | - */ |
|
106 | - public function addAuthScheme($scheme) { |
|
107 | - $this->authSchemes[$scheme] = true; |
|
108 | - return $this; |
|
109 | - } |
|
110 | - |
|
111 | - /** |
|
112 | - * @param array $parameters storage parameters, for dynamic mechanism selection |
|
113 | - * @return AuthMechanism |
|
114 | - */ |
|
115 | - public function getLegacyAuthMechanism(array $parameters = []) { |
|
116 | - if (is_callable($this->legacyAuthMechanism)) { |
|
117 | - return call_user_func($this->legacyAuthMechanism, $parameters); |
|
118 | - } |
|
119 | - return $this->legacyAuthMechanism; |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * @param AuthMechanism $authMechanism |
|
124 | - * @return self |
|
125 | - */ |
|
126 | - public function setLegacyAuthMechanism(AuthMechanism $authMechanism) { |
|
127 | - $this->legacyAuthMechanism = $authMechanism; |
|
128 | - return $this; |
|
129 | - } |
|
130 | - |
|
131 | - /** |
|
132 | - * @param callable $callback dynamic auth mechanism selection |
|
133 | - * @return self |
|
134 | - */ |
|
135 | - public function setLegacyAuthMechanismCallback(callable $callback) { |
|
136 | - $this->legacyAuthMechanism = $callback; |
|
137 | - } |
|
138 | - |
|
139 | - /** |
|
140 | - * Serialize into JSON for client-side JS |
|
141 | - * |
|
142 | - * @return array |
|
143 | - */ |
|
144 | - public function jsonSerialize() { |
|
145 | - $data = $this->jsonSerializeDefinition(); |
|
146 | - $data += $this->jsonSerializeIdentifier(); |
|
147 | - |
|
148 | - $data['backend'] = $data['name']; // legacy compat |
|
149 | - $data['priority'] = $this->getPriority(); |
|
150 | - $data['authSchemes'] = $this->getAuthSchemes(); |
|
151 | - |
|
152 | - return $data; |
|
153 | - } |
|
154 | - |
|
155 | - /** |
|
156 | - * Check if parameters are satisfied in a StorageConfig |
|
157 | - * |
|
158 | - * @param StorageConfig $storage |
|
159 | - * @return bool |
|
160 | - */ |
|
161 | - public function validateStorage(StorageConfig $storage) { |
|
162 | - return $this->validateStorageDefinition($storage); |
|
163 | - } |
|
60 | + use VisibilityTrait; |
|
61 | + use FrontendDefinitionTrait; |
|
62 | + use PriorityTrait; |
|
63 | + use DependencyTrait; |
|
64 | + use StorageModifierTrait; |
|
65 | + use IdentifierTrait; |
|
66 | + |
|
67 | + /** @var string storage class */ |
|
68 | + private $storageClass; |
|
69 | + |
|
70 | + /** @var array 'scheme' => true, supported authentication schemes */ |
|
71 | + private $authSchemes = []; |
|
72 | + |
|
73 | + /** @var AuthMechanism|callable authentication mechanism fallback */ |
|
74 | + private $legacyAuthMechanism; |
|
75 | + |
|
76 | + /** |
|
77 | + * @return string |
|
78 | + */ |
|
79 | + public function getStorageClass() { |
|
80 | + return $this->storageClass; |
|
81 | + } |
|
82 | + |
|
83 | + /** |
|
84 | + * @param string $class |
|
85 | + * @return $this |
|
86 | + */ |
|
87 | + public function setStorageClass($class) { |
|
88 | + $this->storageClass = $class; |
|
89 | + return $this; |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * @return array |
|
94 | + */ |
|
95 | + public function getAuthSchemes() { |
|
96 | + if (empty($this->authSchemes)) { |
|
97 | + return [AuthMechanism::SCHEME_NULL => true]; |
|
98 | + } |
|
99 | + return $this->authSchemes; |
|
100 | + } |
|
101 | + |
|
102 | + /** |
|
103 | + * @param string $scheme |
|
104 | + * @return self |
|
105 | + */ |
|
106 | + public function addAuthScheme($scheme) { |
|
107 | + $this->authSchemes[$scheme] = true; |
|
108 | + return $this; |
|
109 | + } |
|
110 | + |
|
111 | + /** |
|
112 | + * @param array $parameters storage parameters, for dynamic mechanism selection |
|
113 | + * @return AuthMechanism |
|
114 | + */ |
|
115 | + public function getLegacyAuthMechanism(array $parameters = []) { |
|
116 | + if (is_callable($this->legacyAuthMechanism)) { |
|
117 | + return call_user_func($this->legacyAuthMechanism, $parameters); |
|
118 | + } |
|
119 | + return $this->legacyAuthMechanism; |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * @param AuthMechanism $authMechanism |
|
124 | + * @return self |
|
125 | + */ |
|
126 | + public function setLegacyAuthMechanism(AuthMechanism $authMechanism) { |
|
127 | + $this->legacyAuthMechanism = $authMechanism; |
|
128 | + return $this; |
|
129 | + } |
|
130 | + |
|
131 | + /** |
|
132 | + * @param callable $callback dynamic auth mechanism selection |
|
133 | + * @return self |
|
134 | + */ |
|
135 | + public function setLegacyAuthMechanismCallback(callable $callback) { |
|
136 | + $this->legacyAuthMechanism = $callback; |
|
137 | + } |
|
138 | + |
|
139 | + /** |
|
140 | + * Serialize into JSON for client-side JS |
|
141 | + * |
|
142 | + * @return array |
|
143 | + */ |
|
144 | + public function jsonSerialize() { |
|
145 | + $data = $this->jsonSerializeDefinition(); |
|
146 | + $data += $this->jsonSerializeIdentifier(); |
|
147 | + |
|
148 | + $data['backend'] = $data['name']; // legacy compat |
|
149 | + $data['priority'] = $this->getPriority(); |
|
150 | + $data['authSchemes'] = $this->getAuthSchemes(); |
|
151 | + |
|
152 | + return $data; |
|
153 | + } |
|
154 | + |
|
155 | + /** |
|
156 | + * Check if parameters are satisfied in a StorageConfig |
|
157 | + * |
|
158 | + * @param StorageConfig $storage |
|
159 | + * @return bool |
|
160 | + */ |
|
161 | + public function validateStorage(StorageConfig $storage) { |
|
162 | + return $this->validateStorageDefinition($storage); |
|
163 | + } |
|
164 | 164 | |
165 | 165 | } |
166 | 166 |
@@ -31,129 +31,129 @@ |
||
31 | 31 | */ |
32 | 32 | trait FrontendDefinitionTrait { |
33 | 33 | |
34 | - /** @var string human-readable mechanism name */ |
|
35 | - private $text; |
|
36 | - |
|
37 | - /** @var DefinitionParameter[] parameters for mechanism */ |
|
38 | - private $parameters = []; |
|
39 | - |
|
40 | - /** @var string[] custom JS */ |
|
41 | - private $customJs = []; |
|
42 | - |
|
43 | - /** |
|
44 | - * @return string |
|
45 | - */ |
|
46 | - public function getText() { |
|
47 | - return $this->text; |
|
48 | - } |
|
49 | - |
|
50 | - /** |
|
51 | - * @param string $text |
|
52 | - * @return $this |
|
53 | - */ |
|
54 | - public function setText($text) { |
|
55 | - $this->text = $text; |
|
56 | - return $this; |
|
57 | - } |
|
58 | - |
|
59 | - /** |
|
60 | - * @param FrontendDefinitionTrait $a |
|
61 | - * @param FrontendDefinitionTrait $b |
|
62 | - * @return int |
|
63 | - */ |
|
64 | - public static function lexicalCompare(FrontendDefinitionTrait $a, FrontendDefinitionTrait $b) { |
|
65 | - return strcmp($a->getText(), $b->getText()); |
|
66 | - } |
|
67 | - |
|
68 | - /** |
|
69 | - * @return DefinitionParameter[] |
|
70 | - */ |
|
71 | - public function getParameters() { |
|
72 | - return $this->parameters; |
|
73 | - } |
|
74 | - |
|
75 | - /** |
|
76 | - * @param DefinitionParameter[] $parameters |
|
77 | - * @return self |
|
78 | - */ |
|
79 | - public function addParameters(array $parameters) { |
|
80 | - foreach ($parameters as $parameter) { |
|
81 | - $this->addParameter($parameter); |
|
82 | - } |
|
83 | - return $this; |
|
84 | - } |
|
85 | - |
|
86 | - /** |
|
87 | - * @param DefinitionParameter $parameter |
|
88 | - * @return self |
|
89 | - */ |
|
90 | - public function addParameter(DefinitionParameter $parameter) { |
|
91 | - $this->parameters[$parameter->getName()] = $parameter; |
|
92 | - return $this; |
|
93 | - } |
|
94 | - |
|
95 | - /** |
|
96 | - * @return string[] |
|
97 | - */ |
|
98 | - public function getCustomJs() { |
|
99 | - return $this->customJs; |
|
100 | - } |
|
101 | - |
|
102 | - /** |
|
103 | - * @param string $custom |
|
104 | - * @return self |
|
105 | - */ |
|
106 | - public function addCustomJs($custom) { |
|
107 | - $this->customJs[] = $custom; |
|
108 | - return $this; |
|
109 | - } |
|
110 | - |
|
111 | - /** |
|
112 | - * @param string $custom |
|
113 | - * @return self |
|
114 | - * @deprecated 9.1.0, use addCustomJs() instead |
|
115 | - */ |
|
116 | - public function setCustomJs($custom) { |
|
117 | - $this->customJs = [$custom]; |
|
118 | - return $this; |
|
119 | - } |
|
120 | - |
|
121 | - /** |
|
122 | - * Serialize into JSON for client-side JS |
|
123 | - * |
|
124 | - * @return array |
|
125 | - */ |
|
126 | - public function jsonSerializeDefinition() { |
|
127 | - $configuration = []; |
|
128 | - foreach ($this->getParameters() as $parameter) { |
|
129 | - $configuration[$parameter->getName()] = $parameter; |
|
130 | - } |
|
131 | - |
|
132 | - $data = [ |
|
133 | - 'name' => $this->getText(), |
|
134 | - 'configuration' => $configuration, |
|
135 | - 'custom' => $this->getCustomJs(), |
|
136 | - ]; |
|
137 | - return $data; |
|
138 | - } |
|
139 | - |
|
140 | - /** |
|
141 | - * Check if parameters are satisfied in a StorageConfig |
|
142 | - * |
|
143 | - * @param StorageConfig $storage |
|
144 | - * @return bool |
|
145 | - */ |
|
146 | - public function validateStorageDefinition(StorageConfig $storage) { |
|
147 | - foreach ($this->getParameters() as $name => $parameter) { |
|
148 | - $value = $storage->getBackendOption($name); |
|
149 | - if (!is_null($value) || !$parameter->isOptional()) { |
|
150 | - if (!$parameter->validateValue($value)) { |
|
151 | - return false; |
|
152 | - } |
|
153 | - $storage->setBackendOption($name, $value); |
|
154 | - } |
|
155 | - } |
|
156 | - return true; |
|
157 | - } |
|
34 | + /** @var string human-readable mechanism name */ |
|
35 | + private $text; |
|
36 | + |
|
37 | + /** @var DefinitionParameter[] parameters for mechanism */ |
|
38 | + private $parameters = []; |
|
39 | + |
|
40 | + /** @var string[] custom JS */ |
|
41 | + private $customJs = []; |
|
42 | + |
|
43 | + /** |
|
44 | + * @return string |
|
45 | + */ |
|
46 | + public function getText() { |
|
47 | + return $this->text; |
|
48 | + } |
|
49 | + |
|
50 | + /** |
|
51 | + * @param string $text |
|
52 | + * @return $this |
|
53 | + */ |
|
54 | + public function setText($text) { |
|
55 | + $this->text = $text; |
|
56 | + return $this; |
|
57 | + } |
|
58 | + |
|
59 | + /** |
|
60 | + * @param FrontendDefinitionTrait $a |
|
61 | + * @param FrontendDefinitionTrait $b |
|
62 | + * @return int |
|
63 | + */ |
|
64 | + public static function lexicalCompare(FrontendDefinitionTrait $a, FrontendDefinitionTrait $b) { |
|
65 | + return strcmp($a->getText(), $b->getText()); |
|
66 | + } |
|
67 | + |
|
68 | + /** |
|
69 | + * @return DefinitionParameter[] |
|
70 | + */ |
|
71 | + public function getParameters() { |
|
72 | + return $this->parameters; |
|
73 | + } |
|
74 | + |
|
75 | + /** |
|
76 | + * @param DefinitionParameter[] $parameters |
|
77 | + * @return self |
|
78 | + */ |
|
79 | + public function addParameters(array $parameters) { |
|
80 | + foreach ($parameters as $parameter) { |
|
81 | + $this->addParameter($parameter); |
|
82 | + } |
|
83 | + return $this; |
|
84 | + } |
|
85 | + |
|
86 | + /** |
|
87 | + * @param DefinitionParameter $parameter |
|
88 | + * @return self |
|
89 | + */ |
|
90 | + public function addParameter(DefinitionParameter $parameter) { |
|
91 | + $this->parameters[$parameter->getName()] = $parameter; |
|
92 | + return $this; |
|
93 | + } |
|
94 | + |
|
95 | + /** |
|
96 | + * @return string[] |
|
97 | + */ |
|
98 | + public function getCustomJs() { |
|
99 | + return $this->customJs; |
|
100 | + } |
|
101 | + |
|
102 | + /** |
|
103 | + * @param string $custom |
|
104 | + * @return self |
|
105 | + */ |
|
106 | + public function addCustomJs($custom) { |
|
107 | + $this->customJs[] = $custom; |
|
108 | + return $this; |
|
109 | + } |
|
110 | + |
|
111 | + /** |
|
112 | + * @param string $custom |
|
113 | + * @return self |
|
114 | + * @deprecated 9.1.0, use addCustomJs() instead |
|
115 | + */ |
|
116 | + public function setCustomJs($custom) { |
|
117 | + $this->customJs = [$custom]; |
|
118 | + return $this; |
|
119 | + } |
|
120 | + |
|
121 | + /** |
|
122 | + * Serialize into JSON for client-side JS |
|
123 | + * |
|
124 | + * @return array |
|
125 | + */ |
|
126 | + public function jsonSerializeDefinition() { |
|
127 | + $configuration = []; |
|
128 | + foreach ($this->getParameters() as $parameter) { |
|
129 | + $configuration[$parameter->getName()] = $parameter; |
|
130 | + } |
|
131 | + |
|
132 | + $data = [ |
|
133 | + 'name' => $this->getText(), |
|
134 | + 'configuration' => $configuration, |
|
135 | + 'custom' => $this->getCustomJs(), |
|
136 | + ]; |
|
137 | + return $data; |
|
138 | + } |
|
139 | + |
|
140 | + /** |
|
141 | + * Check if parameters are satisfied in a StorageConfig |
|
142 | + * |
|
143 | + * @param StorageConfig $storage |
|
144 | + * @return bool |
|
145 | + */ |
|
146 | + public function validateStorageDefinition(StorageConfig $storage) { |
|
147 | + foreach ($this->getParameters() as $name => $parameter) { |
|
148 | + $value = $storage->getBackendOption($name); |
|
149 | + if (!is_null($value) || !$parameter->isOptional()) { |
|
150 | + if (!$parameter->validateValue($value)) { |
|
151 | + return false; |
|
152 | + } |
|
153 | + $storage->setBackendOption($name, $value); |
|
154 | + } |
|
155 | + } |
|
156 | + return true; |
|
157 | + } |
|
158 | 158 | |
159 | 159 | } |
@@ -29,15 +29,15 @@ |
||
29 | 29 | * Authentication mechanism or backend has insufficient data |
30 | 30 | */ |
31 | 31 | class InsufficientDataForMeaningfulAnswerException extends StorageNotAvailableException { |
32 | - /** |
|
33 | - * StorageNotAvailableException constructor. |
|
34 | - * |
|
35 | - * @param string $message |
|
36 | - * @param int $code |
|
37 | - * @param \Exception|null $previous |
|
38 | - * @since 6.0.0 |
|
39 | - */ |
|
40 | - public function __construct($message = '', $code = self::STATUS_INDETERMINATE, \Exception $previous = null) { |
|
41 | - parent::__construct($message, $code, $previous); |
|
42 | - } |
|
32 | + /** |
|
33 | + * StorageNotAvailableException constructor. |
|
34 | + * |
|
35 | + * @param string $message |
|
36 | + * @param int $code |
|
37 | + * @param \Exception|null $previous |
|
38 | + * @since 6.0.0 |
|
39 | + */ |
|
40 | + public function __construct($message = '', $code = self::STATUS_INDETERMINATE, \Exception $previous = null) { |
|
41 | + parent::__construct($message, $code, $previous); |
|
42 | + } |
|
43 | 43 | } |