本文整理汇总了PHP中Doctrine\ORM\Event\LifecycleEventArgs类的典型用法代码示例。如果您正苦于以下问题:PHP LifecycleEventArgs类的具体用法?PHP LifecycleEventArgs怎么用?PHP LifecycleEventArgs使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了LifecycleEventArgs类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: postLoad
/**
* @param LifecycleEventArgs $event
*/
public function postLoad(LifecycleEventArgs $event)
{
$entity = $event->getEntity();
if ($entity instanceof ConfigurationEntry) {
$entity->init($this->container);
}
}
示例2: prePersist
public function prePersist(LifecycleEventArgs $event)
{
$object = $event->getObject();
if ($object instanceof UuidAwareInterface and !$object->getId()) {
$object->setId((new UuidGenerator())->generate($event->getEntityManager(), $object));
}
}
示例3: preSave
/**
* Handle pre save event
*
* @param LifecycleEventArgs $args Event arguments
*/
protected function preSave(LifecycleEventArgs $args)
{
$annotations = $this->container->get('cyber_app.metadata.reader')->getUploadebleFieldsAnnotations($args->getEntity());
if (0 === count($annotations)) {
return;
}
foreach ($annotations as $field => $annotation) {
$config = $this->container->getParameter('oneup_uploader.config.' . $annotation->endpoint);
if (!(isset($config['use_orphanage']) && $config['use_orphanage'])) {
continue;
}
$value = (array) PropertyAccess::createPropertyAccessor()->getValue($args->getEntity(), $field);
$value = array_filter($value, 'strlen');
$value = array_map(function ($file) {
return pathinfo($file, PATHINFO_BASENAME);
}, $value);
if (empty($value)) {
continue;
}
$orphanageStorage = $this->container->get('oneup_uploader.orphanage.' . $annotation->endpoint);
$files = [];
foreach ($orphanageStorage->getFiles() as $file) {
if (in_array($file->getBasename(), $value, true)) {
$files[] = $file;
}
}
$orphanageStorage->uploadFiles($files);
}
}
示例4: postLoad
/**
* After entity with reminders was loaded, load reminders
*
* @param LifecycleEventArgs $args
*/
public function postLoad(LifecycleEventArgs $args)
{
$entity = $args->getEntity();
if ($entity instanceof RemindableInterface) {
$this->getReminderManager()->loadReminders($entity);
}
}
示例5: postLoad
/**
* Post load
* @param LifecycleEventArgs $args
*/
public function postLoad(LifecycleEventArgs $args)
{
$entity = $args->getEntity();
if ($entity instanceof TranslatableInterface) {
$entity->setLocale($this->locale);
}
}
示例6: postLoad
/**
* @param LifecycleEventArgs $event
*/
public function postLoad(LifecycleEventArgs $event)
{
$settings = $event->getObject();
if ($settings instanceof SettingsInterface) {
$this->reverseTransform($settings);
}
}
示例7: postLoadHandler
/**
* @ORM\PostLoad
*
* @param \Venne\Security\User $user
* @param \Doctrine\ORM\Event\LifecycleEventArgs $event
*/
public function postLoadHandler(User $user, LifecycleEventArgs $event)
{
$em = $event->getEntityManager();
$user->setExtendedUserCallback(function () use($em, $user) {
return $em->getRepository($user->getClass())->findOneBy(array('user' => $user->id));
});
}
示例8: postLoad
public function postLoad(LifecycleEventArgs $args)
{
$entity = $args->getObject();
if ($entity instanceof ServiceAwareEntityInterface) {
$entity->setServiceLocator($this->serviceManager);
}
}
示例9: checkBadWords
/**
* @param LifecycleEventArgs $args
* @return bool
* @throws \Exception
*/
public function checkBadWords(LifecycleEventArgs $args)
{
$entity = $args->getEntity();
if (!$entity instanceof BadWordDetectorInterface) {
return true;
}
$badWords = $args->getEntityManager()->getRepository('RenowazeBundle:BadWord')->findAll();
/** @var BadWordDetector $annotationParams */
$annotationParams = $this->reader->getClassAnnotation(new \ReflectionClass($entity), 'RenowazeBundle\\Annotation\\BadWordDetector');
foreach ($annotationParams->fields as $field) {
$methodName = 'get' . ucfirst($field);
if (!method_exists($entity, $methodName)) {
throw new \Exception(sprintf('Field "%s" not found in entity "%s"', $methodName, get_class($entity)));
}
/** @var BadWord $badWord */
foreach ($badWords as $badWord) {
if (strpos($entity->{$methodName}(), $badWord->getWord()) !== false) {
$entity->setHasBadWords(true);
return true;
}
}
}
$entity->setHasBadWords(false);
return true;
}
示例10: prePersist
/**
* @param LifecycleEventArgs $args
*/
public function prePersist($args)
{
$object = $args->getEntity();
if ($object instanceof Poll && $object->getCreatedOn() === null) {
$object->setCreatedOn(new \DateTime());
}
}
示例11: postPersist
public function postPersist(LifecycleEventArgs $event)
{
/** @var OroEntityManager $em */
$em = $event->getEntityManager();
$entity = $event->getEntity();
$configProvider = $em->getExtendManager()->getConfigProvider();
$className = get_class($entity);
if ($configProvider->hasConfig($className)) {
$config = $configProvider->getConfig($className);
$schema = $config->get('schema');
if (isset($schema['relation'])) {
foreach ($schema['relation'] as $fieldName) {
/** @var Config $fieldConfig */
$fieldConfig = $configProvider->getConfig($className, $fieldName);
if ($fieldConfig->getId()->getFieldType() == 'optionSet' && ($setData = $entity->{Inflector::camelize('get_' . $fieldName)}())) {
$model = $configProvider->getConfigManager()->getConfigFieldModel($fieldConfig->getId()->getClassName(), $fieldConfig->getId()->getFieldName());
/**
* in case of single select field type, should wrap value in array
*/
if ($setData && !is_array($setData)) {
$setData = [$setData];
}
foreach ($setData as $option) {
$optionSetRelation = new OptionSetRelation();
$optionSetRelation->setData(null, $entity->getId(), $model, $em->getRepository(OptionSet::ENTITY_NAME)->find($option));
$em->persist($optionSetRelation);
$this->needFlush = true;
}
}
}
}
}
}
示例12: postLoad
/**
* @param \Doctrine\ORM\Event\LifecycleEventArgs $eventArgs
*/
public function postLoad(LifecycleEventArgs $eventArgs)
{
$action = $eventArgs->getEntity();
$className = get_class($action);
$em = $eventArgs->getEntityManager();
$metadata = $em->getClassMetadata($className);
if ($metadata->reflClass->implementsInterface('Redpanda\Bundle\ActivityStreamBundle\Model\ActionInterface')) {
if ($this->streamableResolver->supports($eventArgs, $action->getActorType())) {
$actorReflProp = $metadata->reflClass->getProperty('actor');
$actorReflProp->setAccessible(true);
$actorReflProp->setValue(
$action, $this->streamableResolver->resolve($eventArgs, $action->getActorType(), $action->getActorId())
);
}
if ($this->streamableResolver->supports($eventArgs, $action->getTargetType())) {
$targetReflProp = $metadata->reflClass->getProperty('target');
$targetReflProp->setAccessible(true);
$targetReflProp->setValue(
$action, $this->streamableResolver->resolve($eventArgs, $action->getTargetType(), $action->getTargetId())
);
}
if (null !== $action->getActionObjectType() && $this->streamableResolver->supports($eventArgs, $action->getActionObjectType())) {
$actionObjReflProp = $metadata->reflClass->getProperty('actionObject');
$actionObjReflProp->setAccessible(true);
$actionObjReflProp->setValue(
$action, $this->streamableResolver->resolve($eventArgs, $action->getActionObjectType(), $action->getActionObjectId())
);
}
}
}
示例13: postLoad
public function postLoad(LifecycleEventArgs $args)
{
$entity = $args->getEntity();
if ($entity instanceof Test) {
$this->calculateCorrectAnswer($entity);
}
}
示例14: preRemove
/**
* @param LifecycleEventArgs $args
*/
public function preRemove(LifecycleEventArgs $args)
{
$file = $args->getEntity();
if ($file instanceof File && $file->getName() !== null && file_exists($file->getPath())) {
$this->cacheManager->remove($file->getPath());
}
}
示例15: postLoadHandler
/** @ORM\PostLoad */
public function postLoadHandler(RouteEntity $route, LifecycleEventArgs $event)
{
$em = $event->getEntityManager();
$route->setExtendedRouteCallback(function () use($em, $route) {
return $em->getRepository($route->getClass())->findOneBy(array('route' => $route->id));
});
}