laravel config app

作者: 3275508ab630 | 来源:发表于2017-12-09 20:27 被阅读308次

app.php

name 注释翻译:

    /*
    |------------------------------------------------------------------
    | Application Name
    |------------------------------------------------------------------
    |
    | This value is the name of your application. This value is used when the
    | framework needs to place the application's name in a notification or
    | any other location as required by the application or its packages.
    |
    */
    'name' => env('APP_NAME', 'Laravel'),
    /*
    |------------------------------------------------------------------
    | 应用名称
    |------------------------------------------------------------------
    |
    | 此值是您的应用程序的名称。 该值用于
    | 框架需要将应用程序的名称放在通知中
    | 应用程序或其软件包所要求的任何其他位置。
    |
    */
    'name' => env('APP_NAME', 'Laravel'),

个人理解:作品名,网站名,应用名。比如发送邮件给用户时,带上这个 name 能让人明白这个邮件是哪个网站发送的。

env 注释翻译:

    /*
    |------------------------------------------------------------------
    | Application Environment
    |------------------------------------------------------------------
    |
    | This value determines the "environment" your application is currently
    | running in. This may determine how you prefer to configure various
    | services your application utilizes. Set this in your ".env" file.
    |
    */
    'env' => env('APP_ENV', 'production'),
    /*
    |------------------------------------------------------------------
    | 应用环境
    |------------------------------------------------------------------
    |
    | 该值决定您的应用程序当前的“运行环境”
    | 应用程序会依据当前的运行环境,使用对应配置的服务。 
    | 在“.env”文件中进行设置。
    |
    */
    'env' => env('APP_ENV', 'production'),

个人理解:程序的运行环境。production 是线上生产环境,local 是本地开发环境。
比如一些代码是测试代码,不能运行在线上环境,可以根据 app.env 先做一下判断。

debug 注释翻译:

    /*
    |------------------------------------------------------------------
    | Application Debug Mode
    |------------------------------------------------------------------
    |
    | When your application is in debug mode, detailed error messages with
    | stack traces will be shown on every error that occurs within your
    | application. If disabled, a simple generic error page is shown.
    |
    */
    'debug' => env('APP_DEBUG', false),
    /*
    |------------------------------------------------------------------
    | 应用程序调试模式
    |------------------------------------------------------------------
    |
    | 当您的应用程序处于调试模式时,会有详细的错误消息
    | 应用每次发生错误会显示详细的错误信息和堆栈。
    | 如果禁用,只会显示一个简单通用的错误页面。
    |
    */
    'debug' => env('APP_DEBUG', false),

个人理解:调试模式。当程序发生错误时,开启的时候时会有报错信息 Whoops,关闭则会展示 500 错误模板。

url 注释翻译:

    /*
    |------------------------------------------------------------------
    | Application URL
    |------------------------------------------------------------------
    |
    | This URL is used by the console to properly generate URLs when using
    | the Artisan command line tool. You should set this to the root of
    | your application so that it is used when running Artisan tasks.
    |
    */
    'url' => env('APP_URL', 'http://localhost'),
    /*
    |------------------------------------------------------------------
    | 应用程序网址
    |------------------------------------------------------------------
    |
    | 当执行Artisan命令时用该URL生成正确的URL。
    | 你应该把它设置为您的应用程序网站首页地址,
    | 以便在运行Artisan任务时使用它。
    |
    */
    'url' => env('APP_URL', 'http://localhost'),

个人理解:网站首页地址。看起来只有 Artisan 需要用到它,比如发送邮件时,可以读取该配置项,生成正确的 url

timezone 注释翻译:

    /*
    |------------------------------------------------------------------
    | Application Timezone
    |------------------------------------------------------------------
    |
    | Here you may specify the default timezone for your application, which
    | will be used by the PHP date and date-time functions. We have gone
    | ahead and set this to a sensible default for you out of the box.
    |
    */
    'timezone' => 'UTC',
    /*
    |------------------------------------------------------------------
    | 应用程序时区
    |------------------------------------------------------------------
    |
    | 在这里,您可以指定应用程序的默认时区,供PHP日期和日期时间函数使用。 
    | 我们设置了一个明智的默认,供您开箱即用。
    | 
    |
    */
    'timezone' => 'UTC',

个人理解:时区。可以修改为 RPC

locale 注释翻译:

    /*
    |------------------------------------------------------------------
    | Application Locale Configuration
    |------------------------------------------------------------------
    |
    | The application locale determines the default locale that will be used
    | by the translation service provider. You are free to set this value
    | to any of the locales which will be supported by the application.
    |
    */
    'locale' => 'en',
    /*
    |------------------------------------------------------------------
    | 应用程序本地化设置
    |------------------------------------------------------------------
    |
    | 翻译服务的默认语言。
    | 您可以自由进行本地化设置以支持各种区域。
    |
    |
    */
    'locale' => 'en',

个人理解:语言本地化。填写的 valueresources => lang 文件夹下面的文件夹名。如果要增加语言,新建对应的文件夹,照搬 en 下的文件做修改即可。

