我有一个实体Acme\Bundle\Entity\Author
,它与Acme\Bundle\Entity\Article
有一对多关系,我有两个实体的两个JMS序列化器事件订阅者。
Acme\Bundle\Entity\Author
;
acm.author_serialization_listener:
class: Acm\Bundle\Listener\AuthorSerializationListener
tags:
- { name: jms_serializer.event_subscriber }
class AuthorSerializationListener implements EventSubscriberInterface
{
/**
* @inheritdoc
*/
public static function getSubscribedEvents()
{
return array(
array('event' => 'serializer.pre_serialize', 'class' => 'Acme\Bundle\Entity\Author' 'method' => 'onPreSerialize'),
);
}
public function onPreSerialize(PreSerializeEvent $event)
{
if($event->getObject() instanceof Author) {
return;
}
}
}
Acme\Bundle\Entity\Article
;
acm.article_serialization_listener:
class: Acm\Bundle\Listener\ArticleSerializationListener
tags:
- { name: jms_serializer.event_subscriber }
class ArticleSerializationListener implements EventSubscriberInterface
{
/**
* @inheritdoc
*/
public static function getSubscribedEvents()
{
return array(
array('event' => 'serializer.pre_serialize', 'class' => 'Acme\Bundle\Entity\Article' 'method' => 'onPreSerialize'),
);
}
public function onPreSerialize(PreSerializeEvent $event)
{
if($event->getObject() instanceof Article) {
return;
}
}
}
onPreSerialize
函数在Author
序列化Article
以及ArticleSerializationListener
订阅者类中的相关Article
时出现问题,其中代理\ __ CG __ \ Acme \ Bundle \ Entity \ Article 而不是 Acme \ Bundle \ Entity \ Article 导致排除相关attribute('innerHTML')
实体的实体。有什么我做错了或有解决方法吗?
答案 0 :(得分:0)
代替private void takeDataFromFirebase(){
Query my_message= mRef.child(USERS_CHILD)
.orderByChild(USER_MESSAGES);
my_message.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String
{
}
@Override
public void onChildChanged(DataSnapshot dataSnapshot, String s) {
}
@Override
public void onChildRemoved(DataSnapshot dataSnapshot) {
}
@Override
public void onChildMoved(DataSnapshot dataSnapshot, String s) {
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
,您应该只使用运算符get_class
,因为代理继承自实体。你比较两个字符串。
instanceof
Sidenode:运营商if($event->getObject() instanceof \Acme\Bundle\Entity\Article) {
return;
}
也不存在。