/**
  * @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);
     }
 }
예제 #2
0
 /**
  * @param  CallbackBag $callbackBag
  * @return mixed
  * @throws \Exception
  */
 public function callback(CallbackBag $callbackBag)
 {
     if (!$callbackBag->argumentExists(0)) {
         throw new \InvalidArgumentException($this->getPrefix() . ' accessor needs at least a value!');
     }
     Hint::validateOrException($callbackBag->getName(), $callbackBag->getArgument(0), $callbackBag->getHint(), $callbackBag->getNullable());
     $this->propertyDefault($callbackBag);
     $this->updateProperty($callbackBag);
     return $callbackBag->getObject();
 }
예제 #3
0
 /**
  * @param CallbackBag $callbackBag
  */
 protected function updateCollectionProperty(CallbackBag $callbackBag)
 {
     $object = $callbackBag->getObject();
     $propertyName = $callbackBag->getName();
     $oldValues = $callbackBag->getProperty();
     $newValues = $callbackBag->getArgument(0);
     $addMethod = Add::PREFIX . ucfirst($propertyName);
     $removeMethod = Remove::PREFIX . ucfirst($propertyName);
     foreach ($oldValues as $oldValue) {
         $object->{$removeMethod}($oldValue);
     }
     foreach ($newValues as $newValue) {
         $object->{$addMethod}($newValue);
     }
 }