{"id":29499044,"url":"https://github.com/apioo/psx-data","last_synced_at":"2025-07-15T20:04:10.794Z","repository":{"id":62531015,"uuid":"55149769","full_name":"apioo/psx-data","owner":"apioo","description":"Data processing library to read and write POPOs in different formats","archived":false,"fork":false,"pushed_at":"2025-03-21T19:55:37.000Z","size":374,"stargazers_count":5,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-14T20:55:19.472Z","etag":null,"topics":["json","php","popo","serializer","xml"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/apioo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"github":"chriskapp","patreon":"fusio","custom":"https://www.paypal.me/fusioapi"}},"created_at":"2016-03-31T12:44:03.000Z","updated_at":"2025-03-21T19:53:45.000Z","dependencies_parsed_at":"2024-06-19T10:00:33.241Z","dependency_job_id":"b15c4d7f-12ce-45fb-bce8-d170bc21374e","html_url":"https://github.com/apioo/psx-data","commit_stats":null,"previous_names":[],"tags_count":41,"template":false,"template_full_name":null,"purl":"pkg:github/apioo/psx-data","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apioo%2Fpsx-data","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apioo%2Fpsx-data/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apioo%2Fpsx-data/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apioo%2Fpsx-data/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/apioo","download_url":"https://codeload.github.com/apioo/psx-data/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apioo%2Fpsx-data/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265457054,"owners_count":23768895,"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":["json","php","popo","serializer","xml"],"created_at":"2025-07-15T20:03:17.299Z","updated_at":"2025-07-15T20:04:10.787Z","avatar_url":"https://github.com/apioo.png","language":"PHP","funding_links":["https://github.com/sponsors/chriskapp","https://patreon.com/fusio","https://www.paypal.me/fusioapi"],"categories":[],"sub_categories":[],"readme":"\n# Data\n\nData processing library which helps to read and write data to and from POPOs\nin different formats.\n\n## Usage\n\nThe following example showcases how you could read/write a complex model.\n\n```php\n// create processor\n$processor = new Processor(Configuration::createDefault());\n\n// example json data which we want to parse in our model\n$in = \u003c\u003c\u003cJSON\n{\n    \"id\": 1,\n    \"title\": \"Lorem ipsum\",\n    \"author\": {\n        \"id\": 1,\n        \"name\": \"Foo\",\n        \"email\": \"foo@bar.com\",\n    },\n    \"comments\": [{\n        \"id\": 1,\n        \"author\": {\n            \"id\": 1,\n            \"name\": \"Foo\",\n            \"email\": \"foo@bar.com\",\n        },\n        \"text\": \"Lorem ipsum\"\n    },{\n        \"id\": 2,\n        \"author\": {\n            \"id\": 1,\n            \"name\": \"Foo\",\n            \"email\": \"foo@bar.com\",\n        },\n        \"text\": \"Lorem ipsum\"\n    }],\n    \"date\": \"2016-03-28T22:40:00Z\"\n}\nJSON;\n\n// reads the json data into a custom model class\n$model = $processor-\u003eread(News::class, Payload::json($in));\n\n// the model can be used to get or set data\n$model-\u003egetAuthor()-\u003egetName();\n$model-\u003egetComments()[0]-\u003egetText();\n\n// writes the model back to json\n$out = $processor-\u003ewrite(Payload::json($model));\n\n// model classes\nclass News\n{\n    private ?int $id = null;\n    private ?string $title = null;\n    protected ?Author $author = null;\n    /**\n     * @var array\u003cComment\u003e|null\n     */\n    private ?array $comments = null;\n     #[Format('date-time')]\n    private ?string $date;\n\n    // getter/setter implementations removed for readability\n}\n\nclass Author\n{\n    private ?int $id = null;\n    private ?string $name = null;\n    private ?string $email = null;\n\n    // getter/setter implementations removed for readability\n}\n\nclass Comment\n{\n    private ?int $id = null;\n    private ?Author $author = null;\n    private ?string $text = null;\n\n    // getter/setter implementations removed for readability\n}\n\n\n```\n\n## Formats\n\nThe library supports different reader and writer classes to produce different\ndata formats. If you want to read a specific format you can provide the content\ntype of the data. I.e. if you want read XML you could use the following\npayload:\n\n```php\n$payload = Payload::create($in, 'application/xml');\n```\n\nThe processor uses a reader factory to obtain the fitting reader for a specific\ncontent type. In this case it would use the XML reader. The reader factory can\nbe easily extended with different reader classes to support other data formats.\n\n```php\n$configuration-\u003egetReaderFactory()-\u003eaddReader(new Acme\\Reader(), 32);\n```\n\nIn order to produce a payload from an incoming HTTP request you simply have to\nset the body as data and the content type from the header. How you access this\ndata depends on the HTTP interface. For an PSR-7 request you could use:\n\n```php\n$payload = Payload::create(\n    (string) $request-\u003egetBody(),\n    $request-\u003egetHeaderLine('Content-Type')\n);\n```\n\nOn the other hand if you want to write data as response you would use:\n\n```php\n$payload = Payload::create(\n    $model,\n    $request-\u003egetHeaderLine('Accept')\n);\n```\n\nThe writer factory can also be extended with custom writer implementations.\n\n```php\n$configuration-\u003egetWriterFactory()-\u003eaddWriter(new Acme\\Writer(), 64);\n```\n\n## Transformations\n\nEach reader class returns the data in a form which can be easily processed. I.e.\nthe json reader returns a `stdClass` produced by `json_decode` and the xml\nreader returns a `DOMDocument`. To unify the output we use transformation\nclasses which take the output of a reader and return a normalized format. I.e.\nfor xml content we apply by default the `XmlArray` transformer which transforms\nthe `DOMDocument`. So you can use a transformer if you directly want to work\nwith the output of the reader.\n\nIn case you want to validate incoming XML data after a XSD schema you could use\nthe `XmlValidator` transformer:\n\n```php\n$payload = Payload::xml($data);\n$payload-\u003esetTransformer(new XmlValidator('path/to/schema.xsd'));\n\n$model = $processor-\u003eread(News::class, $payload);\n\n```\n\n## Exporter\n\nIf you write data you can set as payload an arbitrary object. We use an exporter\nclass to return the actual data representation of that object. By default the\nexporter reads also the psx/schema attributes so you can use the same model for\nincoming and outgoing data. But it is also possible to use different classes.\nI.e. you could create model classes using the psx/schema attributes only for\nincoming data and for outgoing data you could use the JMS exporter in case you\nhave already objects which have these annotations.\n\nIf you have another way how to extract data of an object (i.e. a toArray\nmethod which returns the available fields of the object) you can easily write\na custom exporter.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapioo%2Fpsx-data","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fapioo%2Fpsx-data","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapioo%2Fpsx-data/lists"}