Namespaces

  • 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
  • PHP

Classes

  • Compiler
  • CompilerExtension
  • Configurator
  • Helpers
  • Loader

Interfaces

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