Skip to content

Commit 127f12c

Browse files
committed
Change ResourceController to be cleaner
- Add typehint comments - Whitespace fixes - Code restructure
1 parent f7fbae8 commit 127f12c

File tree

1 file changed

+34
-29
lines changed

1 file changed

+34
-29
lines changed

src/Controller/ResourceController.php

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,11 @@ class ResourceController extends ServerController
1414

1515
/** @var Server */
1616
private $server;
17-
private $DPop;
18-
private $WAC;
17+
/** @var DPop */
18+
private $DPop;
19+
/** @var WAC */
20+
private $WAC;
21+
1922
//////////////////////////////// PUBLIC API \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
2023

2124
final public function __construct(Server $server)
@@ -45,25 +48,27 @@ final public function __invoke(Request $request, array $args) : Response
4548
$allowedOrigins = $this->config->getAllowedOrigins();
4649
$origins = $request->getHeader('Origin');
4750

48-
$isAllowed = false;
49-
foreach ($origins as $origin) {
50-
if ($this->WAC->isAllowed($request, $webId, $origin, $allowedOrigins)) {
51-
$isAllowed = true;
52-
break;
53-
}
54-
}
51+
if ($origins !== []) {
52+
foreach ($origins as $origin) {
53+
if ($this->WAC->isAllowed($request, $webId, $origin, $allowedOrigins)) {
54+
$response = $this->server->respondToRequest($request);
5555

56-
if (! $isAllowed) {
56+
return $this->WAC->addWACHeaders($request, $response, $webId);
57+
}
58+
}
5759
return $this->server->getResponse()->withStatus(403, 'Access denied');
58-
}
60+
} else {
61+
$response = $this->server->respondToRequest($request);
5962

60-
$response = $this->server->respondToRequest($request);
61-
62-
return $this->WAC->addWACHeaders($request, $response, $webId);
63+
return $this->WAC->addWACHeaders($request, $response, $webId);
64+
}
6365
}
6466

65-
private function generateDefaultAcl() {
66-
$defaultProfile = <<< EOF
67+
////////////////////////////// UTILITY METHODS \\\\\\\\\\\\\\\\\\\\\\\\\\\\\
68+
69+
private function generateDefaultAcl()
70+
{
71+
$defaultProfile = <<< EOF
6772
# Root ACL resource for the user account
6873
@prefix acl: <http://www.w3.org/ns/auth/acl#>.
6974
@prefix foaf: <http://xmlns.com/foaf/0.1/>.
@@ -74,26 +79,26 @@ private function generateDefaultAcl() {
7479
acl:accessTo </>;
7580
acl:default </>;
7681
acl:mode
77-
acl:Read.
82+
acl:Read.
7883
7984
# The owner has full access to every resource in their pod.
8085
# Other agents have no access rights,
8186
# unless specifically authorized in other .acl resources.
8287
<#owner>
83-
a acl:Authorization;
84-
acl:agent <{user-profile-uri}>;
85-
# Set the access to the root storage folder itself
86-
acl:accessTo </>;
87-
# All resources will inherit this authorization, by default
88-
acl:default </>;
89-
# The owner has all of the access modes allowed
90-
acl:mode
91-
acl:Read, acl:Write, acl:Control.
88+
a acl:Authorization;
89+
acl:agent <{user-profile-uri}>;
90+
# Set the access to the root storage folder itself
91+
acl:accessTo </>;
92+
# All resources will inherit this authorization, by default
93+
acl:default </>;
94+
# The owner has all of the access modes allowed
95+
acl:mode
96+
acl:Read, acl:Write, acl:Control.
9297
EOF;
9398

94-
$profileUri = $this->getUserProfile();
95-
$defaultProfile = str_replace("{user-profile-uri}", $profileUri, $defaultProfile);
96-
return $defaultProfile;
99+
$profileUri = $this->getUserProfile();
100+
101+
return str_replace("{user-profile-uri}", $profileUri, $defaultProfile);
97102
}
98103

99104
private function getUserProfile() {

0 commit comments

Comments
 (0)