-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
handle pre- and post-routing
- Loading branch information
1 parent
d64460d
commit 80ea3ee
Showing
5 changed files
with
248 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
|
||
namespace Frame\Tests\Controllers; | ||
|
||
use Frame\Core\Controller; | ||
use Frame\Core\Url; | ||
use Frame\Core\Context; | ||
use Frame\Request\RouteParams; | ||
|
||
class Auth extends Controller | ||
{ | ||
|
||
/** | ||
* @before authUser | ||
*/ | ||
public function routeAllowed() | ||
{ | ||
|
||
return "routeAuthOkay"; | ||
|
||
} | ||
|
||
/** | ||
* @before authUser | ||
*/ | ||
public function routeNotAllowed() | ||
{ | ||
|
||
return "routeAuthShouldNotSeeThis"; | ||
|
||
} | ||
|
||
/** | ||
* @before authUser | ||
*/ | ||
public function routeNotAllowedOutside() | ||
{ | ||
|
||
return "routeAuthShouldNotSeeThis"; | ||
|
||
} | ||
|
||
public function routeNotAuthorized() | ||
{ | ||
|
||
return "routeNotAuthorized"; | ||
|
||
} | ||
|
||
/** | ||
* Authorizes the user | ||
*/ | ||
public function authUser(Url $url, Context $context) | ||
{ | ||
|
||
// One method: | ||
switch($url->getRequestUri()) { | ||
case '/auth/notallowed': | ||
return 'routeNotAuthorized'; | ||
} | ||
|
||
// Another method: | ||
switch($context->getCaller()->getMethod()) { | ||
case 'routeNotallowedoutside': // Note case change! | ||
return 'Index::routeNotAuthorized'; | ||
} | ||
|
||
// No response allows the rest through | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -224,4 +224,11 @@ public function routeProducts() | |
|
||
} | ||
|
||
public function routeNotAuthorized() | ||
{ | ||
|
||
echo 'routeIndexNotAuthorized'; | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters