Meet Cycle 2.0!

Meet Cycle 2.0!

It’s been almost 3 years since we released Cycle 1.0, and since then our team has done a great job optimizing the product and adding killer new features.

We’re now super excited to announce the release of Cycle 2.0, the open-source, PHP DataMapper, ORM and Data Modelling engine designed to safely work in classic and daemonized PHP applications. Cycle ORM provides flexible configuration options to model datasets, a powerful query builder and supports dynamic mapping schema. The engine can work with plain PHP objects and support annotation declarations, as well as proxies via extensions.

As always, we love hearing from the community and we are doing our best to support all your requests. We would be thankful to see your feedback and stars on GitHub, Twitter, Discord, and Telegram.

Here are the major changes in Cycle 2.0.

ORM

  • Added composite keys support in entities and relations.
    PK (primary key) scheme and relations (inner key and outer key) now support composite (multiple) keys.

  • ‘Joined Table Inheritance’ and ‘Single Table Inheritance‘. Added an ability to manage the inheritance hierarchy.

    • In JTI each entity in class hierarchy maps to its (separate) table. The only column that repeatedly appears in all the tables is the identifier, which will be used for joining them when needed.
    • The Single Table strategy creates one table for each class hierarchy. This means, all attributes of specified classes in hierarchy are located in one common table. Special discriminator column used to determine which data belongs to which class.
  • Significantly redesigned mappers
    The default mapper now creates proxy entities

    • Working with lazy links became easier;
    • Supports typed class properties;
    • Supports private class properties.

    Added ability to create proxy entities that allows lazy loading of relationships.
    Mapper code is noticeably simplified – it’s easier to work with ORM.

  • We created a new Entities hydrator from the ground up. Now it works much faster and supports working with private class properties.

  • Added support for custom collections in ‘Has Many’ and ‘Many To Many’ relations

    • We don’t use doctrine collections out of the box anymore. The doctrine/collections has been removed from the require section in composer.json.
    • Custom collections can be configured individually for each relationship by specifying aliases and interfaces. Now you can use doctrine collections (doctrine/collections), laravel collections (illuminate/collections), arrays or all at once.
  • Typecasting moved to the mapper and became more flexible and customizable. Now you can customize the typecast rules and their handlers (Typecast Handler). Typecast Handler – provides a convenient method of converting entity property values to common data types.

  • Old Cycle\ORM\Transaction split into Entity Manager and Unit Of Work.

    • Entity Manager replaces Transaction class and provides the ability to handle transaction state and to retry transaction if something went wrong.
    • Now you can save/delete ORM entities in the context of an already opened transaction.
    • Rewritten algorithm for entity persistence.
  • Added PHP v. 8.0+ support

  • Different optimizations and enhancements:

    • Everything associated with Constrain in the ORM was replaced with Scope;
    • Class properties and method signatures are more strictly typed. Some external API methods have clarified their return types;
  • Migrator moved to cycle/migrations. Old cycle/migrations moved to cycle/schema-migrations-generator

Database

  • Spiral/database moved to cycle/database. Its development will continue as part of Cycle;
  • Added support for ReadOnly connections;
  • Configuration via DTO;
  • Added DSN support;
  • Added PostgreSQL scheme support;
  • Added PHP v8.0+ support.

Schema-Builder, Annotations and Attributes

  • All features of ORM v2 are supported:
    • composite keys;
    • custom collections;
    • JTI, STI (new way of configuring, incompatible with the old one).
  • Everything associated with Constrain was replaced with Scope;
  • PHP 8, psalm, various optimizations;
  • Many To Many relation optimization;
  • Added Schema Modifier with appropriate generators for the schema compiler. Relations became as part of schema modifier extensions.
  • Corrections of annoying typos;
  • Added foreign key option ‘onDelete’ in links.

New packages

Schema Renderer – a set of utilities for formatted output of a scheme to the console or php file. May be useful when debugging or caching a schema in a php file.

Entity Behavior - a collection of attributes that add behaviors to Cycle ORM entities. The package also provides a simple API to create custom behavior attributes. The package provides several useful behaviors out of the box: CreatedAt, UpdatedAt, SoftDelete, OptimisticLock and a few more specific behaviors. UUID behaviors uses ramsey uuid package. UUID provides in a separate package.


Earlier we made a large number of other changes, check them all in this article.

Thanks for reading! We would highly appreciate it if you join our communities and share your feedback on GitHub, Twitter, Discord, and Telegram.