Skip to content

Commit 3eba808

Browse files
committed
updated readme
1 parent 342beb6 commit 3eba808

File tree

1 file changed

+57
-68
lines changed

1 file changed

+57
-68
lines changed

README.md

+57-68
Original file line numberDiff line numberDiff line change
@@ -1,104 +1,93 @@
1-
# FlightPHP Active Record
2-
[![Latest Stable Version](http://poser.pugx.org/flightphp/active-record/v)](https://packagist.org/packages/flightphp/active-record)
3-
[![License](https://poser.pugx.org/flightphp/active-record/license)](https://packagist.org/packages/flightphp/active-record)
4-
[![PHP Version Require](http://poser.pugx.org/flightphp/active-record/require/php)](https://packagist.org/packages/flightphp/active-record)
5-
[![Dependencies](http://poser.pugx.org/flightphp/active-record/dependents)](https://packagist.org/packages/flightphp/active-record)
1+
# FlightPHP Session
2+
[![Latest Stable Version](http://poser.pugx.org/flightphp/session/v)](https://packagist.org/packages/flightphp/session)
3+
[![License](https://poser.pugx.org/flightphp/session/license)](https://packagist.org/packages/flightphp/session)
4+
[![PHP Version Require](http://poser.pugx.org/flightphp/session/require/php)](https://packagist.org/packages/flightphp/session)
5+
[![Dependencies](http://poser.pugx.org/flightphp/session/dependents)](https://packagist.org/packages/flightphp/session)
66

7-
An active record is mapping a database entity to a PHP object. Spoken plainly, if you have a users table in your database, you can "translate" a row in that table to a `User` class and a `$user` object in your codebase. See [basic example](#basic-example).
7+
A lightweight, file-based session handler for the Flight framework. It supports non-blocking behavior, optional encryption, and auto-commit functionality. See [basic example](#basic-example).
88

9-
## Basic Example
9+
## Installation
1010

11-
Let's assume you have the following table:
11+
Simply install with Composer
1212

13-
```sql
14-
CREATE TABLE users (
15-
id INTEGER PRIMARY KEY,
16-
name TEXT,
17-
password TEXT
18-
);
13+
```bash
14+
composer require flightphp/session
1915
```
2016

21-
Now you can setup a new class to represent this table:
22-
23-
```php
24-
/**
25-
* An ActiveRecord class is usually singular
26-
*
27-
* It's highly recommended to add the properties of the table as comments here
28-
*
29-
* @property int $id
30-
* @property string $name
31-
* @property string $password
32-
*/
33-
class User extends flight\ActiveRecord {
34-
public function __construct($databaseConnection)
35-
{
36-
parent::__construct($databaseConnection, 'users', [ /* custom values */ ]);
37-
}
38-
}
39-
```
17+
## Basic Example
4018

41-
Now watch the magic happen!
19+
Let's see how easy it is to use FlightPHP Session:
4220

4321
```php
44-
// for sqlite
45-
$database_connection = new PDO('sqlite:test.db'); // this is just for example, you'd probably use a real database connection
22+
// Create a session instance with default settings
23+
$session = new flight\Session();
4624

47-
// for mysql
48-
$database_connection = new PDO('mysql:host=localhost;dbname=test_db&charset=utf8bm4', 'username', 'password');
25+
// Store some data
26+
$session->set('user_id', 123);
27+
$session->set('username', 'johndoe');
28+
$session->set('is_admin', false);
4929

50-
// or mysqli
51-
$database_connection = new mysqli('localhost', 'username', 'password', 'test_db');
52-
// or mysqli with non-object based creation
53-
$database_connection = mysqli_connect('localhost', 'username', 'password', 'test_db');
30+
// Retrieve data
31+
echo $session->get('username'); // Outputs: johndoe
5432

55-
$user = new User($database_connection);
56-
$user->name = 'Bobby Tables';
57-
$user->password = password_hash('some cool password');
58-
$user->insert();
59-
// or $user->save();
33+
// Use a default value if the key doesn't exist
34+
echo $session->get('preferences', 'default_theme'); // Outputs: default_theme
6035

61-
echo $user->id; // 1
36+
// Remove a session value
37+
$session->delete('is_admin');
6238

63-
$user->name = 'Joseph Mamma';
64-
$user->password = password_hash('some cool password again!!!');
65-
$user->insert();
39+
// Check if a value exists
40+
if ($session->get('user_id')) {
41+
echo 'User is logged in!';
42+
}
6643

67-
echo $user->id; // 2
44+
// Clear all session data
45+
$session->clear();
6846
```
6947

70-
And it was just that easy to add a new user! Now that there is a user row in the database, how do you pull it out?
48+
## Advanced Configuration
7149

72-
```php
73-
$user->find(1); // find id = 1 in the database and return it.
74-
echo $user->name; // 'Bobby Tables'
75-
```
76-
77-
And what if you want to find all the users?
50+
You can customize the session handler with various configuration options:
7851

7952
```php
80-
$users = $user->findAll();
53+
$session = new flight\Session([
54+
'save_path' => '/custom/path/to/sessions', // Custom directory for storing session files
55+
'encryption_key' => 'your-secret-32-byte-key', // Enable encryption with a secure key
56+
'auto_commit' => true, // Automatically commit session changes on shutdown
57+
'start_session' => true, // Start the session automatically
58+
'test_mode' => false, // Enable for testing without affecting PHP's session state
59+
]);
8160
```
8261

83-
What about with a certain condition?
62+
## Session Security
63+
64+
When dealing with sensitive user data, it's recommended to use encryption:
8465

8566
```php
86-
$users = $user->like('name', '%mamma%')->findAll();
87-
```
67+
// Create a session with encryption enabled
68+
$session = new flight\Session([
69+
'encryption_key' => 'a-secure-32-byte-key-for-aes-256-cbc',
70+
]);
8871

89-
See how much fun this is? Let's install it and get started!
72+
// Now all session data will be automatically encrypted when stored
73+
$session->set('credit_card', '4111-1111-1111-1111');
74+
```
9075

91-
## Installation
76+
## Session Regeneration
9277

93-
Simply install with Composer
78+
For security purposes, you might want to regenerate the session ID periodically:
9479

9580
```php
96-
composer require flightphp/active-record
81+
// Regenerate the session ID and keep the current session data
82+
$session->regenerate();
83+
84+
// Regenerate the session ID and delete the old session data
85+
$session->regenerate(true);
9786
```
9887

9988
## Documentation
10089

101-
Head over to the [documentation page](https://docs.flightphp.com/awesome-plugins/active-record) to learn more about usage and how cool this thing is! :)
90+
Head over to the [documentation page](https://docs.flightphp.com/awesome-plugins/session) to learn more about usage and how cool this thing is! :)
10291

10392
## License
10493

0 commit comments

Comments
 (0)