Skip to content

Commit 8ac6e85

Browse files
committed
fix(setup): add initial setup
0 parents  commit 8ac6e85

15 files changed

+851
-0
lines changed

.editorconfig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
insert_final_newline = true
7+
indent_style = space
8+
indent_size = 4
9+
trim_trailing_whitespace = true
10+
11+
[*.md]
12+
trim_trailing_whitespace = false
13+
14+
[*.yml]
15+
indent_size = 2

.github/workflows/release.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: New Release
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
7+
jobs:
8+
release:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout
12+
uses: actions/checkout@v3
13+
- name: New Release
14+
uses: cycjimmy/semantic-release-action@v3
15+
id: release # Need an `id` for output variables
16+
env:
17+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
18+
NPM_TOKEN: 000000000000000
19+
GIT_AUTHOR_NAME: sudkumar
20+
GIT_COMMITTER_NAME: sudkumar
21+
with:
22+
extra_plugins: |
23+
@semantic-release/git
24+
@semantic-release/changelog

.github/workflows/test.yml

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
name: tests
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
9+
jobs:
10+
tests:
11+
runs-on: ubuntu-latest
12+
13+
strategy:
14+
fail-fast: true
15+
matrix:
16+
php: [7.1, 7.2, 7.3, 7.4, 8.0, 8.1, 8.2]
17+
laravel: ['5.8.*', '11.*', ^6.0, ^7.0, ^8.0, ^9.0, ^10.0]
18+
exclude:
19+
- php: 7.1
20+
laravel: ^6.0
21+
- php: 7.1
22+
laravel: ^7.0
23+
- php: 7.1
24+
laravel: ^8.0
25+
- php: 7.1
26+
laravel: ^9.0
27+
- php: 7.1
28+
laravel: ^10.0
29+
- php: 7.2
30+
laravel: ^8.0
31+
- php: 7.2
32+
laravel: ^9.0
33+
- php: 7.2
34+
laravel: ^10.0
35+
- php: 7.3
36+
laravel: ^9.0
37+
- php: 7.3
38+
laravel: ^10.0
39+
- php: 7.4
40+
laravel: ^9.0
41+
- php: 7.4
42+
laravel: ^10.0
43+
- php: 8.0
44+
laravel: 5.8.*
45+
- php: 8.0
46+
laravel: ^6.0
47+
- php: 8.0
48+
laravel: ^7.0
49+
- php: 8.0
50+
laravel: ^10.0
51+
- php: 8.1
52+
laravel: 5.8.*
53+
- php: 8.1
54+
laravel: ^6.0
55+
- php: 8.1
56+
laravel: ^7.0
57+
- php: 8.2
58+
laravel: 5.8.*
59+
- php: 8.2
60+
laravel: ^6.0
61+
- php: 8.2
62+
laravel: ^7.0
63+
- laravel: 11.*
64+
php: 7.1
65+
- laravel: 11.*
66+
php: 7.2
67+
- laravel: 11.*
68+
php: 7.3
69+
- laravel: 11.*
70+
php: 7.4
71+
- laravel: 11.*
72+
php: 8.0
73+
- laravel: 11.*
74+
php: 8.1
75+
76+
name: P${{ matrix.php }} - L${{ matrix.laravel }}
77+
78+
steps:
79+
- name: Checkout code
80+
uses: actions/checkout@v3
81+
82+
- name: Cache dependencies
83+
uses: actions/cache@v1
84+
with:
85+
path: ~/.composer/cache/files
86+
key: dependencies-laravel-${{ matrix.laravel }}-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}
87+
88+
- name: Setup PHP
89+
uses: shivammathur/setup-php@v2
90+
with:
91+
php-version: ${{ matrix.php }}
92+
extensions: dom, curl, libxml, mbstring, zip
93+
coverage: none
94+
ini-values: error_reporting=E_ALL
95+
96+
- name: Install dependencies
97+
run: composer require "illuminate/contracts=${{ matrix.laravel }}" --prefer-dist --no-interaction --no-suggest
98+
99+
- name: Execute tests
100+
run: composer run-script test

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.idea
2+
composer.lock
3+
vendor
4+
logs
5+
.php_cs.cache
6+
.phpunit.result.cache
7+
.DS_Store
8+
.phpactor.json

