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)0452.1k↓44.3%2MITPHPPHP ^7.3 || ^8.0

Since Apr 26Pushed 1y 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 1mo 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

35

—

LowBetter than 80% of packages

Maintenance26

Infrequent updates — may be unmaintained

Popularity35

Limited adoption so far

Community11

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

1933d 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

[stfalcon/tinymce-bundle

This Bundle integrates TinyMCE WYSIWYG editor into a Symfony2 project.

2692.9M24](/packages/stfalcon-tinymce-bundle)[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

728272.9k20](/packages/civicrm-civicrm-core)[codefog/contao-haste

haste extension for Contao Open Source CMS

42650.8k139](/packages/codefog-contao-haste)[symfony/object-mapper

Provides a way to map an object to another object

34885.7k18](/packages/symfony-object-mapper)[spomky-labs/pwa-bundle

Progressive Web App Manifest Generator Bundle for Symfony.

6144.4k1](/packages/spomky-labs-pwa-bundle)[netgen/content-browser

Netgen Content Browser is a Symfony bundle that provides an interface which selects items from any kind of backend and returns the IDs of selected items back to the calling code.

14112.1k8](/packages/netgen-content-browser)

PHPackages © 2026

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