PHPackages                             jgswift/xral - 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. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. jgswift/xral

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

jgswift/xral
============

PHP 5.5+ resource abstraction layer

0.1.2(11y ago)55MITPHPPHP &gt;=5.5

Since May 23Pushed 11y ago1 watchersCompare

[ Source](https://github.com/jgswift/xral)[ Packagist](https://packagist.org/packages/jgswift/xral)[ RSS](/packages/jgswift-xral/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (8)Versions (3)Used By (0)

xral
====

[](#xral)

PHP 5.5+ resource abstraction layer

[![Build Status](https://camo.githubusercontent.com/bedb043d10819adc6d23f800e232d1cdcf2b8cc99368ea167b2c44af682c9269/68747470733a2f2f7472617669732d63692e6f72672f6a6773776966742f7872616c2e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/jgswift/xral)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/8582842aa98a199f4dd5316ea9dd534bf275a726ace70b2ddd21c892009b6159/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6a6773776966742f7872616c2f6261646765732f7175616c6974792d73636f72652e706e673f733d30396563663464353938646664623764393930373065376261386137643139376162646466616531)](https://scrutinizer-ci.com/g/jgswift/xral/)[![Latest Stable Version](https://camo.githubusercontent.com/aa9959de47db5705445013389b43fc2fd8926bdf0a11f2a1a6a606a2ddc27737/68747470733a2f2f706f7365722e707567782e6f72672f6a6773776966742f7872616c2f762f737461626c652e737667)](https://packagist.org/packages/jgswift/xral)[![License](https://camo.githubusercontent.com/f0903b8dbabe46435086a4da55ff29f63db1cc892346e381dec919762ab47c87/68747470733a2f2f706f7365722e707567782e6f72672f6a6773776966742f7872616c2f6c6963656e73652e737667)](https://packagist.org/packages/jgswift/xral)[![Coverage Status](https://camo.githubusercontent.com/ca8adc5dc691d59f5bc6e5cfd3d619da276a0f5f7e85dee7e861075b07235a9a/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6a6773776966742f7872616c2f62616467652e706e673f6272616e63683d6d6173746572)](https://coveralls.io/r/jgswift/xral?branch=master)

Installation
------------

[](#installation)

Install via cli using [composer](https://getcomposer.org/):

```
php composer.phar require jgswift/xral:0.1.*
```

Install via composer.json using [composer](https://getcomposer.org/):

```
{
    "require": {
        "jgswift/xral": "0.1.*"
    }
}
```

Description
-----------

[](#description)

xral is a relatively simple package that provides a consistent means to query data using XML, YML, and INI file formats. xral includes 3 query classes to read from and write to each resource respectively. xral also includes 3 adapter and view classes to provide a base for more specific implementations. xral relies on `kfiltr` hooks to customize filtering and mapping procedures performed on query results. xral queries return `qinq` collections to easily enable further object-level transformations

Dependency
----------

[](#dependency)

- php 5.5+
- [jgswift/qtil](http://github.com/jgswift/qtil) - general utilities
- [jgswift/qio](http://github.com/jgswift/qio) - i/o utilities
- [jgswift/observr](http://github.com/jgswift/observr) - observer pattern implementation
- [jgswift/kenum](http://github.com/jgswift/kenum) - enumerator implementation
- [jgswift/qinq](http://github.com/jgswift/qinq) - quasi integrated queries
- [jgswift/kfiltr](http://github.com/jgswift/kfiltr) - filter, map, and hook implementations
- [symfony/yaml](http://github.com/symfony/yaml) - enumerator implementation

Usage
-----

[](#usage)

### XML

[](#xml)

#### SimpleXML

[](#simplexml)

#### Basic

[](#basic)

```
$query = new XML\Simple();

$query->select('//book')
      ->from('library.xml')
      ->where('authors/author','Stephen King');

$result = $query();

var_dump($result); // qinq\Collection [ SimpleXMLElement, SimpleXMLElement, ... ]
```

#### Update

[](#update)

```
$file = new qio\File('library.xml');

$query = new XML\Simple();

// set the author of a specific book
$query->select('library/books/book')
      ->update($file)
      ->set('author','Stephen King')
      ->where('name','The Langoliers');

$query();
```

#### Insert

[](#insert)

```
$file = new qio\File('library.xml');

$query = new XML\Simple();

$query->select('/library/books')
      ->update($file)
      ->insert(['book' => [
          'name' => 'The Catcher In The Rye',
          'authors' => [
              'author' => 'J. D. Salinger'
          ],
          'ISBN' => '0316769533 9780316769532',
          'publisher' => 'Amazon',
          'pages' => 277
      ]]);

$query();
```

#### Delete

[](#delete)

```
$file = new qio\File('library.xml');

$query = new XML\Simple();

$query->delete('//book')
      ->update($file)
      ->where('name','The Catcher In The Rye');

$query();
```

#### DOMDocument

[](#domdocument)

#### Basic

[](#basic-1)

```
$query = new XML\DOM();

$query->select('//book')
      ->from('library.xml')
      ->where('authors/author','Stephen King');

$result = $query();

var_dump($result); // qinq\Collection [ DOMElement, DOMElement, ... ]
```

#### Update

[](#update-1)

```
$file = new qio\File('library.xml');

$query = new XML\DOM();

$query->select('library/books/book')
      ->update($file)
      ->set('author','Stephen King')
      ->where('name','The Langoliers');

$query();
```

#### Insert

[](#insert-1)

```
$file = new qio\File('library.xml');

$query = new XML\DOM();

$query->select('/library/books')
      ->update($file)
      ->insert(['book' => [
          'name' => 'The Catcher In The Rye',
          'authors' => [
              'author' => 'J. D. Salinger'
          ],
          'ISBN' => '0316769533 9780316769532',
          'publisher' => 'Amazon',
          'pages' => 277
      ]]);

$query();
```

#### Delete

[](#delete-1)

```
$file = new qio\File('library.xml');

$query->delete('//book')
      ->update($file)
      ->where('name','The Catcher In The Rye');

$query();
```

### INI

[](#ini)

#### Basic

[](#basic-2)

```
$query = new INI\Query();

$query->section('general')
      ->from('config.ini')
      ->where('debug',0);

$result = $query();

var_dump($result); // qinq\Collection [ array, array, ... ]
```

#### Update

[](#update-2)

```
$file = new qio\File('config.ini');

$query = new INI\Query();

// update debug setting in general section to 1
$query->update($file)
      ->section('general')
      ->set('debug',1);

$query();
```

#### Insert

[](#insert-2)

```
$file = new qio\File('config.ini');

$query->update($file)
      ->section('general')
      ->insert('name','My Application');

$query();
```

#### Delete

[](#delete-2)

```
$file = new qio\File('config.ini');

$query = new INI\Query();

$query->update($file)
      ->section('general')
      ->delete('name');

$query();
```

### YML

[](#yml)

#### Basic

[](#basic-3)

```
$query = new YML\Query();

$query->select('product')
      ->from('invoice.yml')
      ->where('quantity',1);

$result = $query();

var_dump($result); // qinq\Collection [ array, array, ... ]
```

#### Update

[](#update-3)

```
$query = new YML\Query();

$query->select('product')
      ->update('invoice.yml')
      ->where('sku','BB5280R')
      ->set('quantity',5);

$query();
```

#### Insert

[](#insert-3)

```
$query = new YML\Query();

$query->select('product')
      ->update('invoice.yml')
      ->insert([
          'sku' => 'BB5280R',
          'quantity' => 6,
          'description' => 'Baseball Glove',
          'price' => 50
      ]);

$query();
```

#### Delete

[](#delete-3)

```
$query = new YML\Query();

$query->delete('product')
      ->update('invoice.yml')
      ->where('sku','BB5280R');

$query();
```

### JSON

[](#json)

#### Query

[](#query)

```
$query = new JSON\Query();

$query->select(function($person) {
            return $person['firstName'].' '.$person['lastName']
      })
      ->from('people.json')
      ->where(function($person) {
            return ($person['money'] > 5000) ? true : false;
      });

$result = $query();

var_dump($result); // qinq\Collection [ [ 'name' => 'john doe' ], [ 'name' => 'billy bob' ] ]
```

#### Update

[](#update-4)

```
$file = new qio\File('people.json');

$query = new JSON\Query();

// change a persons firstname from 'billy' to 'bob'
$query->update($file)
      ->set('firstName','bob')
      ->where(function($person) {
          return ($person['firstName'] == 'billy') ? true : false;
      });

$query();
```

#### Insert

[](#insert-4)

```
$file = new qio\File('people.json');

$query = new JSON\Query();

$query->update($file)
      ->insert([
          'firstName' => 'jane',
          'lastName' => 'doe',
          'gender' => 'female',
          'money' => 50000
      ]);

$query();
```

#### Delete

[](#delete-4)

```
$file = new qio\File('people.json');

$query = new JSON\Query();

$query->update($file)
      ->delete()
      ->where('gender','female');

$query();
```

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 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 ~104 days

Total

2

Last Release

4265d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e60e96f18d8a9dc2aff1363eedbaf210acc96666e7497d2a83d5a416ef397295?d=identicon)[jgswift](/maintainers/jgswift)

---

Top Contributors

[![jgswift](https://avatars.githubusercontent.com/u/661738?v=4)](https://github.com/jgswift "jgswift (15 commits)")

---

Tags

phpxmlymladapterresourceini

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/jgswift-xral/health.svg)

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

###  Alternatives

[hassankhan/config

Lightweight configuration file loader that supports PHP, INI, XML, JSON, and YAML files

97513.5M169](/packages/hassankhan-config)[m1/vars

Vars is a simple to use and easily extendable configuration loader with in built loaders for ini, json, PHP, toml, XML and yaml/yml file types. It also comes with in built support for Silex and more frameworks to come soon.

69124.2k1](/packages/m1-vars)[goetas-webservices/xsd2php

Convert XSD (XML Schema) definitions into PHP classes and JMS metadata

2411.6M36](/packages/goetas-webservices-xsd2php)[goetas/xsd2php-runtime

Convert XSD (XML Schema) definitions into PHP classes

493.3k](/packages/goetas-xsd2php-runtime)[phppkg/config

Config manage, load, get. Supports INI,JSON,YAML,NEON,PHP format file

133.5k](/packages/phppkg-config)

PHPackages © 2026

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