MonkeysLegion\Template\MLView
Blade-like template engine with components, streaming, and PSR-16 caching.
| Method | Signature | Returns | Description |
|---|
render() | (string $name, array $data = []) | string | Render template to HTML |
make() | (string $name, array $data = []) | ViewData | Deferred rendering object |
renderString() | (string $template, array $data = []) | string | Compile and render inline template |
stream() | (string $name, array $data = []) | Generator | Streaming render (chunks) |
test() | (string $name, array $data = []) | TestView | Testing entry point |
| Method | Signature | Description |
|---|
share() | (string $key, mixed $value): void | Share data across all views |
getShared() | (): array | Get all shared data |
| Method | Signature | Description |
|---|
composer() | (string|array $views, callable $cb): void | Register composer for view patterns |
rendering() | (callable $listener): void | Before-render listener |
rendered() | (callable $listener): void | After-render listener |
| Method | Signature | Description |
|---|
addDirective() | (string $name, callable $handler): void | Custom template directive |
addFilter() | (string $name, callable $handler): void | Custom output filter |
component() | (string $name, callable $fn): void | Register function component |
addNamespace() | (string $ns, string $hint): void | Register namespaced view path |
addViewPath() | (string $path): void | Add view search path |
prependViewPath() | (string $path): void | Prepend view search path |
setTheme() | (string $name, ?string $basePath): void | Activate theme |
clearCache() | (): void | Clear compiled template cache |
| Directive | Usage |
|---|
{{ $var }} | Escaped output (htmlspecialchars) |
{!! $html !!} | Raw HTML output |
@extends('layout') | Inherit from layout |
@section('name') ... @endsection | Define content section |
@yield('name', 'default') | Output section |
@if / @elseif / @else / @endif | Conditionals |
@foreach($items as $item) / @endforeach | Loop |
@for / @endfor | For loop |
@while / @endwhile | While loop |
@isset($var) / @endisset | Isset check |
@empty($var) / @endempty | Empty check |
@env('dev') / @endenv | Environment check |
@include('partial') | Include sub-template |
@push('scripts') / @endpush | Push to stack |
@stack('scripts') | Render stack |
@php / @endphp | Raw PHP block |
{{-- comment --}} | Template comment (stripped) |
<x-component prop="val" /> | Render component |
MonkeysLegion\Events\EventDispatcher implements Psr\EventDispatcher\EventDispatcherInterface
PSR-14 dispatcher with interceptor pipeline, metrics, and event store.
| Property | Type | Description |
|---|
$totalDispatches | int | Total dispatches counter (PHP 8.4 hook) |
| Param | Type | Description |
|---|
$provider | ListenerProvider | Listener provider |
$store | ?EventStoreInterface | Optional event store for recording |
$safeMode | bool | Catch listener exceptions (default: false) |
| Method | Signature | Returns | Description |
|---|
dispatch() | (object $event) | object | PSR-14 dispatch, returns event |
dispatchWithResult() | (object $event) | DispatchResult | Dispatch with full metrics |
dispatchBatch() | (array $events) | list<DispatchResult> | Dispatch multiple events |
addInterceptor() | (InterceptorInterface $i): void | — | Global interceptor |
getProvider() | () | ListenerProvider | Access listener provider |
| Attribute | Target | Description |
|---|
#[Listener(EventClass::class, priority: 10)] | Class/Method | Register listener |
#[Subscriber] | Class | Register event subscriber |
#[BeforeEvent(EventClass::class)] | Method | Before-event interceptor |
#[AfterEvent(EventClass::class)] | Method | After-event interceptor |
#[ListenWhen(method: 'shouldHandle')] | Method | Conditional listener |
| Interface | Description |
|---|
ShouldQueue | Dispatch listener via queue |
ShouldBroadcast | Broadcast event to WebSocket channels |
final readonly class DispatchResult {
public object $event;
public int $listenersInvoked;
public float $durationMs;
public bool $stopped;
public array $errors;
}
MonkeysLegion\Cache\CacheManager
PSR-16 compatible cache with multiple stores and tagged cache support.
| Method | Signature | Returns | Description |
|---|
get() | (string $key, mixed $default = null) | mixed | Retrieve cached value |
set() | (string $key, mixed $value, int|DateInterval $ttl = null) | bool | Store value |
has() | (string $key) | bool | Check key exists |
delete() | (string $key) | bool | Delete key |
clear() | () | bool | Clear entire cache |
getMultiple() | (iterable $keys, mixed $default = null) | iterable | Batch get |
setMultiple() | (iterable $values, int $ttl = null) | bool | Batch set |
deleteMultiple() | (iterable $keys) | bool | Batch delete |
tags() | (string|array $tags) | TaggedCache | Tagged cache instance |
store() | (string $name) | CacheStore | Access specific store |
remember() | (string $key, int $ttl, Closure $cb) | mixed | Get or compute and cache |
forget() | (string $key) | bool | Alias for delete() |
| Store | Config | Description |
|---|
FileStore | CACHE_DRIVER=file | Filesystem cache |
RedisStore | CACHE_DRIVER=redis | Redis cache |
MemcachedStore | CACHE_DRIVER=memcached | Memcached |
ArrayStore | — | In-memory (testing) |
MonkeysLegion\Mail\Mailer
Email sending with multiple transports and template support.
| Method | Signature | Returns | Description |
|---|
send() | (Mailable $mailable) | void | Send a mailable |
raw() | (string $text, Closure $cb) | void | Send raw text email |
to() | (string|array $address) | PendingMail | Set recipient |
queue() | (Mailable $mailable) | void | Queue for async sending |
$message = (new Message())
->from('noreply@example.com', 'App')
->to('user@example.com')
->cc('admin@example.com')
->bcc('archive@example.com')
->replyTo('support@example.com')
->subject('Welcome!')
->html('<h1>Hello</h1>')
->text('Hello')
->attach('/path/to/file.pdf')
->priority(1);
| Transport | Config | Description |
|---|
SmtpTransport | MAIL_DRIVER=smtp | SMTP delivery |
MailgunTransport | MAIL_DRIVER=mailgun | Mailgun API |
SendmailTransport | MAIL_DRIVER=sendmail | Local sendmail |
NullTransport | MAIL_DRIVER=null | Discard (testing) |
MonkeysMailTransport | MAIL_DRIVER=monkeysmail | MonkeysCloud service |
MonkeysLegion\Queue\Contracts\QueueInterface
Background job processing with multiple drivers.
| Method | Signature | Description |
|---|
dispatch() | (JobInterface $job): void | Push job to queue |
dispatchSync() | (JobInterface $job): void | Execute job immediately |
dispatchAfterResponse() | (JobInterface $job): void | Queue after HTTP response |
chain() | (array $jobs): PendingChain | Chain jobs sequentially |
interface JobInterface {
public function handle(): void;
public function failed(\Throwable $e): void;
public function tries(): int;
public function timeout(): int;
public function retryAfter(): int;
}
| Driver | Config | Description |
|---|
sync | QUEUE_CONNECTION=sync | Execute immediately (dev) |
database | QUEUE_CONNECTION=database | Database-backed queue |
redis | QUEUE_CONNECTION=redis | Redis-backed queue |
| Command | Description |
|---|
php vendor/bin/ml queue:work | Start queue worker |
php vendor/bin/ml queue:failed | List failed jobs |
php vendor/bin/ml queue:retry | Retry failed jobs |
php vendor/bin/ml queue:flush | Flush failed jobs |
php vendor/bin/ml queue:clear | Clear pending jobs |
php vendor/bin/ml queue:stats | Queue statistics |
MonkeysLegion\Schedule
Cron-based task scheduling.
$schedule->command('queue:work --stop-when-empty')->everyMinute();
$schedule->call(fn() => $this->cleanup())->daily()->at('03:00');
$schedule->job(new PruneExpiredTokens())->hourly();
| Method | Description |
|---|
everyMinute() | Run every minute |
everyFiveMinutes() | Run every 5 minutes |
everyFifteenMinutes() | Run every 15 minutes |
everyThirtyMinutes() | Run every 30 minutes |
hourly() | Run every hour |
daily() | Run daily at midnight |
dailyAt(string $time) | Run daily at specific time |
weekly() | Run weekly |
monthly() | Run monthly |
cron(string $expression) | Custom cron expression |
MonkeysLegion\I18n
Internationalization support with locale detection middleware.
| Method | Signature | Returns | Description |
|---|
trans() | (string $key, array $replace = [], ?string $locale = null) | string | Translate key |
setLocale() | (string $locale): void | — | Set current locale |
getLocale() | () | string | Get current locale |
Configured in config/files.mlc. File upload and storage abstraction.
| Key | Default | Description |
|---|
files.default_disk | local | Active storage disk |
files.max_bytes | 20971520 (20MB) | Max upload size |
files.mime_allow | ["image/jpeg","image/png","image/webp","application/pdf"] | Allowed MIME types |
| Disk | Description |
|---|
local | Local filesystem (public/files/) |
s3 | AWS S3 bucket |
gcs | Google Cloud Storage |
Configured in config/logging.mlc. PSR-3 compatible logging.
debug → info → notice → warning → error → critical → alert → emergency
| Channel | Driver | Description |
|---|
stack | stack | Combines daily + console |
daily | file | Date-rotated log files |
single | file | Single log file |
console | console | Stdout output |
emergency | file | Emergency-only log |
null | null | Discard all logs |
MonkeysLegion\Mlc\Config
HOCON-like configuration format parser (.mlc files).
# Comment
app {
name = "My App" # String
debug = true # Boolean
port = 8000 # Integer
env = ${APP_ENV:production} # Env var with default
hosts = ["a.com", "b.com"] # Array
nested { # Nested block
key = "value"
}
}
$config = $container->get(MlcConfig::class);
$appName = $config->get('app.name');
$debug = $config->get('app.debug', false);
$hosts = $config->get('app.hosts');
| Attribute | Target | Description |
|---|
#[Singleton] | Class | Register as single-instance in container |
#[Provider] | Class | Mark as service provider (auto-discovered) |
#[BootAfter(OtherProvider::class)] | Class | Provider ordering |
End of API Reference
| Part | Document | Contents |
|---|
| 1 | Core, HTTP & Routing | Application, Response, Route, Middleware |
| 2 | Entity, Query & Repository | Entity Attributes, QueryBuilder, EntityRepository |
| 3 | Auth, Session & Validation | AuthService, JWT, Session, Validation, RBAC |
| 4 | This document | Template, Events, Cache, Mail, Queue, Schedule, I18n, Files, Logger, Config |