Download the PHP package thecodingmachine/funky without Composer

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

Latest Stable Version Total Downloads Latest Unstable Version License Scrutinizer Code Quality Build Status Coverage Status

Work in progress, no stable version yet

thecodingmachine/funky

Funky is tool to help you write service providers compatible with container-interop/service-provider.

Without Funky:

The current trend is to directly implement the ServiceProviderInterface when writing service providers.

For instance:

With Funky:

Funky implements the getFactories and getExtensions methods.

Your class simply extends TheCodingMachine\Funky\ServiceProvider. Funky will scan your class for @Factory and @Extension annotations.

Install

Simply require thecodingmachine/funky from your service provider package.

Usage

Instead of creating a class that implements Interop\Container\ServiceProviderInterface, you extend the TheCodingMachine\Funky\ServiceProvider class.

The @Factory annotation

Default naming

By default, the @Factory is using the return type as the name of the container entry

Specifying a name

You can use the "name" attribute of the @Factory annotation to specify a name:

Using the method name

You can use the "nameFromMethodName" attribute of the @Factory annotation to tell Funky to use the method name as an identifier:

Auto-wiring

Funky supports auto-wiring! You can simply add parameters with the appropriate type-hint in your factories and Funky will look for this dependencies in the container.

If you do not add type-hints (or use a scalar type-hint), Funky will try to fetch the dependency using the parameter name.

Finally, at any point, you can also inject the whole container to fetch any dependency from it:

Extending entries

You can extend entries from the container using the Extension annotation.

You should pass the entry to be extended as the first argument. The remaining arguments can be auto-wired just like you do with the factories.

Specifying a name

You can use the "name" or "nameFromMethodName" attribute of the @Extension annotation to specify the name of the entry to be extended:

Tags

Out of the box, the container-interop/service-provider does not have a notion of tags. However, you can build entries in your container that are actually an array of services. Those arrays can be regarded as "tags".

Funky offers you an easy way to tag services, using the @Tag annotation. This is a great way to remove a lot of boilerplate code!

Here is an example:

This piece of code declares a \MyTwigExtension entry, and adds this entry to the twigExtensions tag.

Thereafter, you can fetch the tagged services from the container easily.

For instance:

You can specify an optional priority level for each tagged service:

Low priority items will appear first. High priority items will appear last.

Note: under the hood, the tagged services are actually \SplPriorityQueue objects. Those are iterables, but are not PHP arrays. If you need arrays, you can use the iterator_to_array PHP function to cast those in arrays.

FAQ

Why the name?

Because the PHP ecosystem loves music (did you notice? Composer, Symfony, ...) And because Funky takes its roots and inspiration from bitexpert/disco, a PSR-11 compliant container that also relies on annotations!

Why do factories need to be static?

In the context of service providers, a factory is a function that builds a service based on the parameters it is passed. If you have done some functional programming, you should consider a factory is a pure function.

Given a set of parameters, it will always generate the same result. Therefore, a factory have no need of any object state (the state is contained in the container that is passed in parameter).

Furthermore, compiled containers (like Symfony or PHP-DI) can use the fact that a factory is public static to greatly optimize the way they work with the service provider. By caching the results given by the getFactories and getExtensions methods, a compiled container can make the overhead of using Funky to nearly 0.

Troubleshooting

It says some file cannot be created

Funky needs to generate some PHP files to be fast. Those files will be written in the Funky 'generated' directory (so most of the time, in vendor/thecodingmachine/funky/generated). If Funky is called from Apache, Apache might not have the right to write files in this directory. You will have to change the rights of this directory to let Apache write in it.

Some xxxHelper class cannot be autoloaded

As explained above, Funky needs to generate some PHP files to be fast. Those classes are written in the Funky 'generated' directory. If you used Composer's autoritative classmap (for instance with the --classmap-authoritative option), Composer will scan all classes of your project to build the classmap. Problem: Funky's classes are not yet written! So Composer classmap will miss those classes. Therefore, when using Funky, you should not use the --classmap-authoritative option.


All versions of funky with dependencies

PHP Build Version
Package Version
Requires php Version >=7.1
container-interop/service-provider Version ^0.4
thecodingmachine/common-factories Version ^0.4
doctrine/annotations Version ^1.5.0
mindplay/composer-locator Version ^2.1.3
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 thecodingmachine/funky contains the following files

Loading the files please wait ....