Download the PHP package dapepe/xily without Composer
On this page you can find all versions of the php package dapepe/xily. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package xily
Short Description Xily is a leight-weight PHP framework to develop XML-based applications.
License LGPL-3.0-or-later
Informations about the package xily
Xily - An XML processing and templating library for PHP
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
Xily has been developed by Peter Haider at ZeyOS. 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?
Lightweight
Xily is focused around it’s core features – which is utilizing XML. The core library consists of 5 files in total!
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
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
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
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
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
The Config
class is a singleton providing access to global configuration settings.
Xily Base
The Base
class provides basic utility methods shared by the Dict
, XML
and Bean
class
Tests and examples
Xily XML
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.
First, we will load the XML structure from a file.
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:
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.
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.
This would be the equivalent to
You can also use a sub-path as a selector. Let's get all recipes that include "Salt" as a ingredient
For more examples, check out the sample script test/test.xml.php
Xily Bean
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
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
This is how the form would look in regular HTML:
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:
Far less clutter right? In order to achieve this, we simply add two new Bean classes to our project:
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:
To stick with our previous example: For our custom beans <form:frame/>
and <form:field/>
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)
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.
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:
XDR | Description |
---|---|
#{.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 variable |
You can also access PHP's predefined variables:
XDR variable name | Description |
---|---|
%SERVER | Equals PHP's $_SERVER variable — Server and execution environment information |
%GET | Equals PHP's $_GET variable — HTTP GET variables |
%POST | Equals PHP's $_POST variable — HTTP POST variables |
%FILES | Equals PHP's $_FILES variable — HTTP File Upload variables |
%REQUEST | Equals PHP's $_REQUEST variable — HTTP Request variables |
%SESSION | Equals PHP's $_SESSION variable — Session variables |
%ENV | Equals PHP's $_ENV variable — Evariable nvironment variables |
%COOKIE | Equals PHP's $_COOKIE variable — HTTP Cookies |
%HTTP | Equals PHP's $HTTP_RAW_POST_DATA variable — Raw POST data |
Xily Config
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:
However, you can also use the load
method do directly load an associative array:
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.
In the same fashion you can use the set
method to change or set single configuration values, e.g.
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:
Also, you can use the get
method to cast a specific variable type and also to initialize a default value.
Specify the expected variable type (string, int, float, array, bool, object) and a default value as additional parameters for the get
method:
For more examples, check out the sample script test/test.config.php
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.
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 http://www.gnu.org/licenses/lgpl.txt.