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
df9130da
Commit
df9130da
authored
Oct 19, 2011
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactoring and working on redis.
parent
ba29a0bd
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
226 additions
and
49 deletions
+226
-49
laravel/bootstrap/constants.php
+12
-14
laravel/bootstrap/errors.php
+14
-3
laravel/cache/drivers/memcached.php
+1
-1
laravel/database/grammars/grammar.php
+16
-4
laravel/database/manager.php
+1
-1
laravel/redis.php
+156
-0
laravel/security/crypter.php
+21
-19
laravel/session/manager.php
+5
-7
No files found.
laravel/bootstrap/constants.php
View file @
df9130da
<?php
<?php
/**
* Define the extensions used by the framework.
*/
define
(
'EXT'
,
'.php'
);
define
(
'BLADE_EXT'
,
'.blade.php'
);
define
(
'BLADE_EXT'
,
'.blade.php'
);
define
(
'CRLF'
,
chr
(
13
)
.
chr
(
10
));
define
(
'EXT'
,
'.php'
);
/**
/**
* Define a function that registers an array of constants
* Define a function that registers an array of constants if they
* if they haven't already been registered. This allows the
* haven't already been registered. This allows the constants to
* constants to be changed from their default values when
* be changed from their default values when unit testing.
* unit testing the framework.
*/
*/
function
constants
(
$constants
)
function
constants
(
$constants
)
{
{
...
@@ -21,9 +18,9 @@ function constants($constants)
...
@@ -21,9 +18,9 @@ function constants($constants)
}
}
/**
/**
* Register the core framework paths. All other paths are
* Register the core framework paths. All other paths are
built on
*
built on top of these core paths. All of these paths are
*
top of these core paths. All of these paths are changable by
*
changable by
the developer in the front controller.
* the developer in the front controller.
*/
*/
$constants
=
array
(
$constants
=
array
(
'APP_PATH'
=>
realpath
(
$application
)
.
'/'
,
'APP_PATH'
=>
realpath
(
$application
)
.
'/'
,
...
@@ -37,8 +34,9 @@ $constants = array(
...
@@ -37,8 +34,9 @@ $constants = array(
constants
(
$constants
);
constants
(
$constants
);
/**
/**
* Register all of the other framework paths. All of these
* Register all of the other framework paths. All of these paths
* paths are built on top of the core paths above.
* are built on top of the core paths above. We still allow the
* developer to override these for easy unit testing.
*/
*/
$constants
=
array
(
$constants
=
array
(
'CACHE_PATH'
=>
STORAGE_PATH
.
'cache/'
,
'CACHE_PATH'
=>
STORAGE_PATH
.
'cache/'
,
...
@@ -63,7 +61,7 @@ unset($constants);
...
@@ -63,7 +61,7 @@ unset($constants);
/**
/**
* Set the Laravel environment configuration path constant.
* Set the Laravel environment configuration path constant.
* The environment is controlle
r
by setting an environment
* The environment is controlle
d
by setting an environment
* variable on the server running Laravel.
* variable on the server running Laravel.
*/
*/
$environment
=
(
isset
(
$_SERVER
[
'LARAVEL_ENV'
]))
?
$_SERVER
[
'LARAVEL_ENV'
]
:
''
;
$environment
=
(
isset
(
$_SERVER
[
'LARAVEL_ENV'
]))
?
$_SERVER
[
'LARAVEL_ENV'
]
:
''
;
...
...
laravel/bootstrap/errors.php
View file @
df9130da
...
@@ -59,20 +59,31 @@ $handler = function($e) use ($message, $severity)
...
@@ -59,20 +59,31 @@ $handler = function($e) use ($message, $severity)
};
};
/**
/**
* Register the PHP exception
, error, and shutdown error handlers.
* Register the PHP exception
handler. The framework throws exceptions
*
These handlers will catch all PHP exceptions and errors and pass
*
on every error that cannot be handled. All of those exceptions will
*
the exceptions into the common Laravel error handler
.
*
fall into this closure for processing
.
*/
*/
set_exception_handler
(
function
(
$e
)
use
(
$handler
)
set_exception_handler
(
function
(
$e
)
use
(
$handler
)
{
{
$handler
(
$e
);
$handler
(
$e
);
});
});
/**
* Register the PHP error handler. All PHP errors will fall into this
* handler, which will convert the error into an ErrorException object
* and pass the exception into the common exception handler.
*/
set_error_handler
(
function
(
$number
,
$error
,
$file
,
$line
)
use
(
$handler
)
set_error_handler
(
function
(
$number
,
$error
,
$file
,
$line
)
use
(
$handler
)
{
{
$handler
(
new
\ErrorException
(
$error
,
$number
,
0
,
$file
,
$line
));
$handler
(
new
\ErrorException
(
$error
,
$number
,
0
,
$file
,
$line
));
});
});
/**
* Register the PHP shutdown handler. This function will be called at
* the end of the PHP script or on a fatal PHP error. If an error has
* occurred, we will convert it to an ErrorException and pass it to
* the common exception handler.
*/
register_shutdown_function
(
function
()
use
(
$handler
)
register_shutdown_function
(
function
()
use
(
$handler
)
{
{
if
(
!
is_null
(
$error
=
error_get_last
()))
if
(
!
is_null
(
$error
=
error_get_last
()))
...
...
laravel/cache/drivers/memcached.php
View file @
df9130da
<?php
namespace
Laravel\Cache\Drivers
;
use
Memcache
,
Laravel\Config
;
<?php
namespace
Laravel\Cache\Drivers
;
use
Memcache
;
class
Memcached
extends
Driver
{
class
Memcached
extends
Driver
{
...
...
laravel/database/grammars/grammar.php
View file @
df9130da
...
@@ -22,7 +22,16 @@ class Grammar {
...
@@ -22,7 +22,16 @@ class Grammar {
*
*
* @var array
* @var array
*/
*/
protected
$components
=
array
(
'aggregate'
,
'selects'
,
'from'
,
'joins'
,
'wheres'
,
'orderings'
,
'limit'
,
'offset'
);
protected
$components
=
array
(
'aggregate'
,
'selects'
,
'from'
,
'joins'
,
'wheres'
,
'orderings'
,
'limit'
,
'offset'
);
/**
/**
* Compile a SQL SELECT statement from a Query instance.
* Compile a SQL SELECT statement from a Query instance.
...
@@ -272,9 +281,12 @@ class Grammar {
...
@@ -272,9 +281,12 @@ class Grammar {
// every insert to the table.
// every insert to the table.
$columns
=
$this
->
columnize
(
array_keys
(
reset
(
$values
)));
$columns
=
$this
->
columnize
(
array_keys
(
reset
(
$values
)));
// We need to create a string of comma-delimited insert segments. Each segment
// Build the list of parameter place-holders for the array of values bound
// contains PDO place-holders for each value being inserted into the table.
// to the query. Each insert statement should have the same number of bound
$parameters
=
implode
(
', '
,
array_fill
(
0
,
count
(
$values
),
'('
.
$this
->
parameterize
(
reset
(
$values
))
.
')'
));
// parameters, so we can just use the first array of values.
$parameters
=
$this
->
parameterize
(
reset
(
$values
));
$parameters
=
implode
(
', '
,
array_fill
(
0
,
count
(
$values
),
'('
.
$parameters
.
')'
));
return
'INSERT INTO '
.
$this
->
wrap
(
$query
->
from
)
.
' ('
.
$columns
.
') VALUES '
.
$parameters
;
return
'INSERT INTO '
.
$this
->
wrap
(
$query
->
from
)
.
' ('
.
$columns
.
') VALUES '
.
$parameters
;
}
}
...
...
laravel/database/manager.php
View file @
df9130da
...
@@ -40,7 +40,7 @@ class Manager {
...
@@ -40,7 +40,7 @@ class Manager {
if
(
is_null
(
$config
))
if
(
is_null
(
$config
))
{
{
throw
new
\Exception
(
"Database connection
configuration
is not defined for connection [
$connection
]."
);
throw
new
\Exception
(
"Database connection is not defined for connection [
$connection
]."
);
}
}
static
::
$connections
[
$connection
]
=
new
Connection
(
static
::
connect
(
$config
),
$config
);
static
::
$connections
[
$connection
]
=
new
Connection
(
static
::
connect
(
$config
),
$config
);
...
...
laravel/redis.php
0 → 100644
View file @
df9130da
<?php
namespace
Laravel
;
class
Redis
{
/**
* The active Redis connections.
*
* @var array
*/
protected
static
$connections
=
array
();
/**
* The name of the Redis connection.
*
* @var string
*/
public
$name
;
/**
* The configuration array for the Redis connection.
*
* @var array
*/
public
$config
=
array
();
/**
* The connection to the Redis database.
*
* @var resource
*/
protected
$connection
;
/**
* Create a new Redis connection instance.
*
* @param string $name
* @param array $config
* @return void
*/
public
function
__construct
(
$name
,
$config
)
{
$this
->
name
=
$name
;
$this
->
config
=
$config
;
}
/**
* Create a new Redis connection instance.
*
* @param string $connection
* @param array $config
* @return Redis
*/
public
static
function
make
(
$name
,
$config
)
{
return
new
static
(
$name
,
$config
);
}
/**
* Create a new Redis connection instance.
*
* Redis connections are managed as singletons, so if the connection has
* already been established, that same connection instance will be returned
* on subsequent requests for the connection.
*
* @param string $connection
* @return Redis
*/
public
static
function
connection
(
$name
)
{
if
(
!
array_key_exists
(
$name
,
static
::
$connections
))
{
$config
=
Config
::
get
(
"database.redis.
{
$name
}
"
);
if
(
is_null
(
$config
))
{
throw
new
\Exception
(
"Redis connection [
$name
] has not been configured."
);
}
static
::
$connections
[
$name
]
=
static
::
make
(
$name
,
$config
)
->
connect
();
}
return
static
::
$connections
[
$name
];
}
/**
* Connect to the Redis database.
*
* The Redis instance itself will be returned by the method.
*
* @return Redis
*/
public
function
connect
()
{
$this
->
connection
=
@
fsockopen
(
$this
->
config
[
'host'
],
$this
->
config
[
'port'
],
$error
,
$message
);
if
(
$this
->
connection
===
false
)
{
throw
new
\Exception
(
"Error establishing Redis connection [
{
$this
->
name
}
]:
{
$error
}
-
{
$message
}
"
);
}
return
$this
;
}
/**
* Execute a command agaisnt the Redis database.
*
* @param string $method
* @param array $parameters
* @return mixed
*/
public
function
do
(
$method
,
$parameters
)
{
fwrite
(
$this
->
connection
,
$this
->
command
(
$method
,
$parameters
));
$reply
=
trim
(
fgets
(
$this
->
connection
,
512
));
}
/**
* Build the Redis command based from a given method and parameters.
*
* @param string $method
* @param array $parameters
* @return string
*/
protected
function
command
(
$method
,
$parameters
)
{
$command
=
'*'
.
(
count
(
$parameters
)
+
1
)
.
CRLF
.
'$'
.
strlen
(
$method
)
.
CRLF
.
strtoupper
(
$method
)
.
CRLF
;
foreach
(
$parameters
as
$parameter
)
{
$command
.=
'$'
.
strlen
(
$parameter
)
.
CRLF
.
$parameter
.
CRLF
;
}
return
$command
;
}
/**
* Dynamically make calls to the Redis database.
*/
public
function
__call
(
$method
,
$parameters
)
{
return
$this
->
do
(
$method
,
$parameters
);
}
/**
* Close the connection to the Redis database.
*
* @return void
*/
public
function
__destruct
()
{
fclose
(
$this
->
connection
);
}
}
\ No newline at end of file
laravel/security/crypter.php
View file @
df9130da
...
@@ -54,52 +54,43 @@ class Crypter {
...
@@ -54,52 +54,43 @@ class Crypter {
$iv
=
mcrypt_create_iv
(
static
::
iv_size
(),
$randomizer
);
$iv
=
mcrypt_create_iv
(
static
::
iv_size
(),
$randomizer
);
$key
=
Config
::
$items
[
'application'
][
'key'
];
return
base64_encode
(
$iv
.
mcrypt_encrypt
(
static
::
$cipher
,
static
::
key
(),
$value
,
static
::
$mode
,
$iv
));
return
base64_encode
(
$iv
.
mcrypt_encrypt
(
static
::
$cipher
,
$key
,
$value
,
static
::
$mode
,
$iv
));
}
}
/**
/**
* Decrypt a string using Mcrypt.
* Decrypt a string using Mcrypt.
*
*
* <code>
* // Decrypt a string using the Mcrypt PHP extension
* $decrypted = Crypter::decrypt($secret);
* </code>
*
* @param string $value
* @param string $value
* @return string
* @return string
*/
*/
public
static
function
decrypt
(
$value
)
public
static
function
decrypt
(
$value
)
{
{
if
(
!
is_string
(
$value
=
base64_decode
(
$value
,
true
)))
list
(
$iv
,
$value
)
=
static
::
parse
(
base64_decode
(
$value
,
true
));
{
throw
new
\Exception
(
'Decryption error. Input value is not valid base64 data.'
);
}
list
(
$iv
,
$value
)
=
static
::
parse
(
$value
);
$key
=
Config
::
$items
[
'application'
][
'key'
];
return
rtrim
(
mcrypt_decrypt
(
static
::
$cipher
,
$key
,
$value
,
static
::
$mode
,
$iv
),
"
\0
"
);
return
rtrim
(
mcrypt_decrypt
(
static
::
$cipher
,
static
::
key
()
,
$value
,
static
::
$mode
,
$iv
),
"
\0
"
);
}
}
/**
/**
* Parse an encrypted value into the input vector and the actual value.
* Parse an encrypted value into the input vector and the actual value.
*
*
* If the given value is not valid base64 data, an exception will be thrown.
*
* @param string $value
* @param string $value
* @return array
* @return array
*/
*/
protected
static
function
parse
(
$value
)
protected
static
function
parse
(
$value
)
{
{
if
(
!
is_string
(
$value
))
{
throw
new
\Exception
(
'Decryption error. Input value is not valid base64 data.'
);
}
return
array
(
substr
(
$value
,
0
,
static
::
iv_size
()),
substr
(
$value
,
static
::
iv_size
()));
return
array
(
substr
(
$value
,
0
,
static
::
iv_size
()),
substr
(
$value
,
static
::
iv_size
()));
}
}
/**
/**
* Get the input vector size for the cipher and mode.
* Get the input vector size for the cipher and mode.
*
*
* Different ciphers and modes use varying lengths of input vectors.
*
* @return int
* @return int
*/
*/
protected
static
function
iv_size
()
protected
static
function
iv_size
()
...
@@ -107,4 +98,14 @@ class Crypter {
...
@@ -107,4 +98,14 @@ class Crypter {
return
mcrypt_get_iv_size
(
static
::
$cipher
,
static
::
$mode
);
return
mcrypt_get_iv_size
(
static
::
$cipher
,
static
::
$mode
);
}
}
/**
* Get the encryption key from the application configuration.
*
* @return string
*/
protected
static
function
key
()
{
return
Config
::
$items
[
'application'
][
'key'
];
}
}
}
\ No newline at end of file
laravel/session/manager.php
View file @
df9130da
...
@@ -67,15 +67,13 @@ class Manager {
...
@@ -67,15 +67,13 @@ class Manager {
$session
=
array
(
'id'
=>
Str
::
random
(
40
),
'data'
=>
array
());
$session
=
array
(
'id'
=>
Str
::
random
(
40
),
'data'
=>
array
());
}
}
// Now that we should have a valid session, we can set the static session
// property and check for session data such as the CSRF token. We will
// also set the static driver and transporter properties, since they
// will be used to close the session at the end of the request.
static
::
$session
=
$session
;
static
::
$session
=
$session
;
// If a CSRF token is not present in the session, we will generate one.
if
(
!
static
::
has
(
'csrf_token'
))
static
::
put
(
'csrf_token'
,
Str
::
random
(
16
));
// These tokens are generated per session to protect against Cross-Site
// Request Forgery attacks on the application.
if
(
!
static
::
has
(
'csrf_token'
))
{
static
::
put
(
'csrf_token'
,
Str
::
random
(
16
));
}
list
(
static
::
$driver
,
static
::
$transporter
)
=
array
(
$driver
,
$transporter
);
list
(
static
::
$driver
,
static
::
$transporter
)
=
array
(
$driver
,
$transporter
);
}
}
...
...
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