1. Go to this page and download the library: Download niktomo/kura 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/ */
niktomo / kura example snippets
// config/kura.php
return [
'prefix' => 'kura',
// Version resolution — how Kura determines which data version to use
'version' => [
'driver' => 'csv', // 'csv' or 'database'
'csv_path' => base_path('data/versions.csv'), // path to versions.csv
'cache_ttl' => 300, // cache all version rows in APCu for 5 min
],
// Rebuild strategy — what happens when cache is missing
'rebuild' => [
'strategy' => 'sync', // 'sync' | 'queue' (recommended for production) | 'callback'
],
];
use Kura\Loader\EloquentLoader;
use Kura\Loader\StaticVersionResolver;
$loader = new EloquentLoader(
query: Station::query(),
tableDirectory: base_path('data/stations'),
resolver: new StaticVersionResolver('v1.0.0'),
);
use Kura\Loader\EloquentLoader;
use Kura\Contracts\VersionResolverInterface;
$loader = new EloquentLoader(
query: Station::query(),
tableDirectory: base_path('data/stations'),
resolver: app(VersionResolverInterface::class),
);
use Kura\Loader\LoaderInterface;
class MyApiLoader implements LoaderInterface
{
public function load(): \Generator { /* fetch & yield records */ }
public function columns(): array { /* column → type map */ }
public function indexes(): array { /* index definitions */ }
public function primaryKey(): string { /* primary key column name */ }
public function version(): string { /* cache key identifier */ }
}
use Kura\Contracts\VersionResolverInterface;
use Kura\Facades\Kura;
use Kura\Loader\CsvLoader;
public function boot(): void
{
// Use the container-bound resolver (configured in config/kura.php)
$resolver = app(VersionResolverInterface::class);
Kura::register('stations', new CsvLoader(
tableDirectory: base_path('data/stations'),
resolver: $resolver,
));
// You can register multiple tables
Kura::register('lines', new CsvLoader(
tableDirectory: base_path('data/lines'),
resolver: $resolver,
));
}