Models
[
class tree: Models
] [
index: Models
] [
all elements
]
Packages:
Application
Bootstrap
Controllers
Models
Source for file Session.php
Documentation is available at
Session.php
<?php
/**
* User_Session
*
* Copyright (C) 2009 Mai (Me Artificial Intelligence)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*
@author
Wouter Bulten (wouterbulten@mai-ai.org)
*
@copyright
Copyright (C) 2009 Mai (Me Artificial Intelligence)
*
@license
http://opensource.org/licenses/gpl-3.0.html GNU General Public License version 3 (GPLv3)
*
@link
http://www.launchpad.net/mai
*
*
@package
Models
*
@subpackage
User
*
*/
/**
* User_Session
*
*
@author
Wouter Bulten (wouterbulten@mai-ai.org)
*
@copyright
Copyright (C) 2009 Mai (Me Artificial Intelligence)
*
@license
http://opensource.org/licenses/gpl-3.0.html GNU General Public License version 3 (GPLv3)
*
@link
http://www.launchpad.net/mai
*
*
@package
Models
*
@subpackage
User
*
*/
class
User_Session
{
/**
* Holds the session namespace.
*
@var
Zend_Session_Namespace
*/
static
private
$_session
;
/**
* Private constructor to prevent construction.
*
@return
void
*/
private
function
__construct
(
)
{
}
/**
* Sets a session using Zend_Session_Namespace.
*
@param
$id
*
@uses
Zend_Session_Namespace
*
@return
void
*/
static
public
function
set
(
$id
)
{
if
(
!
isset
(
$id
)
||
!
is_numeric
(
$id
))
{
throw
UnexpectedValueException
(
'$id is not set or not a integer.'
)
;
}
self
::
$_session
=
new
Zend_Session_Namespace
(
'mai-session'
)
;
self
::
$_session
->
setExpirationSeconds
(
3600
)
;
self
::
$_session
->
ip
=
Base
::
getRealIp
(
)
;
self
::
$_session
->
user_id
=
$id
;
}
/**
* Validates the session.
*
@return
Boolean
*/
static
public
function
isValid
(
)
{
if
(
!
self
::
$_session
||
!
(
self
::
$_session
instanceof
Zend_Session_Namespace
))
{
self
::
$_session
=
new
Zend_Session_Namespace
(
'mai-session'
)
;
}
if
(
isset
(
self
::
$_session
->
ip
)
&&
self
::
$_session
->
ip
==
Base
::
getRealIp
(
)
&& isset
(
self
::
$_session
->
user_id
)
&&
is_numeric
(
self
::
$_session
->
user_id
))
{
return
true
;
}
return
false
;
}
/**
* Return the id of the user is a session excists.
*
@return
Int
*/
static
public
function
returnUserId
(
)
{
if
(
self
::
isValid
(
))
{
return
self
::
$_session
->
user_id
;
}
else
{
trigger_error
(
'Session does not excist.'
,
E_USER_NOTICE
)
;
return
0
;
}
}
/**
* Remove all session data.
*
@return
void
*/
static
public
function
remove
(
)
{
if
(
!
self
::
$_session
||
!
(
self
::
$_session
instanceof
Zend_Session_Namespace
))
{
self
::
$_session
=
new
Zend_Session_Namespace
(
'mai-session'
)
;
}
self
::
$_session
->
unsetAll
(
)
;
}
}
Documentation generated on Mon, 27 Jul 2009 19:51:57 +0200 by
phpDocumentor 1.4.1