1. Go to this page and download the library: Download rayfunghk/razy library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
rayfunghk / razy example snippets
return [
'domains' => [
'example.com' => [
'/' => 'mysite@v2', // standard mapping with tag
],
],
];
return new class extends Controller {
public function __onInit(Agent $agent): bool
{
// Register routes, APIs, events, scripts
$agent->addLazyRoute(['dashboard' => 'dashboard']);
$agent->addAPICommand('getUser', 'api/get_user.php');
$agent->listen('auth/user:onLogin', 'onUserLogin');
return true;
}
public function __onReady(): bool
{
// Safe to call APIs here — all modules are loaded
return true;
}
};
use Razy\PackageManager;
use Razy\PackageManager\FtpTransport;
PackageManager::setDefaultTransport(new FtpTransport(
host: 'mirror.internal',
username: 'deploy',
password: 'secret',
basePath: '/composer',
));
class MyController extends Controller
{
use PackageTrait;
public function __onPackageStart(array $packageInfo): bool
{
// Register package API for co-modules to call
$this->registerPackageAPI('greet', fn(string $name) => "Hello, {$name}!");
// Subscribe to package events
$this->onPackageEvent('data:ready', fn(array $data) => $this->processData($data));
return true; // false aborts execution
}
public function __onPackageExec(array $packageInfo): int
{
// Core logic — return value is the process exit code
$this->emitPackageEvent('data:ready', ['key' => 'value']);
return 0;
}
public function __onPackageServe(array $packageInfo): void
{
// Long-running — start HTTP server, event loop, etc.
// This method should BLOCK until shutdown.
}
public function __onPackageStop(): void
{
// Cleanup: close connections, flush buffers
}
public function __onPackageHealthcheck(): bool
{
return true; // healthy
}
}
// Package A: register an API action
$this->registerPackageAPI('transform', fn($input) => strtoupper($input));
// Package B: call it
$result = $this->callPackageAPI('vendor/a', 'transform', 'hello'); // "HELLO"
// Events: pub/sub between packages
$this->onPackageEvent('config:changed', fn($data) => $this->reload($data));
$this->emitPackageEvent('config:changed', ['key' => 'timeout']);
public function __onInit(Agent $agent): bool
{
if (defined('RAZY_PACKAGE_MODE')) {
// Running as a standalone package
return true;
}
// Normal web mode — register routes, APIs, etc.
$agent->addLazyRoute(['dashboard' => 'dashboard']);
return true;
}
bash
git clone https://github.com/RayFungHK/Razy.git
cd Razy
composer install
php build.php
bash
# Build the Razy environment
php Razy.phar build
# Create a distributor
php Razy.phar init dist mysite
# Generate rewrite rules
php Razy.phar rewrite mysite