Download the PHP package hchokshi/silverstripe-trait-config without Composer

On this page you can find all versions of the php package hchokshi/silverstripe-trait-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 silverstripe-trait-config

silverstripe-trait-config

Merge SilverStripe configuration from traits into class configuration, while avoiding private static property conflicts.

Installation

  1. Require composer package with composer require hchokshi/silverstripe-trait-config.

  2. Add TraitConfigTransformer to your config generation chain in /index.php or /public/index.php (4.1+).

Why?

Traits provide characteristics for classes using them. By default, SilverStripe does not process YAML config from traits and PHP limits classes from overriding properties set by traits, meaning if a trait defines a config private static, any using classes and their subclasses cannot define that config value except by YAML.

This package allows traits to define config by some non-conflicting name in their private statics and map them to an actual SilverStripe config. This module also merges trait YAML into using classes, which SilverStripe does not do by default.

SilverStripe suggests extensions to achieve the desired behaviour, but this comes with its own set of drawbacks - performance, IDE-hinting of method calls, less explicit code. While extensions are still necessary to apply code to classes from vendors etc., traits allow your own classes to be more explicit about their behaviour.

How?

Install the module as instructed under Installation above.

Create a trait and use it in your classes. Define private static properties as below in your trait. Both the @internal and @aliasConfig annotations must be applied for this module to map a static to a different name. Don't add the @config annotation, as that will cause SilverStripe to pick up that property's unmapped name/value and merge it into using classes.

Trait private static properties should be named randomly or with some unique prefix so that there's no chance a using class may want to actually use a property with the same name.

Traits can define config via mapped private static properties or via YAML using aliased names / normal unaliased names. E.g. a trait can define db: in YAML and it'll be merged into the config for any using classes.

While traits can also define YAML using aliased names, it is recommended to use unaliased names in YAML as there is no naming conflict and YAML does not have the inline information about where the value will be merged like @aliasConfig provides for private static variables. If a config value is defined using aliased and unaliased names, the unaliased name will be merged with a higher priority.

Example:

In the example below, MyTrait's database columns will be merged into MyObject.

Priority:

Configuration is merged in the same way as SilverStripe's normal config system (arrays are merged, higher priority scalar values overrule arrays).

Configuration sources for a class are prioritised in the following order, from highest to lowest:

  1. Class config
    • Class YAML
    • Class private statics
  2. Trait config
    • Trait YAML with unmapped config name (e.g. db: in a trait's YAML)
    • Trait YAML with mapped names (e.g. jdalsfjlafdfl_db: in a trait's YAML, where the trait has a private static $jdalsfjlafdfl_db with @internal @aliasConfig $db annotations.)
    • Trait private statics
    • Nested trait config (e.g. if Trait1 has use Trait2, Trait2 config is merged in "Trait config" priority)

All versions of silverstripe-trait-config with dependencies

PHP Build Version
Package Version
Requires php Version ^5.6 || ^7.0
silverstripe/framework Version ^4.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 hchokshi/silverstripe-trait-config contains the following files

Loading the files please wait ....