Skip to content

Commit ae63384

Browse files
committed
event on some .well-known/ request
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
1 parent e02c9ec commit ae63384

10 files changed

Lines changed: 754 additions & 31 deletions

File tree

lib/composer/composer/autoload_classmap.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,8 @@
536536
'OCP\\User\\Events\\UserLoggedOutEvent' => $baseDir . '/lib/public/User/Events/UserLoggedOutEvent.php',
537537
'OCP\\User\\GetQuotaEvent' => $baseDir . '/lib/public/User/GetQuotaEvent.php',
538538
'OCP\\Util' => $baseDir . '/lib/public/Util.php',
539+
'OCP\\WellKnown\\IWellKnownManager' => $baseDir . '/lib/public/WellKnown/IWellKnownManager.php',
540+
'OCP\\WellKnown\\Model\\IWellKnown' => $baseDir . '/lib/public/WellKnown/Model/IWellKnown.php',
539541
'OCP\\WorkflowEngine\\EntityContext\\IContextPortation' => $baseDir . '/lib/public/WorkflowEngine/EntityContext/IContextPortation.php',
540542
'OCP\\WorkflowEngine\\EntityContext\\IDisplayName' => $baseDir . '/lib/public/WorkflowEngine/EntityContext/IDisplayName.php',
541543
'OCP\\WorkflowEngine\\EntityContext\\IDisplayText' => $baseDir . '/lib/public/WorkflowEngine/EntityContext/IDisplayText.php',
@@ -1383,6 +1385,11 @@
13831385
'OC\\User\\NoUserException' => $baseDir . '/lib/private/User/NoUserException.php',
13841386
'OC\\User\\Session' => $baseDir . '/lib/private/User/Session.php',
13851387
'OC\\User\\User' => $baseDir . '/lib/private/User/User.php',
1388+
'OC\\WellKnown\\Event\\WellKnownEvent' => $baseDir . '/lib/private/WellKnown/Event/WellKnownEvent.php',
1389+
'OC\\WellKnown\\Exceptions\\NotManagedWellKnownRequestException' => $baseDir . '/lib/private/WellKnown/Exceptions/NotManagedWellKnownRequestException.php',
1390+
'OC\\WellKnown\\Exceptions\\WellKnownRequestException' => $baseDir . '/lib/private/WellKnown/Exceptions/WellKnownRequestException.php',
1391+
'OC\\WellKnown\\Model\\WellKnown' => $baseDir . '/lib/private/WellKnown/Model/WellKnown.php',
1392+
'OC\\WellKnown\\WellKnownManager' => $baseDir . '/lib/private/WellKnown/WellKnownManager.php',
13861393
'OC_API' => $baseDir . '/lib/private/legacy/OC_API.php',
13871394
'OC_App' => $baseDir . '/lib/private/legacy/OC_App.php',
13881395
'OC_DB' => $baseDir . '/lib/private/legacy/OC_DB.php',

lib/composer/composer/autoload_static.php

