From 28b0e04bb26c32905164f61a05281b3f2b72f588 Mon Sep 17 00:00:00 2001 From: Tom Lingham Date: Wed, 23 Dec 2015 11:24:22 +0000 Subject: [PATCH] Formatting changes and updating class references from strings to use php ::class const --- src/SearchDrivers/BaseSearchDriver.php | 5 +++++ src/SearchDrivers/FuzzySearchDriver.php | 18 +++++++++--------- src/SearchDrivers/LevenshteinSearchDriver.php | 2 +- src/SearchDrivers/SimpleSearchDriver.php | 6 +++--- src/SearchyServiceProvider.php | 18 +++++++++++++++--- 5 files changed, 33 insertions(+), 16 deletions(-) diff --git a/src/SearchDrivers/BaseSearchDriver.php b/src/SearchDrivers/BaseSearchDriver.php index 32a6d64..2c96b75 100755 --- a/src/SearchDrivers/BaseSearchDriver.php +++ b/src/SearchDrivers/BaseSearchDriver.php @@ -7,10 +7,15 @@ use TomLingham\Searchy\Interfaces\SearchDriverInterface; abstract class BaseSearchDriver implements SearchDriverInterface { protected $table; + protected $columns; + protected $searchFields; + protected $searchString; + protected $relevanceFieldName; + protected $query; /** diff --git a/src/SearchDrivers/FuzzySearchDriver.php b/src/SearchDrivers/FuzzySearchDriver.php index bc61c9e..16c14f2 100755 --- a/src/SearchDrivers/FuzzySearchDriver.php +++ b/src/SearchDrivers/FuzzySearchDriver.php @@ -8,13 +8,13 @@ class FuzzySearchDriver extends BaseSearchDriver * @var array */ protected $matchers = [ - 'TomLingham\Searchy\Matchers\ExactMatcher' => 100, - 'TomLingham\Searchy\Matchers\StartOfStringMatcher' => 50, - 'TomLingham\Searchy\Matchers\AcronymMatcher' => 42, - 'TomLingham\Searchy\Matchers\ConsecutiveCharactersMatcher' => 40, - 'TomLingham\Searchy\Matchers\StartOfWordsMatcher' => 35, - 'TomLingham\Searchy\Matchers\StudlyCaseMatcher' => 32, - 'TomLingham\Searchy\Matchers\InStringMatcher' => 30, - 'TomLingham\Searchy\Matchers\TimesInStringMatcher' => 8, - ]; + \TomLingham\Searchy\Matchers\ExactMatcher::class => 100, + \TomLingham\Searchy\Matchers\StartOfStringMatcher::class => 50, + \TomLingham\Searchy\Matchers\AcronymMatcher::class => 42, + \TomLingham\Searchy\Matchers\ConsecutiveCharactersMatcher::class => 40, + \TomLingham\Searchy\Matchers\StartOfWordsMatcher::class => 35, + \TomLingham\Searchy\Matchers\StudlyCaseMatcher::class => 32, + \TomLingham\Searchy\Matchers\InStringMatcher::class => 30, + \TomLingham\Searchy\Matchers\TimesInStringMatcher::class => 8, +]; } diff --git a/src/SearchDrivers/LevenshteinSearchDriver.php b/src/SearchDrivers/LevenshteinSearchDriver.php index a90ff46..3e50946 100755 --- a/src/SearchDrivers/LevenshteinSearchDriver.php +++ b/src/SearchDrivers/LevenshteinSearchDriver.php @@ -8,6 +8,6 @@ class LevenshteinSearchDriver extends BaseSearchDriver * @var array */ protected $matchers = [ - 'TomLingham\Searchy\Matchers\LevenshteinMatcher' => 100, + \TomLingham\Searchy\Matchers\LevenshteinMatcher::class => 100, ]; } diff --git a/src/SearchDrivers/SimpleSearchDriver.php b/src/SearchDrivers/SimpleSearchDriver.php index b0c762f..b18770c 100755 --- a/src/SearchDrivers/SimpleSearchDriver.php +++ b/src/SearchDrivers/SimpleSearchDriver.php @@ -8,8 +8,8 @@ class SimpleSearchDriver extends BaseSearchDriver * @var array */ protected $matchers = [ - 'TomLingham\Searchy\Matchers\ExactMatcher' => 100, - 'TomLingham\Searchy\Matchers\StartOfStringMatcher' => 50, - 'TomLingham\Searchy\Matchers\InStringMatcher' => 30, + \TomLingham\Searchy\Matchers\ExactMatcher::class => 100, + \TomLingham\Searchy\Matchers\StartOfStringMatcher::class => 50, + \TomLingham\Searchy\Matchers\InStringMatcher::class => 30, ]; } diff --git a/src/SearchyServiceProvider.php b/src/SearchyServiceProvider.php index 3c68713..b2fb6cc 100755 --- a/src/SearchyServiceProvider.php +++ b/src/SearchyServiceProvider.php @@ -26,9 +26,21 @@ class SearchyServiceProvider extends ServiceProvider */ public function registerSearchy() { - $this->app->bindShared('searchy', function ($app) { - return new SearchBuilder($app['config']); - }); + // Laravel <= 5.1 + $closure = function ($app) { + return new SearchBuilder( $app['config'] ); + }; + + + if ( method_exists($this->app, 'bindShared') ) + { + $this->app->bindShared('searchy', $closure); + } + + // Laravel 5.2 Goodness :) + else { + $this->app->singleton('searchy', $closure); + } } /**