This commit is contained in:
salam committed 2025-12-05 07:00:25 +01:00
1 parent 7abcc5c56c
commit 90bba45c0a
26 files changed
+3448 -32353

No files matched your search

+76
View File
@@ -0,0 +1,76 @@
<?php
namespace App\Console\Commands;
use App\Utilities\Notice;
class Xml
{
public static $file;
public static function load($url)
{
$debug = NuhBash::$options['d'] ?? 0;
$save = NuhBash::$options['s'] ?? 0;
$read = NuhBash::$options['r'] ?? 0;
$filename = app_path().'/Console/Commands/TestFiles/'.strtolower(str_replace(' ', '_', NuhBash::$options['name'])).'.xml';
if ($debug) {
Notice::note("Loading URL\n".$url);
}
if ($save || $read) {
Notice::note("FILE NAME\n".$filename);
}
if ($read) {
if ($debug) {
Notice::note('READ LOCAL', 'r');
}
// return simplexml_load_file(self::$file, null, LIBXML_NOCDATA);
if (! file_exists($filename)) {
Notice::note("Error: File $filename does not exist.", 'r', 1);
} elseif (! is_readable($filename)) {
Notice::note("Error: File $filename is not readable.", 'r', 1);
} else {
$data = simplexml_load_file($url, 'SimpleXMLElement', LIBXML_NOCDATA);
if ($data === false) {
Notice::note("Error: Failed to load XML from $filename", 'r', 1);
foreach (libxml_get_errors() as $error) {
Notice::note("XML Error: {$error->message}\n", 'r');
}
} else {
// Process the XML object
return $data;
}
}
}
$data = simplexml_load_file($url, 'SimpleXMLElement', LIBXML_NOCDATA);
if ($data === false && $debug) {
Notice::note("Error: Failed to load XML from $url", 'r', 1);
foreach (libxml_get_errors() as $error) {
Notice::note("XML Error: {$error->message}\n", 'r');
}
}
if ($save) {
if (! file_exists($filename)) {
Notice::note("Error: File $filename does not exist.", 'r', 1);
} elseif (! is_readable($filename)) {
Notice::note("Error: File $filename is not readable.", 'r', 1);
} elseif (! is_writable($filename)) {
Notice::note("Error: File $filename is not writable.", 'r', 1);
} else {
$data->asXml($filename);
Notice::note('SAVED AND EXIT', 'b', 1);
}
}
return $data;
}
}