fallback_locale 注释翻译:

    /*
    |------------------------------------------------------------------
    | Application Fallback Locale
    |------------------------------------------------------------------
    |
    | The fallback locale determines the locale to use when the current one
    | is not available. You may change the value to correspond to any of
    | the language folders that are provided through your application.
    |
    */
    'fallback_locale' => 'en',
    /*
    |------------------------------------------------------------------
    | 应用程序备用区域设置
    |------------------------------------------------------------------
    |
    | 当默认的本地化设置不可用时,将使用备用区域设置
    | 您可以将该值修改为对应于任意一个您的应用程序提供的语言文件夹。
    | 
    |
    */
    'fallback_locale' => 'en',

个人理解:语言本地化备用翻译。

key cipher 注释翻译:

    /*
    |------------------------------------------------------------------
    | Encryption Key
    |------------------------------------------------------------------
    |
    | This key is used by the Illuminate encrypter service and should be set
    | to a random, 32 character string, otherwise these encrypted strings
    | will not be safe. Please do this before deploying an application!
    |
    */
    'key' => env('APP_KEY'),
    'cipher' => 'AES-256-CBC',
    /*
    |------------------------------------------------------------------
    | 加密密钥
    |------------------------------------------------------------------
    |
    | 密钥是给Illuminate加密服务使用的,需要设置成一个32位随机字符串,
    | 否则一些加密的字符串将不安全
    | 在部署应用程序之前请先执行此操作!
    |
    */
    'key' => env('APP_KEY'),
    'cipher' => 'AES-256-CBC',

个人理解:密钥。上线程序之前需要自行 php artisan key:generate 会帮你在 .env 文件重新生成一个 APP_KEYcipher是加密算法。

log log_level 注释翻译:

    /*
    |------------------------------------------------------------------
    | Logging Configuration
    |------------------------------------------------------------------
    |
    | Here you may configure the log settings for your application. Out of
    | the box, Laravel uses the Monolog PHP logging library. This gives
    | you a variety of powerful log handlers / formatters to utilize.
    |
    | Available Settings: "single", "daily", "syslog", "errorlog"
    |
    */
    'log' => env('APP_LOG', 'single'),
    'log_level' => env('APP_LOG_LEVEL', 'debug'),
    /*
    |------------------------------------------------------------------
    | 日志记录配置
    |------------------------------------------------------------------
    |
    | 您可以在此配置应用程序的日志设置。
    | Laravel使用Monolog PHP日志库。
    | 你可以使用各种强大的日志处理程序/格式化程序。
    |
    | 可用设置:“单个”,“每日”,“系统日志”,“错误日志”
    |
    */
    'log' => env('APP_LOG', 'single'),
    'log_level' => env('APP_LOG_LEVEL', 'debug'),

个人理解:日志配置。log 推荐设置成 daily,默认的 single 会让所有记录都在一个文件里,让这个文件变得巨大。 等级高于等于当前 log_level 的日志才会被记录下来。
日志等级:debug < info < notice < warning < error < critical < alert < emergency
文档中提到:
在使用 daily 日志模式时,Laravel 默认只保留五天份的日志文件。如果要调整保留文件的数量,就在 app 配置文件中添加一个 log_max_files 配置项:

'log_max_files' => 30

providers 注释翻译:

    /*
    |------------------------------------------------------------------
    | Autoloaded Service Providers
    |------------------------------------------------------------------
    |
    | The service providers listed here will be automatically loaded on the
    | request to your application. Feel free to add your own services to
    | this array to grant expanded functionality to your applications.
    |
    */
    'providers' => [...]
    /*
    |------------------------------------------------------------------
    | 自动加载的服务提供者
    |------------------------------------------------------------------
    |
    | 这里出现的服务提供者将在您使用应用程序的时候自动加载
    | 随意添加自己的服务
    | 这个数组为您的应用程序授予扩展的功能。
    |
    */
    'providers' => [...]

个人理解:服务提供者。这个需要理解 『服务容器』 这个概念。

aliases 注释翻译:

    /*
    |------------------------------------------------------------------
    | Class Aliases
    |------------------------------------------------------------------
    |
    | This array of class aliases will be registered when this application
    | is started. However, feel free to register as many as you wish as
    | the aliases are "lazy" loaded so they don't hinder performance.
    |
    */
    'aliases' => [...]
    /*
    |------------------------------------------------------------------
    | 类别名
    |------------------------------------------------------------------
    |
    | 这个类别名的数组将在这个应用程序开始的时候被注册
    | 但是,请随意注册您想要的数量
    | 这些别名是“懒加载”的,所以它们不会妨碍性能。
    |
    */
    'aliases' => [...]

个人理解:类别名。这个需要理解 『门面』 这个概念。

faker_locale

    'faker_locale' => 'zh_TW'

个人理解:这个字段默认没有写上,但是是有用的。factory() 数据填充本地化。默认是英语,中文有 zh_CNzh_TW,推荐用 zh_TW,虽然是繁体,但是比前面多一个 Text 类型的字段。

相关文章

网友评论

    本文标题:laravel config app

    本文链接:https://www.haomeiwen.com/subject/hmupixtx.html