{"id":17226768,"url":"https://github.com/dantleech/object-renderer","last_synced_at":"2026-02-09T10:02:32.970Z","repository":{"id":56962279,"uuid":"258031564","full_name":"dantleech/object-renderer","owner":"dantleech","description":"Render any object with tempate make pretty","archived":false,"fork":false,"pushed_at":"2024-06-02T10:03:54.000Z","size":43,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-14T01:12:40.081Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dantleech.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-04-22T22:11:08.000Z","updated_at":"2024-06-01T20:43:37.000Z","dependencies_parsed_at":"2022-08-21T10:20:38.806Z","dependency_job_id":null,"html_url":"https://github.com/dantleech/object-renderer","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dantleech%2Fobject-renderer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dantleech%2Fobject-renderer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dantleech%2Fobject-renderer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dantleech%2Fobject-renderer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dantleech","download_url":"https://codeload.github.com/dantleech/object-renderer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248804825,"owners_count":21164135,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-15T04:17:12.028Z","updated_at":"2026-02-09T10:02:32.962Z","avatar_url":"https://github.com/dantleech.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"Object Renderer\n===============\n\n[![Build Status](https://travis-ci.org/dantleech/object-renderer.svg?branch=master)](https://travis-ci.org/dantleech/indexer-extension)\n\nRender / pretty print objects using Twig templates.\n\n- Templates are selected based on the FQN.\n- Templates are fallback based on class hierarchy.\n- Templates can render objects.\n\nThis library, or ones like it, could be suitable for:\n\n- Pretty print `ReflectionClass` and friends, (e.g. printing formatted\n  documentation in a language server).\n- Building a CMS based on _objects_.\n- Other things.\n\nRendering an Object\n-------------------\n\nCreate a renderer and render an object:\n\n```php\n$renderer = ObjectRendererBuilder::create()\n    -\u003eaddTemplatePath('example/path')\n    -\u003ebuild();\n\n$renderer-\u003erender(new \\stdClass());\n```\n\nWill throw an exception:\n\n```\nCould not render object \"stdClass\" using templates \"stdClass.twig\"',\n```\n\nYou can guess what you need to do, create `stdClass.twig` in the path given in\nthe builder:\n\n```\n# stdClass.twig\nHello I am a stdClass\n```\n\nObject Properties and Recursive Rendering\n-----------------------------------------\n\nThe object is available as `object` in the template.\n\nIf the object contains other objects, you can recurisvely render them\nby calling `render(object.anotherObject)`.\n\nAncestor Class Template Resolution\n----------------------------------\n\nIf a template for a given object's class is not found. The renderer will\ntry and locate a template for each of the parent classes.\n\nDOMDocument Example\n-------------------\n\n```\n{# DOMDocument.twig #}\nDOMDocument:\n{% for node in object.childNodes %}\n    - {{ render(node) }}\n{%- endfor -%}\n```\n\n```\n{# DOMElement.twig #}\nElement: \"{{ object.nodeName }}\"\n{% for attribute in object.attributes %}\n      {{ render(attribute) }}\n{%- endfor -%}\n```\n\n```\n{# DOMAttr.twig #}\n{{ object.name }}: {{ object.value }}\n```\n\nRender them like:\n\n```php\n$dom = new DOMDocument();\n$child1 = $dom-\u003ecreateElement('child-1');\n$child1-\u003esetAttribute('foo', 'bar');\n$dom-\u003eappendChild($child1);\n$child2 = $dom-\u003ecreateElement('child-2');\n$child2-\u003esetAttribute('bar', 'foo');\n$dom-\u003eappendChild($child2);\n\n$renderer = ObjectRendererBuilder::create()\n    -\u003eaddTemplatePath('example/path')\n    -\u003ebuild();\n\n$renderer-\u003erender($dom);\n```\n\nShould return something like:\n\n```\nDOMDocument:\n    - Element: \"child-1\"\n      foo: bar\n    - Element: \"child-2\"\n      bar: foo\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdantleech%2Fobject-renderer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdantleech%2Fobject-renderer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdantleech%2Fobject-renderer/lists"}