Skip to content
This repository was archived by the owner on Sep 12, 2022. It is now read-only.

Commit 668e389

Browse files
committed
First Commit
0 parents  commit 668e389

File tree

7 files changed

+353
-0
lines changed

7 files changed

+353
-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+
*.txt
3+
*.DS_Store
4+
.Spotlight-V100
5+
.Trashes

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2016 Michalis Giannas
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.

composer.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "tibian/browser-requirement",
3+
"description": "Browser Requirement for Laravel",
4+
"keywords": ["browser", "requirement", "laravel"],
5+
"type": "project",
6+
"license": "MIT",
7+
"authors": [
8+
{
9+
"name": "Michalis Giannas",
10+
"email": "[email protected]",
11+
"homepage": "https://tibian.me"
12+
}
13+
],
14+
"require": {
15+
"sinergi/browser-detector": "^6.0"
16+
},
17+
"autoload": {
18+
"psr-4": {
19+
"TiBian\\BrowserRequirement\\": "src"
20+
}
21+
}
22+
}

config/browser.php

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?php
2+
3+
use Sinergi\BrowserDetector\Browser;
4+
use Sinergi\BrowserDetector\Os;
5+
6+
return [
7+
8+
/*
9+
|--------------------------------------------------------------------------
10+
| Browser Requirement
11+
|--------------------------------------------------------------------------
12+
|
13+
| Minimum Version of Supported Browsers.
14+
| The following array is a good start point how
15+
| to build your Browser Requirement.
16+
*/
17+
'requirement' => [
18+
// OS X
19+
Os::OSX => [
20+
Browser::CHROME => 25,
21+
Browser::FIREFOX => 25,
22+
Browser::OPERA => 29,
23+
],
24+
// Linux
25+
Os::LINUX => [
26+
Browser::CHROME => 25,
27+
Browser::FIREFOX => 25,
28+
Browser::OPERA => 29,
29+
],
30+
// Windows
31+
Os::WINDOWS => [
32+
Browser::CHROME => 25,
33+
Browser::FIREFOX => 25,
34+
Browser::OPERA => 29,
35+
Browser::SAFARI => 8,
36+
Browser::IE => 9,
37+
Browser::EDGE => 11,
38+
],
39+
// iOS
40+
Os::IOS => [
41+
//
42+
],
43+
// Android
44+
Os::ANDROID => [
45+
//
46+
],
47+
// Windows Phone
48+
Os::WINDOWS_PHONE => [
49+
//
50+
]
51+
],
52+
53+
/*
54+
|--------------------------------------------------------------------------
55+
| Redirect Route on Unsupported Browser.
56+
|--------------------------------------------------------------------------
57+
|
58+
| Create a Route like the follow example.
59+
| Route::get("PATH", "Controller@method")->name('requirement::browser');
60+
*/
61+
'routeUnsupportedBrowser' => 'requirement::browser',
62+
63+
/*
64+
|--------------------------------------------------------------------------
65+
| Redirect Route on Supported Browser.
66+
|--------------------------------------------------------------------------
67+
|
68+
| Redirect if supported version of browser want to visit
69+
| the routeUnsupportedBrowser.
70+
|
71+
| Create a Route like the follow example.
72+
| Route::get("/", "PagesController@index")->name('home');
73+
*/
74+
'routeSupportedBrowser' => 'home',
75+
76+
];

