Parse many many relation class (works with through array syntax)

@param string|array $class
@return string|array
485195
public static function parseRelationClass($class)
    {
        // detect many many through syntax
        if (is_array($class)
            && array_key_exists('through', $class)
            && array_key_exists('to', $class)
        ) {
            $toRelation = $class['to'];

            $hasOne = Config::inst()->get($class['through'], 'has_one');
            if (empty($hasOne) || !is_array($hasOne) || !array_key_exists($toRelation, $hasOne)) {
                return $class;
            }

            return $hasOne[$toRelation];
        }

        return $class;
    }
904158
public function getClass(string $class){
        if(!class_exists($class)){
            throw new \InvalidArgumentException();
        }

        if(!array_key_exists($class, $this->classes)){
            $this->classes[$class]  = new \ReflectionClass($class);
        }

        return $this->classes[$class];
    }
1086834
public function favorites($class = __CLASS__)
    {
        return $this->morphedByMany($class, config('follow.morph_prefix'), config('follow.followable_table'))
                    ->wherePivot('relation', '=', Follow::RELATION_FAVORITE)
                    ->withPivot('followable_type', 'relation', 'created_at');
    }
1253965
protected function getMetadata($class)
    {
        if (array_key_exists($class, $this->cache)) {
            return $this->cache[$class];
        }

        $this->cache[$class] = null;

        foreach ($this->registry->getManagers() as $name => $em) {
            try {
                return $this->cache[$class] = [$em->getClassMetadata($class), $name];
            } catch (MappingException $e) {
                // not an entity or mapped super class
            } catch (LegacyMappingException $e) {
                // not an entity or mapped super class, using Doctrine ORM 2.2
            }
        }

        return $this->cache[$class];
    }
239001
public function getTypesForClass(string $class): array
    {
        $types = array_filter(
            $this->typeMap,
            function ($val) use ($class) {
                return $val === $class;
            }
        );

        if (empty($types)) {
            $error = sprintf('Does not exist any valid type for class "%s"', $class);
            throw new \UnexpectedValueException($error);
        }

        return array_keys($types);
    }
917301
public function get($class=null)
	{
		$class = $this->get_class($class);

		if (isset($this->reflections[$class]))
			return $this->reflections[$class];

		throw new ActiveRecordException("Class not found: $class");
	}
495264
public function forClass(string $class): array
    {
        if (!class_exists($class)) {
            throw new InvalidArgumentException("Cannot get meta for non-exist class '$class'");
        }

        $reflection = $this->factory->reflectClass($class);

        $meta = $this->getClassMeta($reflection);
        $meta['@properties'] = $this->getPropertiesMeta($reflection);

        return $meta;
    }
1042485
public function getByModelClass($class)
    {
        $this->checkInitialization();

        if ( ! array_key_exists($class, $this->modelClassIndex)) {
            return false;
        }

        return $this->getByKey($this->modelClassIndex[$class]);
    }
568447
public function parse($class, array $meta = [])
    {
        $methods = get_class_methods($class);
        foreach($methods as $method) {
            $query = Annotation::ofMethod($class, $method, 'uri');
            if($query) {
                $this->add($query, [$class, $method], $meta);
            }
        }

        return $this;
    }
871178
private function getJoinTable($class)
    {
        $model1 = snake_case($this->getBaseClass());
        $model2 = snake_case($this->getBaseClass($class));
        $models = [$model1, $model2];
        sort($models);

        return implode('_', $models);
    }
381235
public function parse(array $classes)
    {
        $APIAnnotations = [];
        foreach ($classes as $class) {
            $reflectionClass = new \ReflectionClass($class);

            foreach ($reflectionClass->getMethods() as $reflectionMethod) {
                $annotations = $this->getReader()->getMethodAnnotations($reflectionMethod);
                if (!empty($annotations)) {
                    foreach ($annotations as $annotation) {

                        switch (true) {

                            case ($annotation instanceof Route):
                                $APIAnnotations[$class][$reflectionMethod->getName()]['routes'][] = $annotation;
                                break;

                            case ($annotation instanceof ResponseBody):
                                $APIAnnotations[$class][$reflectionMethod->getName()]['requestBody'][] = $annotation;
                                break;

                            case ($annotation instanceof RequestBody):
                                $APIAnnotations[$class][$reflectionMethod->getName()]['responseBody'][] = $annotation;
                                break;

                            default:
                                // Do nothing
                        }
                    }
                }
            }
        }

        return $APIAnnotations;
    }
414550
public function fetchAllObj(string $class = null): array
    {
        if (!$this->wasExecuted()) {
            $this->exec();
        }

        if ($class === null) {
            return $this->getAdapter()->getStatement()->fetchAll(PDO::FETCH_OBJ);
        } else {
            $objects = [];
            foreach ($this->fetchAll() as $record) {
                $objects[] = new $class($record);
            }

            return $objects;
        }
    }
1178844
public static function toObject(&$array, $class='\\stdClass')
  {
    $obj = null;
    if ( is_array($array) ){
      $obj = new $class;
      foreach($array as $k => $v){
        if ( is_array($v) ){
          $obj->$k = self::toObject($v, '\\stdClass');
        }
        else {
          $obj->$k = $v;
        }
      }
    }
    return $obj;
  }
1124919
public static function getAllChildClasses($class): array
    {
        $type = gettype($class);
        $className = '';

        /* If input an object */
        if ($type == 'object') {
            $className = get_class($class);
        }

        /* If input a string */
        elseif ($type == 'string') {
            $className = $class;
        }

        $classes = [];

        /* Go through all classes */
        foreach (get_declared_classes() as $class) {
            if (is_subclass_of($class, $className)) {
                $classes[] = $class;
            }
        }

        return $classes;
    }
476990
private function parseClassMetadata($class)
    {
        $metadata = new ClassMetadata($class);

        //Load up parent and interfaces
        $this->loadParentMetadata($metadata);
        $this->loadInterfaceMetadata($metadata);

        //Load Annotations from Reader
        $this->loader->loadClassMetadata($metadata);

        //Store internally
        $this->setParsedClass($class, $metadata);

        if ($this->cache !== null) {
            $this->cache->save($class, $metadata);
        }

        return $metadata;
    }
1117764
public function sources($class = null) {
		$this->_checkConnection();
		$conn = $this->connection;
		return array_map(function($col) { return $col->getName(); }, $conn->listCollections());
	}
413185
public function findAttributeClass($class)
    {
        if ($this->offsetExists('class')) {
            $matches = [];

            foreach ($this->storage[ 'class' ] as $key => $value) {
                if (preg_match("/\b$class\b/i", $value)) {
                    $matches[] = $value;
                }
            }

            if (count($matches)) {
                return $matches;
            }

        }

        return false;
    }