awixe/session

一个作为包装器的会话处理程序

1.0.0 2017-10-19 04:28 UTC

README

StyleCI PHPVersion License

此模块被设计为包装器,以便可以注入到pimple中。您还可以以另一种方式使用它。例如,您可以直接调用类并调用任何静态函数以获得相同的结果。它使用原生的$_SESSION[]会话变量数组。我们建议您通过pimple的依赖注入器使用它。

安装

您可以通过两种方式安装此模块:使用composer或直接下载,但如果您直接下载且需要更多步骤,您可以在https://github.com/Awixe/Session/releases查看所有可用的下载,所以我们建议您使用composer以使其更简单。

使用composer

composer require awixe/session

用法

如果您使用awixe模块适配器,则可以通过app函数访问它;否则,如果您不使用awixe适配器,则必须声明一个新对象才能使用它。

示例 #1

<?php
// Require composer
require __DIR__ . '/vendor/autoload.php';

// Not required if the bootstrap file is required
session_start();

// Set a new session variable
app('session')->set('hello', 'world');

// Get a session variable
if (app('session')->get('hello')) {

    // Save result
    $output = [
        app('session')->get('hello')
    ];
}

// Delete a session variable
app('session')->del('hello');

// Print the result
print_r($output);

if (app('session')->get('hello')) {
    print(app('session')->get('hello'));
} else {
    var_dump(app('session')->get('hello'));
}

?>

示例 #2

<?php
// Require composer
require __DIR__ . '/vendor/autoload.php';
use Awixe\Module\Session\Handler;

// Not required if the bootstrap file is required
session_start();

// Declare a new object
$session = new Handler();

// Set a new session variable
$session->set('hello', 'world');

// Get a session variable
if ($session->get('hello')) {

    // Save result
    $output = [
        $session->get('hello')
    ];
}

// Delete a session variable
$session->del('hello');

// Print the result
print_r($output);

if ($session->get('hello')) {
    print($session->get('hello'));
} else {
    var_dump($session->get('hello'));
}

?>

结论