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