Download the PHP package grikdotnet/generics without Composer

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

Generics in PHP

Why do you need generics?

Generic programming is an algorithm where data types are declared as "to-be-specified-later", when needed.

It allows writing much less code, and have data types checked by the PHP engine in data sets.

Data may have unexpected structure, especially when it is obtained from databases, APIs, and 3rd party code. For single-value variables we define parameter types, but for the composite types such as array, ArrayObject, SplFixedArray one cannot define types of values in runtime. To define data types for values we could create multiple classes with the same code, where the only difference would be a type of a parameter. E.g.

This feels wrong, and violates the "Don't repeat yourself" principle.

Generics allow defining types of parameters when you create an instance, with just one short clause. And yet you have just one class declaration for all types you need.

How to use

  1. Add the package as a dependency for Composer, as usually: composer require grikdotnet\generics.
  2. Call new \grikdotnet\generics\Enable(); in bootstrap to enable the class loader.
  3. Declare a wildcard class.

Using the trait is optional. It provides a convenient shortcut method T() to create concrete types:

That's it. Now PHP will check the type of values added to the ArrayObject instance, and trigger a TypeError when the type does not match.

Now let's use the typed Collection as a parameter type in a method:

This way data types of elements are checked by the PHP engine, and we can avoid writing a lot of type checks in a loop over data sets in every method.

Find more about syntax in the documentation.


All versions of generics with dependencies

PHP Build Version
Package Version
Requires php Version >=8.2
ext-tokenizer Version *
ext-ctype Version *
ext-mbstring Version *
ext-zend-opcache Version *
composer-runtime-api Version *
nikic/php-parser Version ^5.4
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 grikdotnet/generics contains the following files

Loading the files please wait ...