* @license PHP License * @package Wombat * @subpackage base */ /** * Instance creator * * Functor to encapsulate new operator * * @version 0.5.0 * @package Wombat * @subpackage base */ class WBClass_Creator_patSession extends WBClass_Creator { /** * tells whether this object is the first created * @return bool */ static protected $created = false; /** * Configuration loader * @var WBConfig */ private $config; /** * return new object * * @return object */ public function instantiate($parameter = array()) { if (self::$created) { $obj = patSession::singleton('wombat'); return $obj; } self::$created = true; WBClass::load('WBLog' , 'WBConfig' , 'WBString' , 'WBErrorHandler_Pat' , 'patSession'); $this->config = WBClass::create('WBConfig'); $this->config->load('config'); $sessName = $this->config->get('session/name', 'WBS'); $domain = $this->config->get('session/domain', ''); if (!empty($domain)) { $domain = WBString::replaceSuperplaceholders($domain); } $container = $this->config->get('session/container', 'Native'); $container = WBParam::get('wb/session/container', $container); if (isset($parameter['container'])) { $container = $parameter['container']; } $expire = $this->config->get('session/expire', 86400); $options = array( 'empty-referer' => 'allow', //'security' => 'fix_browser,fix-referer,fix_ip', 'security' => 'fix-referer,fix_ip', 'name' => $sessName, //'id-prefix' => 'WBS', 'cookie-lifetime' => $expire, 'expire' => $expire ); if ($domain) { $options['cookie_domain'] = $domain; $options['allow-referer'] = '*.' . $domain; } // prefer cookies but accept request variables as well if (isset($_COOKIE[$sessName]) && !empty($_COOKIE[$sessName])) { $options['id'] = $_COOKIE[$sessName]; unset($_COOKIE[$sessName]); } if (isset($_POST[$sessName]) && !empty($_POST[$sessName])){ $options['id'] = $_POST[$sessName]; unset($_POST[$sessName]); } /** @var patSession_Storage */ $obj = patSession::singleton('wombat', $container, $options); if ($obj->getState() !== 'active') { WBParam::set('wb/session/id', $obj->id); $logger = WBLog::start('session'); $log = array( 'action' => 'restart', 'state' => $obj->getState() ); $logger->warn($log); $obj->restart(); } // keep orginal session id if ($obj->has('wb/session/id')) { WBParam::set('wb/session/id', $obj->get('wb.session.id')); } else { WBParam::set('wb/session/id', $obj->id); $obj->set('wb.session.id', $obj->id); } // logging facility $logger = WBLog::start('session'); if (!$obj->isNew()) { // log counter $timer = $obj->getTimer(); $log = array( 'action' => 'continue', 'count' => $obj->counter, 'elapsed-start' => $timer['elapsed_start'], 'elapsed-last' => $timer['elapsed_last'], 'cookie' => $options['id'] ); $logger->info( $log ); return $obj; } $stat = WBClass::create('WBStatistic_Session'); $stat->add(); // log everything about browser $log = array( 'action' => 'start', 'user-agent' => 'undefined', 'accept' => 'undefined', 'accept-encoding' => 'undefined', 'accept-lang' => 'undefined', 'accept-charset' => 'undefined' ); if( isset( $_SERVER['HTTP_USER_AGENT'] ) ) { $log['user-agent'] = $_SERVER['HTTP_USER_AGENT']; } if( isset( $_SERVER['HTTP_ACCEPT'] ) ) { $log['accept'] = $_SERVER['HTTP_ACCEPT']; } if( isset( $_SERVER['HTTP_ACCEPT_ENCODING'] ) ) { $log['accept-encoding'] = $_SERVER['HTTP_ACCEPT_ENCODING']; } if( isset( $_SERVER['HTTP_ACCEPT_LANGUAGE'] ) ) { $log['accept-lang'] = $_SERVER['HTTP_ACCEPT_LANGUAGE']; } if( isset( $_SERVER['HTTP_ACCEPT_CHARSET'] ) ) { $log['accept-charset'] = $_SERVER['HTTP_ACCEPT_CHARSET']; } $logger->notice( $log ); return $obj; } }