Repo for the search and displace core module including the interface to select files and search and displace operations to run on them. https://searchanddisplace.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

59 lines
1.3 KiB

<?php
namespace App\SearchDisplace\Searchers;
use Illuminate\Support\Facades\Storage;
class SearchersStorage
{
protected $storage;
protected $searchers = [];
public function __construct()
{
$this->storage = Storage::disk('local');
}
public function all()
{
$searchers = [];
$files = $this->storage->files('searchers');
foreach ($files as $file) {
if (pathinfo($file, PATHINFO_EXTENSION) === 'json') {
$fileName = pathinfo($file, PATHINFO_FILENAME);
$result = explode('_', $fileName);
if (count($result) === 2) {
$searchers[$fileName] = [
'id' => $fileName,
'name' => $result[1],
];
}
}
}
return $searchers;
}
public function has($id)
{
return $this->storage->exists("searchers/$id.json");
}
public function get($id)
{
$contents = $this->storage->get("searchers/$id.json");
return json_decode($contents, true);
}
public function destroy($id)
{
if ( ! $this->has($id)) {
return false;
}
return $this->storage->delete("searchers/$id.json");
}
}