Skip to content

Conversation

@neznaika0
Copy link
Contributor

@neznaika0 neznaika0 commented Jan 8, 2026

Description
I keep track of entity changes. At the moment, I don't see any conflicts when using 'attributes' as the column name.
There was also a bug with the restore of $_cast.

Question: Do I need to get rid of the DataCaster object? For example, I completely disabled casting in the Entity and transform it into a Model. But the object is always being created.

I could, under the condition $_cast = false, not create it or destroy it when calling $this->cast(false). We can simplify by calling getDataCaster() "on the fly", although it's no better to create an object every time. Suggestions?

It is also planned to update the DateCast to use the interface, since it does not always set DateTime, but also DateTimeImmutable.

PR should be taken after #9877 But we can discuss it now.

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value (without duplication)
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

Copy link
Contributor Author

@neznaika0 neznaika0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

@michalsn michalsn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some initial comments added.

If you fix a bug, it should be mentioned in the changelog as well.

@neznaika0
Copy link
Contributor Author

If you fix a bug, it should be mentioned in the changelog as well.

I've lost the changes. I'll fix it

@neznaika0 neznaika0 force-pushed the refactor/entity-rework branch from 6efe618 to 027a0f2 Compare January 10, 2026 14:07
@neznaika0 neznaika0 marked this pull request as ready for review January 10, 2026 14:09
@michalsn michalsn added the 4.7 label Jan 10, 2026
@neznaika0
Copy link
Contributor Author

@neznaika0
Copy link
Contributor Author

Additionally:

  • I would return the array check and fix fill() -null is never needed there.
    public function __construct(array $data = [])
    {
       // ...

        $this->syncOriginal()->fill($data);
    }

    public function fill(array $data)
    {
        // ...
    }

Copy link
Member

@michalsn michalsn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could already with _setAttributes(). Since we dropped setAttributes(), I see no problem with removing this note.

I would return the array check and fix fill() -null is never needed there.

Users are allowed to create the Entity and fill it later. This change could break people's apps.

@neznaika0
Copy link
Contributor Author

Users are allowed to create the Entity and fill it later. This change could break people's apps.

How? Does the default constructor have an empty array, and fill() without an array doesn't matter?

@michalsn
Copy link
Member

How? Does the default constructor have an empty array, and fill() without an array doesn't matter?

This is a BC break, which has no real benefit.

@neznaika0
Copy link
Contributor Author

Good. Let's leave it. But we're breaking in 4.7. In my opinion, using null is the wrong developer code. php8.5 has already been released, and we still support the old standards. Of course, this is a concern for the developers...

@michalsn
Copy link
Member

Good. Let's leave it. But we're breaking in 4.7. In my opinion, using null is the wrong developer code. php8.5 has already been released, and we still support the old standards. Of course, this is a concern for the developers...

We do allow BC breaks, but only when they provide clear value or affect minimally exposed internals. This change does neither and would introduce unnecessary risk for users.

That said, I'm not stubborn... if other maintainers think that this is the right direction, then I won't be opposed.

Copy link
Member

@michalsn michalsn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than this, looks good to me. Thanks.

Copy link
Member

@michalsn michalsn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Final round from me, cleanup only.

Comment on lines +576 to +578
/**
* This method allows you to refuse to contain an unnecessary DataCaster if you do not use casting.
*/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/**
* This method allows you to refuse to contain an unnecessary DataCaster if you do not use casting.
*/
/**
* Returns a DataCaster instance when casts are defined.
* If no casts are configured, no DataCaster is created and null is returned.
*/


// Synchronize option with DataCaster initialization
$this->dataCaster();

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not needed as $_cast does not decide about DataCaster initialization.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants