insert() public method

public insert ( $elements, $point )
Ejemplo n.º 1
0
 /**
  * Insert the file entry into the XML at the given point.
  *
  * @param DOMNode $point Insertion point.
  *
  * @return NULL
  */
 public function insert(DOMNode $point = null)
 {
     if ($point === null) {
         $point = $this->_parent->getDirectoryNode()->lastChild;
     } else {
         if ($point->previousSibling) {
             $ws = trim($point->previousSibling->textContent);
             if (empty($ws)) {
                 $point = $point->previousSibling;
             }
         }
     }
     $this->setFileNode($this->_xml->insert(array("\n " . str_repeat(" ", $this->_level), 'file' => array('name' => $this->_name, 'role' => $this->_role)), $point));
 }
Ejemplo n.º 2
0
 /**
  * Insert the directory entry into the XML at the given point.
  *
  * @param Horde_Pear_Package_Xml_Element_Directory $parent The parent.
  * @param DOMNode                                  $point  Insertion point.
  *
  * @return NULL
  */
 private function _insert(Horde_Pear_Package_Xml_Element_Directory $parent, DOMNode $point = null)
 {
     if ($point === null) {
         $point = $parent->getDirectoryNode()->lastChild;
     } else {
         if ($point->previousSibling) {
             $ws = trim($point->previousSibling->textContent);
             if (empty($ws)) {
                 $point = $point->previousSibling;
             }
         }
     }
     $dir = $this->_xml->insert(array("\n " . str_repeat(" ", $this->_level), 'dir' => array('name' => $this->_name), ' ', $this->_xml->createComment(' ' . $this->_path . ' ')), $point);
     $this->_xml->append("\n" . str_repeat(' ', $this->_level + 1), $dir);
     $this->setDirectoryNode($dir);
 }
Ejemplo n.º 3
0
 /**
  * Add a file to the list.
  *
  * @param string $file   The file name.
  * @param array  $params Additional file parameters.
  *
  * @return NULL
  */
 public function add($file, $params)
 {
     $this->_dir_list->addFile($file, $params);
     if (!in_array($file, array_keys($this->_install_list))) {
         $point = $this->_getInstallInsertionPoint($file);
         if ($point === null) {
             $point = $this->_filelist->lastChild;
         } else {
             if ($point->previousSibling) {
                 $ws = trim($point->previousSibling->textContent);
                 if (empty($ws)) {
                     $point = $point->previousSibling;
                 }
             }
         }
         $this->_install_list[$file] = $this->_xml->insert(array("\n   ", 'install' => array('as' => $params['as'], 'name' => substr($file, 1))), $point);
     }
 }
Ejemplo n.º 4
0
 /**
  * Execute the task.
  *
  * @return NULL
  */
 public function run()
 {
     $contents = $this->_xml->findNode('/p:package/p:contents/p:dir');
     if ($contents && !empty($this->_options['regenerate'])) {
         $contents = $this->_xml->findNode('/p:package/p:contents');
         $this->_xml->removeWhitespace($contents->previousSibling);
         $this->_xml->findNode('/p:package')->removeChild($contents);
         $contents = false;
     }
     $filelist = $this->_xml->findNode('/p:package/p:phprelease/p:filelist');
     if ($filelist && !empty($this->_options['regenerate'])) {
         $filelist = $this->_xml->findNode('/p:package/p:phprelease');
         $this->_xml->removeWhitespace($filelist->previousSibling);
         $this->_xml->findNode('/p:package')->removeChild($filelist);
         $filelist = false;
     }
     if (!$contents) {
         $root = $this->_xml->insert(array('contents' => array(), "\n "), $this->_xml->findNode('/p:package/p:dependencies'));
         $contents = $this->_xml->append(array("\n  ", 'dir' => array('baseinstalldir' => '/', 'name' => '/'), ' ', $this->_xml->createComment(' / '), "\n "), $root);
         $this->_xml->append("\n  ", $contents);
     }
     if (!$filelist) {
         $root = $this->_xml->insert(array('phprelease' => array(), "\n "), $this->_xml->findNode('/p:package/p:changelog'));
         $filelist = $this->_xml->append(array("\n  ", 'filelist' => array(), "\n "), $root);
         $this->_xml->append("\n  ", $filelist);
     }
     $current = $this->_xml->createContents($this->_xml, $contents, $filelist);
     $current->update($this->_content);
     try {
         if (empty($this->_options['no_timestamp'])) {
             $this->_xml->timestamp();
         }
         $this->_xml->syncCurrentVersion();
     } catch (Horde_Pear_Exception $e) {
         /**
          * Ignore errors in this operation as it is not mandatory for
          * updating the file list.
          */
     }
 }