Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
ldy
/
phwoolcon
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 40ea2ef9
authored
Nov 22, 2020
by
yeran
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update router
1 parent
4a38fd80
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
2 deletions
composer.json
src/Router.php
composer.json
View file @
40ea2ef
...
...
@@ -3,7 +3,7 @@
"description"
:
"Phalcon"
,
"keywords"
:
[
"phwoolcon"
],
"type"
:
"library"
,
"version"
:
"1.0.
5
"
,
"version"
:
"1.0.
6
"
,
"license"
:
"proprietary"
,
"authors"
:
[
{
...
...
@@ -24,7 +24,8 @@
"ext-mbstring"
:
"*"
,
"symfony/console"
:
"~3.0"
,
"pda/pheanstalk"
:
"~3.1"
,
"swiftmailer/swiftmailer"
:
"~5.4|~6.0"
"swiftmailer/swiftmailer"
:
"~5.4|~6.0"
,
"opis/closure"
:
"3.0.1"
},
"require-dev"
:
{
},
...
...
src/Router.php
View file @
40ea2ef
...
...
@@ -13,6 +13,7 @@ use Phwoolcon\Exception\Http\ApiException;
use
Phwoolcon\Exception\Http\CsrfException
;
use
Phwoolcon\Exception\Http\NotFoundException
;
use
Phwoolcon\Exception\HttpException
;
use
Opis\Closure\SerializableClosure
;
/**
* Class Router
...
...
@@ -91,6 +92,46 @@ class Router extends PhalconRouter implements ServiceAwareInterface
$this
->
response
->
setStatusCode
(
200
);
}
public
function
addRoutes
(
array
$routes
)
{
foreach
(
$routes
as
$route
)
{
if
(
!
$route
[
2
]
instanceof
Closure
)
{
$pattern
=
$route
[
1
];
$paths
=
$route
[
2
];
$method
=
$route
[
0
];
$filter
=
empty
(
$route
[
3
])
?
null
:
$route
[
3
];
$this
->
quickAdd
(
$pattern
,
$paths
,
$method
,
$filter
);
}
else
{
$pattern
=
$route
[
1
];
$function
=
$route
[
2
];
$method
=
$route
[
0
];
$filter
=
empty
(
$route
[
3
])
?
null
:
$route
[
3
];
$this
->
CquickAdd
(
$pattern
,
$function
,
$method
,
$filter
);
}
}
}
public
function
quickAdd
(
$pattern
,
$paths
,
$method
,
$filter
=
null
)
{
$method
==
'ANY'
and
$method
=
null
;
$method
==
'GET'
and
$method
=
[
'GET'
,
'HEAD'
];
$route
=
$this
->
add
(
$pattern
,
$paths
,
$method
);
is_callable
(
$filter
)
or
$filter
=
null
;
$filter
and
$route
->
beforeMatch
(
$filter
);
return
$route
;
}
public
function
CquickAdd
(
$pattern
,
$function
,
$method
,
$filter
=
null
)
{
$method
==
'ANY'
and
$method
=
null
;
$method
==
'GET'
and
$method
=
[
'GET'
,
'HEAD'
];
$handler
[
'controller'
]
=
new
SerializableClosure
(
$function
);
$route
=
$this
->
add
(
$pattern
,
$handler
,
$method
);
is_callable
(
$filter
)
or
$filter
=
null
;
$filter
and
$route
->
beforeMatch
(
$filter
);
return
$route
;
}
public
static
function
checkCsrfToken
()
{
...
...
Write
Preview
Markdown
is supported
Attach a file
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 post a comment