Download the PHP package mrsuh/php-generics without Composer

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

PHP generics written in PHP

Table of contents

How it works

In a nutshell:

For example, you need to add several PHP files:

src/Box.php

src/Usage.php

bin/test.php

Generate concrete classes from generic classes with composer dump-generics command

What the composer dump-generics command does?

In this case should be generated:

Generate vendor/autoload.php with composer dump-autoload command

Run bin/test.php script

Composer autoload first checks the "cache" directory and then the "src" directory to load the classes.

:blue_book: You can find repository with this example here.

Installation

Require

Install library

Add directory("cache/") to composer autoload PSR-4 for generated classes. It should be placed before the main directory.

composer.json

Monomorphization

A new class is generated for each generic argument combination.

Before monomorphization:

After monomorphization:

Command

Where in class can generics be used?

Where in generic class can parameters be used?

:blue_book: You can read more about monomorphization here.

Type erasure

A new class is generated without generics arguments.

Before type erasure:

After type erasure:

Command

Where in class can generics be used?

Where in generic class can parameters be used?

:blue_book: You can read more about type-erasure here.

Features

What syntax is used?

The RFC does not define a specific syntax so i took this one implemented by Nikita Popov

Syntax example:

Syntax problems

I had to upgrade nikic/php-parser for parse code with new syntax.
You can see here the grammar changes that had to be made for support generics.

Parser use PHP implementation of YACC.
The YACC(LALR) algorithm and current PHP syntax make it impossible to describe the full syntax of generics due to collisions.

Collision example:

Solution options

Therefore, nested generics are not currently supported.

Parameter names have not special restrictions

Several generic parameters support

Default generic parameter support

How fast is it?

All concrete classes are pre-generated and can be cached(should not affect performance).

Generating many concrete classes should negatively impact performance when:

I think it's all individual for a specific case.

Doesn't work without composer autoload

Autoload magic of concrete classes works with composer autoload only.
Nothing will work because of syntax error if you include file by "require"

Reflection

PHP does type checks in runtime.
Therefore, all generics arguments must me available through reflection in runtime.
It can't be, because information about generics arguments is erased after concrete classes are generated.

Tests

How to run tests?

How to add test?


All versions of php-generics with dependencies

PHP Build Version
Package Version
Requires php Version >=7.4
composer-plugin-api Version ^1.0|^2.0
mrsuh/php-parser Version 95.0.2
symfony/console Version ^4.0|^5.0|^6.0
symfony/filesystem Version ^4.0|^5.0|^6.0
symfony/finder Version ^4.0|^5.0|^6.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 mrsuh/php-generics contains the following files

Loading the files please wait ....