Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
U
UserAdminV2
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
庄欣
UserAdminV2
Commits
994949c6
Commit
994949c6
authored
Nov 21, 2011
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactoring various classes.
parent
b0ffc018
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
54 additions
and
29 deletions
+54
-29
.gitignore
+2
-3
laravel/autoloader.php
+2
-2
laravel/laravel.php
+1
-1
laravel/routing/router.php
+19
-6
laravel/session/payload.php
+25
-12
laravel/validator.php
+5
-5
No files found.
.gitignore
View file @
994949c6
favicon.*
favicon.*
.DS_Store
\ No newline at end of file
\ No newline at end of file
laravel/autoloader.php
View file @
994949c6
...
@@ -53,8 +53,8 @@ class Autoloader {
...
@@ -53,8 +53,8 @@ class Autoloader {
protected
static
function
find
(
$class
)
protected
static
function
find
(
$class
)
{
{
// After PHP namespaces were introduced, most libaries ditched underscores for
// After PHP namespaces were introduced, most libaries ditched underscores for
//
namespaces to indicate the class directory hierarchy. We will check for the
//
for namespaces to indicate the class directory hierarchy. We will check for
// presence of namespace slashes to determine the directory separator.
//
the
presence of namespace slashes to determine the directory separator.
$separator
=
(
strpos
(
$class
,
'\\'
)
!==
false
)
?
'\\'
:
'_'
;
$separator
=
(
strpos
(
$class
,
'\\'
)
!==
false
)
?
'\\'
:
'_'
;
$library
=
substr
(
$class
,
0
,
strpos
(
$class
,
$separator
));
$library
=
substr
(
$class
,
0
,
strpos
(
$class
,
$separator
));
...
...
laravel/laravel.php
View file @
994949c6
...
@@ -221,7 +221,7 @@ else
...
@@ -221,7 +221,7 @@ else
*/
*/
if
(
Config
::
$items
[
'session'
][
'driver'
]
!==
''
)
if
(
Config
::
$items
[
'session'
][
'driver'
]
!==
''
)
{
{
IoC
::
core
(
'session'
)
->
save
(
$driver
);
IoC
::
core
(
'session'
)
->
save
();
}
}
$response
->
send
();
$response
->
send
();
laravel/routing/router.php
View file @
994949c6
...
@@ -90,6 +90,9 @@ class Router {
...
@@ -90,6 +90,9 @@ class Router {
{
{
if
(
array_key_exists
(
$name
,
$this
->
names
))
return
$this
->
names
[
$name
];
if
(
array_key_exists
(
$name
,
$this
->
names
))
return
$this
->
names
[
$name
];
// To find a named route, we need to iterate through every route defined
// for the application. We will cache the routes by name so we can load
// them very quickly if we need to find them a second time.
foreach
(
$this
->
loader
->
everything
()
as
$key
=>
$value
)
foreach
(
$this
->
loader
->
everything
()
as
$key
=>
$value
)
{
{
if
(
is_array
(
$value
)
and
isset
(
$value
[
'name'
])
and
$value
[
'name'
]
===
$name
)
if
(
is_array
(
$value
)
and
isset
(
$value
[
'name'
])
and
$value
[
'name'
]
===
$name
)
...
@@ -180,13 +183,16 @@ class Router {
...
@@ -180,13 +183,16 @@ class Router {
if
(
!
is_null
(
$key
=
$this
->
controller_key
(
$segments
)))
if
(
!
is_null
(
$key
=
$this
->
controller_key
(
$segments
)))
{
{
// Extract the controller name from the URI segments.
// Extract the various parts of the controller call from the URI.
// First, we'll extract the controller name, then, since we need
// to extract the method and parameters, we will remove the name
// of the controller from the URI. Then we can shift the method
// off of the array of segments. Any remaining segments are the
// parameters that should be passed to the controller method.
$controller
=
implode
(
'.'
,
array_slice
(
$segments
,
0
,
$key
));
$controller
=
implode
(
'.'
,
array_slice
(
$segments
,
0
,
$key
));
// Remove the controller name from the URI.
$segments
=
array_slice
(
$segments
,
$key
);
$segments
=
array_slice
(
$segments
,
$key
);
// Extract the controller method from the remaining segments.
$method
=
(
count
(
$segments
)
>
0
)
?
array_shift
(
$segments
)
:
'index'
;
$method
=
(
count
(
$segments
)
>
0
)
?
array_shift
(
$segments
)
:
'index'
;
return
new
Route
(
$destination
,
$controller
.
'@'
.
$method
,
$segments
);
return
new
Route
(
$destination
,
$controller
.
'@'
.
$method
,
$segments
);
...
@@ -206,6 +212,9 @@ class Router {
...
@@ -206,6 +212,9 @@ class Router {
*/
*/
protected
function
controller_key
(
$segments
)
protected
function
controller_key
(
$segments
)
{
{
// To find the proper controller, we need to iterate backwards through
// the URI segments and take the first file that matches. That file
// should be the deepest controller matched by the URI.
foreach
(
array_reverse
(
$segments
,
true
)
as
$key
=>
$value
)
foreach
(
array_reverse
(
$segments
,
true
)
as
$key
=>
$value
)
{
{
$controller
=
implode
(
'/'
,
array_slice
(
$segments
,
0
,
$key
+
1
))
.
EXT
;
$controller
=
implode
(
'/'
,
array_slice
(
$segments
,
0
,
$key
+
1
))
.
EXT
;
...
@@ -225,14 +234,14 @@ class Router {
...
@@ -225,14 +234,14 @@ class Router {
*/
*/
protected
function
wildcards
(
$key
)
protected
function
wildcards
(
$key
)
{
{
$
replacements
=
0
;
$
count
=
0
;
// For optional parameters, first translate the wildcards to their
// For optional parameters, first translate the wildcards to their
// regex equivalent, sans the ")?" ending. We will add the endings
// regex equivalent, sans the ")?" ending. We will add the endings
// back on after we know how many replacements we made.
// back on after we know how many replacements we made.
$key
=
str_replace
(
array_keys
(
$this
->
optional
),
array_values
(
$this
->
optional
),
$key
,
$
replacements
);
$key
=
str_replace
(
array_keys
(
$this
->
optional
),
array_values
(
$this
->
optional
),
$key
,
$
count
);
$key
.=
(
$
replacements
>
0
)
?
str_repeat
(
')?'
,
$replacements
)
:
''
;
$key
.=
(
$
count
>
0
)
?
str_repeat
(
')?'
,
$count
)
:
''
;
return
str_replace
(
array_keys
(
$this
->
patterns
),
array_values
(
$this
->
patterns
),
$key
);
return
str_replace
(
array_keys
(
$this
->
patterns
),
array_values
(
$this
->
patterns
),
$key
);
}
}
...
@@ -254,6 +263,10 @@ class Router {
...
@@ -254,6 +263,10 @@ class Router {
$parameters
=
array
();
$parameters
=
array
();
// To find the parameters that should be passed to the route, we will
// iterate through the route segments, and if the segment is enclosed
// in parentheses, we will take the matching segment from the request
// URI and add it to the array of parameters.
for
(
$i
=
0
;
$i
<
$count
;
$i
++
)
for
(
$i
=
0
;
$i
<
$count
;
$i
++
)
{
{
if
(
preg_match
(
'/\(.+\)/'
,
$route
[
$i
])
and
isset
(
$uri
[
$i
]))
if
(
preg_match
(
'/\(.+\)/'
,
$route
[
$i
])
and
isset
(
$uri
[
$i
]))
...
...
laravel/session/payload.php
View file @
994949c6
...
@@ -30,18 +30,32 @@ class Payload {
...
@@ -30,18 +30,32 @@ class Payload {
protected
$exists
=
true
;
protected
$exists
=
true
;
/**
/**
* Start the session handling for the current request.
* The session driver used to retrieve and store the session payload.
*
* @var Driver
*/
protected
$driver
;
/**
* Create a new session payload instance.
*
*
* @param Driver $driver
* @param Driver $driver
* @return void
*/
public
function
__construct
(
Driver
$driver
)
{
$this
->
driver
=
$driver
;
}
/**
* Load the session for the current request.
*
* @param string $id
* @param string $id
* @return void
* @return void
*/
*/
public
function
__construct
(
Driver
$driver
,
$id
)
public
function
load
(
$id
)
{
{
if
(
!
is_null
(
$id
))
if
(
!
is_null
(
$id
))
$this
->
session
=
$this
->
driver
->
load
(
$id
);
{
$this
->
session
=
$driver
->
load
(
$id
);
}
// If the session doesn't exist or is invalid, we will create a new session
// If the session doesn't exist or is invalid, we will create a new session
// array and mark the session as being non-existent. Some drivers, such as
// array and mark the session as being non-existent. Some drivers, such as
...
@@ -64,7 +78,7 @@ class Payload {
...
@@ -64,7 +78,7 @@ class Payload {
if
(
!
$this
->
has
(
'csrf_token'
))
if
(
!
$this
->
has
(
'csrf_token'
))
{
{
$this
->
put
(
'csrf_token'
,
Str
::
random
(
40
));
$this
->
put
(
'csrf_token'
,
Str
::
random
(
40
));
}
}
}
}
/**
/**
...
@@ -236,10 +250,9 @@ class Payload {
...
@@ -236,10 +250,9 @@ class Payload {
/**
/**
* Store the session payload in storage.
* Store the session payload in storage.
*
*
* @param Driver $driver
* @return void
* @return void
*/
*/
public
function
save
(
Driver
$driver
)
public
function
save
()
{
{
$this
->
session
[
'last_activity'
]
=
time
();
$this
->
session
[
'last_activity'
]
=
time
();
...
@@ -247,7 +260,7 @@ class Payload {
...
@@ -247,7 +260,7 @@ class Payload {
$config
=
Config
::
$items
[
'session'
];
$config
=
Config
::
$items
[
'session'
];
$driver
->
save
(
$this
->
session
,
$config
,
$this
->
exists
);
$
this
->
driver
->
save
(
$this
->
session
,
$config
,
$this
->
exists
);
$this
->
cookie
();
$this
->
cookie
();
...
@@ -258,9 +271,9 @@ class Payload {
...
@@ -258,9 +271,9 @@ class Payload {
// occuring is controlled by the "sweepage" configuration option.
// occuring is controlled by the "sweepage" configuration option.
$sweepage
=
$config
[
'sweepage'
];
$sweepage
=
$config
[
'sweepage'
];
if
(
$driver
instanceof
Sweeper
and
(
mt_rand
(
1
,
$sweepage
[
1
])
<=
$sweepage
[
0
]))
if
(
$
this
->
driver
instanceof
Sweeper
and
(
mt_rand
(
1
,
$sweepage
[
1
])
<=
$sweepage
[
0
]))
{
{
$driver
->
sweep
(
time
()
-
(
$config
[
'lifetime'
]
*
60
));
$
this
->
driver
->
sweep
(
time
()
-
(
$config
[
'lifetime'
]
*
60
));
}
}
}
}
...
...
laravel/validator.php
View file @
994949c6
...
@@ -394,7 +394,7 @@ class Validator {
...
@@ -394,7 +394,7 @@ class Validator {
}
}
/**
/**
* Validate tha
t
an attribute is a valid e-mail address.
* Validate tha
n
an attribute is a valid e-mail address.
*
*
* @param string $attribute
* @param string $attribute
* @param mixed $value
* @param mixed $value
...
@@ -406,7 +406,7 @@ class Validator {
...
@@ -406,7 +406,7 @@ class Validator {
}
}
/**
/**
* Validate tha
t
an attribute is a valid URL.
* Validate tha
n
an attribute is a valid URL.
*
*
* @param string $attribute
* @param string $attribute
* @param mixed $value
* @param mixed $value
...
@@ -444,7 +444,7 @@ class Validator {
...
@@ -444,7 +444,7 @@ class Validator {
}
}
/**
/**
* Validate tha
t
an attribute contains only alphabetic characters.
* Validate tha
n
an attribute contains only alphabetic characters.
*
*
* @param string $attribute
* @param string $attribute
* @param mixed $value
* @param mixed $value
...
@@ -456,7 +456,7 @@ class Validator {
...
@@ -456,7 +456,7 @@ class Validator {
}
}
/**
/**
* Validate tha
t
an attribute contains only alpha-numeric characters.
* Validate tha
n
an attribute contains only alpha-numeric characters.
*
*
* @param string $attribute
* @param string $attribute
* @param mixed $value
* @param mixed $value
...
@@ -468,7 +468,7 @@ class Validator {
...
@@ -468,7 +468,7 @@ class Validator {
}
}
/**
/**
* Validate tha
t
an attribute contains only alpha-numeric characters, dashes, and underscores.
* Validate tha
n
an attribute contains only alpha-numeric characters, dashes, and underscores.
*
*
* @param string $attribute
* @param string $attribute
* @param mixed $value
* @param mixed $value
...
...
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