/**
  * @param  CallbackBag $callbackBag
  * @param  bool        $nullValue
  * @throws \Exception
  */
 protected function handleMappedBy(CallbackBag $callbackBag, $nullValue = false)
 {
     if (null === ($mappedBy = $callbackBag->getMappedBy())) {
         throw new \Exception("Remote name needs to be set on '{$callbackBag->getName()}', if remote type is given!");
     }
     $value = false === $nullValue ? $callbackBag->getObject() : null;
     if (false === $callbackBag->getArgument(1, false)) {
         $method = $this->getPrefixByProp($callbackBag->getProp()) . ucfirst($mappedBy);
         $callbackBag->getArgument(0)->{$method}($value, true);
     }
 }
Exemple #2
0
 /**
  * @param CallbackBag $callbackBag
  */
 protected function updateSimpleProperty(CallbackBag $callbackBag)
 {
     $prefixes = $this->getPrefixByProp($callbackBag->getProp());
     $removePrefix = $prefixes[0];
     $addPrefix = $prefixes[1];
     $value = $callbackBag->getArgument(0);
     if (null !== $prefixes && !$callbackBag->getArgument(1, false)) {
         $mappedBy = $callbackBag->getMappedBy();
         $removeMethod = $removePrefix . ucfirst($mappedBy);
         $addMethod = $addPrefix . ucfirst($mappedBy);
         if (!is_null($callbackBag->getProperty())) {
             $callbackBag->getProperty()->{$removeMethod}(Set::PREFIX !== $removePrefix ? $callbackBag->getObject() : null, true);
         }
         if (!is_null($value)) {
             $value->{$addMethod}($callbackBag->getObject(), true);
         }
     }
     $callbackBag->setProperty($value);
 }