Browse Source

Updating the plugin to restore functionality with Laravel 5. Tomorrow... decoupling.

master
Tom Lingham 10 years ago
parent
commit
689d9804c0
  1. 16
      src/TomLingham/Searchy/SearchBuilder.php
  2. 21
      src/TomLingham/Searchy/SearchDrivers/BaseSearchDriver.php
  3. 7
      src/TomLingham/Searchy/SearchyServiceProvider.php

16
src/TomLingham/Searchy/SearchBuilder.php

@ -1,6 +1,6 @@
<?php namespace TomLingham\Searchy;
use Illuminate\Support\Facades\Config;
use Illuminate\Config\Repository;
use TomLingham\Searchy\SearchDrivers\FuzzySearchDriver;
@ -25,6 +25,14 @@ class SearchBuilder {
*/
private $driverName;
private $config;
public function __construct( Repository $config )
{
$this->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

21
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 );
}
}

7
src/TomLingham/Searchy/SearchyServiceProvider.php

@ -1,5 +1,6 @@
<?php namespace TomLingham\Searchy;
use Illuminate\Config\Repository;
use Illuminate\Support\ServiceProvider;
class SearchyServiceProvider extends ServiceProvider {
@ -20,7 +21,7 @@ class SearchyServiceProvider extends ServiceProvider {
{
$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'),
]);
}
/**

Loading…
Cancel
Save