Download the PHP package zenstruck/class-metadata without Composer

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

zenstruck/class-metadata

CI codecov

Add human-readable class aliases and scalar metadata to your classes with an efficient runtime lookup. These can be added via attributes or composer.json configuration.

  1. Alias: short name for a class (could be used as an alternative to storing a FQCN in the database).
  2. Metadata: key-value map of scalar or array values specific to a class (could be used to mark a class as trackable in an auditing system).

This library provides a Composer plugin that hooks into Composer's dump-autoload event to generate a lookup map for use at runtime.

Installation

Note: This package requires composer 2.4+.

  1. composer require zenstruck/class-metadata
  2. When asked to enable the Composer plugin, choose y (yes).

Configuration

Metadata and aliases can be added to class' via attributes or composer.json config.

  1. Aliases must be a non-empty string.
  2. Only 1 alias allowed per class.
  3. Multiple classes cannot have the same alias.
  4. Metadata keys must be strings.
  5. Metadata values must be scalar (bool|float|int|string).

Note: During development, when adding/changing/removing aliases and metadata, you need to run composer dump-autoload for the changes to take effect.

Attributes

When creating the autoload configuration for your application, the composer plugin scans your PSR-4 autoload path(s) (defined in your composer.json) to look for classes with the Alias & Metadata attributes. These are parsed and a mapping file is generated.

Customize Paths

If you have a large code-base, scanning all the files could be time-consuming. You can configure specific paths to scan in your composer.json:

You can disable path scanning entirely and only configure via your composer.json:

composer.json

Metadata and aliases can also be configured in your composer.json. This allows adding aliases and metadata to 3rd party classes:

For the mapping, a string is a shortcut for an alias (class1 in the example above). An array will be used as the metadata except the special alias key. This value will be used as the alias (class2 in the example above).

Runtime API

Since the alias/metadata maps are created when Composer creates the autoload files, runtime lookups are fast - just fetching from generated PHP constant array's.

The following examples use the user class shown above.

Alias Lookup

Metadata Lookup

list-class-metadata Command

A custom Composer command is provided to debug/list all classes that have metadata/aliases configured:

Using the User example above, the following would be output:

Doctrine Bridge

AliasManagerRegistry

This is a decorated ManagerRegistry that allows using aliases for the getRepository() and getManagerForClass() methods:


All versions of class-metadata with dependencies

PHP Build Version
Package Version
Requires php Version >=8.0
composer-plugin-api Version ^2.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 zenstruck/class-metadata contains the following files

Loading the files please wait ....