Skip to content
This repository has been archived by the owner on Nov 4, 2021. It is now read-only.

lumen support #339

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions src/ScoutElasticServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Elasticsearch\ClientBuilder;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Str;
use InvalidArgumentException;
use Laravel\Scout\EngineManager;
use ScoutElastic\Console\ElasticIndexCreateCommand;
Expand All @@ -25,16 +26,20 @@ class ScoutElasticServiceProvider extends ServiceProvider
*/
public function boot()
{
$this->publishes([
__DIR__.'/../config/scout_elastic.php' => config_path('scout_elastic.php'),
]);
if (! $this->isLumen()) {
$this->publishes([
__DIR__.'/../config/scout_elastic.php' => config_path('scout_elastic.php'),
]);

$this->commands([
// make commands
IndexConfiguratorMakeCommand::class,
SearchableModelMakeCommand::class,
SearchRuleMakeCommand::class,
$this->commands([
// make commands
IndexConfiguratorMakeCommand::class,
SearchableModelMakeCommand::class,
SearchRuleMakeCommand::class,
]);
}

$this->commands([
// elastic commands
ElasticIndexCreateCommand::class,
ElasticIndexUpdateCommand::class,
Expand Down Expand Up @@ -78,4 +83,9 @@ public function register()
return ClientBuilder::fromConfig($config);
});
}

protected function isLumen()
{
return Str::contains($this->app->version(), 'Lumen');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, change this check to:

return $this->app() instanceof Laravel\Lumen\Application;

Because it's a lot faster then check the string (yeah, I'm crazy):

Benchmark for 9999999 repeations:

  • Laravel - using Str::contains(): 6.24s (436% slower)
  • Laravel - using instanceof: 1.43s
  • Lumen - using Str::contains(): 4.85s (664% slower)
  • Lumen - using instanceof: 0.73s

}
}