readme.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
## Browser Requirement for Laravel
2+
Now you can easily Set-up your minimum Browser Requirement for your Application.
3+
4+
### Install
5+
Require this package with composer using the following command
6+
```
7+
composer require tibian/browser-requirement
8+
```
9+
After updating composer, add the service provider to the providers array in config/app.php
10+
```
11+
TiBian\BrowserRequirement\BrowserRequirementServiceProvider::class,
12+
```
13+
14+
### Config
15+
Publish the config file to change it as you wish.
16+
```
17+
php artisan vendor:publish --provider="TiBian\BrowserRequirement\BrowserRequirementServiceProvider" --tag=config
18+
```
19+
20+
### Usage
21+
Open the config/browser.php and you are ready to start.
22+
23+
>Let set-up minimum Browser Requirement for OS X and Windows...
24+
```
25+
Os::OSX => [
26+
Browser::CHROME => 25,
27+
Browser::FIREFOX => 25,
28+
Browser::OPERA => 29,
29+
],
30+
// Windows
31+
Os::WINDOWS => [
32+
Browser::CHROME => 25,
33+
Browser::FIREFOX => 25,
34+
Browser::OPERA => 29,
35+
Browser::SAFARI => 8,
36+
Browser::IE => 9,
37+
Browser::EDGE => 11,
38+
],
39+
```
40+
41+
### Routes
42+
This is a Example from the Routes you need, you are free to customize the Routes like you wish.
43+
44+
```
45+
Route::get("requirement-browser", "ErrorsController@browser")
46+
->name('requirement::browser');
47+
```
48+
49+
```
50+
Route::get("/", "PagesController@index")
51+
->name('home');
52+
```
53+
54+
### I'm looking for:
55+
- Individuals who can contribute to the Documentation.
56+
- Participation in other Open Source Projects.
57+
58+
> Visit my Web Site and learn more [about me](https://tibian.me)
59+
60+
##### Any idea for new projects, feel free to Contact me.
61+
62+
##### Thank you for visiting my Repository.

src/BrowserRequirement.php

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
<?php
2+
3+
namespace TiBian\BrowserRequirement;
4+
5+
use Closure;
6+
use Illuminate\Http\Request;
7+
use Sinergi\BrowserDetector\Os;
8+
use Sinergi\BrowserDetector\Browser;
9+
10+
/**
11+
* Class BrowserRequirement
12+
*
13+
* @package TiBian\BrowserRequirement
14+
*/
15+
class BrowserRequirement
16+
{
17+
/**
18+
* Minimum Version of Supported Browsers
19+
*
20+
* @var array
21+
*/
22+
protected $supportedVersions = [];
23+
24+
/**
25+
* Redirect Route on Unsupported Browser
26+
*
27+
* @var string
28+
*/
29+
protected $routeUnsupportedBrowser;
30+
31+
/**
32+
* Redirect Route on Supported Browser
33+
*
34+
* @var string
35+
*/
36+
protected $routeSupportedBrowser;
37+
38+
/**
39+
* Current Page
40+
*
41+
* @var string
42+
*/
43+
protected $currentPage;
44+
45+
/**
46+
* Is Unsupported Browser
47+
*
48+
* @var bool
49+
*/
50+
protected $isUnsupportedBrowser;
51+
52+
/**
53+
* OS Object
54+
*
55+
* @var object Os
56+
*/
57+
protected $os;
58+
59+
/**
60+
* Browser Object
61+
*
62+
* @var object Browser
63+
*/
64+
protected $browser;
65+
66+
/**
67+
* BrowserRequirement constructor.
68+
*
69+
* @param Browser $browser
70+
* @param Os $os
71+
*/
72+
public function __construct(Browser $browser, Os $os)
73+
{
74+
$this->supportedVersions = config('browser.requirement');
75+
$this->routeUnsupportedBrowser = route(config('browser.routeUnsupportedBrowser'));
76+
$this->routeSupportedBrowser = route(config('browser.routeSupportedBrowser'));
77+
$this->currentPage = request()->url();
78+
79+
$this->os = $os;
80+
$this->browser = $browser;
81+
82+
$this->isUnsupportedBrowser();
83+
}
84+
85+
/**
86+
* Determine if the Browser is Unsupported
87+
*
88+
* @return bool
89+
*/
90+
private function isUnsupportedBrowser()
91+
{
92+
if (array_key_exists($this->os->getName(), $this->supportedVersions)) {
93+
94+
$browsers = $this->supportedVersions[$this->os->getName()];
95+
96+
foreach ($browsers as $browser => $version) {
97+
if ($this->browser->getName() === $browser &&
98+
$this->browser->getVersion() < $version
99+
) {
100+
return $this->isUnsupportedBrowser = true;
101+
}
102+
}
103+
}
104+
105+
return $this->isUnsupportedBrowser = false;
106+
}
107+
108+
/**
109+
* Handle an incoming request.
110+
*
111+
* @param \Illuminate\Http\Request $request
112+
* @param \Closure $next
113+
* @return mixed
114+
*/
115+
public function handle(Request $request, Closure $next)
116+
{
117+
if ($this->isUnsupportedBrowser) {
118+
if ($this->currentPage != $this->routeUnsupportedBrowser) {
119+
return redirect($this->routeUnsupportedBrowser);
120+
}
121+
} else {
122+
if ($this->currentPage == $this->routeUnsupportedBrowser) {
123+
return redirect($this->routeSupportedBrowser);
124+
}
125+
}
126+
127+
return $next($request);
128+
}
129+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
namespace TiBian\BrowserRequirement;
4+
5+
use Illuminate\Routing\Router;
6+
use Illuminate\Support\ServiceProvider;
7+
8+
/**
9+
* Class BrowserRequirementServiceProvider
10+
*
11+
* @package TiBian\BrowserRequirement
12+
*/
13+
class BrowserRequirementServiceProvider extends ServiceProvider
14+
{
15+
/**
16+
* Bootstrap the application services.
17+
*
18+
* @return void
19+
*/
20+
public function boot(Router $router)
21+
{
22+
$this->publishes([
23+
__DIR__.'/../config/browser.php' => config_path('browser.php'),
24+
], 'config');
25+
26+
$router->prependMiddlewareToGroup('web', BrowserRequirement::class);
27+
}
28+
29+
/**
30+
* Register the application services.
31+
*
32+
* @return void
33+
*/
34+
public function register()
35+
{
36+
$this->mergeConfigFrom(__DIR__.'/../config/browser.php', 'browser');
37+
}
38+
}

0 commit comments

Comments
 (0)