Source for file ConfigAdapterXml.php

Documentation is available at ConfigAdapterXml.php

  1. 1: <?php
  2. 2:  
  3. 3: /**
  4. 4:  * Nette Framework
  5. 5:  *
  6. 6:  * Copyright (c) 2004, 2009 David Grudl (http://davidgrudl.com)
  7. 7:  *
  8. 8:  * This source file is subject to the "Nette license" that is bundled
  9. 9:  * with this package in the file license.txt.
  10. 10:  *
  11. 11:  * For more information please see https://nette.org
  12. 12:  *
  13. 13:  * @copyright  Copyright (c) 2004, 2009 David Grudl
  14. 14:  * @license    https://nette.org/license  Nette license
  15. 15:  * @link       https://nette.org
  16. 16:  * @category   Nette
  17. 17:  * @package    Nette\Config
  18. 18:  * @version    $Id$
  19. 19:  */
  20. 20:  
  21. 21:  
  22. 22:  
  23. 23: require_once dirname(__FILE__'/../Config/IConfigAdapter.php';
  24. 24:  
  25. 25:  
  26. 26:  
  27. 27: /**
  28. 28:  * Reading and writing XML files.
  29. 29:  *
  30. 30:  * @author     David Grudl
  31. 31:  * @copyright  Copyright (c) 2004, 2009 David Grudl
  32. 32:  * @package    Nette\Config
  33. 33:  */
  34. 34: final class ConfigAdapterXml implements IConfigAdapter
  35. 35: {
  36. 36:  
  37. 37:     /**
  38. 38:      * Static class - cannot be instantiated.
  39. 39:      */
  40. 40:     final public function __construct()
  41. 41:     {
  42. 42:         throw new LogicException("Cannot instantiate static class " get_class($this));
  43. 43:     }
  44. 44:  
  45. 45:  
  46. 46:  
  47. 47:     /**
  48. 48:      * Reads configuration from XML file.
  49. 49:      * @param  string  file name
  50. 50:      * @param  string  section to load
  51. 51:      * @return array 
  52. 52:      */
  53. 53:     public static function load($file$section NULL)
  54. 54:     {
  55. 55:         throw new NotImplementedException;
  56. 56:  
  57. 57:         if (!is_file($file|| !is_readable($file)) {
  58. 58:             throw new FileNotFoundException("File '$file' is missing or is not readable.");
  59. 59:         }
  60. 60:  
  61. 61:         $data new SimpleXMLElement($fileNULLTRUE);
  62. 62:  
  63. 63:         foreach ($data as $secName => $secData{
  64. 64:             if ($secData['extends']{
  65. 65:                 // $data[$child] = $secData;
  66. 66:             }
  67. 67:         }
  68. 68:  
  69. 69:         return $data;
  70. 70:     }
  71. 71:  
  72. 72:  
  73. 73:  
  74. 74:     /**
  75. 75:      * Write XML file.
  76. 76:      * @param  Config to save
  77. 77:      * @param  string  file
  78. 78:      * @return void 
  79. 79:      */
  80. 80:     public static function save($config$file$section NULL)
  81. 81:     {
  82. 82:         throw new NotImplementedException;
  83. 83:     }
  84. 84:  
  85. 85: }