diff --git a/.gitignore b/.gitignore index d750889..bd9cdb9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ -/.idea/ -*.txt +/.idea +/vendor +*.lock *.DS_Store .Spotlight-V100 -.Trashes +.Trashes \ No newline at end of file diff --git a/composer.json b/composer.json index 7ba1643..a2d0c9e 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,8 @@ } ], "require": { - "sinergi/browser-detector": "^6.0" + "php": ">=5.5.9", + "sinergi/browser-detector": "^6.1" }, "autoload": { "psr-4": { diff --git a/config/browser.php b/config/browser.php index 42474bf..594a098 100644 --- a/config/browser.php +++ b/config/browser.php @@ -1,7 +1,7 @@ Let set-up minimum Browser Requirement for OS X and Windows... -``` +```php Os::OSX => [ Browser::CHROME => 25, Browser::FIREFOX => 25, @@ -41,22 +46,16 @@ Os::WINDOWS => [ ### Routes This is a Example from the Routes you need, you are free to customize the Routes like you wish. -``` +```php Route::get("requirement-browser", "ErrorsController@browser") ->name('requirement::browser'); ``` -``` +```php Route::get("/", "PagesController@index") ->name('home'); ``` -### I'm looking for: -- Individuals who can contribute to the Documentation. -- Participation in other Open Source Projects. - -> Visit my Web Site and learn more [about me](https://tibian.me) - ##### Any idea for new projects, feel free to Contact me. ##### Thank you for visiting my Repository. diff --git a/src/BrowserRequirement.php b/src/BrowserRequirement.php index 3277651..9a3b032 100644 --- a/src/BrowserRequirement.php +++ b/src/BrowserRequirement.php @@ -50,24 +50,20 @@ class BrowserRequirement protected $isUnsupportedBrowser; /** - * OS Object - * - * @var object Os + * @var \Sinergi\BrowserDetector\Os */ protected $os; /** - * Browser Object - * - * @var object Browser + * @var \Sinergi\BrowserDetector\Browser */ protected $browser; /** * BrowserRequirement constructor. * - * @param Browser $browser - * @param Os $os + * @param \Sinergi\BrowserDetector\Browser $browser + * @param \Sinergi\BrowserDetector\Os $os */ public function __construct(Browser $browser, Os $os) { @@ -83,14 +79,34 @@ public function __construct(Browser $browser, Os $os) } /** - * Determine if the Browser is Unsupported + * Handle an incoming request. * + * @param \Illuminate\Http\Request $request + * @param \Closure $next + * + * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector + */ + public function handle(Request $request, Closure $next) + { + if ($this->isUnsupportedBrowser) { + if (! $this->isUnsupportedPage()) { + return redirect($this->routeUnsupportedBrowser); + } + } else { + if ($this->isUnsupportedPage()) { + return redirect($this->routeSupportedBrowser); + } + } + + return $next($request); + } + + /** * @return bool */ - private function isUnsupportedBrowser() + protected function isUnsupportedBrowser() { if (array_key_exists($this->os->getName(), $this->supportedVersions)) { - $browsers = $this->supportedVersions[$this->os->getName()]; foreach ($browsers as $browser => $version) { @@ -106,24 +122,10 @@ private function isUnsupportedBrowser() } /** - * Handle an incoming request. - * - * @param \Illuminate\Http\Request $request - * @param \Closure $next - * @return mixed + * @return bool */ - public function handle(Request $request, Closure $next) + protected function isUnsupportedPage() { - if ($this->isUnsupportedBrowser) { - if ($this->currentPage != $this->routeUnsupportedBrowser) { - return redirect($this->routeUnsupportedBrowser); - } - } else { - if ($this->currentPage == $this->routeUnsupportedBrowser) { - return redirect($this->routeSupportedBrowser); - } - } - - return $next($request); + return $this->currentPage == $this->routeUnsupportedBrowser; } } diff --git a/src/BrowserRequirementServiceProvider.php b/src/BrowserRequirementServiceProvider.php index 0f09597..062695d 100644 --- a/src/BrowserRequirementServiceProvider.php +++ b/src/BrowserRequirementServiceProvider.php @@ -15,7 +15,7 @@ class BrowserRequirementServiceProvider extends ServiceProvider /** * Bootstrap the application services. * - * @return void + * @param \Illuminate\Routing\Router $router */ public function boot(Router $router) { @@ -28,8 +28,6 @@ public function boot(Router $router) /** * Register the application services. - * - * @return void */ public function register() {