Skip to main content Link Menu Expand (external link) Document Search Copy Copied

Usage

CLI usage

Now when the parser reads the template, it finds these variables and use them as arguments for the CLI tool during the generation process.

You can then assign any value you want to these parameters during generation. The tool will automatically ask you to provide values for the arguments if you donโ€™t provide any in the initial command.

Terminal output

But if you know what parameters the template needs, you can pass them as an argument to the generate command:

1
vendor/bin/mtrgen generate --path=my.template.yaml name=Hello anotherArg=app/entity/test numberArg=42

Usage in code

You can also use the tool in your code. There are several classes that you are most likely to use:

  • Matronator\Mtrgen\Template\Generator - This class is used for parsing the templates into file objects.
  • Matronator\Mtrgen\FileGenerator - This class is used for writing parsed file objects to actual files.
  • Matronator\Mtrgen\Registry\Profile - This class handles everything related to user profiles.
  • Matronator\Mtrgen\Registry\Connection - This is the main class for communicating with the online template registryโ€™s API.
  • Matronator\Mtrgen\Store\Storage - This handles saving, loading and removing templates and bundles from the local store.

There is also a Matronator\Mtrgen\FileObject class that serves as the main data structure for the parsed templates. It contains all the information about the file that is needed for writing it to the disk.

FileObject structure

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
declare(strict_types=1);

namespace Matronator\Mtrgen;

use Nette\PhpGenerator\PhpFile;

class FileObject
{
    public PhpFile $contents;

    public string $filename;

    public string $directory;

    public ?string $entity = null;

    public function __construct(string $directory, string $filename, PhpFile $contents, ?string $entity = null) {
        $this->filename = $filename . '.php';
        $this->contents = $contents;
        $this->directory = $directory;
        $this->entity = $entity;
    }
}

Parsing templates


Table of contents