Lines changed: 14 additions & 27 deletions
Large diffs are not rendered by default.
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* @copyright 2020, Maxence Lange <maxence@artificial-owl.com>
7+
*
8+
* @author Maxence Lange <maxence@artificial-owl.com>
9+
*
10+
* @license GNU AGPL version 3 or any later version
11+
*
12+
* This program is free software: you can redistribute it and/or modify
13+
* it under the terms of the GNU Affero General Public License as
14+
* published by the Free Software Foundation, either version 3 of the
15+
* License, or (at your option) any later version.
16+
*
17+
* This program is distributed in the hope that it will be useful,
18+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20+
* GNU Affero General Public License for more details.
21+
*
22+
* You should have received a copy of the GNU Affero General Public License
23+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
24+
*
25+
*/
26+
27+
28+
namespace OC\WellKnown\Exceptions;
29+
30+
use Exception;
31+
use Throwable;
32+
33+
/**
34+
* Class NotManagedWellKnownRequestException
35+
*
36+
* @package OC\WellKnown\Exceptions
37+
* @since 21.0.0
38+
*/
39+
class NotManagedWellKnownRequestException extends Exception {
40+
41+
42+
/** @var int */
43+
private $errorCode;
44+
45+
46+
/**
47+
* WellKnownRequestException constructor.
48+
*
49+
* @param int $errorCode
50+
* @param string $message
51+
* @param int $code
52+
* @param Throwable|null $previous
53+
*/
54+
public function __construct($errorCode = 404, $message = "", $code = 0, Throwable $previous = null) {
55+
parent::__construct($message, $code, $previous);
56+
$this->errorCode = $errorCode;
57+
}
58+
59+
60+
/**
61+
* @return int
62+
* @since 21.0.0
63+
*/
64+
public function getErrorCode(): int {
65+
return $this->errorCode;
66+
}
67+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* @copyright 2020, Maxence Lange <maxence@artificial-owl.com>
7+
*
8+
* @author Maxence Lange <maxence@artificial-owl.com>
9+
*
10+
* @license GNU AGPL version 3 or any later version
11+
*
12+
* This program is free software: you can redistribute it and/or modify
13+
* it under the terms of the GNU Affero General Public License as
14+
* published by the Free Software Foundation, either version 3 of the
15+
* License, or (at your option) any later version.
16+
*
17+
* This program is distributed in the hope that it will be useful,
18+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20+
* GNU Affero General Public License for more details.
21+
*
22+
* You should have received a copy of the GNU Affero General Public License
23+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
24+
*
25+
*/
26+
27+
28+
namespace OC\WellKnown\Exceptions;
29+
30+
use Exception;
31+
use Throwable;
32+
33+
/**
34+
* Class WellKnownRequestException
35+
*
36+
* @package OC\WellKnown\Exceptions
37+
* @since 21.0.0
38+
*/
39+
class WellKnownRequestException extends Exception {
40+
41+
42+
/** @var int */
43+
private $errorCode;
44+
45+
46+
/**
47+
* WellKnownRequestException constructor.
48+
*
49+
* @param int $errorCode
50+
* @param string $message
51+
* @param int $code
52+
* @param Throwable|null $previous
53+
*/
54+
public function __construct($errorCode = 404, $message = "", $code = 0, Throwable $previous = null) {
55+
parent::__construct($message, $code, $previous);
56+
$this->errorCode = $errorCode;
57+
}
58+
59+
60+
/**
61+
* @return int
62+
* @since 21.0.0
63+
*/
64+
public function getErrorCode(): int {
65+
return $this->errorCode;
66+
}
67+
}
Lines changed: 207 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,207 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* @copyright 2020, Maxence Lange <maxence@artificial-owl.com>
7+
*
8+
* @author Maxence Lange <maxence@artificial-owl.com>
9+
*
10+
* @license GNU AGPL version 3 or any later version
11+
*
12+
* This program is free software: you can redistribute it and/or modify
13+
* it under the terms of the GNU Affero General Public License as
14+
* published by the Free Software Foundation, either version 3 of the
15+
* License, or (at your option) any later version.
16+
*
17+
* This program is distributed in the hope that it will be useful,
18+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20+
* GNU Affero General Public License for more details.
21+
*
22+
* You should have received a copy of the GNU Affero General Public License
23+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
24+
*
25+
*/
26+
27+
28+
namespace OC\WellKnown\Model;
29+
30+
use JsonSerializable;
31+
use OCP\IRequest;
32+
use OCP\WellKnown\Model\IWellKnown;
33+
34+
/**
35+
* @since 21.0.0
36+
*
37+
* @package OC\WellKnown\Model
38+
*/
39+
final class WellKnown implements IWellKnown, JsonSerializable {
40+
41+
42+
/** @var string */
43+
private $service;
44+
45+
/** @var IRequest */
46+
private $request;
47+
48+
/** @var string */
49+
private $subject = '';
50+
51+
/** @var array */
52+
private $aliases = [];
53+
54+
/** @var array */
55+
private $properties = [];
56+
57+
/** @var array */
58+
private $rels = [];
59+
60+
/** @var array */
61+
private $links = [];
62+
63+
64+
/**
65+
* WellKnown constructor.
66+
*
67+
* @param string $service
68+
* @param IRequest $request
69+
*
70+
* @since 21.0.0
71+
*/
72+
public function __construct(string $service, IRequest $request) {
73+
$this->request = $request;
74+
$this->service = $service;
75+
$this->subject = $request->getParam('resource', '');
76+
}
77+
78+
79+
/**
80+
* @return string
81+
* @since 21.0.0
82+
*/
83+
public function getService(): string {
84+
return $this->service;
85+
}
86+
87+
88+
/**
89+
* @return IRequest
90+
* @since 21.0.0
91+
*/
92+
public function getRequest(): IRequest {
93+
return $this->request;
94+
}
95+
96+
97+
/**
98+
* @return string
99+
* @since 21.0.0
100+
*/
101+
public function getSubject(): string {
102+
return $this->subject;
103+
}
104+
105+
106+
/**
107+
* @return array
108+
* @since 21.0.0
109+
*/
110+
public function getRels(): array {
111+
return $this->rels;
112+
}
113+
114+
115+
/**
116+
* @param string $alias
117+
*
118+
* @return $this
119+
* @since 21.0.0
120+
*/
121+
public function addAlias(string $alias): IWellKnown {
122+
if (!in_array($alias, $this->aliases)) {
123+
$this->aliases[] = $alias;
124+
}
125+
126+
return $this;
127+
}
128+
129+
/**
130+
* @return array
131+
* @since 21.0.0
132+
*/
133+
public function getAliases(): array {
134+
return $this->aliases;
135+
}
136+
137+
138+
/**
139+
* @param string $property
140+
* @param $value
141+
*
142+
* @return IWellKnown
143+
* @since 21.0.0
144+
*/
145+
public function addProperty(string $property, $value): IWellKnown {
146+
$this->properties[$property] = $value;
147+
148+
return $this;
149+
}
150+
151+
/**
152+
* @return array
153+
* @since 21.0.0
154+
*/
155+
public function getProperties(): array {
156+
return $this->properties;
157+
}
158+
159+
160+
/**
161+
* @param array $arr
162+
*
163+
* @return IWellKnown
164+
* @since 21.0.0
165+
*/
166+
public function addLink(array $arr): IWellKnown {
167+
$this->links[] = $arr;
168+
169+
return $this;
170+
}
171+
172+
/**
173+
* @param JsonSerializable $object
174+
*
175+
* @return IWellKnown
176+
* @since 21.0.0
177+
*/
178+
public function addLinkSerialized(JsonSerializable $object): IWellKnown {
179+
$this->links[] = $object;
180+
181+
return $this;
182+
}
183+
184+
/**
185+
* @return array
186+
* @since 21.0.0
187+
*/
188+
public function getLinks(): array {
189+
return $this->links;
190+
}
191+
192+
193+
/**
194+
* @return array
195+
* @since 21.0.0
196+
*/
197+
public function jsonSerialize(): array {
198+
$data = [
199+
'subject' => $this->getSubject(),
200+
'properties' => $this->getProperties(),
201+
'aliases' => $this->getAliases(),
202+
'links' => $this->getLinks()
203+
];
204+
205+
return array_filter($data);
206+
}
207+
}

0 commit comments

Comments
 (0)