{"id":20081729,"url":"https://github.com/theiconic/synopsis","last_synced_at":"2025-05-06T00:31:21.644Z","repository":{"id":37547300,"uuid":"82241599","full_name":"theiconic/synopsis","owner":"theiconic","description":"PHP library to generate a language-agnostic description of PHP objects or values","archived":false,"fork":false,"pushed_at":"2023-04-19T18:38:02.000Z","size":102,"stargazers_count":7,"open_issues_count":2,"forks_count":2,"subscribers_count":77,"default_branch":"master","last_synced_at":"2025-04-21T06:00:41.723Z","etag":null,"topics":["debugging","development","introspection","php","php7","synopsis"],"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/theiconic.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-02-17T01:00:10.000Z","updated_at":"2022-02-12T08:07:04.000Z","dependencies_parsed_at":"2024-11-13T15:44:30.446Z","dependency_job_id":"6a4848a0-b523-4368-88ca-7fbeef5b5f5c","html_url":"https://github.com/theiconic/synopsis","commit_stats":{"total_commits":53,"total_committers":3,"mean_commits":"17.666666666666668","dds":"0.037735849056603765","last_synced_commit":"3851dcdc075db1f5245377c5fa88ecafb52f1fc8"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theiconic%2Fsynopsis","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theiconic%2Fsynopsis/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theiconic%2Fsynopsis/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theiconic%2Fsynopsis/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/theiconic","download_url":"https://codeload.github.com/theiconic/synopsis/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252598291,"owners_count":21774233,"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":["debugging","development","introspection","php","php7","synopsis"],"created_at":"2024-11-13T15:40:07.791Z","updated_at":"2025-05-06T00:31:21.309Z","avatar_url":"https://github.com/theiconic.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# synopsis\nPHP library to generate a language-agnostic description of PHP objects or values\n\n[![Build Status](https://travis-ci.org/theiconic/synopsis.svg?branch=master)](https://travis-ci.org/theiconic/synopsis)\n[![Coverage Status](https://coveralls.io/repos/github/theiconic/synopsis/badge.svg?branch=master\u0026t=2)](https://coveralls.io/github/theiconic/synopsis?branch=master)\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/theiconic/synopsis/badges/quality-score.png?b=master\u0026t=1)](https://scrutinizer-ci.com/g/theiconic/synopsis/?branch=master)\n[![Latest Stable Version](https://poser.pugx.org/theiconic/synopsis/v/stable)](https://packagist.org/packages/theiconic/synopsis)\n[![Total Downloads](https://poser.pugx.org/theiconic/synopsis/downloads)](https://packagist.org/packages/theiconic/synopsis)\n[![License](https://poser.pugx.org/theiconic/synopsis/license)](https://packagist.org/packages/theiconic/synopsis)\n\n## Purpose\nThis library can be used to generate language-agnostic descriptions of\nPHP variables or objects that can then be sent over a transport to\nanother system, e.g. for debugging, monitoring and inspection purposes.\n\nIt generates a standardised representation that can easily be formatted\nin different ways.\n\nE.g. possible use-cases are\n- sending data together with log messages to a logging service\n- sending debug data to a debugging/inspection tool\n- pretty-formatting exceptions including their traces and the arguments in the calls of those traces\n- output data on different channels (e.g. terminal, web, etc.) via standardised formatters\n\n## Setup (via Composer)\nSimply import the library in composer\n```$bash\ncomposer require theiconic/synopsis\n```\n## Basic Usage\nYou will need to start off by instantiating the factory\n```php\n$factory = new TheIconic\\Synopsis\\Factory();\n```\nNow you can synopsise any value\n```php\nclass MyClass\n{\n    public $myProp = 1;\n}\n\n$myObject = new MyClass();\n$myArray = [\n    'string' =\u003e 'Hello World!',\n    'integer' =\u003e 1,\n    'boolean' = true,\n];\n\n$objectSynopsis = $factory-\u003esynopsize($myObject);\n$arraySynopsis = $factory-\u003esynopsize($myArray);\n```\nEach call to `synopsize()` generates an `AbstractSynopsis`\ninstance which describes the passed value.\n\nNow use one of the formatters to format that data in a way\nthat you can send over a transport or use by other components.\n```php\n$formatter = new TheIconic\\Synopsis\\Formatter\\ArrayFormatter();\n$formatter-\u003eformat($objectSynopsis);\n/*\n * [\n *     'type' =\u003e 'MyClass',\n *     'length' =\u003e 1,\n *     'value' =\u003e ''\n *     'children' =\u003e [\n *         'myProp' =\u003e [\n *             'type' =\u003e 'integer',\n *             'length' =\u003e 1,\n *             'value' =\u003e 1,\n *         ]\n *     ]\n * ]\n */\n \n$formatter-\u003eformat($arraySynopsis);\n/*\n * [\n *     'type' =\u003e 'array',\n *     'length' =\u003e 3,\n *     'value' =\u003e ''\n *     'children' =\u003e [\n *         'string' =\u003e [\n *             'type' =\u003e 'string',\n *             'length' =\u003e 12,\n *             'value' =\u003e 'Hello World!',\n *         ]\n *         'integer' =\u003e [\n *             'type' =\u003e 'integer',\n *             'length' =\u003e 1,\n *             'value' =\u003e 1,\n *         ],\n *         'string' =\u003e [\n *             'type' =\u003e 'boolean',\n *             'length' =\u003e 4,\n *             'value' =\u003e 'true',\n *         ]\n *     ]\n * ]\n */\n```\n\n## Object Synopsis\nWhen synopsising objects, the factory checks if a custom\nSynopsis class is registered for the type of the object (i.e. it's class name).\nIf so, then the special Synopsis type is used to synopsise the\nobject and the result entirely depends on its implementation.\n\nCustom object types can be registered via\n```php\n$factory-\u003eaddObjectType(MyClass::$class, MyClassSynopsis::class);\n```\n\nIf no custom type is registered, default object synopsis is used.\n\nA custom IteratorSynopsis type is registered for objects that implement\nIterator or IteratorAggregate interfaces.\n\n### Default Object Synopsis\nThe default ObjectSynopsis implementation will inspect the object\nfor any public properties. Each of those properties will be\ntreated as the objects children and synopsised recursively.\n\nThe **length** will be the number of public properties found.\n\nThe objects class name will be used as the **type**.\n\nTo determine the **value**, the implementation will check for the\npresence and accessibility of any of the following methods in this order\n- __toSynopsisValue\n- __toString\n- getId\n- getName\n\nThe first method found will be executed and it's return value will\nbe cast to string and used as the objects **value**.\n\n### Default Iterator Synopsis\nThe default IteratorSynopsis implementation will iterate through\nthe object, synopsise any of the iteration values and add them as\nchildren.\n\n## Resource Synopsis\nWhen synopsising PHP resource pointers, the factory checks if a custom\nSynopsis class is registered for the type of resource (determined via `get_resource_type()`).\nIf so, that type will be used.\n\nBy default, custom resource types are registered for some filetypes\nand streams and they will use `stream_get_meta_data()` to determine\nthe resource uri and use it as the **value**.\n\nCustom resource types can be registered via\n```php\n$factory-\u003eaddResourceType(MyClass::$class, MyClassSynopsis::class);\n```\n\n## Exception Synopsis\nExceptions and their traces are synopsised in a special way\nadding additional properties to the synopsis objects.\n\nThese can be utilised in special Exception formatters.\n\n### ExceptionSynopsis\n- **type**: the exception type\n- **value**: the exception message\n- **length**: the length of the stack trace\n- **line**: the line\n- **file**: the file\n- **children**: the synopsised stack trace\n\n### TraceSynopsis\n- **type**: a string representation of the full call\n- **value**: a string representation of the file and line\n- **length**: the number of call parameters\n- **line**: the line\n- **file**: the file\n- **class**: the class name\n- **function**: the function/method name\n- **children**: the synopsised call parameters (if any)\n\n## Overriding default Synopsis implementations\nTo override the behaviour for any of the types, simply implement\nyour own Synopsis class (inheriting from `AbstractSynopsis`) and\nregister it with the factory via e.g.\n```php\n$factory-\u003eaddType('string', MyStringSynopsis::class);\n```\n\n## License\nTHE ICONIC Synopsis library for PHP is released under the MIT License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftheiconic%2Fsynopsis","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftheiconic%2Fsynopsis","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftheiconic%2Fsynopsis/lists"}