@param mixed $value Value to copy

@return mixed
@throws \Darvin\Utils\Cloner\ClonerException
197970
private function copyValue($value)
    {
        if (is_array($value)) {
            return $this->copyArray($value, true);
        }
        if (!is_object($value)) {
            return $value;
        }
        if ($value instanceof Collection) {
            return new ArrayCollection($this->copyArray($value->toArray(), false));
        }
        if ($value instanceof \Traversable) {
            throw new ClonerException(sprintf('Traversable class "%s" is not supported.', ClassUtils::getClass($value)));
        }

        return $this->cloneObject($value, false);
    }
136150
protected function storageDataStructure($value)
    {
        if (\is_array($value)) {
            return \serialize($value);
        }

        return (\is_object($value)) ? clone $value : $value;
    }
1213965
public function serialize($value)
    {
        $value = self::replaceKeys($this->replacements, $value);
        $xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><data></data>');
        $this->arrayToXml($value, $xml);

        return $xml->asXML();
    }
1363766
protected function serialize($value)
    {
        if (!is_array($value)) {
            return $value;
        }
        return Serialize::serialize($value, $this->serializer);
    }
892097
protected function mutateMetaAttribute($value)
    {
        if (is_null($value)) {
            return $value;
        }

        if ($value instanceof Arrayable) {
            $value = $value->toArray();
        } elseif (! is_array($value)) {
            $value = (array) $value;
        }

        return json_encode($value);
    }
588720
public static function castToDateTime($value)
    {
        if ($value instanceof \DateTime) {
            return clone $value;
        }
        if (is_numeric($value)) {
            $date = new \DateTime();
            $date->setTimestamp((int)$value);
        } elseif (is_string($value) || (is_object($value) && method_exists($value, '__toString'))) {
            $date = date_create((string)$value);
            if ($date === false) {
                $date = null;
            }
        } else {
            $date = null;
        }
        return $date;
    }
189818
public function makeStorableArrayFieldValue($value)
    {
        if ($this->_isEncodedArrayFieldValue($value)) {
            $value = $this->_decodeArrayFieldValue($value);
        }

        $value = $this->_serializeValue($value);
        return $value;
    }
783090
public function setInternalValue($value)
    {
        if ($value instanceof \ArrayObject) {
            $value = $value->getArrayCopy();
        }

        if ($value instanceof \Iterator) {
            $value = iterator_to_array($value);
        }

        // force null values conversion to empty arrays
        if (is_null($value)) {
            $value = [];
        }

        if (!is_array($value)) {
            $value = [$value];
        }

        $this->clear();

        foreach ($value as $k => $v) {
            $this->set($k, $v);
        }

        return $this;
    }
502223
public static function make($value)
    {
        if (is_resource($value)) {
            $value = null;
        } elseif (Arr::accessible($value)) {
            $value = new ArraySerialization($value);
        } elseif ($value instanceof stdClass) {
            $value = new ObjectSerialization($value);
        } elseif ($value instanceof Container) {
            $value = new ContainerSerialization($value);
        } elseif ($value instanceof DateTime) {
            $value = new DateTimeSerialization($value);
        } elseif ($value instanceof Validator) {
            $value = new ValidatorSerialization($value);
        } elseif ($value instanceof Throwable) {
            $value = new ThrowableSerialization($value);
        } elseif ($value instanceof Closure) {
            $value = null;
        }

        return $value;
    }
741480
public function withTransformations($value) {
        // null for not provided remains untouched
        if ($value === null)
            return null;

        foreach ($this->valueTransformations as $f)
            $value = $f($value);

        return $value;
    }
1009401
public function set($key, $value)
    {
        $cont = clone $this;
        $cont->doSet($key, $this->recursiveClone($value));

        return $cont;
    }
1228025
public function reverseTransform($value)
    {
        if (null === $value) {
            return null;
        }

        $repo = $this->em->getRepository($this->className);
        $entity = $repo->find($value);

        if (!$entity) {
            return null;
        }

        return $entity;
    }
246626
function set($value, $clone = true)
    {
        if ($clone && is_object($value) && !$value instanceof \Exception){
            $this->value = clone $value;
        }else{
            $this->value = $value;
        }
        $this->format = null;
        return $this;
    }
804464
protected function buildValue($value)
    {
        if ($value instanceof Model || is_null($value)) {
            return $value;
        }

        $model = $this->attribute->getAttribute('type');
        $instance = new $model();

        $instance->setAttribute('entity_id', $this->entity->getKey());
        $instance->setAttribute('entity_type', get_class($this->entity));
        $instance->setAttribute($this->attribute->getForeignKey(), $this->attribute->getKey());
        $instance->setAttribute('content', $value);

        return $instance;
    }
1262058
public function value($value)
    {
        if (!$value instanceof Operand\OperandInterface && !$value instanceof Update\Func) {
            $value = new Operand\Value($this, $value);
        }

        return $value;
    }
804045
protected function deep_clone($value) {
        if (is_object($value)) {
            // Objects must be cloned to begin with.
            $value = clone $value;
        }
        if (is_array($value) || is_object($value)) {
            foreach ($value as $key => $subvalue) {
                $value[$key] = $this->deep_clone($subvalue);
            }
        }
        return $value;
    }
809950
protected function Sub( $value )
	{
	    switch ( $value->GetValueCode() )
	    {
	        case DateProxyFactory::Code:
	            return new DayTimeDurationProxy( DateValue::Sub( $this->_value, /* DateValue */ $value->getValue() ) );

	        case YearMonthDurationProxyFactory::Code:
	        	/**
	        	 * @var YearMonthDurationProxy $value
	        	 */
	        	// Clone the DateValue contained in the proxy or the original is changed
	        	$clone = new DateValue( $this->_value->S, clone $this->_value->Value );
	        	$value->getValue()->Value->invert = ! $value->getValue()->Value->invert;
	        	return new DateProxy( DateValue::AddYearMonthDuration( $clone, $value->getValue() ) );

	        case DayTimeDurationProxyFactory::Code:
	        	/**
	        	 * @var DayTimeDurationProxy $value
	        	 */
	        	// Clone the DateValue contained in the proxy or the original is changed
	        	$clone = new DateValue( $this->_value->S, clone $this->_value->Value );
	        	$value->getValue()->Value->invert = ! $value->getValue()->Value->invert;
	        	return new DateProxy( DateValue::AddDayTimeDuration( $clone, $value->getValue() ) );

	        default:
	            throw XPath2Exception::withErrorCodeAndParams( "XPTY0004", Resources::BinaryOperatorNotDefined,
					array(
						"op:sub",
						SequenceType::WithTypeCodeAndCardinality( SequenceType::GetXmlTypeCodeFromObject( $this->_value ), XmlTypeCardinality::One ),
						SequenceType::WithTypeCodeAndCardinality( SequenceType::GetXmlTypeCodeFromObject( $value->getValue() ), XmlTypeCardinality::One )
					)
				);
	    }
	}