Transforms the object.
Called recursively when transforming a collection or a relation.

@param $object
@return array|mixed
330072
public function transform($object)
    {
        if (($collection = $this->normalize($object)) instanceof Collection) {
            return $this->transformCollection($collection);
        }

        // If there are relations setup, transform it along with the object.
        if ($this->relatedCount) {
            return $this->transformWithRelated($object);
        }

        // If another transformation method was requested, use that instead.
        if (is_callable($this->transformationMethod)) {
            return $this->getAlternateTransformation($object);
        }

        return $this->getTransformation($object);
    }
1201301
private function recursiveDeserialize($serializedObject)
    {
        if (!is_array($serializedObject)) {
            return $serializedObject;
        } elseif ($this->dataFormatter->isSerializedObject($serializedObject)) {
            return $this->deserializeObject($serializedObject);
        } else {
            $deserializedArray = [];
            foreach ($serializedObject as $key => $value) {
                $deserializedArray[$key] = $this->recursiveDeserialize($value);
            }

            return $deserializedArray;
        }
    }
19584
public function toArrayFunction($object)
    {
        if (is_string($object)) {
            return json_decode($object, true);
        }

        return json_decode(json_encode($object), true);
    }
548173
public function serialize($object)
    {
        if (!is_object($object)) {
            throw new \InvalidArgumentException('Argument must be an object');
        }

        $reflectedObject = new \ReflectionObject($object);
        $reflectedProperties = $reflectedObject->getProperties();

        $array = array();

        foreach ($reflectedProperties as $property) {
            $value = $this->getValue($object, $property);

            if (null !== $value) {
                if (!is_scalar($value)) {
                    $value = $this->normalize($value);
                }

                $array[$this->formatter->toMongoKey($property->getName())] = $value;
            }
        }

        return $array;
    }
141832
public function transform($collection)
    {
        if ($collection && !is_array($collection) && !($collection instanceof \ArrayAccess)) {
            // in case of single entity, we have to make sure it's managed
            if (!$this->er->getManager()->contains($collection)) {
                $collection = $this->er->getManager()->merge($collection);
            }
        }
        return $collection;
    }
322306
protected function _toArray($object)
    {
        $reflectionClass = new \ReflectionClass(get_class($object));
        $array           = array();
        foreach ($reflectionClass->getProperties() as $property)
        {
            $property->setAccessible(true);
            $array[$property->getName()] = $property->getValue($object);
            $property->setAccessible(false);
        }
        return $array;
    }
284828
public static function toObject( $object )
    {
        //	If we can't iterate over the thing, we bail
        if ( !is_object( $object ) && !is_array( $object ) && !( $object instanceof \Traversable ) )
        {
            return null;
        }

        if ( is_array( $object ) )
        {
            //	Convert to an object
            $_properties = new \stdClass();

            foreach ( $object as $_key => $_value )
            {
                $_properties->{$_key} = $_value;
            }
        }
        else
        {
            $_me = new \ReflectionObject( $object );
            $_properties = $_me->getProperties();
        }

        //	We'll return this
        $_obj = new \stdClass();

        if ( !empty( $_properties ) )
        {
            if ( is_object( $object ) )
            {
                $_myClass = get_class( $object );
            }
            else
            {
                $_myClass = '_array_';
            }

            foreach ( $_properties as $_property )
            {
                //	Only want properties of $object hierarchy...
                if ( isset( $_property->class ) )
                {
                    $_class = new \ReflectionClass( $_property->class );

                    if ( !empty( $_class ) && !$_class->isInstance( $object ) && !$_class->isSubclassOf( $_myClass ) )
                    {
                        unset( $_class );
                        continue;
                    }

                    unset( $_class );
                }

                try
                {
                    $_realPropertyName = $_propertyName = ltrim( $_property->name, '_ ' );

                    if ( false !== strpos( $_propertyName, '_' ) )
                    {
                        $_propertyName = Inflector::tag( $_propertyName );
                    }

                    $_getter = 'get' . $_propertyName;

                    if ( method_exists( $object, $_getter ) )
                    {
                        $_propertyValue = $object->{$_getter}();

                        if ( !is_scalar( $_propertyValue ) )
                        {
                            $_propertyValue = self::toObject( $_propertyValue );
                        }

                        $_obj->{$_realPropertyName} = $_propertyValue;
                    }
                }
                catch ( \Exception $_ex )
                {
                    //	Just ignore, not a valid property if we can't read it with a getter
                }
            }
        }

        return $_obj;
    }
