ICanBoogie/ICanBoogie 4.0.x
  • Namespace
  • Class

Namespaces

  • ICanBoogie
    • Application
    • Autoconfig
    • Binding
    • Routing
    • Session

Classes

  • AlreadyAuthenticated
  • AppConfig
  • Core
  • Debug
  • Helpers
  • Hooks
  • Logger
  • LogLevel
  • SessionWithEvent

Interfaces

  • LoggerInterface

Traits

  • AppAccessor
  • LoggerTrait

Exceptions

  • ApplicationAlreadyBooted
  • ApplicationAlreadyInstantiated
  • ApplicationAlreadyRunning
  • ApplicationNotInstantiated

Constants

  • TOKEN_ALPHA
  • TOKEN_ALPHA_UPCASE
  • TOKEN_NUMERIC
  • TOKEN_SYMBOL
  • TOKEN_SYMBOL_WIDE

Functions

  • app
  • boot
  • excerpt
  • generate_token
  • generate_token_wide
  • get_autoconfig
  • log
  • log_error
  • log_info
  • log_success
  • log_time
  • resolve_app_paths
  • resolve_instance_name
  • strip_root
  1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36  37  38  39  40  41  42  43  44  45  46  47  48  49  50  51  52  53  54  55  56  57  58  59  60  61  62  63  64  65  66  67  68  69  70  71  72  73  74  75  76  77  78  79  80  81  82  83  84  85  86  87  88  89  90  91  92  93  94  95  96  97  98  99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 
<?php

/*
 * This file is part of the ICanBoogie package.
 *
 * (c) Olivier Laviale <olivier.laviale@gmail.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace ICanBoogie;

class AppConfig
{
    /**
     * Whether message catalogs should be cached.
     */
    const CACHE_CATALOGS = 'cache catalogs';

    /**
     * Whether synthesized configuration fragments should be cached.
     */
    const CACHE_CONFIGS = 'cache configs';

    /**
     * Whether module descriptors should be cached.
     */
    const CACHE_MODULES = 'cache modules';

    /**
     * Specify the storage engine for synthesized configurations.
     *
     * The value may be a class name or a callable that would create the instance. The callable
     * should have the following signature:
     *
     * ```
     * callable(\ICanBoogie\Core $app): \ICanBoogie\Storage\Storage
     * ```
     */
    const STORAGE_FOR_CONFIGS = 'storage_for_configs';

    /**
     * Specify the storage engine for variables.
     *
     * The value may be a class name or a callable that would create the instance. The callable
     * should have the following signature:
     *
     * ```
     * callable(\ICanBoogie\Core $app): \ICanBoogie\Storage\Storage
     * ```
     */
    const STORAGE_FOR_VARS = 'storage_for_vars';

    /**
     * Specify the error handler of the application.
     */
    const ERROR_HANDLER = 'error_handler';

    /**
     * Specify the exception handler of the application.
     */
    const EXCEPTION_HANDLER = 'exception_handler';

    /**
     * Specify the path to the _repository_ directory.
     */
    const REPOSITORY = 'repository';

    /**
     * Specify the path to the _cache_ directory.
     *
     * The directory does not have to be a sub-folder of `REPOSITORY`.
     *
     * **Note**: `{repository}` is replaced by the directory specified by `REPOSITORY`.
     */
    const REPOSITORY_CACHE = 'repository/cache';

    /**
     * Specify the path to the _cache/configs_ directory.
     *
     * The directory does not have to be a sub-folder of `REPOSITORY`.
     *
     * **Note**: `{repository}` is replaced by the directory specified by `REPOSITORY`.
     */
    const REPOSITORY_CACHE_CONFIGS = 'repository/cache/configs';

    /**
     * Specify the path to the _files_ directory.
     *
     * The directory does not have to be a sub-folder of `REPOSITORY`.
     *
     * **Note**: `{repository}` is replaced by the directory specified by `REPOSITORY`.
     */
    const REPOSITORY_FILES = 'repository/files';

    /**
     * Specify the path to the _tmp_ directory.
     *
     * The directory does not have to be a sub-folder of `REPOSITORY`.
     *
     * **Note**: `{repository}` is replaced by the directory specified by `REPOSITORY`.
     */
    const REPOSITORY_TMP = 'repository/tmp';

    /**
     * Specify the path to the _var_ directory.
     *
     * The directory does not have to be a sub-folder of `REPOSITORY`.
     *
     * **Note**: `{repository}` is replaced by the directory specified by `REPOSITORY`.
     */
    const REPOSITORY_VARS = 'repository/var';

    /**
     * Specify session parameters.
     */
    const SESSION = 'session';

    /**
     * Synthesize the `app` config, from `app` fragments.
     *
     * @param array $fragments
     *
     * @return array
     */
    static public function synthesize(array $fragments)
    {
        $config = array_merge_recursive(...array_values($fragments));

        self::normalize_repository($config);

        return $config;
    }

    /**
     * Normalize `REPOSITORY*` items.
     *
     * @param array $config
     */
    static private function normalize_repository(array &$config)
    {
        static $interpolatable = [

            self::REPOSITORY_CACHE,
            self::REPOSITORY_CACHE_CONFIGS,
            self::REPOSITORY_FILES,
            self::REPOSITORY_TMP,
            self::REPOSITORY_VARS

        ];

        $repository = &$config[self::REPOSITORY];

        if (!file_exists($repository))
        {
            throw new \LogicException("The directory does not exists: $repository");
        }

        $repository = realpath($repository);

        foreach ($interpolatable as $item)
        {
            $config[$item] = str_replace('{repository}', $repository, $config[$item]) . DIRECTORY_SEPARATOR;
        }

        $repository .= DIRECTORY_SEPARATOR;
    }
}
ICanBoogie/ICanBoogie 4.0.x API documentation generated by ApiGen