Configs 本文未发布 发布文章

未匹配的标注

Definition

Configs are files that container configurations. For more details about them check this doc.
In each Apiato container, there are two types of config files:

  • the container specific config file (a config file that contains the container specific configurations).

  • the container third party packages config files (a config file that belongs to a third party package, required by the composer file of the container).

    Principles

  • Your custom config files and the third party packages config files, should be placed in the Container, unless it’s too generic then it can be placed on the Ship Layer.

  • Container can have as many config files as it needs.

Rules

  • When publishing a third party package config file move it manually to its container or to the Ship Features Config folder in case it is generic.
  • Framework config files (provided by laravel) lives at the default config directory on the root of the project.
  • You SHOULD NOT add any config file to the config directory.
  • The container specific config file, MUST have the same name of the container in lower letters and post-fixed with -container, to prevent conflicts between third party packages and container specific packages.

Folder Structure

 - app
    - Containers
        - {container-name}
            - Configs
                - {container-name}-container.php
                - package-config-file1.php
                - ...
    - Ship
        - Configs
            - apiato.php
            - ...
- config
    - app.php
    - ...

Code Samples

Example simple Config file

<?php
// app/Containers/{ContainerName}/Configs/{container-name}-container.php
return [

    /*
    |--------------------------------------------------------------------------
    | Default Namespace
    |--------------------------------------------------------------------------
    */
    'namespace'       => 'App',

    // some other config params here...

You can access the respective configuration key like this:

$value = Config::get('{container-name}-container.namespace');     // returns 'App'
$value = config('{container-name}-container.namespace');          // same, but using a function

$defaultValue = Config::get('{container-name}-container.unknown.key', 'defaultvalue');   // returns 'defaultvalue' as this key is not set!

本文章首发在 LearnKu.com 网站上。

上一篇 下一篇
《L02 从零构建论坛系统》
以构建论坛项目 LaraBBS 为线索,展开对 Laravel 框架的全面学习。应用程序架构思路贴近 Laravel 框架的设计哲学。
《L01 基础入门》
我们将带你从零开发一个项目并部署到线上,本课程教授 Web 开发中专业、实用的技能,如 Git 工作流、Laravel Mix 前端工作流等。
讨论数量: 0
发起讨论 只看当前版本


暂无话题~