Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
syncEnrollments
Project
Project
Details
Activity
Releases
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
Yeray Santana Hualde
syncEnrollments
Commits
4342f82a
Commit
4342f82a
authored
Oct 13, 2011
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactoring cache and session classes.
parent
9f7ed576
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
66 additions
and
31 deletions
+66
-31
apc.php
laravel/cache/drivers/apc.php
+6
-1
file.php
laravel/cache/drivers/file.php
+11
-6
memcached.php
laravel/cache/drivers/memcached.php
+7
-2
manager.php
laravel/cache/manager.php
+1
-3
proxy.php
laravel/proxy.php
+21
-0
manager.php
laravel/session/manager.php
+16
-12
payload.php
laravel/session/payload.php
+4
-7
No files found.
laravel/cache/drivers/apc.php
View file @
4342f82a
...
@@ -7,7 +7,7 @@ class APC extends Driver {
...
@@ -7,7 +7,7 @@ class APC extends Driver {
*
*
* @var string
* @var string
*/
*/
pr
ivate
$key
;
pr
otected
$key
;
/**
/**
* Create a new APC cache driver instance.
* Create a new APC cache driver instance.
...
@@ -45,6 +45,11 @@ class APC extends Driver {
...
@@ -45,6 +45,11 @@ class APC extends Driver {
/**
/**
* Write an item to the cache for a given number of minutes.
* Write an item to the cache for a given number of minutes.
*
*
* <code>
* // Put an item in the cache for 15 minutes
* Cache::put('name', 'Taylor', 15);
* </code>
*
* @param string $key
* @param string $key
* @param mixed $value
* @param mixed $value
* @param int $minutes
* @param int $minutes
...
...
laravel/cache/drivers/file.php
View file @
4342f82a
<?php
namespace
Laravel\Cache\Drivers
;
use
Laravel\File
as
F
;
<?php
namespace
Laravel\Cache\Drivers
;
class
File
extends
Driver
{
class
File
extends
Driver
{
...
@@ -7,7 +7,7 @@ class File extends Driver {
...
@@ -7,7 +7,7 @@ class File extends Driver {
*
*
* @var string
* @var string
*/
*/
pr
ivate
$path
;
pr
otected
$path
;
/**
/**
* Create a new File cache driver instance.
* Create a new File cache driver instance.
...
@@ -39,9 +39,9 @@ class File extends Driver {
...
@@ -39,9 +39,9 @@ class File extends Driver {
*/
*/
protected
function
retrieve
(
$key
)
protected
function
retrieve
(
$key
)
{
{
if
(
!
F
::
exists
(
$this
->
path
.
$key
))
return
null
;
if
(
!
\Laravel\File
::
exists
(
$this
->
path
.
$key
))
return
null
;
if
(
time
()
>=
substr
(
$cache
=
F
::
get
(
$this
->
path
.
$key
),
0
,
10
))
if
(
time
()
>=
substr
(
$cache
=
\Laravel\File
::
get
(
$this
->
path
.
$key
),
0
,
10
))
{
{
return
$this
->
forget
(
$key
);
return
$this
->
forget
(
$key
);
}
}
...
@@ -52,6 +52,11 @@ class File extends Driver {
...
@@ -52,6 +52,11 @@ class File extends Driver {
/**
/**
* Write an item to the cache for a given number of minutes.
* Write an item to the cache for a given number of minutes.
*
*
* <code>
* // Put an item in the cache for 15 minutes
* Cache::put('name', 'Taylor', 15);
* </code>
*
* @param string $key
* @param string $key
* @param mixed $value
* @param mixed $value
* @param int $minutes
* @param int $minutes
...
@@ -59,7 +64,7 @@ class File extends Driver {
...
@@ -59,7 +64,7 @@ class File extends Driver {
*/
*/
public
function
put
(
$key
,
$value
,
$minutes
)
public
function
put
(
$key
,
$value
,
$minutes
)
{
{
F
::
put
(
$this
->
path
.
$key
,
(
time
()
+
(
$minutes
*
60
))
.
serialize
(
$value
));
\Laravel\File
::
put
(
$this
->
path
.
$key
,
(
time
()
+
(
$minutes
*
60
))
.
serialize
(
$value
));
}
}
/**
/**
...
@@ -70,7 +75,7 @@ class File extends Driver {
...
@@ -70,7 +75,7 @@ class File extends Driver {
*/
*/
public
function
forget
(
$key
)
public
function
forget
(
$key
)
{
{
F
::
delete
(
$this
->
path
.
$key
);
\Laravel\File
::
delete
(
$this
->
path
.
$key
);
}
}
}
}
\ No newline at end of file
laravel/cache/drivers/memcached.php
View file @
4342f82a
...
@@ -7,14 +7,14 @@ class Memcached extends Driver {
...
@@ -7,14 +7,14 @@ class Memcached extends Driver {
*
*
* @var Memcache
* @var Memcache
*/
*/
pr
ivate
$memcache
;
pr
otected
$memcache
;
/**
/**
* The cache key from the cache configuration file.
* The cache key from the cache configuration file.
*
*
* @var string
* @var string
*/
*/
pr
ivate
$key
;
pr
otected
$key
;
/**
/**
* Create a new Memcached cache driver instance.
* Create a new Memcached cache driver instance.
...
@@ -53,6 +53,11 @@ class Memcached extends Driver {
...
@@ -53,6 +53,11 @@ class Memcached extends Driver {
/**
/**
* Write an item to the cache for a given number of minutes.
* Write an item to the cache for a given number of minutes.
*
*
* <code>
* // Put an item in the cache for 15 minutes
* Cache::put('name', 'Taylor', 15);
* </code>
*
* @param string $key
* @param string $key
* @param mixed $value
* @param mixed $value
* @param int $minutes
* @param int $minutes
...
...
laravel/cache/manager.php
View file @
4342f82a
<?php
namespace
Laravel\Cache
;
<?php
namespace
Laravel\Cache
;
use
Laravel\IoC
;
use
Laravel\IoC
;
class
Manager
{
class
Manager
{
...
...
laravel/proxy.php
0 → 100644
View file @
4342f82a
<?php
namespace
Laravel
;
/**
* The Proxy class, like the File class, is primarily intended to get rid of
* the testability problems introduced by PHP's global functions.
*
* For instance, the APC cache driver calls the APC global functions. Instead of
* calling those functions directory in the driver, we inject a Proxy instance into
* the class, which allows us to stub the global functions.
*/
class
Proxy
{
/**
* Magic Method for calling any global function.
*/
public
function
__call
(
$method
,
$parameters
)
{
return
call_user_func_array
(
$method
,
$parameters
);
}
}
\ No newline at end of file
laravel/session/manager.php
View file @
4342f82a
...
@@ -58,9 +58,10 @@ class Manager {
...
@@ -58,9 +58,10 @@ class Manager {
{
{
$session
=
$this
->
driver
->
load
(
$this
->
transporter
->
get
(
$config
));
$session
=
$this
->
driver
->
load
(
$this
->
transporter
->
get
(
$config
));
// If the session is expired, a new session will be generated and all of the data from
// If the session is expired, a new session will be generated and all of
// the previous session will be lost. The new session will be assigned a random, long
// the data from the previous session will be lost. The new session will
// string ID to uniquely identify it among the application's current users.
// be assigned a random, long string ID to uniquely identify it among
// the application's current users.
if
(
is_null
(
$session
)
or
(
time
()
-
$session
[
'last_activity'
])
>
(
$config
[
'lifetime'
]
*
60
))
if
(
is_null
(
$session
)
or
(
time
()
-
$session
[
'last_activity'
])
>
(
$config
[
'lifetime'
]
*
60
))
{
{
$this
->
exists
=
false
;
$this
->
exists
=
false
;
...
@@ -70,10 +71,11 @@ class Manager {
...
@@ -70,10 +71,11 @@ class Manager {
$payload
=
new
Payload
(
$session
);
$payload
=
new
Payload
(
$session
);
// If a CSRF token is not present in the session, we will generate one. These tokens
// If a CSRF token is not present in the session, we will generate one.
// are generated per session to protect against Cross-Site Request Forgery attacks on
// These tokens are generated per session to protect against Cross-Site
// the application. It is up to the developer to take advantage of them using the token
// Request Forgery attacks on the application. It is up to the developer
// methods on the Form class and the "csrf" route filter.
// to take advantage of them using the token methods on the Form class
// and the "csrf" route filter.
if
(
!
$payload
->
has
(
'csrf_token'
))
if
(
!
$payload
->
has
(
'csrf_token'
))
{
{
$payload
->
put
(
'csrf_token'
,
Str
::
random
(
16
));
$payload
->
put
(
'csrf_token'
,
Str
::
random
(
16
));
...
@@ -92,8 +94,9 @@ class Manager {
...
@@ -92,8 +94,9 @@ class Manager {
*/
*/
public
function
close
(
Payload
$payload
,
$config
,
$flash
=
array
())
public
function
close
(
Payload
$payload
,
$config
,
$flash
=
array
())
{
{
// If the session ID has been regenerated, we will need to inform the session driver
// If the session ID has been regenerated, we will need to inform the
// that the session will need to be persisted to the data store as a new session.
// session driver that the session will need to be persisted to the
// data store as a new session.
if
(
$payload
->
regenerated
)
$this
->
exists
=
false
;
if
(
$payload
->
regenerated
)
$this
->
exists
=
false
;
foreach
(
$flash
as
$key
=>
$value
)
foreach
(
$flash
as
$key
=>
$value
)
...
@@ -105,9 +108,10 @@ class Manager {
...
@@ -105,9 +108,10 @@ class Manager {
$this
->
transporter
->
put
(
$payload
->
session
[
'id'
],
$config
);
$this
->
transporter
->
put
(
$payload
->
session
[
'id'
],
$config
);
// Some session drivers implement the Sweeper interface, which specified that the driver
// Some session drivers may implement the Sweeper interface, meaning the
// must do its garbage collection manually. Alternatively, some drivers such as APC and
// driver must do its garbage collection manually. Alternatively, some
// Memcached are not required to manually clean up their sessions.
// drivers such as APC and Memcached are not required to manually
// clean up their sessions.
if
(
mt_rand
(
1
,
$config
[
'sweepage'
][
1
])
<=
$config
[
'sweepage'
][
0
]
and
$this
->
driver
instanceof
Drivers\Sweeper
)
if
(
mt_rand
(
1
,
$config
[
'sweepage'
][
1
])
<=
$config
[
'sweepage'
][
0
]
and
$this
->
driver
instanceof
Drivers\Sweeper
)
{
{
$this
->
driver
->
sweep
(
time
()
-
(
$config
[
'lifetime'
]
*
60
));
$this
->
driver
->
sweep
(
time
()
-
(
$config
[
'lifetime'
]
*
60
));
...
...
laravel/session/payload.php
View file @
4342f82a
<?php
namespace
Laravel\Session
;
<?php
namespace
Laravel\Session
;
use
Closure
,
Laravel\Str
;
use
Closure
;
use
Laravel\Str
;
class
Payload
{
class
Payload
{
...
@@ -119,7 +116,7 @@ class Payload {
...
@@ -119,7 +116,7 @@ class Payload {
*/
*/
public
function
reflash
()
public
function
reflash
()
{
{
$this
->
re
address
(
':old:'
,
':new:'
,
array_keys
(
$this
->
session
[
'data'
]));
$this
->
re
place
(
':old:'
,
':new:'
,
array_keys
(
$this
->
session
[
'data'
]));
}
}
/**
/**
...
@@ -197,7 +194,7 @@ class Payload {
...
@@ -197,7 +194,7 @@ class Payload {
if
(
strpos
(
$key
,
':old:'
)
===
0
)
$this
->
forget
(
$key
);
if
(
strpos
(
$key
,
':old:'
)
===
0
)
$this
->
forget
(
$key
);
}
}
$this
->
re
address
(
':new:'
,
':old:'
,
array_keys
(
$this
->
session
[
'data'
]));
$this
->
re
place
(
':new:'
,
':old:'
,
array_keys
(
$this
->
session
[
'data'
]));
return
$this
->
session
;
return
$this
->
session
;
}
}
...
@@ -210,7 +207,7 @@ class Payload {
...
@@ -210,7 +207,7 @@ class Payload {
* @param array $keys
* @param array $keys
* @return void
* @return void
*/
*/
private
function
re
address
(
$search
,
$replace
,
$keys
)
private
function
re
place
(
$search
,
$replace
,
$keys
)
{
{
$this
->
session
[
'data'
]
=
array_combine
(
str_replace
(
$search
,
$replace
,
$keys
),
array_values
(
$this
->
session
[
'data'
]));
$this
->
session
[
'data'
]
=
array_combine
(
str_replace
(
$search
,
$replace
,
$keys
),
array_values
(
$this
->
session
[
'data'
]));
}
}
...
...
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