• Stars
    star
    8
  • Rank 2,099,232 (Top 42 %)
  • Language
    PHP
  • License
    MIT License
  • Created almost 3 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

ActiveRecord based on Cycle ORM

Cycle Active Record

PHP Latest Version on Packagist GitHub Tests Action Status Total Downloads

ActiveRecord pattern based on Cycle ORM. AR entities work fine with mappers, repositories, behaviors and other Cycle features.

The package just adds to entity such proxy methods like save and delete using a class inheritance.

Requirements

Make sure that your server is configured with following PHP version and extensions:

Installation

You can install the package via composer:

composer require roxblnfk/cycle-active-record

After package install you need to register bootloader from the package.

Note If you are installing the package on the Yii 3 or Spiral Framework with the spiral-packages/discoverer package then you don't need to register bootloader by yourself. It will be registered automatically.

Spiral Framework without discoverer

Update Bootloader list

protected const LOAD = [
    // ...
    \Cycle\ActiveRecord\Boot\CycleActiveRecordBootloader::class,
];

Custom application

After Container initialization just register it in AR static class:

\Cycle\ActiveRecord\StaticOrigin::setContainer($container);

Example

Entity:

use Cycle\ActiveRecord\ActiveRecord;
use Cycle\Annotated\Annotation\Column;
use Cycle\Annotated\Annotation\Entity;

#[Entity(table: 'user')]
class User extends ActiveRecord
{
    #[Column(type: 'primary', typecast: 'int')]
    public int $id;

    public function __construct(
        #[Column(type: 'string')]
        public string $name
    ) {}
}

Usage:

$user1 = new User('Lia');
$user2 = new User('Zaza');

// Persisting
$user1->prepare();
$user2->save(); // Save current and prepared entities

// Find and delete
User::findByPK(10)?->delete();

// Delete multiple
$user1->prepareDeletion();
$user2->delete();

// Use SelectQuery
User::find()->where('id', '>', '10')->fetchData();

Testing

composer test

License

The MIT License (MIT). Please see License File for more information.