Packages

  • Nette
    • Application
      • Diagnostics
      • Responses
      • Routers
      • UI
    • Caching
      • Storages
    • ComponentModel
    • Config
      • Adapters
      • Extensions
    • Database
      • Diagnostics
      • Drivers
      • Reflection
      • Table
    • DI
      • Diagnostics
    • Diagnostics
    • Forms
      • Controls
      • Rendering
    • Http
    • Iterators
    • Latte
      • Macros
    • Loaders
    • Localization
    • Mail
    • Reflection
    • Security
      • Diagnostics
    • Templating
    • Utils
      • PhpGenerator
  • NetteModule
  • none

Classes

Interfaces

  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Other releases
  • Nette homepage
 1: <?php
 2: 
 3: /**
 4:  * This file is part of the Nette Framework (https://nette.org)
 5:  * Copyright (c) 2004 David Grudl (http://davidgrudl.com)
 6:  * @package Nette\Config
 7:  */
 8: 
 9: 
10: 
11: /**
12:  * Configuration helpers.
13:  *
14:  * @author     David Grudl
15:  * @package Nette\Config
16:  */
17: class ConfigHelpers
18: {
19:     const EXTENDS_KEY = '_extends',
20:         OVERWRITE = TRUE;
21: 
22: 
23:     /**
24:      * Merges configurations. Left has higher priority than right one.
25:      * @return array
26:      */
27:     public static function merge($left, $right)
28:     {
29:         if (is_array($left) && is_array($right)) {
30:             foreach ($left as $key => $val) {
31:                 if (is_int($key)) {
32:                     $right[] = $val;
33:                 } else {
34:                     if (is_array($val) && isset($val[self::EXTENDS_KEY])) {
35:                         if ($val[self::EXTENDS_KEY] === self::OVERWRITE) {
36:                             unset($val[self::EXTENDS_KEY]);
37:                         }
38:                     } elseif (isset($right[$key])) {
39:                         $val = self::merge($val, $right[$key]);
40:                     }
41:                     $right[$key] = $val;
42:                 }
43:             }
44:             return $right;
45: 
46:         } elseif ($left === NULL && is_array($right)) {
47:             return $right;
48: 
49:         } else {
50:             return $left;
51:         }
52:     }
53: 
54: 
55:     /**
56:      * Finds out and removes information about the parent.
57:      * @return mixed
58:      */
59:     public static function takeParent(& $data)
60:     {
61:         if (is_array($data) && isset($data[self::EXTENDS_KEY])) {
62:             $parent = $data[self::EXTENDS_KEY];
63:             unset($data[self::EXTENDS_KEY]);
64:             return $parent;
65:         }
66:     }
67: 
68: 
69:     /**
70:      * @return bool
71:      */
72:     public static function isOverwriting(& $data)
73:     {
74:         return is_array($data) && isset($data[self::EXTENDS_KEY]) && $data[self::EXTENDS_KEY] === self::OVERWRITE;
75:     }
76: 
77: 
78:     /**
79:      * @return bool
80:      */
81:     public static function isInheriting(& $data)
82:     {
83:         return is_array($data) && isset($data[self::EXTENDS_KEY]) && $data[self::EXTENDS_KEY] !== self::OVERWRITE;
84:     }
85: 
86: }
87: 
Nette Framework 2.0.18 (for PHP 5.2, un-prefixed) API documentation generated by ApiGen 2.8.0