-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
feat: add EntityInterface #8325
Conversation
53caa77
to
c8647b3
Compare
I'm all for this. I am not sure if all of the methods in the interface need to be in the interface, though, and will have to look over that later. |
They probably don't from a methods utilized within the framework itself standpoint, we'd need to identify which ones are being used though to include. This is just all the public methods which seemed like the safest place to start. |
In this case, the interface needs only the |
Is this a bug fix? If not, please go to |
I think given that this is to align with how you'd build a replacement entity, you'd at minimum want to require the implementation of those methods used in the model such as |
Here's my list of methods we would want in the interface:
To me, those 5 methods are what defines the core of the functionality if you were to create your own. |
Indeed, But there is an opinion that |
I would be in favor of adding bare minimum methods to the interface, which will ensure that everything will work properly with our model. While we may be used to more methods, I feel the custom Entity implementation should not impose anything beyond what is required. That being said I agree with @kenjis - we need only This option would also require a little mention in the user guide. |
If thinking of it purely as a "what does the framework need" to work with an Entity than I agree with both of you. I was thinking of it more from a user's perspective of what's the bare minimum functionality I would need to be able to reasonably swap out usage of Entity types. |
With the point of this interface being to allow for the safe creation of a custom entity, and assuming that the only items required by the framework are Even |
@colethorsen - out of curiosity, why are you implementing your own Entity class? Are you missing some functionality or just have a custom use case? |
Thank you for updating. I think this is an enhancement, not a bug fix. |
35644a2
to
aebe887
Compare
Cole is one of our resident NoSQL devs. In my work with Firebase I definitely had to hack up Entity to get things to work, and eventually ditched it altogether - so my guess is that he's doing the same. |
Please fix the code, and re-run 1 file with changes
===================
1) system/Entity/EntityInterface.php:0
---------- begin diff ----------
@@ @@
<?php
+declare(strict_types=1);
+
/**
* This file is part of CodeIgniter 4 framework.
*
@@ @@
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
-
namespace CodeIgniter\Entity;
/**
----------- end diff ----------- |
d19ee9c
to
f4eda59
Compare
@@ -143,7 +143,7 @@ protected function fetchObject(string $className = 'stdClass') | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update @return
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
--- a/system/Database/SQLite3/Result.php
+++ b/system/Database/SQLite3/Result.php
@@ -128,7 +128,7 @@ class Result extends BaseResult
*
* Overridden by child classes.
*
- * @return Entity|false|object|stdClass
+ * @return EntityInterface|false|object|stdClass
*/
protected function fetchObject(string $className = 'stdClass')
{
CodeIgniter4/system/Database/BaseResult.php Line 162 in b17255a
CodeIgniter4/system/Database/BaseResult.php Line 243 in b17255a
CodeIgniter4/system/Database/BaseResult.php Line 542 in b17255a
|
fb94958
to
557e2b4
Compare
Fix the PHPStan errors. Remove the following Ignored error pattern in
https://github.com/codeigniter4/CodeIgniter4/actions/runs/8423534292/job/23065390399?pr=8325 |
👋 Hi, @colethorsen! |
-only require methods that are required to use the entity with the model. # Conflicts: # system/BaseModel.php
Co-authored-by: kenjis <kenji.uui@gmail.com>
db4fed1
to
c43c429
Compare
Resolve conflicts, please. |
We will release v4.5.0 soon. |
The main CodeIgniter entity couldn't be replaced with a custom one because the database drivers checked to see if entities were extensions of the entity itself and not an interface. Creating an interface allows for a completely new entity to implement the interface instead of having to extend the Entity itself.
Checklist: