Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
muhammetsafak committed Jul 25, 2022
0 parents commit 4d568ac
Show file tree
Hide file tree
Showing 9 changed files with 685 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/.idea/
/.vscode/
/.vs/
/vendor/
/composer.lock
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +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
SOFTWARE.
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# 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)
25 changes: 25 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "initphp/sessions",
"description": "InitPHP Session Manager",
"keywords": ["php", "session", "initphp"],
"type": "library",
"license": "MIT",
"autoload": {
"psr-4": {
"InitPHP\\Sessions\\": "src/"
}
},
"authors": [
{
"name": "Muhammet ŞAFAK",
"email": "info@muhammetsafak.com.tr",
"role": "Developer",
"homepage": "https://www.muhammetsafak.com.tr"
}
],
"minimum-stability": "stable",
"require": {
"php": ">=7.2",
"initphp/parameterbag": "^1.1"
}
}
20 changes: 20 additions & 0 deletions src/Exception/SessionException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
/**
* SessionException.php
*
* This file is part of Sessions.
*
* @author Muhammet ŞAFAK <info@muhammetsafak.com.tr>
* @copyright Copyright © 2022 Muhammet ŞAFAK
* @license ./LICENSE MIT
* @version 1.0
* @link https://www.muhammetsafak.com.tr
*/

declare(strict_types=1);

namespace InitPHP\Sessions\Exception;

class SessionException extends \RuntimeException
{
}
20 changes: 20 additions & 0 deletions src/Exception/SessionInvalidArgumentException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
/**
* SessionInvalidArgumentException.php
*
* This file is part of Sessions.
*
* @author Muhammet ŞAFAK <info@muhammetsafak.com.tr>
* @copyright Copyright © 2022 Muhammet ŞAFAK
* @license ./LICENSE MIT
* @version 1.0
* @link https://www.muhammetsafak.com.tr
*/

declare(strict_types=1);

namespace InitPHP\Sessions\Exception;

class SessionInvalidArgumentException extends \InvalidArgumentException
{
}
64 changes: 64 additions & 0 deletions src/Facede/Session.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php
/**
* Session.php
*
* This file is part of Sessions.
*
* @author Muhammet ŞAFAK <info@muhammetsafak.com.tr>
* @copyright Copyright © 2022 Muhammet ŞAFAK
* @license ./LICENSE MIT
* @version 1.0
* @link https://www.muhammetsafak.com.tr
*/

declare(strict_types=1);

namespace InitPHP\Sessions\Facede;

use InitPHP\Sessions\Session as SessionInstance;

/**
* @mixin SessionInstance
* @method static string getName()
* @method static SessionInstance setName(string $name)
* @method static bool isStarted()
* @method static bool start(array $options = [])
* @method static bool regenerateId(bool $deleteOldSession = false)
* @method static string getID()
* @method static bool setID(string $sessionId)
* @method static array all()
* @method static bool destroy()
* @method static bool flush()
* @method static bool has(string $key)
* @method static mixed get(string $key, mixed $default = null)
* @method static mixed pull(string $key, mixed $default = null)
* @method static SessionInstance set(string $key, mixed $value, null|int $ttl = null)
* @method static mixed push(string $key, mixed $value, null|int $ttl = null)
* @method static SessionInstance setAssoc(array $assoc, null|int $ttl = null)
* @method static SessionInstance remove(string ...$key)
*/
class Session
{

/** @var SessionInstance */
private static $sessionInstance;

private static function getInstance(): SessionInstance
{
if(!isset(self::$sessionInstance)){
self::$sessionInstance = new SessionInstance();
}
return self::$sessionInstance;
}

public function __call($name, $arguments)
{
return self::getInstance()->{$name}(...$arguments);
}

public static function __callStatic($name, $arguments)
{
return self::getInstance()->{$name}(...$arguments);
}

}
Loading

0 comments on commit 4d568ac

Please sign in to comment.