PHPackages                             dapepe/xily - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. dapepe/xily

ActiveLibrary

dapepe/xily
===========

Xily is a leight-weight PHP framework to develop XML-based applications.

1.0.5(8y ago)3327LGPL-3.0-or-laterPHPPHP &gt;=5.4.0

Since Oct 17Pushed 8y ago4 watchersCompare

[ Source](https://github.com/dapepe/xily)[ Packagist](https://packagist.org/packages/dapepe/xily)[ RSS](/packages/dapepe-xily/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (6)DependenciesVersions (7)Used By (0)

Xily - An XML processing and templating library for PHP
=======================================================

[](#xily---an-xml-processing-and-templating-library-for-php)

Purpose
-------

[](#purpose)

Xily is a leight-weight PHP framework to develop XML-based applications. The framework contains five core classes, which enable working. One major aspect is the representation of XML data in an DOM-like object model. Based on this model you can use Xily to add individual parsers (xilyBeans) for each XML tag, which enables developers to create modular, XML-driven web-applications.

A bit of history
----------------

[](#a-bit-of-history)

Xily has been developed by [Peter Haider](https://github.com/dapepe) at [ZeyOS](http://www.zeyos.com). The development started in 2008 when the team was in need for a framework to develop websites and portals. At the time we were looking at a lot of XML-based based templating systems such as Adobe ColdFusion, Open Laszlo or Adobe Flex. The approach to use XML to describe part of the the front-end really appealed to us and we figured that we would like to have something similar for PHP. And since every project might have different requirements it would be nice to extend the XML engine with new behaviour and tags.

The result of all this was Xily, a Framework which enabled us to (a.) process XML documents in PHP and (b.) to develop completely XML-driven applications and websites, by simply encapsulating complex objects and program logic in single objects called Xily Beans.

Why Xily?
---------

[](#why-xily)

### Lightweight

[](#lightweight)

Xily is focused around it’s core features – which is utilizing XML. The core library consists of 5 files in total!

### Focused

[](#focused)

Xily serves one purpose only: To create XML-driven apps in PHP. You can use the xilyXML library to simply process XML documents, while xilyBeans enable you to create XML-driven applications and websites by developing your own set of XML-commands.

### Extensible

[](#extensible)

You can extend and enhance Xily as you go. Xily doesn’t force any specific way of doing things on you – you can even create your own set of XML commands.

Main components
---------------

[](#main-components)

### Xily XML

[](#xily-xml)

The `XML` class is being used to work with XML structures. It can be used to parse an XML file/string and to work dynamically with this information or to manipulate the XML structure.

### Xily Bean

[](#xily-bean)

The `Bean` class allows you to attach application logic to specific XML tags, this means you can practically define your custom XML command palette.

### Xily Dictionary

[](#xily-dictionary)

The `Dictionary` class provides an interface between XML and Array, so that Arrays can be treated like an XML tree within the `Bean` class.

### Xily Config

[](#xily-config)

The `Config` class is a [singleton](http://en.wikipedia.org/wiki/Singleton_pattern) providing access to global configuration settings.

### Xily Base

[](#xily-base)

The `Base` class provides basic utility methods shared by the `Dict`, `XML` and `Bean` class

Tests and examples
------------------

[](#tests-and-examples)

### Xily XML

[](#xily-xml-1)

You will find a couple of test cases in the `/test` directory. Let's just look at a quick example how to process an XML file.

```

		Pancakes

			200g flour
			2 eggs
			3 tea spoons of sugar
			100ml milk
			100ml water

		Barbecue steak

			250g steak
			5 potatoes
			Oil
			Pepper
			Salt
			Garlic
			Chilli

		Scrambled eggs

			3 eggs
			Pepper
			Salt

```

First, we will load the XML structure from a file.

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

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 20 minutes:

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

If you only want to select a single node, you can use the getNodeByPath function. This will select the first node that has a cooking time under 30 minutes and is easy to prepare.

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

A trace returns the value or an attribute of a required node, rather than the node itself. This example get the value of the "title" node.

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

This would be the equivalent to

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

You can also use a sub-path as a selector. Let's get all recipes that include "Salt" as a ingredient

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

For more examples, check out the sample script `test/test.xml.php`

### Xily Bean

[](#xily-bean-1)

When developing XML-based applications, you don't want to use XML only to define the structure and data of your application, but also to define its behaviour and presentation. Xily Beans allow you to divide your application into single, reusable units and to access these units by representing them in an XML structure. This way it becomes easy for you to develop your applications directly in XML - as you would, for example, in Adobe Flex of OpenLaszlo - as the actual coding afford is embedded inside your Xily Bean classes. This way you can focus on factors such as design, architecture and usability rather than on the coding process itself.

#### Creating custom Beans

[](#creating-custom-beans)

Let's create a simple example. Let's say we want to create a simple HTML form. For this example, we will be using [Bootstrap CSS 3.0.2](http://getbootstrap.com/css/#forms)

This is how the form would look in regular HTML:

```

    First name

    Last name

    E-mail

    Region

        - Please Select -
        North America
        Central America
        South America
        European Union
        Eastern Europe
        Africa
        Middle East
        Asia
        Oceania
        The Caribbean

```

As you can see, there's a lot of repetive HTML that could easily be avoided. Also, what if you want to Update Bootstrap later on and class names and HTML structure might have changed? For exactly this reason, it's more efficient to create a class for form elements

Wouldn't it be much nicer to write something like this:

```

		North America
		Central America
		South America
		European Union
		Eastern Europe
		Africa
		Middle East
		Asia
		Oceania
		The Caribbean

```

Far less clutter right? In order to achieve this, we simply add two new Bean classes to our project:

```
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 ''
				.$this->dump($xmlData, $intLevel+1)
				.'';
	}
}

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 = ''
				.''
				.$this->attribute('label')
				.($this->isTrue('required') ? '' : '')
				.''
				.'';

		if ($this->hasChildren()) {
			$elem .= ''
					.($this->hasAttribute('placeholder') ? ''.$this->attribute('placeholder').'' : '');

			foreach ($this->children() as $xmlChild) {
				if (!$xmlChild->hasAttribute('value'))
					$xmlChild->setAttribute('value', trim($xmlChild->value()));
				if ($this->hasAttribute('selected') && $this->attribute('selected') == $xmlChild->attribute('value'))
					$xmlChild->setAttribute('selected', 'selected');

				$elem .= $xmlChild->toString();
			}

			$elem .= '';
		} elseif ($this->attribute('type') == 'multi') {
			$elem .= '';
		} else {
			$elem .= '';
		}

		return $elem.'';
	}
}
```

These two classes automatically generate the entire form. You now have reusable component classes that you can treat just as HTML tags.

In order to make it easier for you to work with different Bean libraries, Xily uses *lazy loading* to include the required files while parsing the XML file. You can simply include your bean directories by adding them to the `BEAN_DIRS` array of the `Bean` class:

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

To stick with our previous example: For our custom beans `` and `` we create a directory in our `custombeans` directory called `form` and create two files called `frame.php` and `field.php`, each containing the corresponding Bean class.

#### Working with Xily Data References (XDR)

[](#working-with-xily-data-references-xdr)

Besides defining custom Beans, once major aspect of are Xily Data References (XDR). XDRs enable you to dynamically reference and access data inside your document.

Let's have a simple example: You want to create a small portal page, where also want to display the recent posts of your blog and display them nicely inside a list.

```

			#{title}
			#{description}
			Read all

```

XDRs offer a variety of methods to access data dynamically. There are 7 different types of XDRs in order to provide a wide range of access possibilities:

XDRDescription`#{.objectpath}`Evaluates an XML path relative to the application's XML structure`#{datapath}`Applies a path to the object's temporary dataset.`#{objectpath->datapath}`Selects a local node and applys a datapath to its default dataset`#{objectpath->dataset->datapath}`Selects a local node and applys a datapath to a specific default dataset`#{object::dataset}`Requests the complete dataset of the specified object`#{%global}`References a global variable`#{%global->datapath}`Applies a data path to a global variableYou can also access PHP's [predefined variables](http://php.net/manual/en/reserved.variables.php):

XDR variable nameDescription%SERVEREquals PHP's [$\_SERVER](http://www.php.net/manual/en/reserved.variables.server.php) variable — Server and execution environment information%GETEquals PHP's [$\_GET](http://www.php.net/manual/en/reserved.variables.get.php) variable — HTTP GET variables%POSTEquals PHP's [$\_POST](http://www.php.net/manual/en/reserved.variables.post.php) variable — HTTP POST variables%FILESEquals PHP's [$\_FILES](http://www.php.net/manual/en/reserved.variables.files.php) variable — HTTP File Upload variables%REQUESTEquals PHP's [$\_REQUEST](http://www.php.net/manual/en/reserved.variables.request.php) variable — HTTP Request variables%SESSIONEquals PHP's [$\_SESSION](http://www.php.net/manual/en/reserved.variables.session.php) variable — Session variables%ENVEquals PHP's [$\_ENV](http://www.php.net/manual/en/reserved.variables.environment.php) variable — Evariable nvironment variables%COOKIEEquals PHP's [$\_COOKIE](http://www.php.net/manual/en/reserved.variables.cookies.php) variable — HTTP Cookies%HTTPEquals PHP's [$HTTP\_RAW\_POST\_DATA](http://www.php.net/manual/en/reserved.variables.httprawpostdata.php) variable — Raw POST data### Xily Config

[](#xily-config-1)

The `Config` class can be used to load and access global app configuration settings.

You can load configuration settings from either JSON or INI files, for instance:

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

However, you can also use the `load` method do directly load an associative array:

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

You can access the configuration option using the `get` method. When loading a multi-dimensional configuration file, you can select single nodes by using a simple dot concatination, e.g.

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

In the same fashion you can use the `set` method to change or set single configuration values, e.g.

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

The `Config` class also includes methods to initialize the return value. For instance, if your config file includes a reference to a directory, you might want to make sure that the value has a trailing slash at the end of the directory name:

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

Also, you can use the `get` method to cast a specific variable type and also to initialize a default value.

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

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

```

Specify the expected variable type (string, int, float, array, bool, object) and a default value as additional parameters for the `get` method:

```
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
```

For more examples, check out the sample script `test/test.config.php`

Contribute
----------

[](#contribute)

Currently, Xily is used in a lot of different projects, so I am constantly trying to enhance and test the framework. I have started with the development of Xily in 2008, so the overall structure and functionality is pretty well tested so far. However, I would be more than happy to find more participants for the project. I am especially looking for help regarding

- Debugging and testing
- Adding more examples and tutorials
- Maintenance of the Xily website
- Writing new Xily Beans to extend the overall functionality

If you’re up to it – I am looking forward to hearing from you! Simply drop me a message on [GitHub](https://github.com/dapepe).

License
-------

[](#license)

Copyright (C) 2008-2016 Peter-Christoph Haider

This work is licensed under the GNU Lesser General Public License (LGPL) which should be included with this software. You may also get a copy of the GNU Lesser General Public License from .

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~240 days

Recently: every ~273 days

Total

6

Last Release

3022d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/73f59bbbf0bea604e68e44b4150ed339c2e789859992ea1ea415aea691e0bde7?d=identicon)[zeyos](/maintainers/zeyos)

---

Top Contributors

[![dapepe](https://avatars.githubusercontent.com/u/89526?v=4)](https://github.com/dapepe "dapepe (28 commits)")

### Embed Badge

![Health badge](/badges/dapepe-xily/health.svg)

```
[![Health](https://phpackages.com/badges/dapepe-xily/health.svg)](https://phpackages.com/packages/dapepe-xily)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
