Skip to content

Instantly share code, notes, and snippets.

@sirawitpra
Last active July 3, 2017 11:51
Show Gist options
  • Save sirawitpra/136a074b5ace8a760e45b3a17371fce3 to your computer and use it in GitHub Desktop.
Save sirawitpra/136a074b5ace8a760e45b3a17371fce3 to your computer and use it in GitHub Desktop.
<?php
class Search
{
private $updateStart;
private $updateEnd;
private $entryCompleted;
public function onUpdateStart(callable $callable)
{
$this->updateStart = $callable;
return $this;
}
public function onUpdateEnd(callable $callable)
{
$this->updateEnd = $callable;
return $this;
}
public function onEachEntryCompleted(callable $callable)
{
$this->entryCompleted = $callable;
return $this;
}
public function update()
{
$entries = Entry::all();
($this->updateStart)($entries->count());
foreach ($entries as $id => $entry) {
$this->index->insert($id, $entry);
($this->entryCompleted)();
}
($this->updateEnd)();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment