-
-
Notifications
You must be signed in to change notification settings - Fork 6.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
[WIP] Extract Object
and Component
into traits
#12929
Conversation
I don't think |
Makes sense to me overall. Do you think it worth also separating events and behaviors? |
This could be merged into 2.0.x IMO. And if we want to prepare to drop
Yes, but I'm not sure if there is a clean way to do this. |
@yiisoft/core-developers need your opinions. |
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.
this proof of concept looks good. I approve the split in traits. I agree with @samdark that we should also split the Events & Behaviors. Those two look less entangled as it first seems. Isnt it possible to create BehaviorTrait.php and a EventTrait in which the EventTrait includes BehaviorTrait.
With respect to className(), that one should stay in Component.php with a @deprecated mark. In 2.1 it will be removed.
} | ||
|
||
/** | ||
* Returns a list of behaviors that this component should behave as. |
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.
I see duplication with the @docs of the ComponentInterface. The docs in the traits can be replaced with @inheritdoc tags.
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.
How IDEs would react to that?
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.
Using @inheritdoc
in trait is incorrect, since traits doesn't handle any inheritance. It even break yii2-apidoc
as far as I remember.
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.
Well, most important is not to have duplicated @docs hanging around. Its hard to keep these synchron.
Of course we can choose not to include the tag. Then an approach like https://www.drupal.org/node/2206175 is favorable. So we should have a method doc starting with a 'Implements method...' line and a @see tag to this method.
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.
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.
As I said:
and a @see tag to this method.
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.
It doesn't change anything - you still doesn't have any real documentation, only references.
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.
Yeah. References are not enough...
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.
Is there a way to re-structure it the way not to duplicate docs and having IDE hints at the same time at all? I don't see a way to do it.
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.
clicking on the reference can be made quite obvious
Doesn't should be opposite? BehaviorTrait includes EventTrait?
I that case we can't say "Don't use deprecated |
The event trait needs
Is that a problem? People can still be advised to use the new traits? And if they want to use the current className(), they still can. Its required for merging in 2.0.x/ |
Behaviors uses Events: https://github.com/yiisoft/yii2/blob/master/framework/base/Behavior.php .
If we are deprecating |
Another entanglement. Lets fix this in another PR and keep this one clean.
|
@rob006 isn't PHP 5.6 |
* @author Robert Korulczyk <robert@korulczyk.pl> | ||
* @since 2.0.11 | ||
*/ | ||
trait MutatorsTrait |
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.
I am unsure about the naming.
Better be VirtualPropertyTrait
Dispite the change itself can be useful, this PR does not solves issue #7936 anyhow. In case I am sure we have a disscussion for such improvement somewhere - but I can not find it. |
Related disscussion: |
@klimov-paul We can't really fix #7936 in 2.0.x, but extracting @samdark You can't use |
Right. I agree on another trait for |
Then issue #7936 should not be placed under 'Fixed issues' section as it produces a delusion.
Disagreed: class Foo extends \yii\base\Object
{
} with: class Foo implements \yii\base\Configurable, \yii\base\MutatorsInterface
{
use \yii\base\ConfigurableTrait;
use \yii\base\MutatorsTrait;
{
} |
The side effect of this PR is sugnificant increase of entities in class herarchy: additional interfaces and traits. It makes the source code a little bit twisted. It would be nice to have @qiangxue opinion on this matter - he was the one insisted inheritance tree should be as simple as possible. Extracting a traits for |
One more related disscussion: #12021 |
I agree with not deprecating Component & Object for clean & easy inheritance (with those traits). I do not agree with keeping the current situation:
|
@klimov-paul no. We won't compose each core class using traits. That's more for user classes which can't inherit from Object but need properties and behaviors at the same time. |
Then what do you mean by telling:
? |
I've meant that that there will be no changes about core classes in 2.0. In 2.1 for some classes it potentially could make sense to remove all properties and either leave constructor only or create setters without defining properties. In many cases behaviors aren't meant to be attached as well. For these cases one may either not use traits at all or use one of them only. |
This is more problematic than I expected. Due some limitations in handling traits and interfaces in PHP 5 (sometimes PHP 5 does not take into account used traits when checking interface implementation, see https://3v4l.org/JWXqX ), we have 3 options:
|
I'd like to have it in 2.1. |
me too |
I don't like splitting the base classes of all classes in Yii into multiple traits, this will blow up the minimum overhead added by the framework, as instead of loading two classes (Object and Component) it would also need to include a set of traits and interface. |
I don't think that 2 traits and an interface is a measurable issue in terms of performance. And even 10 traits and interfaces. Especially in a PHP 7 era. |
Its not only performance its more about general complexity of the base. Yii philosophy is to keep things simple and practical. Separating the base class into multiple traits adds complexity in understanding it. What exactly are the practical benefits of such a separation? |
I was about a performance. My thoughts about a PR usefulness are still controversial. I love Yii's KISS. But I find On the other hand, as far as I understand the whole thing is about breaking inheritance chains. From this point I think this PR is a solid step forward. |
Yes, it's about a step towards removing inheritance chain that's way too long. |
|
Perfectly summarized |
in current state its making inheritance chain more complex.
what kind of third party are you thinking of here? Which package would require
the overhead is marginal and having to decide every time you create a class does not really safe anything, it takes time to make a decision whether to include which kind of trait, and it may limit usage if you later decide to add some behavior. For extensions that means if an extension excluded behaviors you can not inject your functionality and start a discussion with the author instead of using existing functionality that is always there if needed. Having behaviors available by default makes Yii perfectly extensible in many ways by default. I have experienced this when working on HumHub, which is very flexible when writing extensions for it, behaviors allow you to inject a lot of functionality. I'd keep this in by default, arguing about performance here would result in the question whether you'd want to use a framework at all. |
Any yii2 extension that provides integration with any existing non-yii2 library. Instead just wrapping everything you can extend library class, use these traits and interfaces and you will have yii2-like component.
|
This is only proof of concept, it still need adjust naming and fix descriptions.
Closes #9748