Ejemplo n.º 1
0
 /**
  * Save settings
  *
  * Save settings using file path provided. A file path can be an absolute
  * path, relative path to AnEngine root directory (the one with index.php in
  * it) or relative path to include path. File path must contain the target
  * file name including extension.
  *
  * If the file path is not passed, current {@link AeSettings_Driver_Xml::_filename}
  * property value will be used. If the latter is not set either, the file
  * will be created in the AnEngine root dir, with {@link
  * AeSettings_Driver_Xml::_section} plus .xml extension as its filename.
  *
  * Any multi-dimensional arrays, set via advanced <var>$name</var> usage of
  * the {@link AeSettings_Driver_Xml::set()} method, will be written as a
  * multi-dimensional array:
  * <code> $params->set('section.foo.bar', 'baz');
  * $params->save('section.xml');</code>
  *
  * The above code will produce something like this in the xml file:
  * <code> <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  * <settings path="section.xml" date="Sun, 29 Nov 2009 05:48:11 +0200" generator="AeSettings_Driver_Xml">
  *     <section>
  *         <foo>
  *             <bar type="string">baz</bar>
  *         </foo>
  *     </section>
  * </settings></code>
  *
  * @param string $data setting file path
  *
  * @return bool true on success, false otherwise
  */
 public function save($data = null)
 {
     if ($data === null) {
         $data = $this->_filename === null ? $this->_section : $this->_filename;
     }
     // *** Check extension and add if required
     if (strpos($data, '.') === false) {
         $data .= '.' . self::EXTENSION;
     }
     if ($data === null || file_exists($data) && !is_writable($data)) {
         return false;
     }
     $data = AeFile::absolutePath($data);
     $xml = AeXml::element('settings');
     $xml->setAttributes(array('path' => $data, 'date' => date('r'), 'generator' => $this->getClass()));
     if (count($this->_properties) > 0) {
         foreach ($this->_properties as $section => $settings) {
             $this->_valueToString($section, $settings, $xml);
         }
     }
     $xml->save($data);
     return $this;
 }
Ejemplo n.º 2
0
 /**
  * Element start handler
  *
  * This method handles elements' opening tags
  *
  * @param resource $parser     XML Parser
  * @param string   $name       element tag name
  * @param array    $properties element properties
  *
  * @return bool
  */
 public function startElement($parser, $name, $properties = array())
 {
     $level = count($this->_position);
     if ($level == 0) {
         // *** Root element
         $this->_result = AeXml::element($name);
         $this->_position = $this->_result;
     } else {
         $this->_position = $this->_position->addChild($name);
     }
     $this->_position->setAttributes($properties);
     return true;
 }