@@ -29,8 +29,8 @@ |
||
29 | 29 | */ |
30 | 30 | interface IPasswordConfirmationBackend { |
31 | 31 | |
32 | - /** |
|
33 | - * @since 15.0.0 |
|
34 | - */ |
|
35 | - public function canConfirmPassword(string $uid): bool; |
|
32 | + /** |
|
33 | + * @since 15.0.0 |
|
34 | + */ |
|
35 | + public function canConfirmPassword(string $uid): bool; |
|
36 | 36 | } |
@@ -170,7 +170,7 @@ |
||
170 | 170 | )) |
171 | 171 | ->andWhere($update->expr()->like( |
172 | 172 | $update->func()->lower('name'), |
173 | - $update->createNamedParameter('%' . $this->dbConnection->escapeLikeParameter('.' . $ext)) |
|
173 | + $update->createNamedParameter('%'.$this->dbConnection->escapeLikeParameter('.'.$ext)) |
|
174 | 174 | )); |
175 | 175 | return $update->execute(); |
176 | 176 | } |
@@ -35,148 +35,148 @@ |
||
35 | 35 | */ |
36 | 36 | class Loader implements IMimeTypeLoader { |
37 | 37 | |
38 | - /** @var IDBConnection */ |
|
39 | - private $dbConnection; |
|
40 | - |
|
41 | - /** @var array [id => mimetype] */ |
|
42 | - protected $mimetypes; |
|
43 | - |
|
44 | - /** @var array [mimetype => id] */ |
|
45 | - protected $mimetypeIds; |
|
46 | - |
|
47 | - /** |
|
48 | - * @param IDBConnection $dbConnection |
|
49 | - */ |
|
50 | - public function __construct(IDBConnection $dbConnection) { |
|
51 | - $this->dbConnection = $dbConnection; |
|
52 | - $this->mimetypes = []; |
|
53 | - $this->mimetypeIds = []; |
|
54 | - } |
|
55 | - |
|
56 | - /** |
|
57 | - * Get a mimetype from its ID |
|
58 | - * |
|
59 | - * @param int $id |
|
60 | - * @return string|null |
|
61 | - */ |
|
62 | - public function getMimetypeById($id) { |
|
63 | - if (!$this->mimetypes) { |
|
64 | - $this->loadMimetypes(); |
|
65 | - } |
|
66 | - if (isset($this->mimetypes[$id])) { |
|
67 | - return $this->mimetypes[$id]; |
|
68 | - } |
|
69 | - return null; |
|
70 | - } |
|
71 | - |
|
72 | - /** |
|
73 | - * Get a mimetype ID, adding the mimetype to the DB if it does not exist |
|
74 | - * |
|
75 | - * @param string $mimetype |
|
76 | - * @return int |
|
77 | - */ |
|
78 | - public function getId($mimetype) { |
|
79 | - if (!$this->mimetypeIds) { |
|
80 | - $this->loadMimetypes(); |
|
81 | - } |
|
82 | - if (isset($this->mimetypeIds[$mimetype])) { |
|
83 | - return $this->mimetypeIds[$mimetype]; |
|
84 | - } |
|
85 | - return $this->store($mimetype); |
|
86 | - } |
|
87 | - |
|
88 | - /** |
|
89 | - * Test if a mimetype exists in the database |
|
90 | - * |
|
91 | - * @param string $mimetype |
|
92 | - * @return bool |
|
93 | - */ |
|
94 | - public function exists($mimetype) { |
|
95 | - if (!$this->mimetypeIds) { |
|
96 | - $this->loadMimetypes(); |
|
97 | - } |
|
98 | - return isset($this->mimetypeIds[$mimetype]); |
|
99 | - } |
|
100 | - |
|
101 | - /** |
|
102 | - * Clear all loaded mimetypes, allow for re-loading |
|
103 | - */ |
|
104 | - public function reset() { |
|
105 | - $this->mimetypes = []; |
|
106 | - $this->mimetypeIds = []; |
|
107 | - } |
|
108 | - |
|
109 | - /** |
|
110 | - * Store a mimetype in the DB |
|
111 | - * |
|
112 | - * @param string $mimetype |
|
113 | - * @param int inserted ID |
|
114 | - */ |
|
115 | - protected function store($mimetype) { |
|
116 | - $this->dbConnection->insertIfNotExist('*PREFIX*mimetypes', [ |
|
117 | - 'mimetype' => $mimetype |
|
118 | - ]); |
|
119 | - |
|
120 | - $fetch = $this->dbConnection->getQueryBuilder(); |
|
121 | - $fetch->select('id') |
|
122 | - ->from('mimetypes') |
|
123 | - ->where( |
|
124 | - $fetch->expr()->eq('mimetype', $fetch->createNamedParameter($mimetype) |
|
125 | - )); |
|
126 | - |
|
127 | - $result = $fetch->execute(); |
|
128 | - $row = $result->fetch(); |
|
129 | - $result->closeCursor(); |
|
130 | - |
|
131 | - if (!$row) { |
|
132 | - throw new \Exception("Failed to get mimetype id for $mimetype after trying to store it"); |
|
133 | - } |
|
134 | - |
|
135 | - $this->mimetypes[$row['id']] = $mimetype; |
|
136 | - $this->mimetypeIds[$mimetype] = $row['id']; |
|
137 | - return $row['id']; |
|
138 | - } |
|
139 | - |
|
140 | - /** |
|
141 | - * Load all mimetypes from DB |
|
142 | - */ |
|
143 | - private function loadMimetypes() { |
|
144 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
145 | - $qb->select('id', 'mimetype') |
|
146 | - ->from('mimetypes'); |
|
147 | - |
|
148 | - $result = $qb->execute(); |
|
149 | - $results = $result->fetchAll(); |
|
150 | - $result->closeCursor(); |
|
151 | - |
|
152 | - foreach ($results as $row) { |
|
153 | - $this->mimetypes[$row['id']] = $row['mimetype']; |
|
154 | - $this->mimetypeIds[$row['mimetype']] = $row['id']; |
|
155 | - } |
|
156 | - } |
|
157 | - |
|
158 | - /** |
|
159 | - * Update filecache mimetype based on file extension |
|
160 | - * |
|
161 | - * @param string $ext file extension |
|
162 | - * @param int $mimeTypeId |
|
163 | - * @return int number of changed rows |
|
164 | - */ |
|
165 | - public function updateFilecache($ext, $mimeTypeId) { |
|
166 | - $folderMimeTypeId = $this->getId('httpd/unix-directory'); |
|
167 | - $update = $this->dbConnection->getQueryBuilder(); |
|
168 | - $update->update('filecache') |
|
169 | - ->set('mimetype', $update->createNamedParameter($mimeTypeId)) |
|
170 | - ->where($update->expr()->neq( |
|
171 | - 'mimetype', $update->createNamedParameter($mimeTypeId) |
|
172 | - )) |
|
173 | - ->andWhere($update->expr()->neq( |
|
174 | - 'mimetype', $update->createNamedParameter($folderMimeTypeId) |
|
175 | - )) |
|
176 | - ->andWhere($update->expr()->like( |
|
177 | - $update->func()->lower('name'), |
|
178 | - $update->createNamedParameter('%' . $this->dbConnection->escapeLikeParameter('.' . $ext)) |
|
179 | - )); |
|
180 | - return $update->execute(); |
|
181 | - } |
|
38 | + /** @var IDBConnection */ |
|
39 | + private $dbConnection; |
|
40 | + |
|
41 | + /** @var array [id => mimetype] */ |
|
42 | + protected $mimetypes; |
|
43 | + |
|
44 | + /** @var array [mimetype => id] */ |
|
45 | + protected $mimetypeIds; |
|
46 | + |
|
47 | + /** |
|
48 | + * @param IDBConnection $dbConnection |
|
49 | + */ |
|
50 | + public function __construct(IDBConnection $dbConnection) { |
|
51 | + $this->dbConnection = $dbConnection; |
|
52 | + $this->mimetypes = []; |
|
53 | + $this->mimetypeIds = []; |
|
54 | + } |
|
55 | + |
|
56 | + /** |
|
57 | + * Get a mimetype from its ID |
|
58 | + * |
|
59 | + * @param int $id |
|
60 | + * @return string|null |
|
61 | + */ |
|
62 | + public function getMimetypeById($id) { |
|
63 | + if (!$this->mimetypes) { |
|
64 | + $this->loadMimetypes(); |
|
65 | + } |
|
66 | + if (isset($this->mimetypes[$id])) { |
|
67 | + return $this->mimetypes[$id]; |
|
68 | + } |
|
69 | + return null; |
|
70 | + } |
|
71 | + |
|
72 | + /** |
|
73 | + * Get a mimetype ID, adding the mimetype to the DB if it does not exist |
|
74 | + * |
|
75 | + * @param string $mimetype |
|
76 | + * @return int |
|
77 | + */ |
|
78 | + public function getId($mimetype) { |
|
79 | + if (!$this->mimetypeIds) { |
|
80 | + $this->loadMimetypes(); |
|
81 | + } |
|
82 | + if (isset($this->mimetypeIds[$mimetype])) { |
|
83 | + return $this->mimetypeIds[$mimetype]; |
|
84 | + } |
|
85 | + return $this->store($mimetype); |
|
86 | + } |
|
87 | + |
|
88 | + /** |
|
89 | + * Test if a mimetype exists in the database |
|
90 | + * |
|
91 | + * @param string $mimetype |
|
92 | + * @return bool |
|
93 | + */ |
|
94 | + public function exists($mimetype) { |
|
95 | + if (!$this->mimetypeIds) { |
|
96 | + $this->loadMimetypes(); |
|
97 | + } |
|
98 | + return isset($this->mimetypeIds[$mimetype]); |
|
99 | + } |
|
100 | + |
|
101 | + /** |
|
102 | + * Clear all loaded mimetypes, allow for re-loading |
|
103 | + */ |
|
104 | + public function reset() { |
|
105 | + $this->mimetypes = []; |
|
106 | + $this->mimetypeIds = []; |
|
107 | + } |
|
108 | + |
|
109 | + /** |
|
110 | + * Store a mimetype in the DB |
|
111 | + * |
|
112 | + * @param string $mimetype |
|
113 | + * @param int inserted ID |
|
114 | + */ |
|
115 | + protected function store($mimetype) { |
|
116 | + $this->dbConnection->insertIfNotExist('*PREFIX*mimetypes', [ |
|
117 | + 'mimetype' => $mimetype |
|
118 | + ]); |
|
119 | + |
|
120 | + $fetch = $this->dbConnection->getQueryBuilder(); |
|
121 | + $fetch->select('id') |
|
122 | + ->from('mimetypes') |
|
123 | + ->where( |
|
124 | + $fetch->expr()->eq('mimetype', $fetch->createNamedParameter($mimetype) |
|
125 | + )); |
|
126 | + |
|
127 | + $result = $fetch->execute(); |
|
128 | + $row = $result->fetch(); |
|
129 | + $result->closeCursor(); |
|
130 | + |
|
131 | + if (!$row) { |
|
132 | + throw new \Exception("Failed to get mimetype id for $mimetype after trying to store it"); |
|
133 | + } |
|
134 | + |
|
135 | + $this->mimetypes[$row['id']] = $mimetype; |
|
136 | + $this->mimetypeIds[$mimetype] = $row['id']; |
|
137 | + return $row['id']; |
|
138 | + } |
|
139 | + |
|
140 | + /** |
|
141 | + * Load all mimetypes from DB |
|
142 | + */ |
|
143 | + private function loadMimetypes() { |
|
144 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
145 | + $qb->select('id', 'mimetype') |
|
146 | + ->from('mimetypes'); |
|
147 | + |
|
148 | + $result = $qb->execute(); |
|
149 | + $results = $result->fetchAll(); |
|
150 | + $result->closeCursor(); |
|
151 | + |
|
152 | + foreach ($results as $row) { |
|
153 | + $this->mimetypes[$row['id']] = $row['mimetype']; |
|
154 | + $this->mimetypeIds[$row['mimetype']] = $row['id']; |
|
155 | + } |
|
156 | + } |
|
157 | + |
|
158 | + /** |
|
159 | + * Update filecache mimetype based on file extension |
|
160 | + * |
|
161 | + * @param string $ext file extension |
|
162 | + * @param int $mimeTypeId |
|
163 | + * @return int number of changed rows |
|
164 | + */ |
|
165 | + public function updateFilecache($ext, $mimeTypeId) { |
|
166 | + $folderMimeTypeId = $this->getId('httpd/unix-directory'); |
|
167 | + $update = $this->dbConnection->getQueryBuilder(); |
|
168 | + $update->update('filecache') |
|
169 | + ->set('mimetype', $update->createNamedParameter($mimeTypeId)) |
|
170 | + ->where($update->expr()->neq( |
|
171 | + 'mimetype', $update->createNamedParameter($mimeTypeId) |
|
172 | + )) |
|
173 | + ->andWhere($update->expr()->neq( |
|
174 | + 'mimetype', $update->createNamedParameter($folderMimeTypeId) |
|
175 | + )) |
|
176 | + ->andWhere($update->expr()->like( |
|
177 | + $update->func()->lower('name'), |
|
178 | + $update->createNamedParameter('%' . $this->dbConnection->escapeLikeParameter('.' . $ext)) |
|
179 | + )); |
|
180 | + return $update->execute(); |
|
181 | + } |
|
182 | 182 | } |
@@ -32,18 +32,18 @@ |
||
32 | 32 | |
33 | 33 | class Version1008Date20181105112049 extends SimpleMigrationStep { |
34 | 34 | |
35 | - /** |
|
36 | - * @param IOutput $output |
|
37 | - * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
38 | - * @param array $options |
|
39 | - * @return null|ISchemaWrapper |
|
40 | - */ |
|
41 | - public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) { |
|
42 | - /** @var ISchemaWrapper $schema */ |
|
43 | - $schema = $schemaClosure(); |
|
44 | - $table = $schema->getTable('calendarsubscriptions'); |
|
45 | - $table->dropColumn('source_copy'); |
|
35 | + /** |
|
36 | + * @param IOutput $output |
|
37 | + * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
38 | + * @param array $options |
|
39 | + * @return null|ISchemaWrapper |
|
40 | + */ |
|
41 | + public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) { |
|
42 | + /** @var ISchemaWrapper $schema */ |
|
43 | + $schema = $schemaClosure(); |
|
44 | + $table = $schema->getTable('calendarsubscriptions'); |
|
45 | + $table->dropColumn('source_copy'); |
|
46 | 46 | |
47 | - return $schema; |
|
48 | - } |
|
47 | + return $schema; |
|
48 | + } |
|
49 | 49 | } |
@@ -32,18 +32,18 @@ |
||
32 | 32 | |
33 | 33 | class Version1008Date20181105104833 extends SimpleMigrationStep { |
34 | 34 | |
35 | - /** |
|
36 | - * @param IOutput $output |
|
37 | - * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
38 | - * @param array $options |
|
39 | - * @return null|ISchemaWrapper |
|
40 | - */ |
|
41 | - public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) { |
|
42 | - /** @var ISchemaWrapper $schema */ |
|
43 | - $schema = $schemaClosure(); |
|
44 | - $table = $schema->getTable('calendarsubscriptions'); |
|
45 | - $table->dropColumn('source'); |
|
35 | + /** |
|
36 | + * @param IOutput $output |
|
37 | + * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
38 | + * @param array $options |
|
39 | + * @return null|ISchemaWrapper |
|
40 | + */ |
|
41 | + public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) { |
|
42 | + /** @var ISchemaWrapper $schema */ |
|
43 | + $schema = $schemaClosure(); |
|
44 | + $table = $schema->getTable('calendarsubscriptions'); |
|
45 | + $table->dropColumn('source'); |
|
46 | 46 | |
47 | - return $schema; |
|
48 | - } |
|
47 | + return $schema; |
|
48 | + } |
|
49 | 49 | } |
@@ -37,31 +37,31 @@ |
||
37 | 37 | */ |
38 | 38 | interface ICrypto { |
39 | 39 | |
40 | - /** |
|
41 | - * @param string $message The message to authenticate |
|
42 | - * @param string $password Password to use (defaults to `secret` in config.php) |
|
43 | - * @return string Calculated HMAC |
|
44 | - * @since 8.0.0 |
|
45 | - */ |
|
46 | - public function calculateHMAC(string $message, string $password = ''): string; |
|
40 | + /** |
|
41 | + * @param string $message The message to authenticate |
|
42 | + * @param string $password Password to use (defaults to `secret` in config.php) |
|
43 | + * @return string Calculated HMAC |
|
44 | + * @since 8.0.0 |
|
45 | + */ |
|
46 | + public function calculateHMAC(string $message, string $password = ''): string; |
|
47 | 47 | |
48 | - /** |
|
49 | - * Encrypts a value and adds an HMAC (Encrypt-Then-MAC) |
|
50 | - * @param string $plaintext |
|
51 | - * @param string $password Password to encrypt, if not specified the secret from config.php will be taken |
|
52 | - * @return string Authenticated ciphertext |
|
53 | - * @since 8.0.0 |
|
54 | - */ |
|
55 | - public function encrypt(string $plaintext, string $password = ''): string; |
|
48 | + /** |
|
49 | + * Encrypts a value and adds an HMAC (Encrypt-Then-MAC) |
|
50 | + * @param string $plaintext |
|
51 | + * @param string $password Password to encrypt, if not specified the secret from config.php will be taken |
|
52 | + * @return string Authenticated ciphertext |
|
53 | + * @since 8.0.0 |
|
54 | + */ |
|
55 | + public function encrypt(string $plaintext, string $password = ''): string; |
|
56 | 56 | |
57 | - /** |
|
58 | - * Decrypts a value and verifies the HMAC (Encrypt-Then-Mac) |
|
59 | - * @param string $authenticatedCiphertext |
|
60 | - * @param string $password Password to encrypt, if not specified the secret from config.php will be taken |
|
61 | - * @return string plaintext |
|
62 | - * @throws \Exception If the HMAC does not match |
|
63 | - * @throws \Exception If the decryption failed |
|
64 | - * @since 8.0.0 |
|
65 | - */ |
|
66 | - public function decrypt(string $authenticatedCiphertext, string $password = ''): string; |
|
57 | + /** |
|
58 | + * Decrypts a value and verifies the HMAC (Encrypt-Then-Mac) |
|
59 | + * @param string $authenticatedCiphertext |
|
60 | + * @param string $password Password to encrypt, if not specified the secret from config.php will be taken |
|
61 | + * @return string plaintext |
|
62 | + * @throws \Exception If the HMAC does not match |
|
63 | + * @throws \Exception If the decryption failed |
|
64 | + * @since 8.0.0 |
|
65 | + */ |
|
66 | + public function decrypt(string $authenticatedCiphertext, string $password = ''): string; |
|
67 | 67 | } |
@@ -33,27 +33,27 @@ |
||
33 | 33 | class Version1008Date20181114084440 extends SimpleMigrationStep { |
34 | 34 | |
35 | 35 | |
36 | - /** |
|
37 | - * @param IOutput $output |
|
38 | - * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
39 | - * @param array $options |
|
40 | - * @return null|ISchemaWrapper |
|
41 | - */ |
|
42 | - public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) { |
|
43 | - /** @var ISchemaWrapper $schema */ |
|
44 | - $schema = $schemaClosure(); |
|
45 | - |
|
46 | - if ($schema->hasTable('calendarchanges')) { |
|
47 | - $calendarChangesTable = $schema->getTable('calendarchanges'); |
|
48 | - if ($calendarChangesTable->hasIndex('calendarid_calendartype_synctoken')) { |
|
49 | - $calendarChangesTable->dropIndex('calendarid_calendartype_synctoken'); |
|
50 | - } |
|
51 | - |
|
52 | - if (!$calendarChangesTable->hasIndex('calid_type_synctoken')) { |
|
53 | - $calendarChangesTable->addIndex(['calendarid', 'calendartype', 'synctoken'], 'calid_type_synctoken'); |
|
54 | - } |
|
55 | - } |
|
56 | - |
|
57 | - return $schema; |
|
58 | - } |
|
36 | + /** |
|
37 | + * @param IOutput $output |
|
38 | + * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
39 | + * @param array $options |
|
40 | + * @return null|ISchemaWrapper |
|
41 | + */ |
|
42 | + public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) { |
|
43 | + /** @var ISchemaWrapper $schema */ |
|
44 | + $schema = $schemaClosure(); |
|
45 | + |
|
46 | + if ($schema->hasTable('calendarchanges')) { |
|
47 | + $calendarChangesTable = $schema->getTable('calendarchanges'); |
|
48 | + if ($calendarChangesTable->hasIndex('calendarid_calendartype_synctoken')) { |
|
49 | + $calendarChangesTable->dropIndex('calendarid_calendartype_synctoken'); |
|
50 | + } |
|
51 | + |
|
52 | + if (!$calendarChangesTable->hasIndex('calid_type_synctoken')) { |
|
53 | + $calendarChangesTable->addIndex(['calendarid', 'calendartype', 'synctoken'], 'calid_type_synctoken'); |
|
54 | + } |
|
55 | + } |
|
56 | + |
|
57 | + return $schema; |
|
58 | + } |
|
59 | 59 | } |
@@ -37,15 +37,15 @@ |
||
37 | 37 | */ |
38 | 38 | interface IActivatableByAdmin extends IProvider { |
39 | 39 | |
40 | - /** |
|
41 | - * Enable this provider for the given user. |
|
42 | - * |
|
43 | - * @param IUser $user the user to activate this provider for |
|
44 | - * |
|
45 | - * @return void |
|
46 | - * |
|
47 | - * @since 15.0.0 |
|
48 | - */ |
|
49 | - public function enableFor(IUser $user); |
|
40 | + /** |
|
41 | + * Enable this provider for the given user. |
|
42 | + * |
|
43 | + * @param IUser $user the user to activate this provider for |
|
44 | + * |
|
45 | + * @return void |
|
46 | + * |
|
47 | + * @since 15.0.0 |
|
48 | + */ |
|
49 | + public function enableFor(IUser $user); |
|
50 | 50 | |
51 | 51 | } |
@@ -37,15 +37,15 @@ |
||
37 | 37 | */ |
38 | 38 | interface IDeactivatableByAdmin extends IProvider { |
39 | 39 | |
40 | - /** |
|
41 | - * Disable this provider for the given user. |
|
42 | - * |
|
43 | - * @param IUser $user the user to deactivate this provider for |
|
44 | - * |
|
45 | - * @return void |
|
46 | - * |
|
47 | - * @since 15.0.0 |
|
48 | - */ |
|
49 | - public function disableFor(IUser $user); |
|
40 | + /** |
|
41 | + * Disable this provider for the given user. |
|
42 | + * |
|
43 | + * @param IUser $user the user to deactivate this provider for |
|
44 | + * |
|
45 | + * @return void |
|
46 | + * |
|
47 | + * @since 15.0.0 |
|
48 | + */ |
|
49 | + public function disableFor(IUser $user); |
|
50 | 50 | |
51 | 51 | } |
@@ -38,87 +38,87 @@ |
||
38 | 38 | */ |
39 | 39 | class Validator implements IValidator { |
40 | 40 | |
41 | - /** @var Definitions */ |
|
42 | - protected $definitions; |
|
43 | - |
|
44 | - /** @var array[] */ |
|
45 | - protected $requiredParameters = []; |
|
46 | - |
|
47 | - /** |
|
48 | - * Constructor |
|
49 | - * |
|
50 | - * @param Definitions $definitions |
|
51 | - */ |
|
52 | - public function __construct(Definitions $definitions) { |
|
53 | - $this->definitions = $definitions; |
|
54 | - } |
|
55 | - |
|
56 | - /** |
|
57 | - * @param string $subject |
|
58 | - * @param array[] $parameters |
|
59 | - * @throws InvalidObjectExeption |
|
60 | - * @since 11.0.0 |
|
61 | - */ |
|
62 | - public function validate($subject, array $parameters) { |
|
63 | - $matches = []; |
|
64 | - $result = preg_match_all('/\{([a-z0-9]+)\}/i', $subject, $matches); |
|
65 | - |
|
66 | - if ($result === false) { |
|
67 | - throw new InvalidObjectExeption(); |
|
68 | - } |
|
69 | - |
|
70 | - if (!empty($matches[1])) { |
|
71 | - foreach ($matches[1] as $parameter) { |
|
72 | - if (!isset($parameters[$parameter])) { |
|
73 | - throw new InvalidObjectExeption('Parameter is undefined'); |
|
74 | - } |
|
75 | - } |
|
76 | - } |
|
77 | - |
|
78 | - foreach ($parameters as $parameter) { |
|
79 | - if (!\is_array($parameter)) { |
|
80 | - throw new InvalidObjectExeption('Parameter is malformed'); |
|
81 | - } |
|
82 | - |
|
83 | - $this->validateParameter($parameter); |
|
84 | - } |
|
85 | - } |
|
86 | - |
|
87 | - /** |
|
88 | - * @param array $parameter |
|
89 | - * @throws InvalidObjectExeption |
|
90 | - */ |
|
91 | - protected function validateParameter(array $parameter) { |
|
92 | - if (!isset($parameter['type'])) { |
|
93 | - throw new InvalidObjectExeption('Object type is undefined'); |
|
94 | - } |
|
95 | - |
|
96 | - $definition = $this->definitions->getDefinition($parameter['type']); |
|
97 | - $requiredParameters = $this->getRequiredParameters($parameter['type'], $definition); |
|
98 | - |
|
99 | - $missingKeys = array_diff($requiredParameters, array_keys($parameter)); |
|
100 | - if (!empty($missingKeys)) { |
|
101 | - throw new InvalidObjectExeption('Object is invalid'); |
|
102 | - } |
|
103 | - } |
|
104 | - |
|
105 | - /** |
|
106 | - * @param string $type |
|
107 | - * @param array $definition |
|
108 | - * @return string[] |
|
109 | - */ |
|
110 | - protected function getRequiredParameters($type, array $definition) { |
|
111 | - if (isset($this->requiredParameters[$type])) { |
|
112 | - return $this->requiredParameters[$type]; |
|
113 | - } |
|
114 | - |
|
115 | - $this->requiredParameters[$type] = []; |
|
116 | - foreach ($definition['parameters'] as $parameter => $data) { |
|
117 | - if ($data['required']) { |
|
118 | - $this->requiredParameters[$type][] = $parameter; |
|
119 | - } |
|
120 | - } |
|
121 | - |
|
122 | - return $this->requiredParameters[$type]; |
|
123 | - } |
|
41 | + /** @var Definitions */ |
|
42 | + protected $definitions; |
|
43 | + |
|
44 | + /** @var array[] */ |
|
45 | + protected $requiredParameters = []; |
|
46 | + |
|
47 | + /** |
|
48 | + * Constructor |
|
49 | + * |
|
50 | + * @param Definitions $definitions |
|
51 | + */ |
|
52 | + public function __construct(Definitions $definitions) { |
|
53 | + $this->definitions = $definitions; |
|
54 | + } |
|
55 | + |
|
56 | + /** |
|
57 | + * @param string $subject |
|
58 | + * @param array[] $parameters |
|
59 | + * @throws InvalidObjectExeption |
|
60 | + * @since 11.0.0 |
|
61 | + */ |
|
62 | + public function validate($subject, array $parameters) { |
|
63 | + $matches = []; |
|
64 | + $result = preg_match_all('/\{([a-z0-9]+)\}/i', $subject, $matches); |
|
65 | + |
|
66 | + if ($result === false) { |
|
67 | + throw new InvalidObjectExeption(); |
|
68 | + } |
|
69 | + |
|
70 | + if (!empty($matches[1])) { |
|
71 | + foreach ($matches[1] as $parameter) { |
|
72 | + if (!isset($parameters[$parameter])) { |
|
73 | + throw new InvalidObjectExeption('Parameter is undefined'); |
|
74 | + } |
|
75 | + } |
|
76 | + } |
|
77 | + |
|
78 | + foreach ($parameters as $parameter) { |
|
79 | + if (!\is_array($parameter)) { |
|
80 | + throw new InvalidObjectExeption('Parameter is malformed'); |
|
81 | + } |
|
82 | + |
|
83 | + $this->validateParameter($parameter); |
|
84 | + } |
|
85 | + } |
|
86 | + |
|
87 | + /** |
|
88 | + * @param array $parameter |
|
89 | + * @throws InvalidObjectExeption |
|
90 | + */ |
|
91 | + protected function validateParameter(array $parameter) { |
|
92 | + if (!isset($parameter['type'])) { |
|
93 | + throw new InvalidObjectExeption('Object type is undefined'); |
|
94 | + } |
|
95 | + |
|
96 | + $definition = $this->definitions->getDefinition($parameter['type']); |
|
97 | + $requiredParameters = $this->getRequiredParameters($parameter['type'], $definition); |
|
98 | + |
|
99 | + $missingKeys = array_diff($requiredParameters, array_keys($parameter)); |
|
100 | + if (!empty($missingKeys)) { |
|
101 | + throw new InvalidObjectExeption('Object is invalid'); |
|
102 | + } |
|
103 | + } |
|
104 | + |
|
105 | + /** |
|
106 | + * @param string $type |
|
107 | + * @param array $definition |
|
108 | + * @return string[] |
|
109 | + */ |
|
110 | + protected function getRequiredParameters($type, array $definition) { |
|
111 | + if (isset($this->requiredParameters[$type])) { |
|
112 | + return $this->requiredParameters[$type]; |
|
113 | + } |
|
114 | + |
|
115 | + $this->requiredParameters[$type] = []; |
|
116 | + foreach ($definition['parameters'] as $parameter => $data) { |
|
117 | + if ($data['required']) { |
|
118 | + $this->requiredParameters[$type][] = $parameter; |
|
119 | + } |
|
120 | + } |
|
121 | + |
|
122 | + return $this->requiredParameters[$type]; |
|
123 | + } |
|
124 | 124 | } |