1. Go to this page and download the library: Download vagento/file-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/ */
vagento / file-generator example snippets
use Vagento\FileGenerator\AbstractStubFileGenerator;
class MyFileGenerator extends AbstractStubFileGenerator
{
// Required: This is the path to the file that will be generated
public function getPath(): string
{
return 'path/to/fileToGenerate.php';
}
// Required: This is the path to the stub file
public function getStubPath(): string
{
return __DIR__ . '/stubs/file.blade.php';
}
// Optional: This is the data that will always be passed to the stub file
public function getStubData(): array
{
// [Key (string) => Value (mixed)]
return ['always' => 5];
}
}
$generator = new MyFileGenerator();
// Generate the file
$generator->generate();
$generator = new \Vagento\FileGenerator\Generators\StubFileGenerator(
'path/to/fileToGenerate.php', // Path to the file which will be generated
__DIR__ . '/stubs/file.blade.php', // Path to the stub file
['dataToAdd' => 10] // Optional: Data that will be passed to the stub file
);
// Generate the file
$generator->generate();
// OR
$generator = new \Vagento\FileGenerator\Generators\StubFileGenerator();
// Set the path to the file which will be generated
$generator->setPath('path/to/fileToGenerate.php');
// Set the path to the stub file
$generator->setStubPath(__DIR__ . '/stubs/file.blade.php');
// Optional: Add data to the stub file
$generator->addStubData(['dataToAdd', 10]);
// Generate the file
$generator->generate();
// OR
// Chain methods
$generator->setPath('path/to/fileToGenerate.php')
->setStubPath(__DIR__ . '/stubs/file.blade.php')
->addStubData(['dataToAdd', 10])
->generate();
Filename: file.blade.php
Always: {{ $always }}
Filename: file.blade.php
Always: 5
Filename: file.blade.php
Data to add: {{ $dataToAdd }}
Filename: file.blade.php
Data to add: 10
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.