PHP code example of dapepe / xily

1. Go to this page and download the library: Download dapepe/xily library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

dapepe / xily example snippets


$xmlRecipes = Xily\XML::create('data/recipes.xml', true);

$arrRecipes = $xmlRecipes->getNodesByPath('recipe(@cookingtime < 30)');
foreach ($arrRecipes as $xmlRecipe)
	echo $xmlRecipe->trace('title');

$xmlSomeRecipe = $xmlRecipes->getNodeByPath('recipe(@cookingtime < 30, @level == "easy")');

$xmlRecipes->trace('recipe(@id == "soup").title');

$xmlRecipes->getNodeByPath('recipe(@id == "soup")')->child('title')->value();

$arrRecipes = $xmlRecipes->getNodesByPath('recipe(ingredients.item == "Salt")');

class FormFrame extends Bean {
	public function result($xmlData, $intLevel=0) {
		if ($this->hasAttribute('left')) {
			if ($xmlData instanceof XML)
				$xmlData->setAttribute('left', $this->attribute('left'));
			else
				$xmlData = new XML('data', null, array('left' => $this->attribute('left')));
		}

		return '<form class="form-horizontal" role="form"'
				.($this->hasAttribute('id') ? ' id="'.$this->attribute('id').'"' : '')
				.($this->hasAttribute('action') ? ' action="'.$this->attribute('action').'"' : '')
				.($this->hasAttribute('target') ? ' target="'.$this->attribute('target').'"' : '')
				.($this->hasAttribute('style') ? ' style="'.$this->attribute('style').'"' : '')
				.'>'
				.$this->dump($xmlData, $intLevel+1)
				.'</form>';
	}
}

class FormField extends Bean {
	public function result($xmlData, $intLevel=0) {
		$widthLeft = 2;
		if ($this->hasAttribute('left'))
			$widthLeft = (int) $this->attribute('left');
		elseif ($xmlData instanceof XML && $xmlData->hasAttribute('left'))
			$widthLeft = (int) $xmlData->attribute('left');

		$widthRight = 12 - $widthLeft; // Bootstrap's grid system is based on 12 columns

		$id   = $this->attribute('id');
		$name = $this->attribute('name');

		if (!$id || $id == '') {
			if (!$name || $name == '')
				return; // Either a name or an ID will have to be specified

			$id = 'txt'.ucfirst($name); // Automatically create an ID based on the name
		} elseif (!$name || $name == '') {
			$name = $id;
		}

		$elem = '<div class="form-group">'
				.'<label for="'.$id.'" class="col-sm-'.$widthLeft.' control-label">'
				.$this->attribute('label')
				.($this->isTrue('

\Xily\Bean::$BEAN_DIRS[] = LIB_DIR.'xily/src/beans';
\Xily\Bean::$BEAN_DIRS[] = LIB_DIR.'custombeans';

Xily\Config::load('config.ini');

Xily\Config::load([
	'general' => [
		'option1' => 'value1',
		'option2' => 'value2'
	]
]);

Xily\Config::get('general.option1'); // Return "value1"

Xily\Config::set('general.option1', 'new value');

Xily\Config::set('mydir', '/var/www');
Xily\Config::getDir('mydir'); // Return "/var/www/"

Xily\Config::load('config.ini');
Xily\Config::get('general.debug', 'bool', true); // Returns FALSE
Xily\Config::get('numeric.taxrate', 'float', 1.19); // Returns the default value 1.19
Xily\Config::get('numeric.discount', 'float', 0); // Return 0.6

; config.ini
[general]
dir = "/var/www"
debug = 0

[numeric]
taxrate = "1,20"
discount = "0.60"