Download the PHP package grifart/scaffolder without Composer

On this page you can find all versions of the php package grifart/scaffolder. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package scaffolder

grifart/scaffolder – The (class) scaffolder project.

It was designed to generated classes with none to simple logic. Typical usage is:

It is developed at gitlab.grifart.cz, automatically mirrored to GitHub and distributed over Composer packagist:grifart/scaffolder.

You can also watch introduction (in Czech) on 🎥 YouTube.

Installation

We recommend to use Composer:

Quick start

  1. Create a definition file. Definition file must return a list of ClassDefinitions. By default, its name must end with .definition.php. We commonly use just .definition.php:

  2. Run scaffolder. You can provide the path to the definition file (or a directory which is then recursively searched for definition files) as an argument. It defaults to the current working directory if omitted.

    The recommended way is to run the pre-packaged Composer binary:

Alternative way: Register scaffolder as a Symfony command into you app. Alternatively, you can register the `Grifart\ClassScaffolder\Console\ScaffoldCommand` into your application's DI container and run scaffolder through *symfony/console*. This makes it easier to access your project's services and environment in definition files. *This is considered advanced usage and is not necessary in most cases.*
  1. Your class is ready. Scaffolder generates classes from definitions, one class per file, residing in the same directory as the definition file. By default, scaffolder makes the file read-only to prevent you from changing it accidentally.

  2. Use static analysis tool such as PHPStan or Psalm to make sure that everything still works fine if you've changed any definition file.

  3. Make sure that you haven't accidentally changed any generated file by adding composer exec scaffolder check .definition.php to your CI workflow. The command fails if any generated class differs from its definition, and thus running the scaffolder would result in losing your changes.

Definition files

A definition file must return a list of ClassDefinitions. The easiest way to create a definition is to use the definitionOf() function:

The definitionOf() accepts the name of the generated class and optionally a map of its fields and their types, and returns a ClassDefinition. You can further add fields and capabilities to the definition.

Fields and types

Since scaffolder is primarily designed to generate various data transfer objects, fields are first-class citizens. Every field must have a type: scaffolder has an abstraction over PHP types and provides functions to compose even the most complex of types. It adds phpdoc type annotations where necessary so that static analysis tools can perfectly understand your code.

The available types are:

Capabilities

Fields on their own are not represented in the generated code, they just describe which fields the resulting class should contain. To add any behaviour to the class, you need to add capabilities to it. Scaffolder comes prepared with a bundle of capabilities for the most common use-cases:

Adding and preserving logic

Scaffolder regenerates your classes every time it runs. If you make any changes to the generated classes, you will lose them the next time you run scaffolder. (Scaffolder prevents this by making the generated files read-only, but that can be easily worked around.) However, even DTOs can contain some simple logic, for example concatenating the first and last name.

Consider the following definition:

It results in the generated class:

We want to add a getFullName() method and preserve it when scaffolder runs next time. The trick is to mark the method with the #[Preserve] attribute:

and add the preservedAnnotatedMethods() capability to the definition:

The next time you run scaffolder, the getFullName() method will be kept intact as long as it has the #[Preserve] attribute.

Alternatively, you can use the preservedMethod($methodName) capability that keeps only methods that are explicitly listed in the capability function.

⚠️ The method-preserving capabilities are best accompanied by preservedUseStatements() capability which makes sure that all use statements from the original file are preserved.

Custom capabilities

Capability is a very simple interface, so you can easily create and use your own:

ℹ️ Tip: If you need just single-purpuse capability, you can define it as a anonymous class. e.g.:

Do not repeat yourself

As the definition file is a plain old PHP file, you can use any language construct to your advantage. We commonly define functions which preconfigure capabilities and even fields for repeating patterns:

Such functions can then easily be reused throughout your definition files:

⚠️ Scaffolder relies on Composer autoloader. To be able to access your functions in definition files, you should add them into the files autoloading section in composer.json, or wrap them into static classes that can be automatically autoloaded by Composer. If you have your custom autoloader, please register this library as a command into your application. It will then use your custom environment.


All versions of scaffolder with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
ext-tokenizer Version *
nette/finder Version ^2.5||^3.0
nette/php-generator Version ^4.0.1
nette/utils Version ^3.0||^4.0
symfony/console Version ^6.0||^7.0
symfony/filesystem Version ^6.0||^7.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package grifart/scaffolder contains the following files

Loading the files please wait ....