1355811
public function extract( $object )
    {
        $data = $this->getMapper()
                     ->extract( $object );

        if ( isset( $data['properties'] ) &&
             is_array( $data['properties'] ) )
        {
            foreach ( $data['properties'] as $key => $value )
            {
                $newKey = String::camelize( $key );

                if ( is_array( $value ) &&
                     array_key_exists( 'value', $value ) )
                {
                    $data['properties'][$key] = $value['value'];
                }

                if ( $newKey != $key )
                {
                    $data['properties'][$newKey] = $data['properties'][$key];
                    unset( $data['properties'][$key] );
                }
            }
        }

        return $data;
    }
1306409
private function normalizeObject($object)
    {
        if ($this->objectToIndex->contains($object)) {
            return [$this->classAnnotation => '@' . $this->objectToIndex[$object]];
        }
        $this->objectToIndex->attach($object, $this->objectIndex++);

        $normalizedObject = [$this->classAnnotation => get_class($object)];
        $normalizedObject += array_map([$this, 'normalizeValue'], $this->extractObjectProperties($object));

        return $normalizedObject;
    }
131398
public function clon(&$object=null) {
    list($object) = self::_wrapArgs(func_get_args(), 1);
    
    $clone = null;
    if(is_array($object)) $clone = (array) clone (object) $object;
    elseif(!is_object($object)) $clone = $object;
    elseif(!$clone) $clone = clone $object;
    
    // shallow copy object
    if(is_object($clone) && count($clone) > 0) {
      foreach($clone as $k=>$v) {
        if(is_array($v) || is_object($v)) $clone->$k =& $object->$k;
      }
    }
    
    // shallow copy array
    elseif(is_array($clone) && count($clone) > 0) {
      foreach($clone as $k=>$v) {
        if(is_array($v) || is_object($v)) $clone[$k] =& $object[$k];
      }
    }
    return self::_wrap($clone);
  }
1064595
protected static function rawData( $object )
    {
        if ( is_object( $object ) )
        {
            $hash = spl_object_hash( $object );

            if ( isset( self::$rawCheck[$hash] ) )
            {
                return array( '#recursion#' => $hash );
            }

            self::$rawCheck[$hash] = true;
        }

        $object = (array) $object;

        foreach ( $object as $key => $value )
        {
            if ( is_array( $value ) || is_object( $value ) )
            {
                $object[$key] = self::rawData( $value );
            }
        }

        return (object) $object;
    }
690118
protected function objectKey($object)
	{
		return base64_encode(json_encode(['id' => $object->id, 'type' => $object->type, 'relations' => $this->relations]));
	}
1028541
private function _recursiveGetObjectVars($object)
    {
        $vars = $object;
        if ( is_object($object) ) {
            $vars = get_object_vars($object);
            foreach ($vars as $key => $value) {
                $vars[$key] = $this->_recursiveGetObjectVars($value);
            }
        }

        return $vars;
    }
1118887
public function loadFromArray($object)
    {
        unset($this->custom1, $this->custom2, $this->custom3, $this->custom4);

        return parent::loadFromArray($object);
    }
934640
public function objectToArray($object)
    {
        if (!is_object($object) && !is_array($object)) {
            return $object;
        }
        if (is_object($object)) {
            $object = get_object_vars($object);
        }

        return array_map([get_class(), 'objectToArray'], $object);
    }
563078
public static function objectArray($object)
    {
        if (is_object($object)) {
            $reflectionClass = new \ReflectionClass(get_class($object));
            $array = [];
            foreach ($reflectionClass->getProperties() as $property) {
                $property->setAccessible(true);
                $array[$property->getName()] = $property->getValue($object);
                $property->setAccessible(false);
            }

            //If above method failed? try, this one.
            $array = (empty($array)) ? json_decode(json_encode($object), true) : $array;

            return $array;
        }

        return false;
    }
360797
public function transform($collection)
    {
        if (!$collection instanceof Collection) {
            // If given "collection" is an object we need to wrap it into an array, and pass into collection.
            $collection = new Collection(is_array($collection) ? $collection : [$collection]);
        }

        // If transform is declared or set, we can execute transform on his object.
        if ($this->hasTransformer()) {
            return $this->transform->executeOn($collection);
        }

        // Otherwise, we can return collection without transformation.
        return $collection;
    }