Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Q
question2answer
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
outils
question2answer
Commits
4a64df7a
Commit
4a64df7a
authored
Dec 25, 2017
by
pupi1985
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extract HTTP method to own variable
parent
175a7421
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
1 deletions
+16
-1
Router.php
qa-src/Http/Router.php
+16
-1
No files found.
qa-src/Http/Router.php
View file @
4a64df7a
...
...
@@ -29,6 +29,9 @@ class Router
/** @var array */
private
$paramsConverterValues
;
/** @var string */
private
$httpMethod
;
public
function
__construct
(
$routeData
=
array
())
{
$this
->
routes
=
$routeData
;
...
...
@@ -39,6 +42,8 @@ class Router
);
$this
->
paramsConverterKeys
=
array_keys
(
$paramsConverter
);
$this
->
paramsConverterValues
=
array_values
(
$paramsConverter
);
$this
->
httpMethod
=
strtoupper
(
$_SERVER
[
'REQUEST_METHOD'
]);
}
public
function
addRoute
(
$id
,
$httpMethod
,
$routePath
,
$class
,
$func
)
...
...
@@ -55,7 +60,7 @@ class Router
list
(
$httpMethod
,
$routePath
,
$callClass
,
$callFunc
)
=
$route
;
if
(
strtoupper
(
$httpMethod
)
!==
strtoupper
(
$_SERVER
[
'REQUEST_METHOD'
])
)
{
if
(
strtoupper
(
$httpMethod
)
!==
$this
->
httpMethod
)
{
continue
;
}
...
...
@@ -82,4 +87,14 @@ class Router
{
return
'#^'
.
str_replace
(
$this
->
paramsConverterKeys
,
$this
->
paramsConverterValues
,
$routePath
)
.
'$#'
;
}
/**
* Return the HTTP method of the current request.
*
* @return string
*/
public
function
getHttpMethod
()
{
return
$this
->
httpMethod
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment