Skip to content

Commit

Permalink
v2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
muhammetsafak committed Dec 9, 2022
1 parent 4d568ac commit 7eca70c
Show file tree
Hide file tree
Showing 20 changed files with 1,312 additions and 665 deletions.
10 changes: 5 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/.idea/
/.vscode/
/.vs/
/vendor/
/composer.lock
/.idea/
/.vscode/
/.vs/
/vendor/
/composer.lock
40 changes: 20 additions & 20 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
MIT License

Copyright (c) 2022 InitPHP

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
MIT License
Copyright (c) 2022 InitPHP
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
175 changes: 141 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,141 @@
# InitPHP Session Manager


## Requirements

- PHP 7.2 or later
- [InitPHP ParameterBag Library](https://github.com/InitPHP/ParameterBag)

## Installation

```
composer require initphp/sessions
```

## Usage

```php
require_once "vendor/autoload.php";
use InitPHP\Sessions\Facede\Session;

Session::start();

Session::set('username', 'admin')
->set('mail', 'admin@example.com');
// ...
```

## Credits

- [Muhammet ŞAFAK](https://github.com/muhammetsafak) <<info@muhammetsafak.com.tr>>

## License

Copyright &copy; 2022 [MIT License](./LICENSE)
# InitPHP Session Manager


## Requirements

- PHP 7.4 or later

**Note :** Adapters used may have different dependencies.

## Installation

```
composer require initphp/sessions
```

## Usage

```php
require_once "vendor/autoload.php";
use InitPHP\Sessions\Session;

Session::createImmutable()
->start();


Session::set('username', 'admin')
->set('mail', 'admin@example.com');
/**
* OR
*
* $_SESSION['username'] = 'admin';
* $_SESSION['mail'] = 'admin@example.com';
*/

echo Session::get('username', 'Undefined');
/**
* OR
*
* echo $_SESSION['username'] ?? 'Undefined';
*/
```

### Redis Adapter Usage

```php
require_once "vendor/autoload.php";
use InitPHP\Sessions\Session;
use InitPHP\Sessions\Adapters\RedisAdapter;

$adapter = new RedisAdapter([
'host' => '127.0.0.1', // string
'port' => 6379, // int
'timeout' => 0, // int
'password' => null, // null or string
], 0, 86400, 'sess');

Session::createImmutable($adapter)
->start();
```

### PDO Adapter Usage

```php
require_once "vendor/autoload.php";
use InitPHP\Sessions\Session;
use InitPHP\Sessions\Adapters\PDOAdapter;

$pdo = new \PDO('mysql:host=localhost;dbname=test', 'root', '');

$adapter = new PDOAdapter($pdo, 'app_sessions');

Session::createImmutable($adapter)
->start();
```

Example MySQL Table Create SQL :

```sql
CREATE TABLE `sessions` (
`id` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`sess_timestamp` timestamp NULL DEFAULT NULL,
`sess_ip_address` varchar(48) COLLATE utf8mb4_unicode_ci DEFAULT NULL
`sess_data` text COLLATE utf8mb4_unicode_ci NOT NULL,
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
ALTER TABLE `sessions` ADD PRIMARY KEY (`id`);
```


### Memcache Adapter Usage

```php
require_once "vendor/autoload.php";
use InitPHP\Sessions\Session;
use InitPHP\Sessions\Adapters\MemCacheAdapter;

$adapter = new MemCacheAdapter([
'host' => '127.0.0.1', // string
'port' => 11211, // int
'weight' => 1, // int
'raw' => false, // boolean
'prefix' => null, // null or string
'ttl' => 86400, // int
]);

Session::createImmutable($adapter)
->start();
```

### Cookie Adapter Usage

```php
require_once "vendor/autoload.php";
use InitPHP\Sessions\Session;
use InitPHP\Sessions\Adapters\CookieAdapter;

$adapter = new CookieAdapter('sessDataCookieName', 'topSecretAppKey', 86400);

Session::createImmutable($adapter)
->start();
```

### MongoDB Adapter Usage

```php
require_once "vendor/autoload.php";
use InitPHP\Sessions\Session;
use InitPHP\Sessions\Adapters\MongoDBAdapter;

$adapter = new MongoDBAdapter('mongodb://127.0.0.1:27017', 'sessDbName.sessCollectionName');

Session::createImmutable($adapter)
->start();
```

## Credits

- [Muhammet ŞAFAK](https://github.com/muhammetsafak) <<info@muhammetsafak.com.tr>>

## License

Copyright &copy; 2022 [MIT License](./LICENSE)
11 changes: 5 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "initphp/sessions",
"description": "InitPHP Session Manager",
"keywords": ["php", "session", "initphp"],
"description": "InitPHP Sessions Manager",
"keywords": ["initphp", "sessions", "session", "session handler", "cookie", "memcache", "memcached", "mongodb", "pdo", "mysql", "postgresql", "postgres", "sql", "sqlite", "redis"],
"type": "library",
"license": "MIT",
"autoload": {
Expand All @@ -13,13 +13,12 @@
{
"name": "Muhammet ŞAFAK",
"email": "info@muhammetsafak.com.tr",
"role": "Developer",
"homepage": "https://www.muhammetsafak.com.tr"
"homepage": "https://www.muhammetsafak.com.tr",
"role": "Developer"
}
],
"minimum-stability": "stable",
"require": {
"php": ">=7.2",
"initphp/parameterbag": "^1.1"
"php": ">=7.4"
}
}
59 changes: 59 additions & 0 deletions src/AbstractAdapter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php
/**
* AbstractAdapter.php
*
* This file is part of InitPHP Sessions.
*
* @author Muhammet ŞAFAK <info@muhammetsafak.com.tr>
* @copyright Copyright © 2022 Muhammet ŞAFAK
* @license ./LICENSE MIT
* @version 2.0
* @link https://www.muhammetsafak.com.tr
*/

namespace InitPHP\Sessions;

abstract class AbstractAdapter implements Interfaces\AdapterInterface
{

/**
* @inheritDoc
*/
public function close()
{
return true;
}

/**
* @inheritDoc
*/
abstract public function destroy($id);

/**
* @inheritDoc
*/
public function gc($max_lifetime)
{
return true;
}

/**
* @inheritDoc
*/
public function open($path, $name)
{
return true;
}

/**
* @inheritDoc
*/
abstract public function read($id);

/**
* @inheritDoc
*/
abstract public function write($id, $data);


}
Loading

0 comments on commit 7eca70c

Please sign in to comment.