Get the typename from the casts array

@param Model  $model
@param string $key

@return string The type name
555900
protected function getFromCasts(Model $model, $key)
    {
        $casts = $this->getCasts($model);

        if (!isset($casts[$key])) {
            return '';
        }

        $cast = $casts[$key];

        foreach ($this->xTypeToCasts as $xType=>$casts) {
            if (in_array($cast, $casts)) {
                return $xType;
            }
        }

        return 'string';
    }
136085
protected function mapTypeName(AbstractModel $model)
    {
        if ($model instanceof CurrentSession) {
            $mapped = 'current_session';
        } else {
            $classname = $this->getType($model);
            $mapped = str_replace(
                array(
                '\\',
                'invoice_History',
                'contact_Note',
                ), array(
                '_',
                'historie',
                'note',
                ), lcfirst($classname)
            );
            if (false !== ($pos = strpos($mapped, '_'))) {
                $mapped = substr($mapped, 0, $pos);
            }
            $mapped = strtolower(
                    preg_replace_callback('/([A-Z])/', array($this, 'classnameToUrlpartCallback'), $mapped)
                ) . 's';
        }
        return $mapped;
    }
601226
private function getModelNameFromClass($model_class)
    {
        if (($pos = strrpos($model_class, '\\')) !== false) {
            return Inflector::pluralize(Inflector::tableize(substr($model_class, $pos + 1)));
        } else {
            return Inflector::pluralize(Inflector::tableize($model_class));
        }
    }
667027
protected function getFormFieldValuesFromModel(Model $model, array $keys)
    {
        $values = [];

        foreach ($keys as $key) {

            $field    = $this->getModelFormFieldDataForKey($key);
            $instance = $this->getFormFieldStoreStrategyInstanceForField($field);

            $instance->setFormFieldData($field);
            $instance->setParameters(
                $this->getFormFieldStoreStrategyParametersForField($field)
            );

            // If we're creating a new model, pre-select the form field for the active list parent
            if ( ! $model->exists && $this->isFieldValueBeDerivableFromListParent($field->key)) {

                try {
                    $values[ $key ] = $instance->valueForListParentKey($this->getListParentRecordKey());

                    // @codeCoverageIgnoreStart
                } catch (Exception $e) {
                    $message = "Failed retrieving value for form field '{$key}' (using " . get_class($instance)
                             . " (valueForListParentKey)): \n{$e->getMessage()}";

                    throw new StrategyRetrievalException($message, $e->getCode(), $e);
                    // @codeCoverageIgnoreEnd
                }

                continue;
            }

            try {
                $values[ $key ] = $instance->retrieve($model, $field->source ?: $field->key);

                // @codeCoverageIgnoreStart
            } catch (Exception $e) {
                $message = "Failed retrieving value for form field '{$key}' (using " . get_class($instance)
                         . "): \n{$e->getMessage()}";

                throw new StrategyRetrievalException($message, $e->getCode(), $e);
                // @codeCoverageIgnoreEnd
            }
        }

        return $values;
    }
1272153
public function process(Model $model)
    {
        $resource = $model->getData();
        $type = get_resource_type($resource);
        $typeString = 'resource (' . $type . ')';

        switch ($type) {
            case 'stream':
                $meta = stream_get_meta_data($resource);
                break;

            case 'curl':
                // No need to check for a curl installation, because we are
                // facing a curl instance right here.
                $meta = curl_getinfo($resource);
                break;

            default:
                $meta = array();
        }

        // Check, if we have something useful.
        if (empty($meta)) {
            // If we are facing a closed resource, 'Unknown' is a little bit sparse.
            // PHP 7.2 can provide more info by calling gettype().
            if (version_compare(phpversion(), '7.2.0', '>=')) {
                $typeString = gettype($resource);
            }
            return $this->pool->render->renderSingleChild(
                $model->setData($typeString)
                    ->setNormal($typeString)
                    ->setType(static::TYPE_RESOURCE)
            );
        }

        // Output meta data from the class.
        return $this->pool->render->renderExpandableChild(
            $model->setType(static::TYPE_RESOURCE)
                ->addParameter(static::PARAM_DATA, $meta)
                ->setNormal($typeString)
                ->injectCallback(
                    $this->pool->createClass('Brainworxx\\Krexx\\Analyse\\Callback\\Iterate\\ThroughResource')
                )
        );
    }
533774
public function getIdMetaMapByType( $model, $type ) {

		$modelMetaService = Yii::$app->factory->get( 'modelMetaService' );

		return $modelMetaService->getIdMetaMapByType( $model->id, static::$parentType, $type );
	}
71590
public function getModelName($model) {
        if (is_object($model)) {
            $model = get_class($model);
        }
        // This guess may work if the extension uses its lowercased name as model group name.
        $result = strtolower(preg_replace(
            '~^[^_]+_([^_]+)_Model_(.+)$~', '$1/$2', $model ));
        // This check is not expensive because the answer should come from Magento's classNameCache
        $checkModel = Mage::getConfig()->getModelClassName($result);
        if ('Mage_' == substr($checkModel, 0, 5) && ! class_exists($result)) {
            // Fallback to full model name.
            $result = $model;
        }
        return $result;
    }
