Pimcore\Tool\Session::get PHP Method

get() public static method

public static get ( string $namespace = "pimcore_admin", boolean $readOnly = false ) : Zend_Session_Namespace
$namespace string
$readOnly boolean
return Zend_Session_Namespace
    public static function get($namespace = "pimcore_admin", $readOnly = false)
    {
        $initSession = !\Zend_Session::isStarted();
        $forceStart = !$readOnly;
        // we don't force the session to start in read-only mode (default behavior)
        $sName = self::getOption("name");
        if (self::backupForeignSession()) {
            $initSession = true;
            $forceStart = true;
        }
        if ($initSession) {
            \Zend_Session::setOptions(self::$options);
        }
        try {
            try {
                if ($initSession) {
                    // only set the session id if the cookie isn't present, otherwise Set-Cookie is always in the headers
                    if (array_key_exists($sName, $_REQUEST) && !empty($_REQUEST[$sName]) && (!array_key_exists($sName, $_COOKIE) || empty($_COOKIE[$sName]))) {
                        // get zend_session work with session-id via get (since SwfUpload doesn't support cookies)
                        \Zend_Session::setId($_REQUEST[$sName]);
                    }
                }
            } catch (\Exception $e) {
                Logger::error("Problem while starting session");
                Logger::error($e);
            }
        } catch (\Exception $e) {
            Logger::emergency("there is a problem with admin session");
            die;
        }
        if ($initSession) {
            \Zend_Session::start();
        }
        if ($forceStart) {
            @session_start();
            self::$sessionCookieCleanupNeeded = true;
        }
        if (!array_key_exists($namespace, self::$sessions) || !self::$sessions[$namespace] instanceof \Zend_Session_Namespace) {
            try {
                self::$sessions[$namespace] = new Session\Container($namespace);
            } catch (\Exception $e) {
                // invalid session, regenerate the session, and return a dummy object
                \Zend_Session::regenerateId();
                return new \stdClass();
            }
        }
        self::$openedSessions++;
        self::$sessions[$namespace]->unlock();
        return self::$sessions[$namespace];
    }

Usage Example

Exemplo n.º 1
0
 public function init()
 {
     parent::init();
     // PHP 7.0 compatibility of adminer (throws some warnings)
     ini_set("display_errors", 0);
     // only for admins
     $this->checkPermission("adminer");
     // call this to keep the session 'open' so that Adminer can write to it
     $session = \Pimcore\Tool\Session::get();
     $this->adminerHome = PIMCORE_DOCUMENT_ROOT . '/vendor/vrana/adminer/';
     // proxy for resources
     $path = $this->getRequest()->getPathInfo();
     $path = str_replace("/admin/external_adminer/", "", $path);
     if (preg_match("@\\.(css|js|ico|png|jpg|gif)\$@", $path)) {
         $filePath = $this->adminerHome . "/" . $path;
         // it seems that css files need the right content-type (Chrome)
         if (preg_match("@.css\$@", $path)) {
             header("Content-Type: text/css");
         } elseif (preg_match("@.js\$@", $path)) {
             header("Content-Type: text/javascript");
         }
         if (file_exists($filePath)) {
             echo file_get_contents($filePath);
             if (preg_match("@default.css\$@", $path)) {
                 // append custom styles, because in Adminer everything is hardcoded
                 echo file_get_contents($this->adminerHome . "designs/konya/adminer.css");
                 echo file_get_contents(PIMCORE_DOCUMENT_ROOT . "/pimcore/static6/css/adminer-modifications.css");
             }
         }
         exit;
     }
 }
All Usage Examples Of Pimcore\Tool\Session::get