Guide
Infrastructure
Cache, sessions, uploads, filesystem, and HTTP clients without coupling the application to framework internals.
Cache data that can be rebuilt
Use CacheManager for data that can be recomputed, such as article lists or navigation. Cache is not a source of truth.
use Lemonade\Framework\Cache\CacheManager;
final class ArticleFeed
{
public function __construct(
private readonly CacheManager $cache,
) {}
public function latest(): array
{
return $this->cache->remember('articles.latest', 600, function (): array {
return [];
});
}
}Sessions and flash messages
Inside controllers, flash() is a convenient way to send one-time messages across a redirect. Outside controllers, inject the session or flash abstraction explicitly.
$this->flash()->set('success', 'Article saved.');
return $this->redirect($this->url()->route('articles.index'));Uploads and filesystem
Use upload() with configured profiles for uploads and filesystem() for file operations. Keep limits and target directories in YAML configuration.
$image = $this->upload()->uploadImage('image', 'article_image');
$content = $this->filesystem()->read($this->app()->basePath('README.md'));HTTP client
For outbound integrations, inject Psr\Http\Client\ClientInterface together with a PSR request factory. Configure timeouts and SSL in HttpClient.yaml.
<?php
declare(strict_types=1);
namespace App\Services;
use Psr\Http\Client\ClientInterface;
use Psr\Http\Message\RequestFactoryInterface;
final class StatusApi
{
public function __construct(
private readonly ClientInterface $client,
private readonly RequestFactoryInterface $requests,
) {}
public function check(): void
{
$request = $this->requests->createRequest('GET', 'https://status.example.test/health');
$this->client->sendRequest($request);
}
}