-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4d568ac
commit 7eca70c
Showing
20 changed files
with
1,312 additions
and
665 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 © 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 © 2022 [MIT License](./LICENSE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
||
|
||
} |
Oops, something went wrong.