{"id":20945102,"url":"https://github.com/vjik/cycle-typecast","last_synced_at":"2025-09-06T22:38:59.808Z","repository":{"id":39856526,"uuid":"326253758","full_name":"vjik/cycle-typecast","owner":"vjik","description":"Helper of typecast data in Cycle ORM","archived":false,"fork":false,"pushed_at":"2025-04-18T06:43:46.000Z","size":54,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-08-27T04:34:30.535Z","etag":null,"topics":["cycle"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vjik.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","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":"2021-01-02T19:14:12.000Z","updated_at":"2025-04-18T06:43:13.000Z","dependencies_parsed_at":"2024-11-18T23:48:28.652Z","dependency_job_id":"8cc06622-9fec-4a84-8241-ea4f30b641f6","html_url":"https://github.com/vjik/cycle-typecast","commit_stats":{"total_commits":19,"total_committers":2,"mean_commits":9.5,"dds":0.1578947368421053,"last_synced_commit":"99a9bd30f6a4d234df4ab503747b6fbbd14aff71"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":"vjik/package-template","purl":"pkg:github/vjik/cycle-typecast","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vjik%2Fcycle-typecast","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vjik%2Fcycle-typecast/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vjik%2Fcycle-typecast/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vjik%2Fcycle-typecast/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vjik","download_url":"https://codeload.github.com/vjik/cycle-typecast/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vjik%2Fcycle-typecast/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273973979,"owners_count":25200579,"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","status":"online","status_checked_at":"2025-09-06T02:00:13.247Z","response_time":2576,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["cycle"],"created_at":"2024-11-18T23:46:40.111Z","updated_at":"2025-09-06T22:38:59.787Z","avatar_url":"https://github.com/vjik.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Cycle Typecast\n\n[![Latest Stable Version](https://poser.pugx.org/vjik/cycle-typecast/v)](https://packagist.org/packages/vjik/cycle-typecast)\n[![Total Downloads](https://poser.pugx.org/vjik/cycle-typecast/downloads)](https://packagist.org/packages/vjik/cycle-typecast)\n[![Build status](https://github.com/vjik/cycle-typecast/actions/workflows/build.yml/badge.svg)](https://github.com/vjik/cycle-typecast/actions/workflows/build.yml)\n[![Mutation testing badge](https://img.shields.io/endpoint?style=flat\u0026url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fvjik%2Fcycle-typecast%2Fmaster)](https://dashboard.stryker-mutator.io/reports/github.com/vjik/cycle-typecast/master)\n[![static analysis](https://github.com/vjik/cycle-typecast/workflows/static%20analysis/badge.svg)](https://github.com/vjik/cycle-typecast/actions?query=workflow%3A%22static+analysis%22)\n[![psalm-level](https://shepherd.dev/github/vjik/cycle-typecast/level.svg)](https://shepherd.dev/github/vjik/cycle-typecast)\n\nThe package provides:\n\n- `Typecaster` that help typecast data in [Cycle ORM](https://cycle-orm.dev/) and abstract `TypecastHandler` that used it;\n- `AttributeTypecastHandler` that use attributes for typecast data;\n- `TypeInterface` that must be implemented by classes used in `Typecaster` and `AttributeTypecastHandler`;\n- classes for `DateTimeImmutable`, `UUID`, `Array` and `Enum` types.\n\n## Installation\n\nThe package could be installed with [composer](https://getcomposer.org/download/):\n\n```shell\ncomposer require vjik/cycle-typecast\n```\n\n## General Usage\n\n### Attributes\n\n```php\nuse Vjik\\CycleTypecast\\AttributeTypecastHandler;\nuse Vjik\\CycleTypecast\\UuidString\\UuidStringToBytesType;\nuse Vjik\\CycleTypecast\\DateTimeImmutable\\DateTimeImmutableToIntegerType;\n\n#[Entity(\n    // ...\n    typecast: AttributeTypecastHandler::class,\n)]\nfinal class User\n{\n    // ...\n\n    #[Column(type: 'primary', primary: true)]\n    #[UuidStringToBytesType]\n    private string $id;\n\n    #[Column(type: 'int')]\n    #[DateTimeImmutableToIntegerType]\n    private DateTimeImmutable $createDate;\n```\n\n### Custom Typecast Handler\n\n```php\nuse Vjik\\CycleTypecast\\ArrayToStringType;\nuse Vjik\\CycleTypecast\\DateTimeImmutable\\DateTimeImmutableToIntegerType;\nuse Vjik\\CycleTypecast\\TypecastHandler;\nuse Vjik\\CycleTypecast\\UuidString\\UuidStringToBytesType;\n\nfinal class UserTypecastHandler extends Vjik\\CycleTypecast\\TypecastHandler\n{\n    protected function getConfig(): array\n    {\n        return [\n            'id' =\u003e new UuidStringToBytesType(),\n            'createDate' =\u003e new DateTimeImmutableToIntegerType(),\n            'modifyDate' =\u003e new DateTimeImmutableToIntegerType(),\n            'tags' =\u003e new ArrayToStringType(','),\n        ];\n    }\n}\n```\n\n### Custom Mapper\n\n```php\nuse Cycle\\ORM\\ORMInterface;\nuse Cycle\\ORM\\PromiseMapper\\PromiseMapper;\nuse Vjik\\CycleTypecast\\Typecaster;\nuse Vjik\\CycleTypecast\\ArrayToStringType;\nuse Vjik\\CycleTypecast\\DateTimeImmutable\\DateTimeImmutableToIntegerType;\nuse Vjik\\CycleTypecast\\UuidString\\UuidStringToBytesType;\n\nfinal class UserMapper extends PromiseMapper\n{\n    private Typecaster $typecaster;\n\n    public function __construct(ORMInterface $orm, string $role)\n    {\n        // Typecast configuration\n        $this-\u003etypecaster = new Typecaster([\n            'id' =\u003e new UuidStringToBytesType(),\n            'createDate' =\u003e new DateTimeImmutableToIntegerType(),\n            'modifyDate' =\u003e new DateTimeImmutableToIntegerType(),\n            'tags' =\u003e new ArrayToStringType(','),\n        ]);\n        \n        parent::__construct($orm, $role);\n    }\n\n    public function extract($entity): array\n    {\n        $data = parent::extract($entity);\n        \n        // Typecast after extract from entity\n        return $this-\u003etypecaster-\u003eprepareAfterExtract($data);\n    }\n\n    public function hydrate($entity, array $data)\n    {\n        // Typecast before hydrate entity\n        $data = $this-\u003etypecaster-\u003eprepareBeforeHydrate($data);\n        \n        return parent::hydrate($entity, $data);\n    }\n}\n```\n\n## Types\n\n### `ArrayToStringType`\n\n```php\nnew ArrayToStringType(',');\n``` \n\nEntity value: array of strings. For example, `['A', 'B', 'C']`.\n\nDatabase value: array concatenated into string with delimiter setted in constructor. For example, `A,B,C`.\n\n### `DateTimeImmutableToIntegerType`\n\n```php\nnew DateTimeImmutableToIntegerType();\n```\n\nEntity value: `DateTimeImmutable`.\n\nDatabase value: timestamp as string (example, `1609658768`).\n\n### `IntegerEnumType`\n\n```php\nnew IntegerEnumType(IntegerEnum::class);\n```\n\nEntity value: integer typed enumeration.\n\nDatabase value: enumeration value of integer type.\n\n### `StringEnumType`\n\n```php\nnew StringEnumType(StringEnum::class);\n```\n\nEntity value: string typed enumeration.\n\nDatabase value: enumeration value of string type.\n\n### `UuidStringToBytesType`\n\n```php\nnew UuidStringToBytesType();\n```\n\nEntity value: string standard representation of the UUID. For example, `1f2d3897-a226-4eec-bd2c-d0145ef25df9`.\n\nDatabase value: binary string representation of the UUID.\n\n## Testing\n\n### Unit Testing\n\nThe package is tested with [PHPUnit](https://phpunit.de/). To run tests:\n\n```shell\n./vendor/bin/phpunit\n```\n\n### Mutation Testing\n\nThe package tests are checked with [Infection](https://infection.github.io/) mutation framework with\n[Infection Static Analysis Plugin](https://github.com/Roave/infection-static-analysis-plugin). To run it:\n\n```shell\n./vendor/bin/roave-infection-static-analysis-plugin\n```\n\n### Static Analysis\n\nThe code is statically analyzed with [Psalm](https://psalm.dev/). To run static analysis:\n\n```shell\n./vendor/bin/psalm\n```\n\n## License\n\nThe Cycle Typecast is free software. It is released under the terms of the BSD License.\nPlease see [`LICENSE`](./LICENSE.md) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvjik%2Fcycle-typecast","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvjik%2Fcycle-typecast","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvjik%2Fcycle-typecast/lists"}