承接 jevets/kirby-phpdotenv 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

jevets/kirby-phpdotenv

最新稳定版本:0.0.3

Composer 安装命令:

composer require jevets/kirby-phpdotenv

包简介

PHPDotenv for Kirby CMS

README 文档

README

A simple wrapper around vlucas' PHP dotenv library for Kirby CMS.

Why?

I've been using .env in my Kirby projects for a while, but I got tired of pasting in the env() function for every new site. So, I created this package instead.

Quick Example

# .env
APP_DEBUG=true
# site/config/config.php
c::set('debug', env('APP_DEBUG', false));
# elsewhere
c::get('debug'); // true

Install

Install via composer

composer require jevets/kirby-phpdotenv 

Usage

1. Instantiate

In your site's index.php file (or in site.php file), load Composer's autoloader.

require_once 'path/to/vendor/autoload.php';

Then instantiate with:

  1. The path where dotenv can find your .env file
  2. A file name other than .env
new Jevets\Kirby\Dotenv\Dotenv(__DIR__ . DS, '.env');

Note: Jevets\Kirby\Dotenv\Dotenv will instantiate and run [dotenv]->load() for you.

2. Create your .env file

KIRBY_LICENSE=1234-12345-123456

APP_MODE=production
APP_DEBUG=true

3. Use in config.php file(s)

c::set('license', env('KIRBY_LICENSE', 'put your license in .env'));
c::set('debug', env('APP_DEBUG', false));

c::get('license'); // "1234-12345-123456"
c::get('debug'); // true

This library loads a global helper function:

function env($key, $default = '') {...}

Note function env() declaration is wrapped in if (!function_exists('env')) so you can override it or use your own method.

Customized folder setup

In my Kirby projects, I usually keep this folder structure:

project/
  .env
  .env.example
  .gitignore
  package.json
  composer.json
  site/
    accounts/
    blueprints/
    cache/
    config/
    snippets/
    templates/
  public/
    kirby/
      toolkit/
    panel/
    content/
    assets/
    thumbs/
    index.php
    site.php
  src/
  vendor/

And here's my typical site.php

# Composer autoload
require __DIR__ . DS . '..' . DS . 'vendor' . DS . 'autoload.php';

# DotEnv
new Jevets\Kirby\Dotenv\Dotenv(__DIR__ . DS . '..');

# Setup Kirby
$kirby = kirby();
$kirby->roots()->site = __DIR__ . DS . '..' . DS . 'site';

ChangeLog

0.0.3

  • Rename class alias in helpers.php from String to Str for PHP7 compatibility

0.0.2

  • Initial release

Collaborating

Pull requests and suggestions are quite welcome!

Credits

  • All credit for dotenv goes to vlucas for his great work on PHP dotenv. I just wrapped it up in a package to speed up development of Kirby-based sites.
  • I stole Taylor Otwell's env() function from Laravel 5.1, with a couple tweaks to get it working with Kirby.

Bugs/Issues

Please use the issue tracker on the GitHub repo.

统计信息

  • 总下载量: 9.77k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 5
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 5
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: BSD
  • 更新时间: 2015-12-23