Transforms a domain specific Trash Item object into a Trash Item's identifier.

@param mixed $value

@return mixed|null

@throws TransformationFailedException
490142
public function transform($value): ?int
    {
        if (null === $value) {
            return null;
        }

        if (!$value instanceof TrashItem) {
            throw new TransformationFailedException('Expected a ' . TrashItem::class . ' object.');
        }

        return $value->id;
    }
698440
private function transformIfId($value)
    {
        if ($value && $this->isObjectId($value)) {
            $value = new ObjectId($value);
        }

        return $value;
    }
1174531
public function reverseTransform($value)
    {
        if (null === $value || !is_array($value)) {
            return null;
        }

        if (!array_key_exists('content_info', $value) || !array_key_exists('version_no', $value)) {
            throw new TransformationFailedException(
                "Invalid data. Value array is missing 'content_info' and/or 'version_no' keys"
            );
        }

        if (null === $value['content_info'] || null === $value['version_no']) {
            return null;
        }

        return $this->contentService->loadVersionInfo($value['content_info'], $value['version_no']);
    }
11088
public function transform($value)
    {
        if (is_array($value)) {
            $value = $value[FileType::UPLOAD_FIELDNAME];
        }

        try {
            return array(
                FileType::UPLOAD_FIELDNAME => new File(call_user_func($this->callback, $value, $this->property))
            );
        } catch (FileNotFoundException $e) {
            return null;
        }
    }
1126176
public function transform($value)
    {
        if ($value === null || $value == '') {
            return null;
        }
        if (!($value instanceof File)) {
            throw new TransformationFailedException('Expected an instance of a concrete5 file object.');
        }
        return intval($value->getFileID());
    }
695174
public function transform($value): ?string
    {
        if (null === $value) {
            return '';
        }

        if (!$value instanceof MoneyValue) {
            throw new TransformationFailedException('Expected a MoneyValue object.');
        }

        if (!$this->formatter) {
            $this->formatter = new DecimalMoneyFormatter(new ISOCurrencies());
        }

        if (!$value->withCurrency) {
            return $this->formatter->format($value->value);
        }

        return ((string) $value->value->getCurrency()).' '.$this->formatter->format($value->value);
    }
562448
public function transform($value)
    {
        if ($value instanceof JsonSerializable || $value instanceof StdClass) {
            return json_encode($value);
        }

        // If a toJson() method exists, the object can cast itself automatically.
        if (method_exists($value, 'toJson')) {
            return $value;
        }

        // Otherwise, if the object doesn't even have a __toString() method, we can't proceed.
        if (! method_exists($value, '__toString')) {
            throw new \Exception('Cannot transform this object to JavaScript.');
        }

        return "'{$value}'";
    }
875904
public function reverseTransform($value): ?array
    {
        if (empty($value)) {
            return [];
        }

        if (!is_string($value)) {
            throw new TransformationFailedException('Expected a string.');
        }

        $value = explode(',', $value);

        try {
            return array_map([$this->locationService, 'loadLocation'], $value);
        } catch (NotFoundException $e) {
            throw new TransformationFailedException($e->getMessage(), $e->getCode(), $e);
        }
    }
434036
public function reverseTransform($value)
    {
        if (!$value) {
            return null;
        }

        if (!is_string($value)) {
            throw new TransformationFailedException('Expected a string.');
        }

        if (!$value || !$this->parseUrl($value)) {
            throw new TransformationFailedException('Empty or invalid string.');
        }

        $video = $this->videoManager->findByVideoId($this->videoId);

        if (!$video) {
            $video = $this->videoManager->createVideo();

            $video->setVideoId($this->videoId);
            $video->setType($this->videoType);
            $video->setUrl($value);
        }

        return $video;
    }
443402
public function reverseTransform($value): ?APIRoleAssignment
    {
        if (empty($value)) {
            return null;
        }

        try {
            return $this->roleService->loadRoleAssignment($value);
        } catch (NotFoundException $e) {
            throw new TransformationFailedException($e->getMessage(), $e->getCode(), $e);
        }
    }
