Download the PHP package murtukov/php-code-generator without Composer

On this page you can find all versions of the php package murtukov/php-code-generator. 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 php-code-generator

PHPCodeGenerator

A library to generate PHP 7.4 code

Scrutinizer Code Quality Code Coverage Build Status Code Intelligence Status

Installation

Components

File

Result:

Class

Result:

Interface

Result:

Trait

Result:

Function

Result:

Method

Result:

Constructor property promotion

Result:

Same but creating from a class object:

Modifiers can also be set directly on argument objects:

Closure

Result:

Arrow Function

Result:

Object Instantiation

Result:

You can prevent shortening of the class qualifier by prefixing its name with @ symbol.

Result:

The @ suppress symbol can by changed with static config class.

Arrays

This library provides a useful tool to stringify variables: Utils::stringify(). It is similar to the var_export function, but with more control over arrays formatting. Arrays can also be wrapped by the Collection class, which internally use Utils::stringify().

Arrays with 0-key defined are considered "numeric" and are stringified inline and without keys by default.

Result:

All other arrays are stringified multiline and with keys:

Result:

If you want to define yourself, how arrays are stringified, simply wrap them into Collection class:

Result:

assoc collection example:

Result:

The Collection class applies its formatting rules only to the top level array, using default formatting for all nested arrays:

Result:

If ... else

Result:

Loops

Results:

Comments

Result:

Namespaces

PhpFile component automatically resolves class qualifiers from all its child components during the rendering.

Result:

However class qualifiers are NOT resolved from scalaras and arrays, unless wrapped in special objects:

Result:

You can always add use statements manually by calling $file->addUse() or $file->addUseGroup():

Result:

Although all components of this library implement the magic __toString() method, avoid concatenating them, as it will convert them into string scalars and all class qualifiers will be lost.

So instead of concatenation:

pass parts as separate arguments, as append is a variadic function:

Literal

Generates code literally as provided (without any additional processing)

Result:

The string can hold placeholders similar to sprintf function:

Result:

Escaping the reserved % char:

Result:

Global Configs

All global configs are stored as static properties in the Config class.

Indent

Default indent contains 4 spaces. You can change it by rewriting the $indent property:

Shorten qualifiers

As mentioned in the Namespaces section, class qualifiers are shortened automatically and added to the top of PhpFile output. In order to disable it overwrite the $shortenQualifiers property:

Suppress symbol

As mentioned in the Object Instantiation section, you can suppress shortening of class qualifiers by prefixing them with the @ symbol. In order to change this symbol, overwrite the $suppressSymbol property:


All versions of php-code-generator with dependencies

PHP Build Version
Package Version
Requires php Version >=7.4
ext-json Version *
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 murtukov/php-code-generator contains the following files

Loading the files please wait ....