本文整理汇总了PHP中Gedmo\Tool\Wrapper\AbstractWrapper::getMetadata方法的典型用法代码示例。如果您正苦于以下问题:PHP AbstractWrapper::getMetadata方法的具体用法?PHP AbstractWrapper::getMetadata怎么用?PHP AbstractWrapper::getMetadata使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Gedmo\Tool\Wrapper\AbstractWrapper
的用法示例。
在下文中一共展示了AbstractWrapper::getMetadata方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: findTranslation
/**
* {@inheritDoc}
*/
public function findTranslation(AbstractWrapper $wrapped, $locale, $field, $translationClass, $objectClass)
{
$em = $this->getObjectManager();
// first look in identityMap, will save one SELECT query
foreach ($em->getUnitOfWork()->getIdentityMap() as $className => $objects) {
if ($className === $translationClass) {
foreach ($objects as $trans) {
$isRequestedTranslation = !$trans instanceof Proxy && $trans->getLocale() === $locale && $trans->getField() === $field;
if ($isRequestedTranslation) {
if ($this->usesPersonalTranslation($translationClass)) {
$isRequestedTranslation = $trans->getObject() === $wrapped->getObject();
} else {
$isRequestedTranslation = $trans->getForeignKey() === $wrapped->getIdentifier() && $trans->getObjectClass() === $wrapped->getMetadata()->name;
}
}
if ($isRequestedTranslation) {
return $trans;
}
}
}
}
$qb = $em->createQueryBuilder();
$qb->select('trans')->from($translationClass, 'trans')->where('trans.locale = :locale', 'trans.field = :field');
$qb->setParameters(compact('locale', 'field'));
if ($this->usesPersonalTranslation($translationClass)) {
$qb->andWhere('trans.object = :object');
$qb->setParameter('object', $wrapped->getObject());
} else {
$qb->andWhere('trans.foreignKey = :objectId');
$qb->andWhere('trans.objectClass = :objectClass');
$qb->setParameter('objectId', $wrapped->getIdentifier());
$qb->setParameter('objectClass', $objectClass);
}
$q = $qb->getQuery();
$q->setMaxResults(1);
$result = $q->getResult();
if ($result) {
return array_shift($result);
}
return null;
}