1. Go to this page and download the library: Download inventor96/inertia-offline 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/ */
inventor96 / inertia-offline example snippets
use inventor96\InertiaOffline\OfflineCacheable;
final class PostController
{
#[OfflineCacheable(ttl: 3600)]
public function index(): mixed
{
// ...
}
}
use inventor96\InertiaOffline\Pagination\QueryPaginationUrlExpander;
$expander = new QueryPaginationUrlExpander(pageKey: 'page');
use inventor96\InertiaOffline\AbstractOfflineRouteList;
use inventor96\InertiaOffline\Contracts\PaginationUrlExpanderInterface;
use inventor96\InertiaOffline\OfflineCacheable;
use inventor96\InertiaOffline\Pagination\QueryPaginationUrlExpander;
final class OfflineRoutes extends AbstractOfflineRouteList
{
public function __construct(
// ...
private readonly ?PaginationUrlExpanderInterface $paginationUrlExpander = null,
) {}
protected function expandPaginationUrls(
string $baseUrl,
mixed $pagination,
mixed $route,
OfflineCacheable $attribute,
array $routeParams = [],
): array {
$expander = $this->paginationUrlExpander ?? new QueryPaginationUrlExpander();
return $expander->expand($baseUrl, $pagination, $route, $attribute, $routeParams);
}
// ...
}
namespace Acme\InertiaOfflineYourFramework;
use inventor96\InertiaOffline\AbstractOfflineRouteList;
use inventor96\InertiaOffline\OfflineCacheable;
final class OfflineRoutes extends AbstractOfflineRouteList
{
protected function getRoutes(): iterable
{
// Return the entire set of routes from your framework's router.
}
protected function getRoutePattern(mixed $route): string
{
// Return route pattern, e.g. /posts/{id}.
// `$route` is a single item from the iterable returned by `getRoutes()`
}
protected function getRouteAction(mixed $route): mixed
{
// Return route action in any supported format.
// `$route` is a single item from the iterable returned by `getRoutes()`
}
protected function invokeAction(mixed $action, array $parameters = []): mixed
{
// Use your framework or DI container/invoker to resolve dependencies
// and call an action.
// `$action` is the normalized action from `getRouteAction()`.
}
protected function expandPaginationUrls(
string $baseUrl, // from route pattern + params, e.g. /posts/42
mixed $pagination, // pagination metadata from `pagination_resolver` action
mixed $route, // the original route item from `getRoutes()`
OfflineCacheable $attribute, // the attribute instance from the reflected action
array $routeParams = [], // the parameter set used to generate the base URL, e.g. ['id' => 42]
): array {
// Convert pagination metadata into concrete URLs
// e.g. /posts?page=1, /posts?page=2, ...
}
protected function logWarning(string $message): void
{
// Optional: send warnings to framework logger
}
}
use inventor96\InertiaOffline\OfflineCacheable;
final class PostController
{
#[OfflineCacheable(
ttl: 1800,
param_generator: [PostOfflineParams::class, 'recent'],
pagination_resolver: [PostOfflinePagination::class, 'resolve'],
access_control: [PostOfflineAccess::class, 'canUseOffline']
)]
public function show(int $id): mixed
{
// ...
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.