-
-
Notifications
You must be signed in to change notification settings - Fork 312
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
Add support for Traits (PHP 5.4) #102
Comments
I have the same problem |
👍 |
Same here |
+1 |
5 similar comments
+1 |
+1 |
+1 |
👍 |
+1 |
+1, exposing Doctrine behaviour traits (https://github.com/Atlantic18/DoctrineExtensions/blob/master/doc/timestampable.md#traits) involves a load of redundant copy/pasting without trait support in the serializer. |
+1 |
1 similar comment
+1 |
What is the current status? |
+1 |
1 similar comment
+1 |
+1 As a workaround I created a field in the to be serialized class, annotated it wit "@expose" and just before serializing I copied the values from the field in the trait to that one. That works for me. Ugly, but working. // source is the field in the trait |
+1 Anyone find a solution for this? |
I'm not having any problems with fields on traits being serialized, just using the Doctrine\ORM\Mapping and JMS\Serializer\Annotation annotations and it works for me. |
+1 |
Traits methods aren't available after deserialization |
+1 |
1 similar comment
+1 |
+1 |
I found a solution (for me) Before, my code was this :
Working code :
|
I have the exact opposite problem. I am using the When I set How do others handle this? Combining knplabs/doctrine-behaviors and friendsofsymfony/user-bundle should not be the rarest case. |
Not planning to "add" some special "trait" support since the traits are already working as they are. When using traits there are some scenarios:
When using YAML or XML mapping info for a trait should be placed on the class-metadata file that "uses" the trait. Example: trait PhysicalAddress
{
public $city;
}
class Address
{
use PhysicalAddress;
public $firstName;
public $lastName;
} Metadata for Address:
properties:
firstName:
expose: true
lastName:
exclude: true
city: # this property is coming from the trait
exclude: true
|
PHP 5.4.0 includes support for Traits and with them, new patterns for "drop in" functionality will likely gain attraction in the following months.
For example, a
User
could use Traits for mapping social networks profiles, such as Facebook or Twitter. Another interesting use case is to easily include Doctrine behaviors without having to rely on much more complex code. KnpLabs recently blogged about this new way of dealing with behaviors on a blog post.This issue is a request to include support for mapping metadata when using Traits.
The text was updated successfully, but these errors were encountered: