123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318 |
- <?php
- namespace ZN\Services;
- class __USE_STATIC_ACCESS__Session implements SessionInterface
- {
- /***********************************************************************************/
- /* SESSION COMPONENT */
- /***********************************************************************************/
- /* Yazar: Ozan UYKUN <ozanbote@windowslive.com> | <ozanbote@gmail.com>
- /* Site: www.zntr.net
- /* Lisans: The MIT License
- /* Telif Hakkı: Copyright (c) 2012-2016, zntr.net
- /*
- /* Sınıf Adı: Session
- /* Versiyon: 1.2
- /* Tanımlanma: Dinamik
- /* Dahil Edilme: Gerektirmez
- /* Erişim: Session:: $this->Session, zn::$use->Session, uselib('Session')
- /* Not: Büyük-küçük harf duyarlılığı yoktur.
- /***********************************************************************************/
-
- //----------------------------------------------------------------------------------------------------
- // Const CONFIG_NAME
- //----------------------------------------------------------------------------------------------------
- //
- // @const string
- //
- //----------------------------------------------------------------------------------------------------
- const CONFIG_NAME = 'Services:session';
-
- //----------------------------------------------------------------------------------------------------
- // Session Cookie Common
- //----------------------------------------------------------------------------------------------------
- //
- // ErrorControlTrait
- // CallUndefinedMethodTrait
- //
- // $config
- // $name
- // $value
- // $regenerate
- // $encode
- //
- // name()
- // encode()
- // decode()
- // regenerate()
- // value()
- // defaultVariable()
- //
- //----------------------------------------------------------------------------------------------------
- use SessionTrait;
-
- //----------------------------------------------------------------------------------------------------
- // Construct
- //----------------------------------------------------------------------------------------------------
- //
- // @param void
- // @return bool
- //
- //----------------------------------------------------------------------------------------------------
- public function __construct()
- {
- $this->config();
-
- \Config::iniSet(\Config::get('Htaccess', 'session')['settings']);
-
- $this->start();
- }
-
- //----------------------------------------------------------------------------------------------------
- // Insert Method Başlangıç
- //----------------------------------------------------------------------------------------------------
- /******************************************************************************************
- * INSERT *
- *******************************************************************************************
- | Genel Kullanım: Oturum oluşturmak için kullanılır. |
- | |
- | Parametreler: 2 parametresi vardır. |
- | 1. string var @name => Oluşturulacak oturumun adı. |
- | 2. mixed var @value => Oluşturulacak oturumun tutacağı değer. |
- | |
- | Örnek Kullanım: insert('isim', 'Değer'); |
- | Not: Application/Config/Session.php dosyası üzerinden ayarlarını yapılandırabilirsiniz. |
- | |
- ******************************************************************************************/
- public function insert($name = '', $value = '')
- {
- if( ! empty($name) )
- {
- if( ! isChar($name) )
- {
- \Errors::set('Error', 'valueParameter', 'name');
- return false;
- }
-
- $this->name($name);
- }
-
- if( ! empty($value) )
- {
- $this->value($value);
- }
-
- if( ! empty($this->encode) )
- {
- if( isset($this->encode['name']) )
- {
- if( isHash($this->encode['name']) )
- {
- $this->name = hash($this->encode['name'], $this->name);
- }
- }
-
- if( isset($this->encode['value']) )
- {
- if( isHash($this->encode['value']) )
- {
- $this->value = hash($this->encode['value'], $this->value);
- }
- }
- }
-
- $sessionConfig = $this->config;
-
- if( ! isset($this->encode['name']))
- {
- $encode = $sessionConfig["encode"];
-
- if( $encode === true )
- {
- $this->name = md5($this->name);
- }
- elseif( is_string($encode) )
- {
- if( isHash($encode) )
- {
- $this->name = hash($encode, $this->name);
- }
- }
- }
-
- $_SESSION[$this->name] = $this->value;
-
- if( $_SESSION[$this->name] )
- {
- if( $this->regenerate === true )
- {
- session_regenerate_id();
- }
-
- $this->defaultVariable();
-
- return true;
- }
- else
- {
- return false;
- }
- }
-
- //----------------------------------------------------------------------------------------------------
- // Insert Method Bitiş
- //----------------------------------------------------------------------------------------------------
-
- //----------------------------------------------------------------------------------------------------
- // Select Methods Başlangıç
- //----------------------------------------------------------------------------------------------------
- public function select($name = '')
- {
- if( ! is_scalar($name) || empty($name) )
- {
- return \Errors::set('Error', 'valueParameter', 'name');
- }
-
- if( isset($this->encode['name']) )
- {
- if( isHash($this->encode['name']) )
- {
- $name = hash($this->encode['name'], $name);
- $this->encode = [];
- }
- }
- else
- {
- $encode = $this->config['encode'];
-
- if( $encode === true )
- {
- $name = md5($name);
- }
- elseif( is_string($encode) )
- {
- if( isHash($encode) )
- {
- $name = hash($encode, $name);
- }
- }
- }
-
- if( isset($_SESSION[$name]) )
- {
- return $_SESSION[$name];
- }
- else
- {
- return false;
- }
- }
-
- /******************************************************************************************
- * SELECT ALL *
- *******************************************************************************************
- | Genel Kullanım: Oluşturulmuş tüm oturumlara erişmek için kullanılır. |
- | |
- | Parametreler: Herhangi bir parametresi yoktur. |
- | |
- | Örnek Kullanım: selectAll(); |
- | |
- ******************************************************************************************/
- public function selectAll()
- {
- return $_SESSION;
- }
-
- /******************************************************************************************
- * START *
- *******************************************************************************************
- | Genel Kullanım: Session oturumu başlatmak için kullanılır . |
- | |
- | Parametreler: Herhangi bir parametresi yoktur. |
- | |
- | Örnek Kullanım: start(); |
- | |
- ******************************************************************************************/
- public function start()
- {
- if( ! isset($_SESSION) )
- {
- session_start();
- }
- }
-
- //----------------------------------------------------------------------------------------------------
- // Select Methods Bitiş
- //----------------------------------------------------------------------------------------------------
-
- //----------------------------------------------------------------------------------------------------
- // Delete Methods Başlangıç
- //----------------------------------------------------------------------------------------------------
- public function delete($name = '')
- {
- if( ! is_scalar($name) || empty($name) )
- {
- return \Errors::set('Error', 'valueParameter', 'name');
- }
-
- $sessionConfig = $this->config;
-
- if( isset($this->encode['name']) )
- {
- if( isHash($this->encode['name']) )
- {
- $name = hash($this->encode['name'], $name);
- $this->encode = [];
- }
- }
- else
- {
- $encode = $sessionConfig["encode"];
-
- if( $encode === true )
- {
- $name = md5($name);
- }
- elseif( is_string($encode) )
- {
- if( isHash($encode) )
- {
- $name = hash($encode, $name);
- }
- }
- }
-
- if( isset($_SESSION[$name]) )
- {
- unset($_SESSION[$name]);
- }
- else
- {
- return false;
- }
- }
-
-
-
- /******************************************************************************************
- * DELETE ALL *
- *******************************************************************************************
- | Genel Kullanım: Oluşturulmuş tüm oturumları silmek için kullanılır. |
- | |
- | Parametreler: Herhangi bir parametresi yoktur. |
- | |
- | Örnek Kullanım: deleteAll(); |
- | |
- ******************************************************************************************/
- public function deleteAll()
- {
- session_destroy();
- }
-
- //----------------------------------------------------------------------------------------------------
- // Delete Methods Bitiş
- //----------------------------------------------------------------------------------------------------
- }
|