Return the manually setted config of Model or an empty array

@param Model $model

@return array
330005
protected function getManualConfig(Model $model)
    {
        if (!method_exists($model, 'xTypeConfig')) {
            return [];
        }

        $config = $model->xTypeConfig();
        $parsed = [];
        $foreignKeys = [];

        foreach ($config as $key=>$rule) {
            if ($rule != 'relation') {
                $parsed[$key] = $rule;
                continue;
            }

            $relation = $this->relationReflector->buildRelationXTypeInfo($model, $key);

            $parsed[$key] = $relation['type'];

            if ($relation['foreign_keys']) {
                $foreignKeys += $relation['foreign_keys'];
            }
        }

        return $parsed;
    }
1261576
private function getModelAttributes(&$model)
	{
		$response 	= array();
		$reflection = new ReflectionClass($model);
		$properties = $reflection->getProperties(ReflectionProperty::IS_PROTECTED);

		foreach ($properties as $property)
			$response[$property->name] = $model[$property->name];

		return $response;
	}
919139
protected function getRelatedModels(Model $model)
    {
        // Store the class name
        $modelClass = get_class($model);

        // Check if we already know the related models for this model
        if (!isset($this->relatedModels[$modelClass]))
        {
            $relatedModels = [];

            $methods = with(new \ReflectionClass($model))->getMethods();

            // Iterate all class methods
            foreach ($methods as $method)
            {
                // Check if this method returns an Eloquent relation
                if ($method->class == $modelClass &&
                    preg_match('/@return\s+\\\\Illuminate\\\\Database\\\\Eloquent\\\\Relations/', $method->getDocComment())
                )
                {
                    // Get the method name, so that we can call it on the model
                    $relationMethod = $method->name;

                    // Find the relation
                    $relation = $model->$relationMethod();

                    if ($relation instanceof Relation)
                    {
                        // Find the related model
                        $related = $relation->getRelated();

                        // Store the method to help build the inverse path
                        $this->relationClassMethods[$modelClass][get_class($related)] = $relationMethod;

                        $relatedModels[] = ['model' => $related, 'method' => $method];
                    }
                }
            }

            // Cache related models for this model
            $this->relatedModels[$modelClass] = $relatedModels;

            // Return the related models
            return $relatedModels;
        } else
        {
            // Return from cache
            return $this->relatedModels[$modelClass];
        }
    }
664757
protected function prepareModel(Model $model)
    {
        if (is_callable($this->prepareModel)) {
            call_user_func($this->prepareModel, $model);
        } else {
            foreach ($model->attributes() as $attribute) {
                $value = Yii::$app->settings->get($this->getSection($model), $attribute);

                if (!is_null($value)) {
                    $model->{$attribute} = $value;
                }
            }
        }
    }
1133400
public function getModelCallbacks(Model $model, $scope = '*') {
        $callbacks = array();
        $models = Configure::read('Admin.modelCallbacks');

        if (isset($models[$model->qualifiedName])) {
            foreach ($models[$model->qualifiedName] as $method => $options) {
                if (is_string($options)) {
                    $options = array('title' => $options, 'access' => 'update', 'scope' => '*');
                } else {
                    $options = $options += array('access' => 'update', 'scope' => '*');
                }

                if ($options['scope'] !== $scope) {
                    continue;
                }

                if ($this->hasAccess($model->qualifiedName, $options['access'])) {
                    $callbacks[$method] = __d('admin', $options['title'], $model->singularName);
                }
            }
        }

        return $callbacks;
    }
7292
private function getMutableAttributes($model)
    {
        $attrs = get_object_vars($model);
        unset($attrs[$this->key]);
        
        // remove reference attributes, if any
        if ($model instanceof ManagedModelInterface) {
            foreach (array_keys($model->getReferences()) as $ref) {
                unset($attrs[$ref]);
            }
        }
        
        return $attrs;
    }
615161
protected function determineModelReferenceSource(Model $model)
    {
        $source = $this->getReferenceSource($model);

        // If we have no source to fall back on at all, use the model key
        if ( ! $source) {
            $source = $model->getKeyName();
        }

        return $source;
    }
752394
public function getModelCacheKeys(Cacheable $model)
    {
        // Build list of cache keys we need to clear.
        $cacheKeys = [
            implode(':', [$model->getTable(), 'index']),
        ];

        // If the model has an primary key add the cache key.
        if (!empty($model->getPrimaryKeyValue())) {
            $cacheKeys[] = implode(':', [$model->getTable(), $model->getPrimaryKeyValue()]);
        }

        // Add the cache keys for the model attributes.
        $this->addAttributeCacheKeys($cacheKeys, $model);

        return $cacheKeys;
    }
