Esempio n. 1
0
<?php

namespace Moccalotto\Reporter;

use Commando\Command;
require_once 'vendor/autoload.php';
$app = new App(['version' => '@git-version@', 'args' => function ($app) {
    $args = new Command();
    $args->argument()->aka('config')->describedAs('Use a given configuration file. Defaults to reporter.php if it exists.')->defaultsTo('reporter.php')->file()->must(function ($file) {
        Ensure::fileIsReadable($file);
        return true;
    });
    $args->option('d')->aka('dump-config')->map(function ($file) {
        if (null === $file) {
            return 'php://output';
        }
        return $file;
    })->must(function ($file) {
        Ensure::that(!is_dir($file), sprintf('Cannot dump config to %s. It is a directory', $file));
        if (is_file($file)) {
            Ensure::that(is_writable($file), sprintf('Cannot dump config to %s. It is not writable', $file));
        }
        return true;
    })->describedAs('Dump the config to the the specified file. Defaults to stdout.');
    $args->option('k')->aka('new-key')->map(function ($file) {
        if (null === $file) {
            return 'php://stdout';
        }
        return $file;
    })->must(function ($file) {
        Ensure::that(!is_dir($file), sprintf('Cannot dump config to %s. It is a directory', $file));
Esempio n. 2
0
 /**
  * Create an instance from a file
  *
  * Merge the config data from the file with the defaults.
  *
  * @param string $file The filename
  * @param array $default
  * @return Config
  */
 public static function fromFile($file, array $defaults = [])
 {
     Ensure::fileIsReadable($file);
     $config = (require $file);
     return static::fromArray($config, $defaults);
 }