Skip to content

Commit 4d568ac

Browse files
committed
First commit
0 parents  commit 4d568ac

File tree

9 files changed

+685
-0
lines changed

9 files changed

+685
-0
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/.idea/
2+
/.vscode/
3+
/.vs/
4+
/vendor/
5+
/composer.lock

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2022 InitPHP
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# InitPHP Session Manager
2+
3+
4+
## Requirements
5+
6+
- PHP 7.2 or later
7+
- [InitPHP ParameterBag Library](https://github.com/InitPHP/ParameterBag)
8+
9+
## Installation
10+
11+
```
12+
composer require initphp/sessions
13+
```
14+
15+
## Usage
16+
17+
```php
18+
require_once "vendor/autoload.php";
19+
use InitPHP\Sessions\Facede\Session;
20+
21+
Session::start();
22+
23+
Session::set('username', 'admin')
24+
->set('mail', 'admin@example.com');
25+
// ...
26+
```
27+
28+
## Credits
29+
30+
- [Muhammet ŞAFAK](https://github.com/muhammetsafak) <<info@muhammetsafak.com.tr>>
31+
32+
## License
33+
34+
Copyright &copy; 2022 [MIT License](./LICENSE)

composer.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"name": "initphp/sessions",
3+
"description": "InitPHP Session Manager",
4+
"keywords": ["php", "session", "initphp"],
5+
"type": "library",
6+
"license": "MIT",
7+
"autoload": {
8+
"psr-4": {
9+
"InitPHP\\Sessions\\": "src/"
10+
}
11+
},
12+
"authors": [
13+
{
14+
"name": "Muhammet ŞAFAK",
15+
"email": "info@muhammetsafak.com.tr",
16+
"role": "Developer",
17+
"homepage": "https://www.muhammetsafak.com.tr"
18+
}
19+
],
20+
"minimum-stability": "stable",
21+
"require": {
22+
"php": ">=7.2",
23+
"initphp/parameterbag": "^1.1"
24+
}
25+
}

src/Exception/SessionException.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
/**
3+
* SessionException.php
4+
*
5+
* This file is part of Sessions.
6+
*
7+
* @author Muhammet ŞAFAK <info@muhammetsafak.com.tr>
8+
* @copyright Copyright © 2022 Muhammet ŞAFAK
9+
* @license ./LICENSE MIT
10+
* @version 1.0
11+
* @link https://www.muhammetsafak.com.tr
12+
*/
13+
14+
declare(strict_types=1);
15+
16+
namespace InitPHP\Sessions\Exception;
17+
18+
class SessionException extends \RuntimeException
19+
{
20+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
/**
3+
* SessionInvalidArgumentException.php
4+
*
5+
* This file is part of Sessions.
6+
*
7+
* @author Muhammet ŞAFAK <info@muhammetsafak.com.tr>
8+
* @copyright Copyright © 2022 Muhammet ŞAFAK
9+
* @license ./LICENSE MIT
10+
* @version 1.0
11+
* @link https://www.muhammetsafak.com.tr
12+
*/
13+
14+
declare(strict_types=1);
15+
16+
namespace InitPHP\Sessions\Exception;
17+
18+
class SessionInvalidArgumentException extends \InvalidArgumentException
19+
{
20+
}

src/Facede/Session.php

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
/**
3+
* Session.php
4+
*
5+
* This file is part of Sessions.
6+
*
7+
* @author Muhammet ŞAFAK <info@muhammetsafak.com.tr>
8+
* @copyright Copyright © 2022 Muhammet ŞAFAK
9+
* @license ./LICENSE MIT
10+
* @version 1.0
11+
* @link https://www.muhammetsafak.com.tr
12+
*/
13+
14+
declare(strict_types=1);
15+
16+
namespace InitPHP\Sessions\Facede;
17+
18+
use InitPHP\Sessions\Session as SessionInstance;
19+
20+
/**
21+
* @mixin SessionInstance
22+
* @method static string getName()
23+
* @method static SessionInstance setName(string $name)
24+
* @method static bool isStarted()
25+
* @method static bool start(array $options = [])
26+
* @method static bool regenerateId(bool $deleteOldSession = false)
27+
* @method static string getID()
28+
* @method static bool setID(string $sessionId)
29+
* @method static array all()
30+
* @method static bool destroy()
31+
* @method static bool flush()
32+
* @method static bool has(string $key)
33+
* @method static mixed get(string $key, mixed $default = null)
34+
* @method static mixed pull(string $key, mixed $default = null)
35+
* @method static SessionInstance set(string $key, mixed $value, null|int $ttl = null)
36+
* @method static mixed push(string $key, mixed $value, null|int $ttl = null)
37+
* @method static SessionInstance setAssoc(array $assoc, null|int $ttl = null)
38+
* @method static SessionInstance remove(string ...$key)
39+
*/
40+
class Session
41+
{
42+
43+
/** @var SessionInstance */
44+
private static $sessionInstance;
45+
46+
private static function getInstance(): SessionInstance
47+
{
48+
if(!isset(self::$sessionInstance)){
49+
self::$sessionInstance = new SessionInstance();
50+
}
51+
return self::$sessionInstance;
52+
}
53+
54+
public function __call($name, $arguments)
55+
{
56+
return self::getInstance()->{$name}(...$arguments);
57+
}
58+
59+
public static function __callStatic($name, $arguments)
60+
{
61+
return self::getInstance()->{$name}(...$arguments);
62+
}
63+
64+
}

0 commit comments

Comments
 (0)