Introduce Composer

This commit is contained in:
Ramon Caballero 2026-04-05 18:53:09 +01:00
parent ef51985bf0
commit 7cd237485a
9 changed files with 68 additions and 11 deletions

3
.gitignore vendored
View File

@ -1,3 +1,6 @@
# Config files: # Config files:
/config/*.json /config/*.json
!/config/pb-dydns.example.json !/config/pb-dydns.example.json
# Composer files:
/vendor/

View File

@ -1,13 +1,14 @@
#!/usr/bin/env php #!/usr/bin/env php
<?php <?php
require __DIR__ . "/PorkbunAPI.php"; require __DIR__ . '/../vendor/autoload.php';
require __DIR__ . "/Config.php";
require __DIR__ . "/Logger.php";
require __DIR__ . "/UpdateDnsCommand.php";
$config = new Config(__DIR__ . "/pb-dydns.json"); use App\Config\Config;
$logger = new Logger(__DIR__ . "/pb-dydns.log"); use App\Util\Logger;
use App\Command\UpdateDnsCommand;
$config = new Config(__DIR__ . "/../config/pb-dydns.json");
$logger = new Logger(__DIR__ . "/../logs/pb-dydns.log");
$cmd = new UpdateDnsCommand($config, $logger); $cmd = new UpdateDnsCommand($config, $logger);
$cmd->run($argv); $cmd->run($argv);

13
composer.json Normal file
View File

@ -0,0 +1,13 @@
{
"name": "ramoncaballero.dev/pb-dydns",
"description": "Dynamic DNS updater for Porkbun",
"type": "project",
"autoload":
{
"psr-4":
{
"App\\": "src/"
}
},
"require": {}
}

18
composer.lock generated Normal file
View File

@ -0,0 +1,18 @@
{
"_readme": [
"This file locks the dependencies of your project to a known state",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "9462733d0fea3fd21d03aa382b606406",
"packages": [],
"packages-dev": [],
"aliases": [],
"minimum-stability": "stable",
"stability-flags": {},
"prefer-stable": false,
"prefer-lowest": false,
"platform": {},
"platform-dev": {},
"plugin-api-version": "2.6.0"
}

View File

@ -1,5 +1,10 @@
<?php <?php
namespace App\Api;
use stdClass;
use App\Util\Console;
// //
// Wrapper class to communicate with Porkbun API. // Wrapper class to communicate with Porkbun API.
// //

View File

@ -1,9 +1,11 @@
<?php <?php
require_once __DIR__ . '/../Api/PorkbunAPI.php'; namespace App\Command;
require_once __DIR__ . '/../Config/Config.php';
require_once __DIR__ . '/../Util/Logger.php'; use App\Api\PorkbunAPI;
require_once __DIR__ . '/../Util/Console.php'; use App\Config\Config;
use App\Util\Logger;
use App\Util\Console;
class UpdateDnsCommand class UpdateDnsCommand
{ {
@ -78,9 +80,14 @@ class UpdateDnsCommand
if ($record->content != $myIp) if ($record->content != $myIp)
{ {
Console::echo("Let's change that... "); Console::echo("Let's change that... ");
$name = rtrim(strstr($record->name, $domain, true), "."); $name = rtrim(strstr($record->name, $domain, true), ".");
$result = json_decode($api->edit($domain, $record->id, $myIp, $name)); $result = json_decode($api->edit($domain, $record->id, $myIp, $name));
if ($result->status == "SUCCESS") Console::echo("Done!" . PHP_EOL);
if ($result->status == "SUCCESS")
{
Console::echo("Done!" . PHP_EOL);
}
$this->logger->log("Updated DNS on $record->name from $record->content to $myIp"); $this->logger->log("Updated DNS on $record->name from $record->content to $myIp");
} }
@ -89,6 +96,8 @@ class UpdateDnsCommand
{ {
Console::echo("Nothing needs to be changed!" . PHP_EOL); Console::echo("Nothing needs to be changed!" . PHP_EOL);
} }
Console::echo("");
} }
} }
} }

View File

@ -1,5 +1,9 @@
<?php <?php
namespace App\Config;
use RuntimeException;
class Config class Config
{ {
private array $data; private array $data;

View File

@ -1,5 +1,7 @@
<?php <?php
namespace App\Util;
class Console class Console
{ {
public static function echo(string $message): void public static function echo(string $message): void

View File

@ -1,5 +1,7 @@
<?php <?php
namespace App\Util;
class Logger class Logger
{ {
private string $filename; private string $filename;