521066
public function cacheKey(Model $model, $keys, $prefix = true)
    {

        // TranslateBehavior support
        if (!empty($model->locale)) {
            $keys = array_merge((array)$model->locale, (array)$keys);
        }

        if (is_array($keys)) {
            $key = array_shift($keys);

            if ($keys) {
                foreach ($keys as $value) {
                    if (is_array($value)) {
                        $key .= '-' . md5(json_encode($value));
                    } else if ($value) {
                        $key .= '-' . $value;
                    }
                }
            }
        } else {
            $key = (string)$keys;
        }

        if ($prefix) {
            $key = (string)$this->settings[$model->alias]['prefix'] . $key;
        }

        // Replace AppModel with the current Model so we don't run into conflicts
        $key = str_replace(array('AppModel', '::'), array($model->alias, '_'), $key);

        return $key;
    }
1206085
protected function _pluralizeModelName($key) {
		$pos = strpos($key, '.');
		if ($pos !== false) {
			$key = Inflector::pluralize(substr($key, 0, $pos)) . '.' . substr($key, $pos + 1);
		}
		return $key;
	}
1018992
public function getName(Model $model, $id = null) {
		if (empty($id) || empty($model->displayField)) {
			return false;
		}
		if (is_array($id)) {
			if (!isset($id[$model->alias][$model->displayField])) {
				return false;
			}

			$result = $id[$model->alias][$model->displayField];
		} else {
			$model->id = $id;
			$result = $model->field($model->displayField);
		}

		return $result;
	}
57293
private static function typeCastModel(LightModel $model)
    {
        if (in_array(self::OPTIONS_TYPECAST, self::$initOptions))
        {
            foreach ($model->getTable()->getColumns() as $column)
            {
                /* @var $column Column */
                if (in_array($column->getField(), get_object_vars($model)))
                {
                    if ($column->getType() === Column::TYPE_INT)
                    {
                        $field = $column->getField();
                        settype($model->$field, Column::TYPE_INT);
                    }
                }
            }
        }

        return $model;
    }
427462
public function __( $key, $params = array() )
	{
		$namespace = explode( "\\", get_called_class() );

		$class = strtolower( 'model/'.str_replace( '_', '/', array_pop( $namespace ) ) );

		$namespace = implode( "\\", $namespace );

		if ( $namespace )
		{
				$class = $namespace.'::'.$class;
		}

		return __( $class.'.label.'.$key, $params );
	}
623783
protected function getModelByKey($model, $key)
    {
        if (is_string($model)) {
            $model = new $model;
        }

        /** @var Model $model */
        return $model->withoutGlobalScopes()->find($key);
    }
2944
public function getModelNamePlural(Model $model, $toLowerCase = false) {
		$modelName = $this->getModelName($model, $toLowerCase);

		return Inflector::pluralize($modelName);
	}
1097777
public function toArray(Model $model)
    {
        // start with the base representation of the model
        if (method_exists($model, 'withoutArrayHook')) {
            $model->withoutArrayHook();
        }
        $result = $model->toArray();

        // apply namespacing to excluded properties
        $namedExc = [];
        foreach ($this->exclude as $k) {
            array_set($namedExc, $k, true);
        }

        // apply namespacing to included properties
        $namedInc = [];
        foreach ($this->include as $k) {
            array_set($namedInc, $k, true);
        }

        // apply namespacing to expanded properties
        $namedExp = [];
        foreach ($this->expand as $k) {
            array_set($namedExp, $k, true);
        }

        // remove excluded properties
        foreach (array_keys($result) as $k) {
            if (isset($namedExc[$k]) && !is_array($namedExc[$k])) {
                unset($result[$k]);
            }
        }

        // add included properties
        foreach (array_keys($namedInc) as $k) {
            if (!isset($result[$k]) && isset($namedInc[$k])) {
                $result[$k] = $model->$k;
                if ($result[$k] instanceof Model) {
                    $subExc = array_value($namedExc, $k);
                    $subInc = array_value($namedInc, $k);
                    $subExp = array_value($namedExp, $k);

                    // convert exclude, include, and expand into dot notation
                    // then take the keys for a flattened dot notation
                    $flatExc = is_array($subExc) ? array_keys(array_dot($subExc)) : [];
                    $flatInc = is_array($subInc) ? array_keys(array_dot($subInc)) : [];
                    $flatExp = is_array($subExp) ? array_keys(array_dot($subExp)) : [];

                    $serializer = new self($this->request);
                    $serializer->setExclude($flatExc)
                        ->setInclude($flatInc)
                        ->setExpand($flatExp);

                    $result[$k] = $serializer->toArray($result[$k]);
                }
            }
        }

        // expand any relational model properties
        $result = $this->expand($model, $result, $namedExc, $namedInc, $namedExp);

        // apply hooks, if available
        if (method_exists($model, 'toArrayHook')) {
            $model->toArrayHook($result, $namedExc, $namedInc, $namedExp);
        }

        // order the properties array by name for consistency
        // since it is constructed in a random order
        ksort($result);

        return $result;
    }
1006027
protected static function modelEntityType($model)
    {
        if ($model instanceof QuestionInterface) {
            return self::ENTITY_QUESTION;
        } elseif ($model instanceof AnswerInterface) {
            return self::ENTITY_ANSWER;
        } else {
            $className = get_class($model);
            throw new UnknownClassException("Model class '{$className}' not supported");
        }
    }
1111196
protected function getModelPrimaryKeyString($model)
    {
        return is_array($model->getPrimaryKey()) ? implode('-', $model->getPrimaryKey()) : $model->getPrimaryKey();
    }