Просмотр исходного кода

ZF-2060
- Added a method getOptions($optionName = null) to Zend_Session as compliment of setOptions()

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@15638 44c647ce-9c0f-0410-b52a-842ac1e357ba

ralph 16 лет назад
Родитель
Сommit
b58da4eebe
1 измененных файлов с 57 добавлено и 11 удалено
  1. 57 11
      library/Zend/Session.php

+ 57 - 11
library/Zend/Session.php

@@ -57,6 +57,13 @@ class Zend_Session extends Zend_Session_Abstract
     public static $_unitTestEnabled = false;
 
     /**
+     * $_throwStartupException
+     *
+     * @var bool
+     */
+    protected static $_throwStartupExceptions = true;
+    
+    /**
      * Check whether or not the session was started
      *
      * @var bool
@@ -119,8 +126,9 @@ class Zend_Session extends Zend_Session_Abstract
      * @var array
      */
     private static $_localOptions = array(
-        'strict'                => '_strict',
-        'remember_me_seconds'   => '_rememberMeSeconds'
+        'strict'                   => '_strict',
+        'remember_me_seconds'      => '_rememberMeSeconds',
+        'throw_startup_exceptions' => '_throwStartupExceptions'
     );
 
     /**
@@ -221,6 +229,31 @@ class Zend_Session extends Zend_Session_Abstract
         }
     }
 
+    /**
+     * getOptions()
+     *
+     * @param string $optionName OPTIONAL
+     * @return array|string
+     */
+    public static function getOptions($optionName = null)
+    {
+        $options = array();
+        foreach (ini_get_all('session') as $sysOptionName => $sysOptionValues) {
+            $options[substr($sysOptionName, 8)] = $sysOptionValues['local_value'];
+        }
+        foreach (self::$_localOptions as $localOptionName => $localOptionMemberName) {
+            $options[$localOptionName] = self::${$localOptionMemberName};
+        }
+        
+        if ($optionName) {
+            if (array_key_exists($optionName, $options)) {
+                return $options[$optionName];
+            }
+            return null;
+        }
+        
+        return $options;
+    }
 
     /**
      * setSaveHandler() - Session Save Handler assignment
@@ -413,6 +446,7 @@ class Zend_Session extends Zend_Session_Abstract
             throw new Zend_Session_Exception('You must explicitly start the session with Zend_Session::start() when session options are set to strict.');
         }
 
+        $filename = $linenum = null;
         if (!self::$_unitTestEnabled && headers_sent($filename, $linenum)) {
             /** @see Zend_Session_Exception */
             require_once 'Zend/Session/Exception.php';
@@ -433,15 +467,27 @@ class Zend_Session extends Zend_Session_Abstract
          */
         /** @see Zend_Session_Exception */
         if (!self::$_unitTestEnabled) {
-            require_once 'Zend/Session/Exception.php';
-            set_error_handler(array('Zend_Session_Exception', 'handleSessionStartError'), E_ALL);
-            session_start();
-            restore_error_handler();
-            if (Zend_Session_Exception::$sessionStartError !== null) {
-            set_error_handler(array('Zend_Session_Exception', 'handleSilentWriteClose'), E_ALL);
-            session_write_close();
-            restore_error_handler();
-            throw new Zend_Session_Exception(__CLASS__ . '::' . __FUNCTION__ . '() - ' . Zend_Session_Exception::$sessionStartError);
+            
+            if (self::$_throwStartupExceptions) {
+                require_once 'Zend/Session/Exception.php';
+                set_error_handler(array('Zend_Session_Exception', 'handleSessionStartError'), E_ALL);
+            }
+            
+            $startedCleanly = session_start();
+            
+            if (self::$_throwStartupExceptions) {
+                restore_error_handler();
+            }
+            
+            if ($startedCleanly || Zend_Session_Exception::$sessionStartError !== null) {
+                if (self::$_throwStartupExceptions) {
+                    set_error_handler(array('Zend_Session_Exception', 'handleSilentWriteClose'), E_ALL);
+                }
+                session_write_close();
+                if (self::$_throwStartupExceptions) {
+                    restore_error_handler();
+                }
+                throw new Zend_Session_Exception(__CLASS__ . '::' . __FUNCTION__ . '() - ' . Zend_Session_Exception::$sessionStartError);
             }
         }