PHPackages                             mk/hal - 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. [API Development](/categories/api)
4. /
5. mk/hal

ActiveLibrary[API Development](/categories/api)

mk/hal
======

Implementation of HAL standart for using in REST API responses or similiar

2.0.1(7y ago)0501MITPHP

Since Jan 29Pushed 7y ago1 watchersCompare

[ Source](https://github.com/Mo0812/MKHal)[ Packagist](https://packagist.org/packages/mk/hal)[ RSS](/packages/mk-hal/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependencies (1)Versions (5)Used By (0)

MKHal
=====

[](#mkhal)

[![Build status](https://camo.githubusercontent.com/f20ae4ecc74fddf055728ceab148bf1fbdd0c72fd87982a9b652aa7c3de86527/68747470733a2f2f7472617669732d63692e6f72672f4d6f303831322f4d4b48616c2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/Mo0812/MKHal.svg?branch=master)[![Codacy Badge](https://camo.githubusercontent.com/dec8e66d13b1833e42f6170c70d208f8796043b53af8d8b6a5ca798ac5271289/68747470733a2f2f6170692e636f646163792e636f6d2f70726f6a6563742f62616467652f47726164652f3864373564396362653336663432343338636533626363396439636262323764)](https://www.codacy.com/app/Mo0812/MKHal?utm_source=github.com&utm_medium=referral&utm_content=Mo0812/MKHal&utm_campaign=Badge_Grade)[![Latest Stable Version](https://camo.githubusercontent.com/12015e2d66a36b50b53fe321ae9e69dd7eb2071f404d1daaf94a3f68d9681f36/68747470733a2f2f706f7365722e707567782e6f72672f6d6b2f68616c2f762f737461626c65)](https://packagist.org/packages/mk/hal)[![Latest Unstable Version](https://camo.githubusercontent.com/96e3eb53c24ca6050a5d816bd9cbd529762a084b6696bce25102943424563255/68747470733a2f2f706f7365722e707567782e6f72672f6d6b2f68616c2f762f756e737461626c65)](https://packagist.org/packages/mk/hal)[![License](https://camo.githubusercontent.com/ed14adbecc9634a0c6323e7910bab114fe562611230e33c96976c3daf12dbcdb/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f4d6f303831322f4d4b48616c2e737667)](https://img.shields.io/github/license/Mo0812/MKHal.svg)

> This repository is still in a early development stage. If you find any issues or miss any feature please feel free to raise an issue.

MKHal is an implementation of the [HAL specification](http://stateless.co/hal_specification.html) written in PHP. It can be used to build a HAL specific data structure and convert it to JSON or XML. It can be easily implemented in your current API backend workflow.

Requirements
------------

[](#requirements)

- PHP 7.0 or higher

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

[](#installation)

You can clone or download the package and use it in your project or just install it via **composer**:

```
composer require mk/hal
```

Usage
-----

[](#usage)

### Object types

[](#object-types)

MKHal offers different class types to represent the structure of a typical HAL implementation:

- **HALObject:** The `HALObject` class represents the main resource in the HAL specification. It can hold normal data, `HALLink` objects and `HALCurie` objects. It can also embed additional `HALObjects` in referred by labels.
- **HALLink:** The `HALLink` class represents a typical link resources in the \_*links* section of the HAL document. It can hold different information like the *href* attribute. It get automatically serialized along with an `HALObject` instance. A `HALObject` can hold additional links after different labels.
- **HALCurie:** The `HALCurie` class is the representation of the *curies* attribute in HAL. An `HALObject` instance can have multiple curies inside of it.

### Basic usage

[](#basic-usage)

```
use MK\HAL\HALObject;
use MK\HAL\HALLink;
use MK\HAL\HALCurie;

$hal = new HALObject('/orders');

$hal->addData(array(
    "offers" => 5,
    "prices" => array(
        "normal" => "10.99",
        "season" => "5.99"
    )
));

$hal->addCurie(new HALCurie('ea', 'http://example.com/docs/rels/{rel}'));

$hal->addLink('next', new HALLink('/orders?page=2'));

$hal->addLinkCollection('ea:admin', array(
    new HALLink('/admin/2'),
    new HALLink('/admin/5')
));

$product = new HALObject('/product/1');
$product->addLink('next', new HALLink('/product/2'));

$hal->embed('product', $product);

$hal->embedCollection('coupon', array(
    new HALObject('/coupon/5'),
    new HALObject('/coupon/6')
));

// use export() for json serialization
echo $hal->export(); // calls json_encode internally
// or simple encode the HALObject
echo json_encode($hal);
```

The call of the `export()` method creates a JSON representation of the HAL specification:

```
{
    "_links": {
        "self": {
            "href": "/orders"
        },
        "curies": [
            {
                "name": "ea",
                "href": "http://example.com/docs/rels/{rel}",
                "templated": true
            }
        ],
        "next": {
            "href": "/orders?page=2"
        },
        "ea:admin": [
            {
                "href": "/admin/2"
            },
            {
                "href": "/admin/5"
            }
        ]
    },
    "offers": 5,
    "prices": {
        "normal": "10.99",
        "season": "5.99"
    },
    "_embedded": {
        "product": {
            "_links": {
                "self": {
                    "href": "/product/1"
                },
                "next": {
                    "href": "/product/2"
                }
            }
        },
        "coupon": [
            {
                "_links": {
                    "self": {
                        "href": "/coupon/5"
                    }
                }
            },
            {
                "_links": {
                    "self": {
                        "href": "/coupon/6"
                    }
                }
            }
        ]
    }
}
```

Roadmap
-------

[](#roadmap)

- Implement basic HAL specification
- Enable *curies*
- Well structured class hierarchy
- JSON export / output
- Auto create HAL data from given objects
- XML export / output
- Read HAL objects to use library as client too
- Slim Framework integration

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity63

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

Total

4

Last Release

2656d ago

Major Versions

1.0.0 → 2.0.02019-01-31

### Community

Maintainers

![](https://www.gravatar.com/avatar/134c178d792d4442760905accc7bf50d6a1a5f0f02a7ddbde1786fe298b49123?d=identicon)[mojo101](/maintainers/mojo101)

---

Top Contributors

[![Mo0812](https://avatars.githubusercontent.com/u/1677918?v=4)](https://github.com/Mo0812 "Mo0812 (30 commits)")

---

Tags

haljson-hyper-schemaphpphp-library

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/mk-hal/health.svg)

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

###  Alternatives

[stripe/stripe-php

Stripe PHP Library

4.0k143.3M480](/packages/stripe-stripe-php)[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M272](/packages/twilio-sdk)[knplabs/github-api

GitHub API v3 client

2.2k15.8M187](/packages/knplabs-github-api)[facebook/php-business-sdk

PHP SDK for Facebook Business

90121.9M34](/packages/facebook-php-business-sdk)[meilisearch/meilisearch-php

PHP wrapper for the Meilisearch API

73813.7M114](/packages/meilisearch-meilisearch-php)[google/gax

Google API Core for PHP

263103.1M454](/packages/google-gax)

PHPackages © 2026

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