-
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added PHP equivalents for Python dependencie
- Loading branch information
1 parent
ac56520
commit 5181fb3
Showing
1 changed file
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
namespace Dna\Snps\IO; | ||
|
||
use Exception; | ||
use GuzzleHttp\Client; | ||
|
||
class FileHandler | ||
{ | ||
public static function writeFile(string $path, string $content): void | ||
{ | ||
$file = fopen($path, 'w'); | ||
fwrite($file, $content); | ||
fclose($file); | ||
} | ||
} | ||
|
||
class DataManipulator | ||
{ | ||
public static function filterArray(array $data, callable $callback): array | ||
{ | ||
return array_filter($data, $callback, ARRAY_FILTER_USE_BOTH); | ||
} | ||
|
||
public static function sortArray(array &$data, callable $callback): void | ||
{ | ||
usort($data, $callback); | ||
} | ||
} | ||
|
||
class ExternalDataFetcher | ||
{ | ||
private Client $client; | ||
|
||
public function __construct() | ||
{ | ||
$this->client = new Client(); | ||
} | ||
|
||
public function fetchData(string $url): ?array | ||
{ | ||
try { | ||
$response = $this->client->request('GET', $url); | ||
if ($response->getStatusCode() === 200) { | ||
return json_decode($response->getBody()->getContents(), true); | ||
} | ||
return null; | ||
} catch (Exception $e) { | ||
error_log("Failed to fetch data from {$url}: " . $e->getMessage()); | ||
return null; | ||
} | ||
} | ||
} |