Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ORM Heap Cleaning Default Behavior #37

Merged
merged 2 commits into from
Jan 19, 2024
Merged

Update ORM Heap Cleaning Default Behavior #37

merged 2 commits into from
Jan 19, 2024

Conversation

butschster
Copy link
Member

@butschster butschster commented Jan 18, 2024

This PR introduces significant enhancements to the heap cleaning mechanism within the ORM factory. The primary focus is to provide more control over when and how heap cleaning occurs during entity creation.

Key Changes:

  1. Global Control of Heap Cleaning: A new static property AbstractFactory::$cleanHeap has been introduced. This property allows developers to control heap cleaning behavior at a global level.

To change the heap cleaning behavior globally across all instances of the factory, set the AbstractFactory::$cleanHeap property. By default, heap cleaning is turned off.

AbstractFactory::$cleanHeap = true; // Enable heap cleaning globally
  1. Instance-level Control: The create and createOne methods now accept an optional $cleanHeap parameter. This enables fine-grained control over heap cleaning for individual entity creation operations.
$factory->create(cleanHeap: true); // Heap cleaning will be performed after creating entities
$factory->createOne(cleanHeap: false); // No heap cleaning after creating a single entity

Other changes

Enhancements to __get Method in ORM Factory

This Pull Request introduces improvements to the __get magic method in our ORM Factory. We've added additional properties that can be accessed magically, namely data, entity, and entities. These enhancements simplify the process of obtaining different types of outputs from the factory, making the interface more intuitive and flexible for various use cases.

1. Accessing data:

You can now retrieve the raw data used for entity creation simply by accessing the data property. This is particularly useful for debugging or logging purposes.

$rawData = $factory->data;

2. Accessing entity:

Creating a single entity is now more straightforward. Accessing the entity property will trigger the creation of one entity based on the current factory state.

$singleEntity = $factory->entity;

3. Accessing entities:

Similarly, for creating multiple entities, you can use the entities property. It respects the amount setting of the factory and returns an array of created entities.

$multipleEntities = $factory->entities;

- Altered default setting to disable ORM heap cleaning automatically.
- To enable heap cleaning after entity creation, set the `$cleanHeap` argument to `true`. Examples:
  $factory->create(cleanHeap: true);
  $factory->createOne(cleanHeap: true);
- To modify this behavior globally, use `AbstractFactory::$cleanHeap = true`.

2. Enhanced PHPDoc Annotations for Factory

- Enhanced state management with new types `TState`, `TEntityState`, and `TCallback` for more precise typing in factory methods.
- Refined method signatures and PHPDoc for `raw`, `object`, `applyEntityState`, and `callAfterCreating` methods for better type hinting and clarity.
@butschster butschster added the enhancement New feature or request label Jan 18, 2024
@butschster butschster self-assigned this Jan 18, 2024
@butschster butschster added this to the 3.x milestone Jan 18, 2024
@butschster butschster merged commit 361c64f into 3.x Jan 19, 2024
6 of 7 checks passed
@butschster butschster deleted the hotifx/heap branch January 19, 2024 07:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants