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.
 
 
 
 
 
 

77 lines
1.9 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) {
continue;
}
$contents = json_decode($this->storage->get($file), true);
$description = $contents['description'];
$searchers[$fileName] = [
'id' => $fileName,
'name' => $result[1],
'description' => $description,
'tag' => '',
'param' => SearchersCollection::PARAM_REQUIRED,
];
if (count($result) === 3) {
$searchers[$fileName]['tag'] = $result[2];
// $searchers[$fileName]['param'] = SearchersCollection::PARAM_REQUIRED;
}
// if (count($result) === 3) {
// $searchers[$fileName]['param'] = $result[2];
// }
}
}
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");
}
}