milosh012 / fractal

Output complex, flexible, AJAX/RESTful data structures.

Home Page:fractal.thephpleague.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Fractal

Build Status Coverage Status Total Downloads Latest Stable Version

Fractal provides a presentation and transformation layer for complex data output, the like found in RESTful APIs, and works really well with JSON.

When building an API it is common for people to just grab stuff from the database and pass it to json_encode(). This might be passable for "trivial" API's but if they are in use by the public, or used by an iPhone application then this will quickly lead to inconsistent output.

Goals

  • Create a "barrier" between source data and output, so schema changes do not affect users
  • Systematic type-casting of data, to avoid foreach()ing through and (bool)ing everything
  • Embed (or nest) relationships for complex data structures
  • Support the pagination of data results, for small and large data sets alike
  • Generally ease the subtle complexities of outputting data in a non-trivial API

This package is compliant with PSR-1, PSR-2 and PSR-4. If you notice compliance oversights, please send a patch via pull request.

Install

Via Composer

{
    "require": {
        "league/fractal": "0.7.*"
    }
}

Requirements

The following versions of PHP are supported by this version.

  • PHP 5.3
  • PHP 5.4
  • PHP 5.5
  • PHP 5.6

HHVM support is also experimentally supported. It basically works, but CodeSniffer installation is screwing it up on Travis-CI.

Documentation

Fractal has full documentation, powered by Sculpin.

Contribute to this documentation in the sculpin branch.

Todo

  • Switch return array to use instance properties in transform()
  • Implement HATEOAS/HAL links
  • Add smart embed syntax, e.g: ?embed=foo:limit(5):order(something,asc)

Testing

$ phpunit

Contributing

Please see CONTRIBUTING for details.

Credits

License

The MIT License (MIT). Please see License File for more information.

About

Output complex, flexible, AJAX/RESTful data structures.

fractal.thephpleague.com

License:MIT License


Languages

Language:PHP 99.4%Language:Ruby 0.6%