From 689d9804c042d8a03cb06a40036778481bfac484 Mon Sep 17 00:00:00 2001 From: Tom Lingham Date: Thu, 19 Feb 2015 00:17:57 +1100 Subject: [PATCH] Updating the plugin to restore functionality with Laravel 5. Tomorrow... decoupling. --- src/TomLingham/Searchy/SearchBuilder.php | 16 +++++++++++----- .../Searchy/SearchDrivers/BaseSearchDriver.php | 21 +++++++++++++-------- src/TomLingham/Searchy/SearchyServiceProvider.php | 9 ++++++--- 3 files changed, 30 insertions(+), 16 deletions(-) diff --git a/src/TomLingham/Searchy/SearchBuilder.php b/src/TomLingham/Searchy/SearchBuilder.php index 815d086..2bc66e1 100755 --- a/src/TomLingham/Searchy/SearchBuilder.php +++ b/src/TomLingham/Searchy/SearchBuilder.php @@ -1,6 +1,6 @@ config = $config; + } + /** * @param $table * @return $this @@ -84,13 +92,11 @@ class SearchBuilder { if ( $this->driverName ){ $driverName = $this->driverName; } else { - $driverName = Config::get('searchy::default'); + $driverName = $this->config->get('searchy.default'); } - // Gets the details for the selected driver from the configuration file - $driverMap = Config::get("searchy::drivers.$driverName"); - + $driverMap = $this->config->get("searchy.drivers.$driverName"); // Create a new instance of the selected drivers 'class' and pass // through table and fields to search diff --git a/src/TomLingham/Searchy/SearchDrivers/BaseSearchDriver.php b/src/TomLingham/Searchy/SearchDrivers/BaseSearchDriver.php index 414c823..7e4f650 100755 --- a/src/TomLingham/Searchy/SearchDrivers/BaseSearchDriver.php +++ b/src/TomLingham/Searchy/SearchDrivers/BaseSearchDriver.php @@ -23,32 +23,37 @@ abstract class BaseSearchDriver implements SearchDriverInterface { */ protected $table; + protected $columns; + /** * @param null $table * @param array $searchFields + * @param array $columns */ - public function __construct( $table = null, $searchFields = [] ) + public function __construct( $table = null, $searchFields = [], $columns = ['*'] ) { $this->searchFields = $searchFields; $this->table = $table; + $this->columns = $columns; } /** * @param $searchString * @return \Illuminate\Database\Query\Builder|mixed|static - * @throws \Whoops\Example\Exception */ public function query( $searchString ) { - if(\Config::get('searchy::sanitize')) + if(\Config::get('searchy.sanitize')) $this->searchString = $this->sanitize($searchString); $results = \DB::table($this->table) - ->select('*') + ->select( implode($this->columns, ', ') ) ->addSelect($this->buildSelectQuery( $this->searchFields )) - ->orderBy(\Config::get('searchy::fieldName'), 'desc') - ->having(\Config::get('searchy::fieldName'),'>', 0); + ->orderBy(\Config::get('searchy.fieldName'), 'desc') + ->having(\Config::get('searchy.fieldName'),'>', 0); + + die($results->toSQL()); return $results; } @@ -71,7 +76,7 @@ abstract class BaseSearchDriver implements SearchDriverInterface { } } - return \DB::raw(implode(' + ', $query) . ' AS ' . \Config::get('searchy::fieldName')); + return \DB::raw(implode(' + ', $query) . ' AS ' . \Config::get('searchy.fieldName')); } @@ -113,7 +118,7 @@ abstract class BaseSearchDriver implements SearchDriverInterface { */ private function sanitize( $searchString ) { - return preg_replace(\Config::get('searchy::sanitizeRegEx'), '', $searchString ); + return preg_replace(\Config::get('searchy.sanitizeRegEx'), '', $searchString ); } } \ No newline at end of file diff --git a/src/TomLingham/Searchy/SearchyServiceProvider.php b/src/TomLingham/Searchy/SearchyServiceProvider.php index 249b913..11b92ef 100755 --- a/src/TomLingham/Searchy/SearchyServiceProvider.php +++ b/src/TomLingham/Searchy/SearchyServiceProvider.php @@ -1,5 +1,6 @@ app->bindShared('searchy', function($app) + $this->app->bindShared('searchy', function( $app ) { - return new SearchBuilder(); + return new SearchBuilder( $app['config'] ); }); } @@ -29,7 +30,9 @@ class SearchyServiceProvider extends ServiceProvider { */ public function boot() { - $this->package('tom-lingham/searchy'); + $this->publishes([ + __DIR__.'/../../config/config.php' => config_path('searchy.php'), + ]); } /**