示例#1
0
文件: Dict.php 项目: dapepe/xily
 /**
  * Converts the array into an Xily\Xml object
  *
  * @param Xily\Xml $xmlNode
  * @param array $mxtData
  * @param bool $bolAssoc
  * @return Xily\Xml
  */
 private function fromXml($xmlNode, $mxtData, $bolAssoc)
 {
     if (is_array($mxtData)) {
         if ($bolAssoc && self::checkAssoc($mxtData)) {
             foreach ($mxtData as $key => $value) {
                 $xmlChild = new Xml($key);
                 $xmlNode->addChild(self::fromXml($xmlChild, $value, $bolAssoc));
             }
         } else {
             foreach ($mxtData as $key => $value) {
                 $xmlChild = new Xml('node', null, array('key' => $key));
                 $xmlNode->addChild(self::fromXml($xmlChild, $value, $bolAssoc));
             }
         }
     } else {
         $xmlNode->setValue($mxtData);
     }
     return $xmlNode;
 }
示例#2
0
文件: View.php 项目: dapepe/microdb
 /**
  * Returns an xilyXML object of the table.
  * $mxtResource can be either an array (as a result of the chart() method)
  * or a string representing a WHERE statement to execute the chart() method.
  *
  * @param string|object $mxtResource Optional WHETE statement or an array containing the results of the chart() function
  * @return xilyXML|false Returns a xilyXML object
  */
 public function toXML($mxtResource = "")
 {
     if (is_string($mxtResource) || !$mxtResource) {
         $mxtResource = $this->chart($mxtResource);
     }
     if (is_array($mxtResource)) {
         $xlyXML = new \Xily\Xml($this->strID);
         // Array format should be $row[0]['name']
         for ($i = 0; $i < sizeof($mxtResource); $i++) {
             $arrAttributes = array();
             $arrChildren = array();
             $z = 0;
             foreach ($mxtResource[$i] as $key => $value) {
                 if (!$this->arrExclued[$key]) {
                     if ($this->arrAsTag[$key]) {
                         $arrChildren[$key] = $value;
                     } else {
                         $arrAttributes[$key] = $value;
                     }
                 }
             }
             if ($this->strMainTag) {
                 $strItemName = $this->strMainTag;
             } else {
                 $strItemName = 'item';
             }
             $xlyXML->addChild(new \Xily\Xml($strItemName, '', $i, '', $arrAttributes));
             // print_r($arrChildren);
             foreach ($arrChildren as $tag => $value) {
                 $xlyXML->child($i)->addChild(new \Xily\Xml($tag, '', $z, $value));
                 $z++;
             }
         }
         return $xlyXML;
     } else {
         throw new Exception('Could not generate XML object: No valid data resource available');
     }
 }
示例#3
0
文件: test.xml.php 项目: dapepe/xily
<?php

header('Content-type: text/plain; charset=UTF-8');
include dirname(__FILE__) . '/../src/config.php';
include dirname(__FILE__) . '/../src/base.php';
include dirname(__FILE__) . '/../src/xml.php';
$data = Xily\Xml::create(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'library.xml', 1);
/* First, we will load the XML structure from a file. */
$xmlRecipes = Xily\XML::create('data/recipes.xml', true);
/* We can also load the XML object from a string */
$xmlTest = Xily\XML::create('
	<mytag>
		<subtag attribute="hello world">some value</subtag>
		<anothertag>and so on</anothertag>
	</mytag>
');
// You can convert the document back to a string
echo $xmlRecipes->toString() . "\n";
// You can also display a XML document as tree
echo $xmlRecipes->toTree() . "\n";
/* Xily XML uses a syntax similar to E4X to select nodes in the strucute
 * The getNodeByPath function gets all nodes that match the path's description
 * This example lists all recipes which have a cookingtime under 30 minutes and
 * are easy to prepare: */
echo 'Recipes with cooking time < 30' . "\n";
$arrRecipes = $xmlRecipes->getNodesByPath('recipe(@cookingtime < 30)');
foreach ($arrRecipes as $xmlRecipe) {
    echo ' - ' . $xmlRecipe->trace('title') . "\n";
}
/* If you only want to select a single node, you can use the getNodeByPath function */
$xmlSomeRecipe = $xmlRecipes->getNodeByPath('recipe(@cookingtime < 30, @level == "easy")');
示例#4
0
文件: index.php 项目: dapepe/tymio
             }
             echo json_encode($res);
         }
     }
 } elseif (isset($_REQUEST['_lang'])) {
     /* RETURN THE LANGUAGE FILE AS A JAVASCRIPT OBJECT
     		-------------------------------------------------------------------- */
     header('Content-type: text/javascript; charset=utf-8');
     echo 'var $LANG = ' . $locale->getJSON(\Xily\Config::get('app.cache', 'bool', false) ? CACHE_DIR . 'locales' : false) . ';';
 } elseif (!empty($_POST['return']) and Form::verify('login')) {
     HTTP::forwardTo(HTTP::readPOST('return') . '?username='******'username']) ? $_POST['username'] : ''));
 } else {
     /* LOAD THE VIEW/CONTROLLER/MODULE
     		-------------------------------------------------------------------- */
     $view = isset($_REQUEST['view']) ? $_REQUEST['view'] : VIEW_DEFAULT;
     $xmlMeta = new \Xily\Xml();
     // The meta object will be passed on when the bean is run
     try {
         if (!preg_match('`^[a-z]{1,32}$`', $view)) {
             throw new Exception('View "' . $view . '" not found.');
         }
         if (!$userAuthenticated) {
             if (isset($_REQUEST['username']) && $_REQUEST['username'] != '') {
                 $message = 'Wrong username or password!';
             } else {
                 $message = 'Please login!';
             }
             throw new Exception($message);
         }
     } catch (Exception $e) {
         if ($e->getMessage() != '') {