778597
public function reverseTransform($value)
    {
        if (!is_scalar($value)) {
            throw new TransformationFailedException('Expected a scalar.');
        }

        if ('' === $value) {
            return null;
        }

        $result = $value;

        if (!is_numeric($result)) {
            throw new TransformationFailedException('Value is not numeric.');
        }

        if (\is_string($result)) {
            if (false !== mb_strpos($result, '.')) {
                $result = (float) $result;
            } else {
                $result = (int) $result;
            }
        }

        if ($result >= PHP_INT_MAX || $result <= -PHP_INT_MAX) {
            throw new TransformationFailedException('I don\'t have a clear idea what infinity looks like.');
        }

        return $this->round($result);
    }
733016
public function transform($value)
    {
        if (null === $value) {
            return null;
        }

        if (!$value instanceof Language) {
            throw new TransformationFailedException('Expected a ' . Language::class . ' object.');
        }

        return $value->languageCode;
    }
279413
public function reverseTransform($value): ?MoneyValue
    {
        if (null === $value || '' === $value) {
            return null;
        }

        if (!\is_string($value)) {
            throw new TransformationFailedException('Expected a string or null.');
        }

        $withCurrency = true;
        $result = $value;

        if (false !== mb_strpos($value, ' ')) {
            list($currency, $result) = explode(' ', $value, 2);

            if (mb_strlen($currency) !== 3) {
                throw new TransformationFailedException(
                    sprintf('Value does not contain a valid 3 character currency code, got "%s".', $currency)
                );
            }
        } else {
            $withCurrency = false;
            $currency = $this->defaultCurrency;
        }

        if (!$this->moneyParser) {
            $this->moneyParser = new DecimalMoneyParser(new ISOCurrencies());
        }

        try {
            return new MoneyValue($this->moneyParser->parse($result, $currency), $withCurrency);
        } catch (ParserException | UnknownCurrencyException $e) {
            throw new TransformationFailedException($e->getMessage(), 0, $e);
        }
    }
1072341
public function reverseTransform($value)
    {
        if ('' === $value || null === $value) {
            return null;
        }

        if (!is_scalar($value)) {
            throw new TransformationFailedException('Value is not scalar');
        }

        try {
            $hash = $this->getCacheHash($value);
            if (array_key_exists($hash, $this->cachedResults)) {
                $entity = $this->cachedResults[$hash];
            } else {
                //Result not in cache

                $alias = current($this->queryBuilder->getRootAliases());
                $query = $this->queryBuilder->andWhere(
                    sprintf('%s.%s = :key_transformer', $alias, $this->identifier)
                )
                    ->setParameter('key_transformer', $value)
                    ->getQuery();

                $entity = $query->getSingleResult();
                $this->cachedResults[$hash] = $entity; //Saves result in cache
            }
        } catch (\Exception $e) {
            if ($this->throwExceptionIfValueNotFoundInReverse) {
                throw new TransformationFailedException(
                    sprintf('The entity with key "%s" could not be found or is not unique', $value)
                );
            } else {
                return null;
            }
        }

        return $entity;
    }
1101277
public function reverseTransform($value): ?array
    {
        if (null === $value) {
            return null;
        }

        if (!is_string($value)) {
            throw new TransformationFailedException('Expected a string.');
        }

        $parts = explode(':', $value);

        if (count($parts) < 3) {
            throw new TransformationFailedException('Policy string must contain at least 3 parts.');
        }

        return [
            'id' => $parts[0],
            'module' => $parts[1],
            'function' => $parts[2],
        ];
    }
308585
public function transform($value)
    {
        if (null !== $value && 1 !== $this->divisor) {
            if (!is_numeric($value)) {
                throw new TransformationFailedException('Expected a numeric.');
            }
            $value /= $this->divisor;
        }

        return parent::transform($value);
    }
348198
public function transform($value)
    {
        if (null === $value) {
            return null;
        }

        if (!$value instanceof Value) {
            throw new TransformationFailedException(
                sprintf('Expected a %s, got %s instead', Value::class, gettype($value))
            );
        }

        if (null === $value->date) {
            return null;
        }

        return $value->date->getTimestamp();
    }