All Projects → 2amigos → yii2-config-kit

2amigos / yii2-config-kit

Licence: other
Configuration kit for Yii applications

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to yii2-config-kit

yii2-multi-select-widget
Bootstrap MultiSelect and MultiSelect Listbox widgets for Yii2
Stars: ✭ 45 (+87.5%)
Mutual labels:  yii2, 2amigos
yii2-switch-widget
Bootstrap Switch Widget for Yii2
Stars: ✭ 17 (-29.17%)
Mutual labels:  yii2, 2amigos
Config
Yii2 application runtime configuration support
Stars: ✭ 54 (+125%)
Mutual labels:  yii2, configuration
yii2-flysystem-component
The League Flysystem Library for Yii Framework
Stars: ✭ 22 (-8.33%)
Mutual labels:  yii2, 2amigos
yii2-grid-view-library
Highly enhanced GridView widget and grid components for Yii2
Stars: ✭ 57 (+137.5%)
Mutual labels:  yii2, 2amigos
yii2-merchant
Payment merchants extension for Yii2
Stars: ✭ 17 (-29.17%)
Mutual labels:  yii2
konfsave
Easy saving and switching between multiple KDE configurations.
Stars: ✭ 42 (+75%)
Mutual labels:  configuration
pconf
Hierarchical python configuration with files, environment variables and command-line arguments.
Stars: ✭ 17 (-29.17%)
Mutual labels:  configuration
notus-js
Notus JS: Free Tailwind CSS UI Kit and Admin
Stars: ✭ 191 (+695.83%)
Mutual labels:  kit
build-nginx
Fetches nginx and any optional third-party modules and dependencies you specify, such as openssl and PCRE and then configures and builds.
Stars: ✭ 48 (+100%)
Mutual labels:  configuration
yii2-newsletter
Module for saving user contacts from newsletter form to database
Stars: ✭ 17 (-29.17%)
Mutual labels:  yii2
yii2-inertia
The Yii 2 server-side adapter for Inertia.js.
Stars: ✭ 52 (+116.67%)
Mutual labels:  yii2
sitri
Sitri - powerful settings & configs for python
Stars: ✭ 20 (-16.67%)
Mutual labels:  configuration
yii2-notifications
This Yii2 extension provides support for sending notifications across a variety of delivery channels, including mail, SMS, Slack, Telegram etc.
Stars: ✭ 62 (+158.33%)
Mutual labels:  yii2
yii2-gallery-widget
BlueImp Gallery Widget for Yii2
Stars: ✭ 60 (+150%)
Mutual labels:  2amigos
runtime-config-loader
This is an Angular library that provides an easy way to load a configuration JSON file for runtime configuration.
Stars: ✭ 32 (+33.33%)
Mutual labels:  configuration
yii2-s
🚀speed up yii2 tcp server、 restful by swoole
Stars: ✭ 34 (+41.67%)
Mutual labels:  yii2
Dark Souls Config Utility
All-in-one installer and configuration UI for various mods/fixes for Dark Souls™: Prepare to Die Edition.
Stars: ✭ 27 (+12.5%)
Mutual labels:  configuration
config-webpack-plugin
💫 Merge one or more configuration files together with environment variables too.
Stars: ✭ 18 (-25%)
Mutual labels:  configuration
swift-declarative-configuration
Declarative configuration for your objects
Stars: ✭ 46 (+91.67%)
Mutual labels:  configuration

ConfigKit

Packagist Version Latest Stable Version Total Downloads

In order to provide ourselves a higher flexibility with the way we build templates for our Yii based projects, we built this kit. It is, in a way, the newest generation of the widely used YiiBootstrap, but it is so much better structured and less complex than the previously mentioned was.

As we all know, Yii has a very cumbersome array configuration for its bootstrap process. The main.php script normally contains a lot of information in it regarding application settings, components, modules and parameters, and many times we find ourselves dealing with a huge file with settings that, even though they are ordered by keys, fails to be clear due to the amount of lines within it.

ConfigKit tries to solve that issue, allowing us to create project templates with a different bootstrap and configuration building process. It proposes the following configuration folder structure:

config 
├── codeception [ application name that contains its configuration ]
|   ├── app.php
├── console [ application name ]
|   | 
|   ├── components 
|   ├── params 
|   └──app.php [ app.php contains simple attribute configuration ]
|
└── web [ application name ]
    | 
    ├── components [ main section on configuration ]
    |   ├── cache.php [ the name of the file, is the name of the component ]
    |   ├── db.php  [ the contents of the file, are the settings of the component ]
    |   └── log.php
    ├── params  [ main section on app configuration ]
    |   └── mail.php 
    └── app.php
    

