PHP code example of monkeyscloud / monkeyslegion-cli
1. Go to this page and download the library: Download monkeyscloud/monkeyslegion-cli 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/ */
monkeyscloud / monkeyslegion-cli example snippets
declare(strict_types=1);
namespace App\Entity;
use MonkeysLegion\Entity\Attributes\Entity;
use MonkeysLegion\Entity\Attributes\Field;
use MonkeysLegion\Entity\Attributes\Id;
#[Entity]
class Product
{
#[Id]
#[Field(type: 'unsignedBigInt', autoIncrement: true)]
public private(set) int $id;
#[Field(type: 'string')]
public string $name;
#[Field(type: 'decimal', nullable: true)]
public ?float $price = null;
#[Field(type: 'string')]
public string $sku;
#[Field(type: 'boolean')]
public bool $active;
}
declare(strict_types=1);
namespace App\Command;
use MonkeysLegion\Cli\Console\Attributes\Command as CommandAttr;
use MonkeysLegion\Cli\Console\Command;
#[CommandAttr('app:sync', 'Sync data from external API', aliases: ['sync'])]
final class SyncCommand extends Command
{
public function __construct(
private readonly ApiClient $client,
) {
parent::__construct();
}
protected function handle(): int
{
$count = $this->option('limit', 100);
$force = $this->hasOption('force');
$this->info("Syncing {$count} records...");
$result = $this->spinner('Fetching data...', function () use ($count) {
return $this->client->fetch((int) $count);
});
$this->table(
['ID', 'Name', 'Status'],
array_map(fn($r) => [$r->id, $r->name, $r->status], $result),
);
$this->info("✅ Synced " . count($result) . " records.");
return self::SUCCESS;
}
}
// Progress bar with ETA
$this->progressStart(1000, 'Migrating');
// → [████████████░░░░░░░░░░░░░░░░░░] 40% 400/1000 ETA 0:02
// Spinner for indeterminate operations
$result = $this->spinner('Analyzing schema...', fn() => $scanner->scan());
// → ⠙ Analyzing schema...
// → ✓ Analyzing schema
bash
php ml make:entity User
bash
# With argument
php ml make:service UserService
# Interactive (no argument)
php ml make:service
# → prompts for name
# Force overwrite
php ml make:service UserService --force
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.