PHPackages                             dantleech/object-renderer - 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. dantleech/object-renderer

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

dantleech/object-renderer
=========================

Render/pretty-print objects

0.1.1(5y ago)0509.5k↑39.9%2MITPHPPHP ^7.3 || ^8.0CI failing

Since Apr 26Pushed 2y ago1 watchersCompare

[ Source](https://github.com/dantleech/object-renderer)[ Packagist](https://packagist.org/packages/dantleech/object-renderer)[ RSS](/packages/dantleech-object-renderer/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependencies (6)Versions (4)Used By (2)

Object Renderer
===============

[](#object-renderer)

[![Build Status](https://camo.githubusercontent.com/ea0cbd74b529b3fcb21ae4802152b299729fce21d8c4bd9444a8684fa83da806/68747470733a2f2f7472617669732d63692e6f72672f64616e746c656563682f6f626a6563742d72656e64657265722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/dantleech/indexer-extension)

Render / pretty print objects using Twig templates.

- Templates are selected based on the FQN.
- Templates are fallback based on class hierarchy.
- Templates can render objects.

This library, or ones like it, could be suitable for:

- Pretty print `ReflectionClass` and friends, (e.g. printing formatted documentation in a language server).
- Building a CMS based on *objects*.
- Other things.

Rendering an Object
-------------------

[](#rendering-an-object)

Create a renderer and render an object:

```
$renderer = ObjectRendererBuilder::create()
    ->addTemplatePath('example/path')
    ->build();

$renderer->render(new \stdClass());
```

Will throw an exception:

```
Could not render object "stdClass" using templates "stdClass.twig"',

```

You can guess what you need to do, create `stdClass.twig` in the path given in the builder:

```
# stdClass.twig
Hello I am a stdClass

```

Object Properties and Recursive Rendering
-----------------------------------------

[](#object-properties-and-recursive-rendering)

The object is available as `object` in the template.

If the object contains other objects, you can recurisvely render them by calling `render(object.anotherObject)`.

Ancestor Class Template Resolution
----------------------------------

[](#ancestor-class-template-resolution)

If a template for a given object's class is not found. The renderer will try and locate a template for each of the parent classes.

DOMDocument Example
-------------------

[](#domdocument-example)

```
{# DOMDocument.twig #}
DOMDocument:
{% for node in object.childNodes %}
    - {{ render(node) }}
{%- endfor -%}

```

```
{# DOMElement.twig #}
Element: "{{ object.nodeName }}"
{% for attribute in object.attributes %}
      {{ render(attribute) }}
{%- endfor -%}

```

```
{# DOMAttr.twig #}
{{ object.name }}: {{ object.value }}

```

Render them like:

```
$dom = new DOMDocument();
$child1 = $dom->createElement('child-1');
$child1->setAttribute('foo', 'bar');
$dom->appendChild($child1);
$child2 = $dom->createElement('child-2');
$child2->setAttribute('bar', 'foo');
$dom->appendChild($child2);

$renderer = ObjectRendererBuilder::create()
    ->addTemplatePath('example/path')
    ->build();

$renderer->render($dom);
```

Should return something like:

```
DOMDocument:
    - Element: "child-1"
      foo: bar
    - Element: "child-2"
      bar: foo

```

###  Health Score

34

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity37

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity53

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

Total

2

Last Release

1979d ago

PHP version history (2 changes)0.1.0PHP ^7.3

0.1.1PHP ^7.3 || ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/24ec7d5d6b7ea54007be5d7b4f43800381cc1e22929f7d2276fba30e497fdfa6?d=identicon)[dantleech](/maintainers/dantleech)

---

Top Contributors

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

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/dantleech-object-renderer/health.svg)

```
[![Health](https://phpackages.com/badges/dantleech-object-renderer/health.svg)](https://phpackages.com/packages/dantleech-object-renderer)
```

###  Alternatives

[symfony/symfony

The Symfony PHP framework

31.4k87.2M2.2k](/packages/symfony-symfony)[drupal/core-recommended

Locked core dependencies; require this project INSTEAD OF drupal/core.

6942.5M421](/packages/drupal-core-recommended)[ecotone/ecotone

Enterprise architecture layer for Laravel and Symfony — CQRS, Event Sourcing, Durable Workflows (Sagas, Orchestrators), Projections, and Outbox messaging via PHP attributes.

564576.7k52](/packages/ecotone-ecotone)[metamodels/core

MetaModels core

10156.4k66](/packages/metamodels-core)

PHPackages © 2026

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