1149859
public static function getInstance(Model $model, array $conf = []) {
        if (null === self::$instance) {
            self::$instance = new RedisCachedModelManager();
        }
        self::$instance->model = $model;
        self::$instance->conf = [
            'redisId'  => 'redis',
            'duration' => [
                'pool'  => 3600,
                'many'  => 300,
                'one'   => 300,
                'count' => 300,
            ],
        ];
        Toolkit::override(self::$instance->conf, $conf);
        return self::$instance;
    }
836129
protected function getConfigFromReflector(Model $model)
    {
        $config = [];
        foreach ($this->reflector->keys($model) as $key) {
            $config[$key] = $this->reflector->typeString($model, $key);
        }
        return $config;
    }
488963
public static function castModel(Model $model)
    {
        $attributes = array_merge(
            $model->getAttributes(),
            $model->getRelations()
        );

        $visible = array_flip(
            $model->getVisible() ?: array_diff(array_keys($attributes), $model->getHidden())
        );

        $results = [];

        foreach (array_intersect_key($attributes, $visible) as $key => $value) {
            $results[(isset($visible[$key]) ? Caster::PREFIX_VIRTUAL : Caster::PREFIX_PROTECTED).$key] = $value;
        }

        return $results;
    }
902043
protected function collectColumns(Model $model = null)
    {
        if (!$model) {
            return new MutableCollection([]);
        }

        $pk = $model->getKeyName();

        $fillable = array_merge(
            is_array($pk) ? $pk : [$pk],
            $model->getFillable()
        );
        $hidden = $model->getHidden();

        if ($model instanceof Translatable && method_exists($model, 'getTranslatedAttributes')) {
            $fillable = array_merge($fillable, $model->getTranslatedAttributes());
            $hidden = array_merge($hidden, $model->getTranslationModel()->getHidden());
        }

        $fillable = array_unique(array_diff($fillable, $hidden));

        /**
         * Create collection.
         */
        $elements = new MutableCollection($fillable);

        if ($this->includeDateColumns && count($dates = $model->getDates())) {
            // allow setting specific timestamp: created_at
            if (is_string($this->includeDateColumns)) {
                $dates = array_intersect($dates, [$this->includeDateColumns]);

                $elements = $elements->merge($dates);
            } else {
                // add timestamps group
                $elements->group('dates', function (Group $group) use ($dates) {
                    $group->merge($dates);

                    return $group;
                });
            }
        }

        return $elements->build(
            new GridDecorator($model)
        );
    }
769457
protected function _getAliases(Model $Model) {
		$aliases = array_merge(array(
			//$Model->name,
			$Model->alias
				), $this->config[$Model->alias]['aliases']
		);

		foreach ($Model->associations() as $associationType) {
			foreach ($Model->$associationType as $associationKey => $association) {
				if ($association['className'] === $Model->name) {
					$aliases[] = $associationKey;
				}
			}
		}

		return $aliases;
	}
848730
protected function migratePivotAttributes(Model $model)
    {
        $values = [];

        foreach ($model->getAttributes() as $key => $value) {
            // To get the pivots attributes we will just take any of the attributes which
            // begin with "pivot_" and add those to this arrays, as well as unsetting
            // them from the parent's models since they exist in a different table.
            if (strpos($key, 'pivot_') === 0) {
                $values[substr($key, 6)] = $value;

                $model->{$key} = null;
            }
        }

        return $values;
    }
615914
public function retrieve(Model $model, $source)
    {
        return [
            'from' => parent::retrieve($model, $this->getAttributeFrom()),
            'to'   => parent::retrieve($model, $this->getAttributeTo()),
        ];
    }
694699
public function getTransformedFiles(Model $model) {
        if (isset($this->_uploads[$model->alias])) {
            return $this->_uploads[$model->alias]->getTransformedFiles();
        }

        return array();
    }
700442
protected function setColumns($model)
    {
        $schema = $model->getConnection()->getDoctrineSchemaManager();
        $platform = $schema->getDatabasePlatform();

        // Prevents a DBALException if the table contains an enum.
        $platform->registerDoctrineTypeMapping('enum', 'string');

        list($table, $database) = $this->getTableAndDatabase($model);

        $this->columns = $model->getConnection()->getDoctrineConnection()->fetchAll(
            $platform->getListTableColumnsSQL($table, $database)
        );

        $this->rejectVirtualColumns();

        $columns = $this->columns;
        $this->columns = call_user_func(\Closure::bind(function () use ($table, $database, $columns) {
            return $this->_getPortableTableColumnList($table, $database, $columns);
        }, $schema, $schema));

        return $this->unquoteColumnNames($platform->getIdentifierQuoteCharacter());
    }