Skip to content

Commit 45ec694

Browse files
committed
Jet Core
------------ * New feature: MVC_Controller_Router_Action - authorizer
1 parent 03836a1 commit 45ec694

File tree

1 file changed

+27
-11
lines changed

1 file changed

+27
-11
lines changed

library/Jet/MVC/Controller/Router/Action.php

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,26 @@ class MVC_Controller_Router_Action extends BaseObject
2828
* @var string
2929
*/
3030
protected string $module_action = '';
31-
31+
3232
/**
33-
* @var callable|null
33+
* @var null|callable
3434
*/
3535
protected $resolver = null;
36-
3736
/**
38-
* @var callable
37+
* @var null|callable
38+
*/
39+
protected $URI_creator = null;
40+
/**
41+
* @var null|callable
3942
*/
40-
protected $URI_creator;
43+
protected $authorizer = null;
4144

4245
/**
4346
* @param MVC_Controller_Router $router
4447
* @param string $controller_action
4548
* @param string $module_action
4649
*/
47-
public function __construct( MVC_Controller_Router $router, string $controller_action, string $module_action )
50+
public function __construct( MVC_Controller_Router $router, string $controller_action, string $module_action='' )
4851
{
4952
$this->router = $router;
5053
$this->controller_action = $controller_action;
@@ -86,10 +89,6 @@ public function getModuleAction(): string
8689

8790

8891
/**
89-
* Callback prototype:
90-
*
91-
* someCallback( MVC_Controller_Router_Action $action )
92-
*
9392
* Callback return value: bool, true if resolved
9493
*
9594
* @param callable $resolver
@@ -114,7 +113,15 @@ public function setURICreator( callable $URI_creator ): static
114113

115114
return $this;
116115
}
116+
117+
public function setAuthorizer( callable $authorizer ): static
118+
{
119+
$this->authorizer = $authorizer;
120+
121+
return $this;
122+
}
117123

124+
118125

119126
/**
120127
*
@@ -140,10 +147,14 @@ public function resolve(): bool|string
140147
*/
141148
public function URI( ...$arguments ): string|bool
142149
{
150+
if(!$this->URI_creator) {
151+
return false;
152+
}
153+
143154
if( !$this->authorize() ) {
144155
return false;
145156
}
146-
157+
147158
return call_user_func_array( $this->URI_creator, $arguments );
148159
}
149160

@@ -153,6 +164,11 @@ public function URI( ...$arguments ): string|bool
153164
*/
154165
public function authorize(): bool
155166
{
167+
if($this->authorizer) {
168+
$authorizer = $this->authorizer;
169+
170+
return $authorizer();
171+
}
156172

157173
$module_action = $this->getModuleAction();
158174

0 commit comments

Comments
 (0)