chubbyphp/chubbyphp-config

Chubbyphp Config

1.2.0 2019-05-11 09:20 UTC

README

Build Status Scrutinizer Code Quality Code Coverage Total Downloads Monthly Downloads Latest Stable Version Latest Unstable Version

Description

A simple config.

Requirements

  • php: ~7.0

Suggest

  • pimple/pimple: ~3.0
  • slim/slim: ~3.0
  • symfony/console: ~2.8|~3.0|~4.0

Installation

Through Composer as chubbyphp/chubbyphp-config.

composer require chubbyphp/chubbyphp-config "^1.2"

Usage

Command

Slim

Bootstrap

<?php

namespace MyProject;

use Chubbyphp\Config\ConfigProvider;
use Chubbyphp\Config\ConfigMapping;
use Chubbyphp\Config\Pimple\ConfigServiceProvider;
use Chubbyphp\Config\Slim\SlimSettingsServiceProvider;
use MyProject\Config\DevConfig;
use MyProject\Config\ProdConfig;
use Pimple\Container;

$configProvider = new ConfigProvider(__DIR__, [
    new ConfigMapping('dev', DevConfig::class),
    new ConfigMapping('prod', ProdConfig::class),
]);

$container = new Container(['env' => 'dev']);
$container->register(new ConfigServiceProvider($configProvider));
$container->register(new SlimSettingsServiceProvider($configProvider));

Config

<?php

namespace MyProject\Config;

use Chubbyphp\Config\ConfigInterface;
use Chubbyphp\Config\Slim\SlimSettingsInterface;

class DevConfig implements ConfigInterface, SlimSettingsInterface
{
    /**
     * @var string
     */
    private $rootDir;

    private function __construct()
    {
    }

    /**
     * @param string $rootDir
     *
     * @return self
     */
    public static function create(string $rootDir): ConfigInterface
    {
        $config = new self;
        $config->rootDir = $rootDir;

        return $config;
    }

    /**
     * @return array
     */
    public function getConfig(): array
    {
        return [
            'env' => 'dev',
            'rootDir' => $this->rootDir
        ];
    }

    /**
     * @return array
     */
    public function getDirectories(): array
    {
        return [
            'cache' => $this->rootDir . '/var/cache/dev',
            'logs' => $this->rootDir . '/var/logs/dev',
        ];
    }

    /**
     * @return array
     */
    public function getSlimSettings(): array
    {
        return [
            'displayErrorDetails' => false,
        ];
    }
}

Copyright

Dominik Zogg 2018