PHPackages                             vjik/cycle-typecast - 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. [Database &amp; ORM](/categories/database)
4. /
5. vjik/cycle-typecast

ActiveLibrary[Database &amp; ORM](/categories/database)

vjik/cycle-typecast
===================

Helper of typecast data in Cycle ORM

3.0.1(2mo ago)79.3k2BSD-3-ClausePHPPHP 8.1 - 8.5CI passing

Since Dec 1Pushed 2mo ago2 watchersCompare

[ Source](https://github.com/vjik/cycle-typecast)[ Packagist](https://packagist.org/packages/vjik/cycle-typecast)[ RSS](/packages/vjik-cycle-typecast/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (6)Dependencies (10)Versions (8)Used By (2)

Cycle Typecast
==============

[](#cycle-typecast)

[![Latest Stable Version](https://camo.githubusercontent.com/b4c0e16d815432f954aec37479b0e30f64554f2b5534a125224a656711ef9782/68747470733a2f2f706f7365722e707567782e6f72672f766a696b2f6379636c652d74797065636173742f76)](https://packagist.org/packages/vjik/cycle-typecast)[![Total Downloads](https://camo.githubusercontent.com/9940ac5e54087dec7cc883fec5479eb85a34f4cd9d319b0219d2f0f4a1c917f8/68747470733a2f2f706f7365722e707567782e6f72672f766a696b2f6379636c652d74797065636173742f646f776e6c6f616473)](https://packagist.org/packages/vjik/cycle-typecast)[![Build status](https://github.com/vjik/cycle-typecast/actions/workflows/build.yml/badge.svg)](https://github.com/vjik/cycle-typecast/actions/workflows/build.yml)[![Mutation testing badge](https://camo.githubusercontent.com/280686c13b1b4c60629a7c631c33b25efd076d05f264e77ba386e0e3bb21748b/68747470733a2f2f696d672e736869656c64732e696f2f656e64706f696e743f7374796c653d666c61742675726c3d687474707325334125324625324662616467652d6170692e737472796b65722d6d757461746f722e696f2532466769746875622e636f6d253246766a696b2532466379636c652d74797065636173742532466d6173746572)](https://dashboard.stryker-mutator.io/reports/github.com/vjik/cycle-typecast/master)[![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)[![psalm-level](https://camo.githubusercontent.com/f48f003de6665d13c7d5a1adce9ac41c1a1e0f65a19e86d585a94cb5e31a5cd1/68747470733a2f2f73686570686572642e6465762f6769746875622f766a696b2f6379636c652d74797065636173742f6c6576656c2e737667)](https://shepherd.dev/github/vjik/cycle-typecast)

The package provides:

- `Typecaster` that help typecast data in [Cycle ORM](https://cycle-orm.dev/) and abstract `TypecastHandler` that used it;
- `AttributeTypecastHandler` that use attributes for typecast data;
- `TypeInterface` that must be implemented by classes used in `Typecaster` and `AttributeTypecastHandler`;
- classes for `DateTimeImmutable`, `UUID`, `Array` and `Enum` types.

Installation
------------

[](#installation)

The package could be installed with [composer](https://getcomposer.org/download/):

```
composer require vjik/cycle-typecast
```

General Usage
-------------

[](#general-usage)

### Attributes

[](#attributes)

```
use Vjik\CycleTypecast\AttributeTypecastHandler;
use Vjik\CycleTypecast\UuidString\UuidStringToBytesType;
use Vjik\CycleTypecast\DateTimeImmutable\DateTimeImmutableToIntegerType;

#[Entity(
    // ...
    typecast: AttributeTypecastHandler::class,
)]
final class User
{
    // ...

    #[Column(type: 'primary', primary: true)]
    #[UuidStringToBytesType]
    private string $id;

    #[Column(type: 'int')]
    #[DateTimeImmutableToIntegerType]
    private DateTimeImmutable $createDate;
```

### Custom Typecast Handler

[](#custom-typecast-handler)

```
use Vjik\CycleTypecast\ArrayToStringType;
use Vjik\CycleTypecast\DateTimeImmutable\DateTimeImmutableToIntegerType;
use Vjik\CycleTypecast\TypecastHandler;
use Vjik\CycleTypecast\UuidString\UuidStringToBytesType;

final class UserTypecastHandler extends Vjik\CycleTypecast\TypecastHandler
{
    protected function getConfig(): array
    {
        return [
            'id' => new UuidStringToBytesType(),
            'createDate' => new DateTimeImmutableToIntegerType(),
            'modifyDate' => new DateTimeImmutableToIntegerType(),
            'tags' => new ArrayToStringType(','),
        ];
    }
}
```

### Custom Mapper

[](#custom-mapper)

```
use Cycle\ORM\ORMInterface;
use Cycle\ORM\PromiseMapper\PromiseMapper;
use Vjik\CycleTypecast\Typecaster;
use Vjik\CycleTypecast\ArrayToStringType;
use Vjik\CycleTypecast\DateTimeImmutable\DateTimeImmutableToIntegerType;
use Vjik\CycleTypecast\UuidString\UuidStringToBytesType;

final class UserMapper extends PromiseMapper
{
    private Typecaster $typecaster;

    public function __construct(ORMInterface $orm, string $role)
    {
        // Typecast configuration
        $this->typecaster = new Typecaster([
            'id' => new UuidStringToBytesType(),
            'createDate' => new DateTimeImmutableToIntegerType(),
            'modifyDate' => new DateTimeImmutableToIntegerType(),
            'tags' => new ArrayToStringType(','),
        ]);

        parent::__construct($orm, $role);
    }

    public function extract($entity): array
    {
        $data = parent::extract($entity);

        // Typecast after extract from entity
        return $this->typecaster->prepareAfterExtract($data);
    }

    public function hydrate($entity, array $data)
    {
        // Typecast before hydrate entity
        $data = $this->typecaster->prepareBeforeHydrate($data);

        return parent::hydrate($entity, $data);
    }
}
```

Types
-----

[](#types)

### `ArrayToStringType`

[](#arraytostringtype)

```
new ArrayToStringType(',');
```

Entity value: array of strings. For example, `['A', 'B', 'C']`.

Database value: array concatenated into string with delimiter setted in constructor. For example, `A,B,C`.

### `DateTimeImmutableToIntegerType`

[](#datetimeimmutabletointegertype)

```
new DateTimeImmutableToIntegerType();
```

Entity value: `DateTimeImmutable`.

Database value: timestamp as string (example, `1609658768`).

### `IntegerEnumType`

[](#integerenumtype)

```
new IntegerEnumType(IntegerEnum::class);
```

Entity value: integer typed enumeration.

Database value: enumeration value of integer type.

### `StringEnumType`

[](#stringenumtype)

```
new StringEnumType(StringEnum::class);
```

Entity value: string typed enumeration.

Database value: enumeration value of string type.

### `UuidStringToBytesType`

[](#uuidstringtobytestype)

```
new UuidStringToBytesType();
```

Entity value: string standard representation of the UUID. For example, `1f2d3897-a226-4eec-bd2c-d0145ef25df9`.

Database value: binary string representation of the UUID.

Testing
-------

[](#testing)

### Unit Testing

[](#unit-testing)

The package is tested with [PHPUnit](https://phpunit.de/). To run tests:

```
./vendor/bin/phpunit
```

### Mutation Testing

[](#mutation-testing)

The package tests are checked with [Infection](https://infection.github.io/) mutation framework with [Infection Static Analysis Plugin](https://github.com/Roave/infection-static-analysis-plugin). To run it:

```
./vendor/bin/roave-infection-static-analysis-plugin
```

### Static Analysis

[](#static-analysis)

The code is statically analyzed with [Psalm](https://psalm.dev/). To run static analysis:

```
./vendor/bin/psalm
```

License
-------

[](#license)

The Cycle Typecast is free software. It is released under the terms of the BSD License. Please see [`LICENSE`](./LICENSE.md) for more information.

###  Health Score

53

—

FairBetter than 97% of packages

Maintenance87

Actively maintained with recent releases

Popularity27

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity72

Established project with proven stability

 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 ~313 days

Recently: every ~347 days

Total

6

Last Release

63d ago

Major Versions

1.0.0 → 2.0.02022-05-24

2.2.0 → 3.0.02025-04-18

PHP version history (4 changes)1.0.0PHP ^7.4|^8.0

2.0.0PHP ^8.0

3.0.0PHP 8.1 - 8.4

3.0.1PHP 8.1 - 8.5

### Community

Maintainers

![](https://www.gravatar.com/avatar/53e5ee1dedd50f71e4aeeac2929f786cdfb400359d4776e6cd806388d0d5df2c?d=identicon)[vjik](/maintainers/vjik)

---

Top Contributors

[![vjik](https://avatars.githubusercontent.com/u/525501?v=4)](https://github.com/vjik "vjik (31 commits)")

---

Tags

cyclecycledatamappertypecast

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/vjik-cycle-typecast/health.svg)

```
[![Health](https://phpackages.com/badges/vjik-cycle-typecast/health.svg)](https://phpackages.com/packages/vjik-cycle-typecast)
```

###  Alternatives

[vlucas/spot2

Simple DataMapper built on top of Doctrine DBAL

605392.8k7](/packages/vlucas-spot2)[analogue/orm

An intuitive Data Mapper ORM for PHP and Laravel

63547.1k3](/packages/analogue-orm)[wayofdev/laravel-cycle-orm-adapter

🔥 A Laravel adapter for CycleORM, providing seamless integration of the Cycle DataMapper ORM for advanced database handling and object mapping in PHP applications.

3516.7k3](/packages/wayofdev-laravel-cycle-orm-adapter)[cycle/active-record

Provides a simple way to work with your database using Active Record pattern and Cycle ORM

671.3k3](/packages/cycle-active-record)[cviebrock/eloquent-typecast

Trait for Eloquent models to force type-casting on retrieved values

2468.0k](/packages/cviebrock-eloquent-typecast)

PHPackages © 2026

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