2017 © Pedro Peláez
 

library kirby-phpdotenv

PHPDotenv for Kirby CMS

image

jevets/kirby-phpdotenv

PHPDotenv for Kirby CMS

  • Monday, July 3, 2017
  • by jevets
  • Repository
  • 1 Watchers
  • 3 Stars
  • 3,040 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 2 Versions
  • 11 % Grown

The README.md

kirby-phpdotenv

A simple wrapper around vlucas' PHP dotenv library for Kirby CMS., (*1)

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., (*2)

Quick Example

# .env
APP_DEBUG=true

```php, (*3)

site/config/config.php

c::set('debug', env('APP_DEBUG', false));, (*4)

```php
# elsewhere
c::get('debug'); // true

Install

Install via composer, (*5)

composer require jevets/kirby-phpdotenv 

Usage

1. Instantiate

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

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

Then instantiate with:, (*7)

  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., (*8)

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:, (*9)

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

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

Customized folder setup

In my Kirby projects, I usually keep this folder structure:, (*12)

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, (*13)

# 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!, (*14)

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., (*15)

The Versions

03/07 2017

dev-master

9999999-dev https://github.com/jevets/kirby-phpdotenv

PHPDotenv for Kirby CMS

  Sources   Download

BSD

The Requires

 

by Steve Jamesson

environment dotenv kirby

30/03 2016

0.0.3

0.0.3.0 https://github.com/jevets/kirby-phpdotenv

PHPDotenv for Kirby CMS

  Sources   Download

BSD

The Requires

 

by Steve Jamesson

environment dotenv kirby