PHP code example of stwarog / fuel-fixtures-generator
1. Go to this page and download the library: Download stwarog/fuel-fixtures-generator 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/ */
stwarog / fuel-fixtures-generator example snippets
# The best approach is using some DI container implementation and fetch the service from there:
use Stwarog\FuelFixturesGenerator\{Config as FixtureGeneratorConfig,
Factory as FixtureChunkFactory,
FixtureFactory,
FuelAwareNameGenerator,
NameGenerator,
Renderer\Engine,
Renderer\Engine as FixtureGeneratorViewEngine,
Renderer\File,
Renderer\Service as Generator,
Renderer\Storage};
# e.g. entry configuration
return [
NameGenerator::class => fn(Container $c) => new FuelAwareNameGenerator($c->get(FixtureGeneratorConfig::class)),
Storage::class => fn(Container $c) => new File(),
FixtureChunkFactory::class => fn(Container $c) => new FixtureFactory(
$c->get(NameGenerator::class),
$c->get(FixtureGeneratorConfig::class)
),
// Adapter for Twig of Fixture Generator Engine
FixtureGeneratorViewEngine::class => function (Container $c): Engine {
return new class ($c->get(TwigViewRenderer::class)) implements FixtureGeneratorViewEngine {
private ViewRendererContract $renderer;
public function __construct(TwigViewRenderer $renderer)
{
$this->renderer = $renderer;
}
public function render(string $fileName, array $params = []): string
{
return $this->renderer->render('fixture.twig', $params);
}
};
},
FixtureGeneratorConfig::class => function (Container $c): FixtureGeneratorConfig {
return new class () implements FixtureGeneratorConfig {
public function getNameSpace(): string
{
return 'Tests\Fixtures';
}
public function storagePath(): string
{
return APPPATH . 'tests/fixtures/';
}
public function outputTemplate(): string
{
return 'fixture.twig';
}
};
},
Generator::class => fn(Container $c) => new Generator(
$c->get(FixtureChunkFactory::class),
$c->get(FixtureGeneratorViewEngine::class),
$c->get(Storage::class),
$c->get(FixtureGeneratorConfig::class),
),
];
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.