本文整理汇总了PHP中Doctrine\Common\Persistence\Mapping\ClassMetadata::getReflectionProperty方法的典型用法代码示例。如果您正苦于以下问题:PHP ClassMetadata::getReflectionProperty方法的具体用法?PHP ClassMetadata::getReflectionProperty怎么用?PHP ClassMetadata::getReflectionProperty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\Common\Persistence\Mapping\ClassMetadata
的用法示例。
在下文中一共展示了ClassMetadata::getReflectionProperty方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getGroups
/**
*
* @param array $config
* @param ClassMetadata $meta
* @param object $object
*
* @return array
*/
private function getGroups($meta, $config, $object)
{
$groups = array();
if (isset($config['groups'])) {
foreach ($config['groups'] as $group) {
$groups[$group] = $meta->getReflectionProperty($group)->getValue($object);
}
}
return $groups;
}
示例2: updateField
/**
* Updates a field
*
* @param object $object
* @param AdapterInterface $eventAdapter
* @param ClassMetadata $meta
* @param string $field
*/
protected function updateField($object, $eventAdapter, $meta, $field)
{
/** @var \Doctrine\Orm\Mapping\ClassMetadata|\Doctrine\ODM\MongoDB\Mapping\ClassMetadata $meta */
$property = $meta->getReflectionProperty($field);
$oldValue = $property->getValue($object);
$newValue = $this->getFieldValue($meta, $field, $eventAdapter);
// if field value is reference, persist object
if ($meta->hasAssociation($field) && is_object($newValue)) {
$eventAdapter->getObjectManager()->persist($newValue);
}
$property->setValue($object, $newValue);
if ($object instanceof NotifyPropertyChanged) {
$uow = $eventAdapter->getObjectManager()->getUnitOfWork();
$uow->propertyChanged($object, $field, $oldValue, $newValue);
}
}
示例3: updateField
/**
* @param object $object
* @param object $uow
* @param AdapterInterface $ea
* @param ClassMetadata $meta
* @param String $field
* @param mixed $value
* @param bool $notifyPropertyChanged
*/
protected function updateField($object, $uow, AdapterInterface $ea, ClassMetadata $meta, $field, $value, $notifyPropertyChanged = true)
{
$property = $meta->getReflectionProperty($field);
$oldValue = $property->getValue($object);
$ucField = ucfirst($field);
$prefixes = ['add', 'set', 'property'];
foreach ($prefixes as $prefix) {
$method = $prefix . $ucField;
if (method_exists($object, $method)) {
$object->{$method}($value);
break;
}
if ($prefix === 'property') {
$property->setValue($object, $value);
break;
}
}
if ($notifyPropertyChanged && $object instanceof NotifyPropertyChanged) {
$uow->propertyChanged($object, $field, $oldValue, $value);
}
}
示例4: updateField
/**
* @param object $object
* @param object $uow
* @param AdapterInterface $ea
* @param ClassMetadata $meta
* @param String $field
* @param mixed $value
* @param bool $notifyPropertyChanged
*/
protected function updateField($object, $uow, AdapterInterface $ea, ClassMetadata $meta, $field, $value, $notifyPropertyChanged = true)
{
$property = $meta->getReflectionProperty($field);
$oldValue = $property->getValue($object);
$property->setValue($object, $value);
if ($notifyPropertyChanged && $object instanceof NotifyPropertyChanged) {
$uow = $ea->getObjectManager()->getUnitOfWork();
$uow->propertyChanged($object, $field, $oldValue, $value);
}
}
示例5: updateField
/**
* Updates a field
*
* @param object $object
* @param AdapterInterface $eventAdapter
* @param ClassMetadata $meta
* @param string $field
*/
protected function updateField($object, $eventAdapter, $meta, $field)
{
/** @var \Doctrine\Orm\Mapping\ClassMetadata|\Doctrine\ODM\MongoDB\Mapping\ClassMetadata $meta */
$property = $meta->getReflectionProperty($field);
$oldValue = $property->getValue($object);
$newValue = $this->getFieldValue($meta, $field, $eventAdapter);
// if field value is reference, persist object
if ($meta->hasAssociation($field) && is_object($newValue)) {
$uow = $eventAdapter->getObjectManager()->getUnitOfWork();
// Check to persist only when the entity isn't already managed, persists always for MongoDB
if (!$uow instanceof UnitOfWork || $uow->getEntityState($newValue) !== UnitOfWork::STATE_MANAGED) {
$eventAdapter->getObjectManager()->persist($newValue);
}
}
$property->setValue($object, $newValue);
if ($object instanceof NotifyPropertyChanged) {
$uow = $eventAdapter->getObjectManager()->getUnitOfWork();
$uow->propertyChanged($object, $field, $oldValue, $newValue);
}
}