A PSR-compliant client for interacting with the MyOwnFreeHost (MOFH) API. This library provides a structured, type-safe way to manage hosting accounts, domains, and support tickets.
- PSR-18 Compliant: Use any compatible HTTP client (Guzzle, Symfony, etc.).
- PSR-17 Compliant: Decoupled request factories.
- PSR-3 Logging: Built-in support for logging request/response cycles.
- Domain Driven Design: Separated repositories for Accounts, Domains, Support, and System.
- Strictly Typed: Utilizes DTOs (Data Transfer Objects) for all API interactions.
You can install the package via Composer:
composer require fyennyi/mofh-api-clientuse Fyennyi\MofhApi\Client;
use Fyennyi\MofhApi\Connection;
use GuzzleHttp\Client as GuzzleClient;
use GuzzleHttp\Psr7\HttpFactory;
// Initialize dependencies
$httpClient = new GuzzleClient(['verify' => false]); // MOFH certificates are often expired
$requestFactory = new HttpFactory();
$connection = new Connection('your_api_username', 'your_api_password');
// Create the client
$mofh = new Client($connection, $httpClient, $requestFactory);use Fyennyi\MofhApi\Dto\Account\CreateAccountRequest;
use Fyennyi\MofhApi\Dto\Support\TicketReply;
// Create a new hosting account
try {
$request = new CreateAccountRequest(
username: 'exampleuser',
password: 'secure_password',
contactEmail: '[email protected]',
domain: 'user.yourdomain.com',
plan: 'MyPlan'
);
$response = $mofh->account->create($request);
echo "Account created: " . $response->vPanelUsername;
} catch (\Exception $e) {
echo "Error: " . $e->getMessage();
}
// Support System: Create and Reply to tickets
$ticketId = $mofh->support->createTicket('hname_1234', 'Issue', 'Text', 'domain.com');
$mofh->support->reply(new TicketReply($ticketId, 'My response message'));
// Suspend an account
$mofh->account->suspend('hname_12345678', 'Policy violation.');// Check if a domain is available
$isAvailable = $mofh->domain->checkAvailability('test.example.com');
// Get account info by domain name
$userData = $mofh->domain->getUserByDomain('test.example.com');
// Get CNAME validation token (MD5)
$token = $mofh->system->getCnameToken('my-new-site.com');
// List available hosting packages
$packages = $mofh->system->getPackages();
foreach ($packages as $package) {
echo "Plan: {$package->name} | Quota: {$package->diskQuota}MB\n";
}The library throws Fyennyi\MofhApi\Exception\MofhException for API-level errors or transport issues.
try {
$mofh->account->remove('hname_12345678');
} catch (\Fyennyi\MofhApi\Exception\MofhException $e) {
// Handle specific API error
}- PHP 8.1 or higher.
ext-jsonandext-simplexmlextensions.
Contributions are welcome and appreciated! Here's how you can contribute:
- Fork the project
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
Please make sure to update tests as appropriate and adhere to the existing coding style.
This library is licensed under the CSSM Unlimited License v2.0 (CSSM-ULv2). See the LICENSE file for details.