.releaserc.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"plugins": [
3+
"@semantic-release/commit-analyzer",
4+
"@semantic-release/release-notes-generator",
5+
"@semantic-release/changelog",
6+
[
7+
"@semantic-release/git",
8+
{
9+
"message": "chore(release): ${nextRelease.version} :tada: :rocket:\n\n${nextRelease.notes}"
10+
}
11+
],
12+
"@semantic-release/github"
13+
]
14+
}

CHANGELOG.md

Whitespace-only changes.

LICENCE.txt

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

README.md

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# Laravel Redis Session Enhanced Driver
2+
3+
<p>
4+
<a href="https://packagist.org/packages/craftsys/laravel-redis-session-enhanced"><img src="https://img.shields.io/packagist/dt/craftsys/laravel-redis-session-enhanced" alt="Total Downloads" /></a>
5+
<a href="https://packagist.org/packages/craftsys/laravel-redis-session-enhanced"><img src="https://img.shields.io/packagist/v/craftsys/laravel-redis-session-enhanced?label=version" alt="Latest Stable Version" /></a>
6+
<a href="https://packagist.org/packages/craftsys/laravel-redis-session-enhanced"><img src="https://img.shields.io/packagist/l/craftsys/laravel-redis-session-enhanced" alt="License" /></a>
7+
<a href="https://packagist.org/packages/craftsys/laravel-redis-session-enhanced"><img src="https://img.shields.io/github/workflow/status/craftsys/laravel-redis-session-enhanced/tests?label=tests" alt="Status" /></a>
8+
</p>
9+
10+
11+
The [Laravel's Database Session Driver](https://laravel.com/docs/session#database) manages sessions in the Database which associates following attributes (along with the payload) with every session update: `user_id`, `ip_address`, `user_agent`, and `last_activty`. These attributes can be accessed and modified to provide following capabilities to your customers
12+
13+
- Track Active Sessions
14+
- Remove Other Sessions (Logout from other devices)
15+
- Allow Admins to force logout some/everyone
16+
- Block Multiple Sessions
17+
18+
But with the Database driver, **every request to your application will do a Database update** to sessions table to track the latest session information, specifically, the `last_activty` attribute. This database update is required to validate unauthenticated requests if the session becomes inactive for the configured `SESSION_LIFETIME`. These session updates on every requests are fast and should not have much performance impact on your request time. But, if you ARE facing performance issues and want to store the session in the redis cache, you can go the [Laravel's Redis Session Driver](https://laravel.com/docs/session#redis). The redis driver will store and validate the session automatically but you will loose the above mentioned capabilities for your customers (tracking, logouts etc.).
19+
20+
If you want to have similar capabilities as the Database Session driver but want to use Redis for session storage, this project is for you.
21+
22+
23+
## Table of Contents
24+
25+
- [Installation](#installation)
26+
- [Configuration](#configuration)
27+
- [Usage](#usage)
28+
29+
## Installation
30+
31+
The packages is available on [Packagist](https://packagist.org/packages/craftsys/laravel-redis-session-enhanced) and can be installed via [Composer](https://getcomposer.org/) by executing following command in shell.
32+
33+
```bash
34+
composer require craftsys/laravel-redis-session-enhanced
35+
```
36+
37+
**prerequisite**
38+
39+
- php^7.1
40+
- laravel^5|^6|^7|^8|^9|^10|^11
41+
- redis installed and configured for laravel
42+
43+
The package is tested for 5.8+,^6.0,^7.0,^8.0,^9.0,^10.0,^11.0 only.
44+
45+
### Laravel 5.5+
46+
47+
If you're using Laravel 5.5 or above, the package will automatically register the `Craftsys\LaravelRedisSessionEnhanced\RedisSessionEnhancedServiceProvider` provider.
48+
49+
### Laravel 5.4 and below
50+
51+
Add `Craftsys\LaravelRedisSessionEnhanced\RedisSessionEnhancedServiceProvider` to the `providers` array in your `config/app.php`:
52+
53+
```php
54+
'providers' => [
55+
// Other service providers...
56+
Craftsys\LaravelRedisSessionEnhanced\RedisSessionEnhancedServiceProvider::class,
57+
],
58+
```
59+
60+
## Configuration
61+
62+
1. Add a new connection named `session` in your `config/database.php` redis configuration
63+
64+
```php
65+
[
66+
'redis' => [
67+
// ... existing configuration
68+
// Add new connection for session
69+
'session' => [
70+
'host' => env('REDIS_HOST', '127.0.0.1'),
71+
'password' => env('REDIS_PASSWORD', null),
72+
'port' => env('REDIS_PORT', 6379),
73+
// new DB, only for sessions for quick access and cleanup, change the value if 2 is already taken
74+
'database' => env('REDIS_CACHE_DB', 2),
75+
],
76+
]
77+
];
78+
```
79+
80+
2. Update the .env file with the session driver and connection
81+
82+
```sh
83+
SESSION_DRIVER=redis-session
84+
SESSION_CONNECTION=session
85+
```
86+
87+
88+
## Usage

composer.json

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
{
2+
"name": "craftsys/laravel-redis-session-enhanced",
3+
"description": "Enhanced redis driver for sessions in Laravel",
4+
"license": "MIT",
5+
"type": "library",
6+
"authors": [
7+
{
8+
"name": "Sudhir Mitharwal",
9+
"email": "luckysud4@gmail.com",
10+
"role": "Developer",
11+
"homepage": "http://github.com/sudkumar"
12+
}
13+
],
14+
"keywords": [
15+
"php",
16+
"laravel",
17+
"session",
18+
"redis"
19+
],
20+
"homepage": "https://github.com/craftsys/laravel-redis-session-enhanced",
21+
"support": {
22+
"issues": "https://github.com/craftsys/laravel-redis-session-enhanced/issues",
23+
"source": "https://github.com/craftsys/laravel-redis-session-enhanced",
24+
"email": "luckysud4@gmail.com"
25+
},
26+
"require": {
27+
"php": "^7.1.3|^8.0|^8.1",
28+
"illuminate/support": "^5.2|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0"
29+
},
30+
"require-dev": {
31+
"orchestra/testbench": "~3.8|^4.0|^5.0|^6.0|^7.0|^8.0|^9.0",
32+
"phpunit/phpunit": "^5.3|^6.0|^7.0|^8.0|^9.4|^10.0"
33+
},
34+
"config": {
35+
"optimize-autoloader": true,
36+
"sort-packages": true
37+
},
38+
"prefer-stable": true,
39+
"minimum-stability": "dev",
40+
"autoload": {
41+
"psr-4": {
42+
"Craftsys\\LaravelRedisSessionEnhanced\\": "src/"
43+
}
44+
},
45+
"autoload-dev": {
46+
"psr-4": {
47+
"Craftsys\\Tests\\LaravelRedisSessionEnhanced\\": "tests/"
48+
}
49+
},
50+
"extra": {
51+
"branch-alias": {
52+
"dev-master": "0.x.x-dev"
53+
},
54+
"laravel": {
55+
"providers": [
56+
"Craftsys\\LaravelRedisSessionEnhanced\\RedisSessionEnhancedProvider"
57+
]
58+
}
59+
},
60+
"scripts": {
61+
"test": "phpunit --colors=always"
62+
}
63+
}

phpunit.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" colors="true" bootstrap="vendor/autoload.php" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd">
3+
<testsuites>
4+
<testsuite name="unit">
5+
<directory>./tests/</directory>
6+
</testsuite>
7+
</testsuites>
8+
<source>
9+
<include>
10+
<directory suffix=".php">./src/</directory>
11+
</include>
12+
</source>
13+
</phpunit>

0 commit comments

Comments
 (0)