Download the PHP package aimeos/macro without Composer

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

PHP Macro

The PHP Macro package offers closure (anonymous function) based setter dependency injection by providing a trait which can be included into any class.

This package is for application, framework and library developers who want to allow customizing the behavior of their code by their users.

Why macros

In applications, frameworks or libraries which are build for customization it’s necessary to allow overwriting existing functionality to be able customize its behavior. This is where macros are very handy because they can add custom code using closures.

With the PHP Macro package, you can also allow users to overwrite methods in base classes without forcing your users to extend these classes. The PHP Macro package uses NO reflection or other hacks, just pure PHP methods.

There are some pros and cons when compared to class based depencency injection:

Pro:

Con:

Thus, it's not a replacement for class based depencency injection but a lightweight addition for small extension points where full-blown dependency injection using classes implementing interfaces are too much work.

Allow customization

The result of existing methods can be modified if the original method checks for an existing macro and use that instead its own implementation:

Now, you can add your custom orderNumber macro that will be used instead:

Thus, you can generate own output or pass a different result to subseqent methods within the application.

Access class properties

When macros are called in an object context, they can also access class properties:

Here, the private property $name is available in the macro:

The macro can use the property as input for creating the returned value.

Use inherited macros

The PHP macro package also allows to inherit macros from parent classes. Then, they can access class properties of the child class just like regular class methods:

Macros added to the parent class will be available in child classes too:

Class B extends from class A but provides a different $name property. The macro inherited from class A will now use the property of class B.

Overwrite inherited macros

It's also possible to overwrite macros inherited from parent classes as it's possible with regular class methods:

Now you can add macros to the parent class and one of the child classes:

This enables you to add special handling for single classes even if all other classes still use the macro added to class A.

Overwrite protected methods

Base classes often offer a set of methods that are used by the child classes. In PHP, replacing the methods of a base class is impossible and thus, you have to overwrite each child class with your own implementation.

To avoid that, the original method can use the call() method instead of calling the method of the parent class directly:

This will check if there's a macro getName available and will call that instead of the getName() method:

The original getName() method can still be used in the macro.

Reset macros

Sometimes, it may be necessary to remove macros from objects, especially when running automated tests. You can unset a macro by using:


All versions of macro with dependencies

PHP Build Version
Package Version
Requires php Version ~7.1||~8.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 aimeos/macro contains the following files

Loading the files please wait ....