/** * @param CallbackBag $callbackBag * @return mixed */ public function callback(CallbackBag $callbackBag) { if (count($callbackBag->getArguments()) !== 0) { throw new \InvalidArgumentException($this->getPrefix() . ' accessor allows no argument!'); } return $callbackBag->getProperty(); }
/** * @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); } }
/** * @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(); }
/** * @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); } }