Download the PHP package melchiorkokernoot/laravel-autowire-config without Composer

On this page you can find all versions of the php package melchiorkokernoot/laravel-autowire-config. 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 laravel-autowire-config

Banner

Configuration autowiring and injection

Latest Version on Packagist GitHub Tests Action Status Total Downloads

Enable laravel configuration injection through auto-wired constructor arguments.

Installation

You can install the package via composer:

Configuration

The package will automatically register itself. You can publish the config file with:

Note that it is not necessary to publish the config file, nor is it necessary to configure the package. Only change the config file when you know why you are doing it.

This is the contents of the published config file:

You can choose between two strategies:

More on the strategies below.

Usage

Usage through Custom Application class (Recommended)

Starting from version 3.0.0, the package can be used through a custom Application class. This is the recommended way of using the package, as it will offer a more "natural" way of using the package.

The only thing one needs to do to enable this behaviour, is to swap out the default Application class in bootstrap/app.php with the MelchiorKokernoot\LaravelAutowireConfig\Application class.

So change this:

Into this:

Advantages of using the custom application class:

Currently this only works with the attribute strategy, but you do not need to configure this. Once you start using the new Application class, the package will automatically disable old way of using the package, so no resources are wasted on duplicate resolution.

To demonstrate this, let's take a look at the following example:

When resolving this Foo class from the container, the package will automatically resolve the config value for app.name and inject it into the $myConfiguredAppName property.

Usage through Service provider

Starting from Version 2.0.0 the package can be used in two ways:

Usage through attribute autowiring (AttributeStrategy)

Firstly, implement the AutowiresConfigs interface on your class. Typehint one of the typed config classes in your constructor, and use that typehint as an attribute on the property, finally pass the config key as the attribute value.

Note you do not have to name the variable to match the config key now, but you still have to type-hint the config class.

When using this class from the container (through dependency injection e.g.), the config value will be injected as if you do this:

Usage through constructor property name autowiring (PropNameStrategy)

Firstly, implement the AutowiresConfigs interface on your class. Typehint one of the typed config classes in your constructor, and use the camelCase version of the config key as the property name.

You need to match the config key to the property name, so app.name will become appName.

When using this class from the container (through dependency injection e.g.), the config value will be injected as if you do this:

The benefit of this, is that you keep a clear separation between your application logic and your configuration layer. No more service locators, no more config() calls in your code, just clean dependencies.

Accessing the config values

Because the config values are wrapped in a typed config class, you cannot access the value directly. Instead, you can access the value through the value method. For convenience, the __toString magic method is also implemented, so you can use the config value as a string (in the case of a value that can be casted to a string,of course) directly. Furthermore, the shorthands $object->config->v()and $object->config->v() are also available for accessing the value.

Typed config classes

The following config classes are available:

Pitfalls

This package hooks into the afterResolving callback, which means that it will only work for classes that are resolved through the container. This that the config values will only be populated after the constructor has been called, so the values will not be available in the constructor.

Testing

Roadmap

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.


All versions of laravel-autowire-config with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
illuminate/contracts Version >=9.0
illuminate/support Version >=9.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 melchiorkokernoot/laravel-autowire-config contains the following files

Loading the files please wait ....