Gumbo PHP Library API Documentation
Session
[
class tree
] [
index
] [
all elements
]
Todo List
Packages:
Buffer
Collection
Composite
Config
Converter
Curl
Date
DB
Debug
Encryption
Error
Factory
Filter
Flyweight
Http
Input
Iterator
List
Load
Lockable
Log
Map
Number
Observer
Output
Query
Record
Router
Session
Setting
Singleton
Template
Timer
Utility
Valid
Source for file Encrypt.class.php
Documentation is available at
Encrypt.class.php
<?php
/**
* Gumbo Library Framework
*
* LICENSE
* This library is being released under the terms of the New BSD License. A
* copy of the license is packaged with the software (LICENSE.txt). If no
* copy is found, a copy of the license template can be found at:
* http://www.opensource.org/licenses/bsd-license.php
*
*
@category
Gumbo
*
@package
Session
*
@copyright
Copyright (c) 2007, iBayou, Michael Luster
*
@license
http://www.opensource.org/licenses/bsd-license.php New BSD License
*
@author
Michael Luster <mluster79@yahoo.com>
*
@link
http://sourceforge.net/projects/phpgumbo
*
@version
0.0.1
*/
/**
* Encrypted Session Class
*
*
@category
Gumbo
*
@package
Session
*
@copyright
Copyright (c) 2007, iBayou, Michael Luster
*
@license
http://www.opensource.org/licenses/bsd-license.php New BSD License
*
@author
Michael Luster <mluster79@yahoo.com>
*
@link
http://sourceforge.net/projects/phpgumbo
*
@desc
Encrypted Session Class
*
@version
0.0.1
*/
gumbo_load
(
"Interface_Session_Encrypt"
)
;
gumbo_load
(
"Session_Basic"
)
;
gumbo_load
(
"Encrypt"
)
;
gumbo_load
(
"Decrypt"
)
;
class
Gumbo_Session_Encrypt
extends
Gumbo_Session_Basic
implements
Gumbo_Interface_Session_Encrypt
{
/**
@var
Gumbo_Encrypt
$_encrypt
*/
private
$_encrypt
;
/**
@var
Gumbo_Decrypt
$_decrypt
*/
private
$_decrypt
;
/**
* Constructor
*
@param
string
$key
Encryption key
*
@param
string
$cipher
Encryption Cipher
*
@param
string
$mode
Encryption Mode
*/
public
function
__construct
(
$key
=
null
,
$cipher
=
null
,
$mode
=
null
)
{
$this
->
setEncryptionSettings
(
$key
,
$cipher
,
$mode
)
;
}
/** MUTATOR METHODS **/
/**
* Sets Encryption/Decryption settings for the Encrypted Session
*
@param
string
$key
*
@param
string
$cipher
*
@param
string
$mode
*
@uses
Gumbo_Encrypt, Gumbo_Decrypt
*/
public
function
setEncryptionSettings
(
$key
=
null
,
$cipher
=
null
,
$mode
=
null
)
{
$this
->
_encrypt
=
new
Gumbo_Encrypt
(
null
,
$key
,
$cipher
,
$mode
,
true
)
;
$this
->
_decrypt
=
new
Gumbo_Decrypt
(
null
,
$key
,
$cipher
,
$mode
,
true
)
;
}
/**
* Sets a value inside the Session array
*
@param
string
$key
*
@param
mixed
$val
(primitive values only)
*
@throws
Gumbo_Exception
*/
public
function
set
(
$key
,
$val
)
{
try
{
// verify precondition
if
(
!
is_string
(
$key
))
{
throw
new
Gumbo_Exception
(
"
Invalid
Argument
'
key
:
str
' => {
$key
}
:
"
.
gettype
(
$key
))
;
}
if
(
!
is_null
(
$val
)
&&
!
is_bool
(
$val
)
&&
!
is_numeric
(
$val
)
&&
!
is_string
(
$val
))
{
throw
new
Gumbo_Exception
(
"
Invalid
Argument
'
val
:
num
|
str
|
bool
' => {
$val
}
:
"
.
gettype
(
$val
))
;
}
$this
->
_encrypt
->
setData
(
$key
)
;
$key
=
$this
->
_encrypt
->
parse
(
)
;
if
(
!
is_null
(
$val
))
{
$this
->
_encrypt
->
setData
(
$val
)
;
$val
=
$this
->
_encrypt
->
parse
(
)
;
}
$_SESSION
[
$key
]
=
$val
;
}
catch
(
Gumbo_Exception
$e
)
{
$e
->
setFunction
(
__METHOD__
)
;
gumbo_trigger
(
$e
)
;
}
}
/** ACCESSOR METHODS **/
/**
* Returns the value of the Session variable
*
@param
string
$key
*
@return
string
*
@throws
Gumbo_Exception
*/
public
function
get
(
$key
)
{
try
{
// verify precondition
if
(
!
is_string
(
$key
))
{
throw
new
Gumbo_Exception
(
"
Invalid
Argument
'
key
:
str
' => {
$key
}
:
"
.
gettype
(
$key
))
;
}
$this
->
_encrypt
->
setData
(
$key
)
;
$key
=
$this
->
_encrypt
->
parse
(
)
;
if
(
!
isset
(
$_SESSION
[
$key
]
))
{
throw
new
Gumbo_Exception
(
"
Invalid
Session
Variable
: {
$key
}
"
)
;
}
$this
->
_decrypt
->
setData
(
$_SESSION
[
$key
]
)
;
return
$this
->
_decrypt
->
parse
(
)
;
}
catch
(
Gumbo_Exception
$e
)
{
$e
->
setFunction
(
__METHOD__
)
;
gumbo_trigger
(
$e
)
;
}
return
null
;
}
}
?>