[ Index ]
 

Code source de Symfony 1.0.0

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/lib/vendor/propel-generator/templates/conf/ -> xml.tpl (source)

   1  <?php
   2  
   3  /**
   4   * Template that converts XML files into PHP arrays.
   5   *
   6   * See the provided projects/bookstore/runtime-conf.xml file for an example.
   7   *
   8   * @author Hans Lellelid <hans@xmpl.org>
   9   * @version $Revision: 1.2 $
  10   */
  11   
  12   // --------------------------------------------------------------------------------
  13  
  14  // Added function_exists check for ticket:244, allowing multiple calls to convert-props
  15  if (!function_exists('simplexml_to_array')) {
  16  /**
  17   * Converts simplexml object into array, turning attributes into child elements.
  18   *
  19   * From a helpful php.net comment.
  20   * @author Christophe VG
  21   */ 
  22  function &simplexml_to_array( $xml ) {
  23      $ar = array();
  24  
  25      foreach( $xml->children() as $k => $v ) {        
  26          
  27          // recurse the child
  28          $child = simplexml_to_array( $v );
  29          
  30          //print "Recursed down and found: " . var_export($child, true) . "\n";
  31          
  32          // if it's not an array, then it was empty, thus a value/string
  33          if( count($child) == 0 ) {            
  34              $child = (string)$v;
  35          }
  36      
  37          // add the childs attributes as if they where children
  38          foreach( $v->attributes() as $ak => $av ) {
  39              
  40              // if the child is not an array, transform it into one
  41              if( !is_array( $child ) ) {
  42                  $child = array( "value" => $child );
  43              }
  44  
  45              if ($ak == 'id') {
  46                  // special exception: if there is a key named 'id'
  47                  // then we will name the current key after that id
  48                  $k = (string) $av;
  49              } else {
  50                  // otherwise, just add the attribute like a child element
  51                  $child[$ak] = (string) $av;
  52              }
  53          }
  54          
  55           // if the $k is already in our children list, we need to transform
  56           // it into an array, else we add it as a value
  57           if( !in_array( $k, array_keys($ar) ) ) {
  58               $ar[$k] = $child;
  59           } else {
  60               // if the $ar[$k] element is not already an array, then we need to make it one
  61               if ( !is_array( $ar[$k] ) ) { $ar[$k] = array( $ar[$k] ); }
  62               $ar[$k][] = $child;
  63           }
  64      
  65      }
  66      return $ar;
  67  }
  68  } // if (!function_exists...)
  69   
  70   // we expect to have:
  71   //        $propertiesFile - path to properties file.
  72  
  73   $xmlDom = new DOMDocument();
  74   
  75   $xmlDom->load($propertiesFile);
  76   $xml = simplexml_load_string($xmlDom->saveXML());
  77   
  78   echo '<' . '?' . "php\n";
  79   echo "// This file generated by Propel convert-props target on " . strftime("%c") . "\n";
  80   echo "// from XML runtime conf file " . $pfile->getPath() . "\n";
  81   echo "return ";
  82   var_export(simplexml_to_array( $xml ));
  83   echo ";"; 


Généré le : Fri Mar 16 22:42:14 2007 par Balluche grâce à PHPXref 0.7