Please, keep in mind that the above configuration folder structure is really up to you. ConfigKit requires a ConfigurationBuilder that you are responsible to develop and it can have the above recommendation or another one. For an example of a ConfigurationBuilder please visit https://github.com/sidekit/yii2-app-template/blob/master/src/App/Configuration/ConfigurationBuilder.php

Config File Examples

Example of app.php

<?php

use Da\Config\Configuration;

return [

    /*
     * --------------------------------------------------------------------------
     * Application
     * --------------------------------------------------------------------------
     *
     * Base class for all application classes. Here we configure the attributes
     * that do not hold any object configuration such as "components" or
     * "modules". The configuration of those properties are within submodules of
     * the same name.
     */

    'id' => 'application-id',

    'basePath' => Configuration::app()->getBasePath(),

    'vendorPath' => Configuration::app()->getVendorPath(),

    'runtimePath' => Configuration::app()->getRuntimePath(),

    'language' => Configuration::env()->get('APP_LANGUAGE'),

    'bootstrap' => ['log'],
];

Example of a component file: db.php

<?php

use Da\Config\Configuration;

return [

    /*
     * --------------------------------------------------------------------------
     * Connection
     * --------------------------------------------------------------------------
     *
     * Represents a connection to a database via PDO.
     */

    'class' => 'yii\db\Connection',

    'dsn' => Configuration::env()->get('DATABASE_DSN'),

    'username' => Configuration::env()->get('DATABASE_USER'),

    'password' => Configuration::env()->get('DATABASE_PASSWORD'),

    'charset' => Configuration::env()->get('DATABASE_CHARSET'),

    'tablePrefix' => Configuration::env()->get('DATABASE_TABLE_PREFIX'),
];

Environment Settings Overrides

We know how important settings for different environments are , such as: test, local, stage and prod environments. The proposed solution to dealing with them is as simple as adding a config folder with the name of the environment needed that has the same structure within, as the previously mentioned the folder. We never found ourselves having to clone the entire structure, so you can just simply place in it the files that contains the settings you wish to override.

env
|
└── local [ the environment name ]
    └── web [ the application which settings we need to override ]
        | 
        ├── components
        |   └── db.php  [ the component (filename) and its settings that we wish to override ]
        └── params
            └── mail.php [ the parameters to override ]
        

Bootstrapping

We believe that application bootstrapping should also be as structured as its configuration. That way, all processes are much clear and easier to manage and scale. In the Yii 2 proposed project's template https://github.com/2amigos/yii2-app-template you can see a working sample of ConfigKit library + a proposed bootstrapping process. The following is the startup process of a web application:

<?php

/*
 * --------------------------------------------------------------------------
 * Register auto loaders
 * --------------------------------------------------------------------------
 *
 * Add registered class loaders required for our application.
 *
 */

require __DIR__ . '/../bootstrap/autoload.php';

/*
 * --------------------------------------------------------------------------
 * Initialize SideKit library
 * --------------------------------------------------------------------------
 *
 * This step is required *prior* adding the application script.
 *
 */

require __DIR__ . '/../bootstrap/sidekit.php';

/*
 * --------------------------------------------------------------------------
 * Initialize custom aliases
 * --------------------------------------------------------------------------
 *
 * Add custom aliases to the application. Added after sidekit to take
 * advantage of its loaded configuration values
 */

require __DIR__ . '/../bootstrap/aliases.php';

/*
 * --------------------------------------------------------------------------
 * Configure and Go!
 * --------------------------------------------------------------------------
 *
 * Bootstrap the configuration processes and get and Application ready to use.
 * Applying configuration details in a different file allow us to free up
 * unnecessary code on the entry script.
 */

$app = require __DIR__ . '/../bootstrap/web.php';

$app->run();

Clean code

We have added some development tools for you to contribute to the library with clean code:

  • PHP mess detector: Takes a given PHP source code base and look for several potential problems within that source.
  • PHP code sniffer: Tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.
  • PHP code fixer: Analyzes some PHP source code and tries to fix coding standards issues.

And you should use them in that order.

Using php mess detector

Sample with all options available:

 ./vendor/bin/phpmd ./src text codesize,unusedcode,naming,design,controversial,cleancode

Using code sniffer

 ./vendor/bin/phpcs -s --report=source --standard=PSR2 ./src

Using code fixer

We have added a PHP code fixer to standardize our code. It includes Symfony, PSR2 and some contributors rules.

./vendor/bin/php-cs-fixer fix ./src --config .php_cs.dist

Testing

  • TODO

2amigOS!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].