📜 ⬆️ ⬇️

qJerry: write less, do more. Now in PHP.

Somehow, invisibly on Habré, the appearance of an interesting, in my opinion, library passed.

About qJerry library


qJerry is a library for working with XML documents written in PHP. The main mission of qJerry is to make working with XML more comfortable than standard PHP tools, such as the DOM extension, allow.

When developing modern web applications, XML, PHP and JavaScript are often found together in order to realize the miracle called AJAX. However, the developer of such a meeting can cost a lot of time and nerves if he does not arm himself with good tools. One such tool that makes life easier for us is the jQuery library. It would not be an exaggeration to say that it is so easy to use, and the principles underlying it are so simple and ingenious that you want to take them beyond the bounds of JavaScript and use them everywhere you have to work with XML. The qJerry library is just such an attempt to project on the PHP approach used in jQuery.
')
Undoubtedly, the most pleasant feature of jQuery is that the code written with it is several times smaller than the functionally similar code written using standard tools, not to mention a significant time saving. Like jQuery, which saved honest JavaScript programmers from a lot of extra work, qJerry tries to do the same for those who write in PHP. And while qJerry is primarily aimed at web application creators, it can be useful to anyone who has to work with XML in PHP.

qJerry is a kind of wrapper for the DOM extension and almost completely copies the behavior and API of the jQuery library, familiar to many web developers. There are several important differences:



QJerry usage examples


Simple example

Suppose we need to create such an XML document:
  <? xml version = "1.0" encoding = "UTF-8"?>
 <items> <item id = "1" /> <item id = "2" /> </ items> 


We do this using the traditional DOM:
$dom = new DOMDocument('1.0', 'UTF-8');
$dom->appendChild($dom->createElement('items'));
$dom->documentElement->appendChild($dom->createElement('item'))->setAttribute('id', '1');
$dom->documentElement->appendChild($dom->createElement('item'))->setAttribute('id', '2');
echo $dom->saveXML();


And now the same thing with qJerry:
q('items')->append('item')->attr('id', '1')->end()->append('item')->attr('id', '2')->dump();

It's not hard to see that qJerry makes working with XML much easier than DOM, even in the most trivial case, not to mention the complex manipulations with multiple queries and changes to the XML tree.

Well, actually the library: qJerry

Source: https://habr.com/ru/post/55963/


All Articles