public function importValue($value) { if ($value instanceof UnifiedContainer) { if ($value->isLazy()) { return $this->import([$this->name => $value->getList()]); } elseif ($value->getParentObject()->getId() && ($list = $value->getList())) { return $this->import([$this->name => ArrayUtils::getIdsArray($list)]); } else { return parent::importValue(null); } } if (is_array($value)) { try { if ($this->scalar) { Assert::isScalar(current($value)); } else { Assert::isInteger(current($value)); } return $this->import([$this->name => $value]); } catch (WrongArgumentException $e) { return $this->import([$this->name => ArrayUtils::getIdsArray($value)]); } } return parent::importValue($value); }
public function import($scope) { $savedRaw = null; if (isset($scope[$this->name]) && $scope[$this->name]) { $savedRaw = $scope[$this->name]; $this->customError = null; try { list($class, $id) = explode(self::DELIMITER, $savedRaw, 2); } catch (BaseException $e) { $this->customError = self::WRONG_CID_FORMAT; } if (!$this->customError && !ClassUtils::isInstanceOf($class, $this->baseClassName)) { $this->customError = self::WRONG_CLASS; } if (!$this->customError) { parent::of($class); $scope[$this->name] = $id; } } else { // we need some class in any case parent::of($this->baseClassName); } if (!$this->customError) { $result = parent::import($scope); } else { $this->value = null; $result = false; } if ($savedRaw) { $this->raw = $savedRaw; } return $result; }