Page Menu
Home
GitPull.it
Search
Configure Global Search
Log In
Files
F15178581
Router.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Authored By
Unknown
Size
1 KB
Referenced Files
None
Subscribers
None
Router.php
View Options
<?php
namespace
Wikicaptcha
\
Backend
;
use
Psr
\
Http
\
Message
\
ResponseInterface
;
use
Psr
\
Http
\
Message
\
ServerRequestInterface
;
use
Psr
\
Http
\
Server
\
MiddlewareInterface
;
use
Psr
\
Http
\
Server
\
RequestHandlerInterface
;
use
Zend
\
Diactoros
\
Response
\
JsonResponse
;
class
Router
implements
MiddlewareInterface
{
public
function
process
(
ServerRequestInterface
$request
,
RequestHandlerInterface
$handler
)
:
ResponseInterface
{
$dispatcher
=
\
FastRoute
\
simpleDispatcher
(
function
(
\
FastRoute
\
RouteCollector
$r
)
{
$r
->
get
(
'/'
,
Index
::
class
)
;
$r
->
get
(
'/test'
,
Test
::
class
)
;
$r
->
post
(
'/questions'
,
Questions
::
class
)
;
$r
->
put
(
'/answers'
,
Answers
::
class
)
;
}
)
;
$route
=
$dispatcher
->
dispatch
(
$request
->
getMethod
(
)
,
$request
->
getUri
(
)
->
getPath
(
)
)
;
switch
(
$route
[
0
]
)
{
case
\
FastRoute
\
Dispatcher
::
FOUND
:
/** @var MiddlewareInterface $method */
$method
=
$route
[
1
]
;
$request
=
$request
->
withAttribute
(
'Method'
,
$method
)
;
return
$handler
->
handle
(
$request
)
;
default
:
case
\
FastRoute
\
Dispatcher
::
NOT_FOUND
:
return
new
JsonResponse
(
[
'error'
=>
'Not found'
]
,
404
)
;
case
\
FastRoute
\
Dispatcher
::
METHOD_NOT_ALLOWED
:
return
new
JsonResponse
(
[
'error'
=>
'Method not allowed'
]
,
405
,
[
'Allow'
=>
implode
(
', '
,
$route
[
1
]
)
]
)
;
}
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Thu, Nov 19, 04:32 (19 h, 11 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2264751
Default Alt Text
Router.php (1 KB)
Attached To
Mode
R20 WikiCAPTCHA API RESTful
Attached
Detach File
Event Timeline