Recursively convert an object hierarchy into an associative array.

@param mixed $subject An object or array of objects
@return array The subject represented as an array
@throws \InvalidArgumentException
438419
public static function convertObjectToArray($subject): array
    {
        if (!is_object($subject) && !is_array($subject)) {
            throw new \InvalidArgumentException('convertObjectToArray expects either array or object as input, ' . gettype($subject) . ' given.', 1287059709);
        }
        if (is_object($subject)) {
            $subject = (array)$subject;
        }
        foreach ($subject as $key => $value) {
            if (is_array($value) || is_object($value)) {
                $subject[$key] = self::convertObjectToArray($value);
            }
        }
        return $subject;
    }
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;
    }
1066046
private function validateTypeArray($subject): bool
    {
        if (!\is_array($subject)) {
            return false;
        }
        if (count($subject) > 0 && !\is_int(\array_keys($subject)[0])) {
            return false;
        }
        return true;
    }
113827
public function subject($subject = null)
    {
        deprecationWarning('Email::subject() is deprecated. Use Email::setSubject() or Email::getSubject() instead.');

        if ($subject === null) {
            return $this->getSubject();
        }

        return $this->setSubject($subject);
    }
564566
public function loadSubjectObjectives($subject)
    {
        $target = $this->getSubjectType($subject);
        $repoMethod = "findBy{$target}";

        return $this->objectiveRepo->{$repoMethod}($subject);
    }
1020059
public function __toArray($recursive = false)
    {
        if ($recursive) {
            return Util::convertEasyPostObjectToArray($this->_values);
        }

        return $this->_values;
    }
727708
public function transform($object)
    {
        if (null === $object) {
            return;
        }

        if (!(is_array($object) || $object instanceof \Traversable)) {
            throw new \InvalidArgumentException(sprintf(
                'Traversable element expected, %s given',
                is_object($object) ? get_class($object) : gettype($object)
            ));
        }

        $result = [];
        foreach ($object as $key => $item) {
            $result[$key] = $this->transformer->transform($item);
        }

        return $result;
    }
1133092
protected function collection_to_array($collection)
    {
        if ($collection instanceof self) {
            return $collection->toArray();

        } else if ($collection instanceof \Traversable) {
            return iterator_to_array($collection);

        } else if ($collection instanceof Arrayable) {
            return $collection->toArray();

        } else if ($collection instanceof Jsonable) {
            return json_decode($collection->toJson(), true);

        } else if (is_object($collection) || is_array($collection)) {
            return (array)$collection;

        } else {
            throw new \InvalidArgumentException(sprintf(
                '$collection has type %s, which is not collection-like',
                gettype($collection)
            ));
        }
    }
144809
public function setSubject($subject)
    {
        if (!$this->setHeaderFieldModel('Subject', $subject)) {
            $this->getHeaders()->addTextHeader('Subject', $subject);
        }

        return $this;
    }
1035391
public static function toArray($object, $recursive = true)
    {
        $array = [];

        if ($object instanceof BaseObject) {
            return $object->toArray($recursive);
        }

        foreach ($object as $key => $value) {
            if ($value instanceof BaseObject) {
                $newValue = $value->toArray($recursive);
            } else {
                $newValue = (is_array($value) || is_object($value)) && $recursive ? self::toArray($value) : $value;
            }

            $array[$key] = $newValue;
        }

        return $array;
    }
851221
public function upsertToIndex($subject, $indexName = null)
    {
        $indexName = $this->resolveIndexName($indexName);

        if ($subject instanceof Searchable) {
            $subject = [$subject];
        }

        if (is_array($subject) || $subject instanceof Traversable) {
            $searchableItems = collect($subject)
                ->each(function ($item) {
                    if (!$item instanceof Searchable) {
                        throw new InvalidArgumentException();
                    }
                })
                ->flatMap(function ($item) use($indexName) {
                    return
                        [
                            [
                                'index' => [
                                    '_id'    => $item->getSearchableId(),
                                    '_index' => $indexName,
                                    '_type'  => $item->getSearchableType(),
                                ],
                            ],

                            $item->getSearchableBody(),
                        ];
                })
                ->toArray();

            $payload['body'] = $searchableItems;

            $this->elasticsearch->bulk($payload);

            return;
        }

        throw new InvalidArgumentException('Subject must be a searchable or array of searchables');
    }
809217
private function getMessage($subject)
    {
        if (method_exists($subject, 'getMessage')) {
            $message = $subject->getMessage();
        } else {
            $message = $this->useReflectionToGetMessage($subject);
        }

        return $message;
    }
206249
public function toArray(array $keys = [], $accessLevel = \ReflectionProperty::IS_PUBLIC, $underscoreKeys = false)
    {
        $collection = [];
        $reflection = new \ReflectionObject($this);
        
        foreach ($reflection->getProperties($accessLevel) as $property) {
            
            if (empty($keys) || in_array($property->getName(), $keys, true)) {
                
                $propertyValue = $property->getValue($this);
                $propertyName = $underscoreKeys ? Inflector::underscore($property->getName()) : $property->getName();
                
                $collection[$propertyName] = ($propertyValue instanceof EntityInterface)
                    ? $propertyValue->toArray([], $accessLevel) : $propertyValue;
                
            }
        }
        
        return $collection;
    }
984190
public function withSubject(Name $subject): self
    {
        $obj = clone $this;
        $obj->_subject = $subject;
        return $obj;
    }
833731
public function object_to_array($object, array $fields){
        $array= array();
        if(is_array($object) || $object instanceof \Traversable){
            $array= array();
            foreach ($object as $var) {
                $array[]= $this->object_to_array_internal($var, $fields);
            }
        }else if(! is_null($object)){        
            $array= $this->object_to_array_internal($object, $fields);
        }else{
            $array= NULL;
        }
        return $array;        
    }
754685
public function convert($subject)
    {
        $fqcn = starts_with('\\', $subject) ? $subject : '\\' . $subject;

        $obj = new \stdClass;

        $obj->fqcn = $fqcn;
        $obj->model = ltrim($fqcn, '\\');
        $obj->basename = class_basename($fqcn);
        $obj->object = str_singular(strtolower($obj->basename));
        $obj->transformer = ucfirst($obj->basename) . 'Transformer';
        $obj->route = 'api.v1.' . str_plural(strtolower($obj->basename)) . '.show';

        return $obj;
    }
913631
public function setSubject($subject) {
    if (!is_string($subject)) {
      $error = sprintf("Subject given is not a string (Actual type: %s).",
               gettype($subject));
      throw new \InvalidArgumentException($error);
    }
    $this->message->setSubject($subject);
  }