PHPackages                             boyhagemann/hydra - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. boyhagemann/hydra

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

boyhagemann/hydra
=================

Simple PHP Hydra wrapper class

110PHP

Since May 1Pushed 12y ago1 watchersCompare

[ Source](https://github.com/boyhagemann/hydra)[ Packagist](https://packagist.org/packages/boyhagemann/hydra)[ RSS](/packages/boyhagemann-hydra/feed)WikiDiscussions master Synced 5d ago

READMEChangelogDependenciesVersions (1)Used By (0)

Hydra
-----

[](#hydra)

[Hydra](http://www.markus-lanthaler.com/hydra) is an effort to simplify the development of interoperable, hypermedia-driven Web APIs. The two fundamental building blocks of Hydra are JSON‑LD and the Hydra Core Vocabulary.

JSON‑LD is the serialization format used in the communication between the server and its clients. The Hydra Core Vocabulary represents the shared vocabulary between them. By specifying a number of concepts which are commonly used in Web APIs it can be used as the foundation to build Web services that share REST's benefits in terms of loose coupling, maintainability, evolvability, and scalability. Furthermore it enables the creation of generic API clients instead of requiring specialized clients for every single API.

This package provides simple wrapper classes to read JSON-LD config and presents them as Hydra objects. You can then use the Form utility class to render an HTML form based on the Hydra properties.

Reading the JSON-LD file
------------------------

[](#reading-the-json-ld-file)

The config file can return an object that represents the json structure. For now, only a Hydra Class and its Supported Properties can be read.

```
$hydra = HydraClassFactory::fromPath('path/to/your/config.jsonld');

// Get all supported properties
$hydra->getProperties(); // returns an array of HydraProperty objects
```

Utility classes
---------------

[](#utility-classes)

### Form

[](#form)

The Form class can build a HTML form based on the Hydra config file.

#### Adding elements

[](#adding-elements)

Elements are nothing more than a callback. This callback must return a string value, usually a HTML form element representation. The callback receive a `Boyhagemann\Hydra\HydraProperty` which contains useful information to render the HTML.

```
$form->element('text', function($property) {
	return sprintf('', $property->getName());
});
```

#### Mapping elements

[](#mapping-elements)

Every property type can be mapped to an element.

```
$form->map('http://schema.org/name', 'text'); // We have added 'text' as an element earlier.
```

#### Building the form

[](#building-the-form)

The form HTML itself can also be build with a callback. You can use your favorite rendering engine to nicely render your form template.

```
$form->build(function(Array $elements) {

	$form = '';
	$form .= implode(PHP_EOL, $elements);
	$form .= '';

	return $form;
});
```

#### Render the form

[](#render-the-form)

Now that all elements and mappings are completed, we can render the Hydra class.

```
$form->render($hydra);
```

Todo
----

[](#todo)

- Add a Grid or List utility class
- Implement Members

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity41

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/2a43699bf9428b2ee2e827915e14321f44c4cb7e6fbf4c6a3faf086937a852ce?d=identicon)[boyhagemann](/maintainers/boyhagemann)

---

Top Contributors

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

### Embed Badge

![Health badge](/badges/boyhagemann-hydra/health.svg)

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

###  Alternatives

[aaronvangeffen/awstatsparser

A series of classes to help read and merge Awstats data files

112.8k](/packages/aaronvangeffen-awstatsparser)[sivka/paginator

bootstrap-4 fork of jasongrimes/php-paginator, a lightweight PHP paginator, for generating pagination controls in the style of Stack Overflow and Flickr. The 'first' and 'last' page links are shown inline as page numbers, and excess page numbers are replaced by ellipses.

141.3k](/packages/sivka-paginator)

PHPackages © 2026

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