@param mixed $model

@return mixed
13110
protected function getModel($model)
    {
        if ($model instanceof Model) {
            return $model;
        }

        if (!class_exists($model) || !is_string($model) || !is_subclass_of($model, Model::class)) {
            throw new \InvalidArgumentException("Invalid model [$model] !");
        }

        return new $model();
    }
1281815
public function delete($model)
    {
        $this->fire($this->event('destroying'), [$model]);
        $model->delete();
        $this->fire($this->event('destroyed'), [$model]);
        return $model;
    }
120372
public function defaultModel($model = null)
    {
        if ($model !== null) {
            $this->_defaultModel = $model;
        }
        if ($this->_defaultModel) {
            return $this->_defaultModel;
        }
        if (!$this->_View->getRequest()->getParam('paging')) {
            return null;
        }
        list($this->_defaultModel) = array_keys($this->_View->getRequest()->getParam('paging'));

        return $this->_defaultModel;
    }
90496
protected function parseModel($model)
    {
        if (false === strpos($model, '\\')) {
            $path = explode('\\', static::class);
            array_pop($path);
            array_push($path, Db::parseName($model, 1));
            $model = implode('\\', $path);
        }

        return $model;
    }
757859
public static function getCleanClassName($model)
    {
        $className = get_class($model);
        $className = explode('\\', $className);

        return $className[count($className) - 1];
    }
702775
protected function resolveQueryBuilderFromModel($model)
    {
        if ($this->isEloquentModel($model)) {
            return $model->newQuery();
        } elseif ($this->isEloquentRelationModel($model)) {
            return $model->getQuery();
        } elseif (! $this->isQueryBuilder($model)) {
            throw new InvalidArgumentException('Unable to load Query Builder from $model');
        }

        return $model;
    }
1109053
public function bulkSerialise($model)
    {
        $class = get_class($model);
        if (!$model instanceof Model) {
            throw new InvalidOperationException($class);
        }
        // dig up metadata
        if (!isset(self::$metadataCache[$class])) {
            self::$metadataCache[$class] = $model->metadata();
        }
        $meta = self::$metadataCache[$class];
        $keys = array_keys($meta);
        // dig up getter list - we only care about the mutators that end up in metadata
        if (!isset(self::$mutatorCache[$class])) {
            $getterz = [];
            $datez = $model->getDates();
            $castz = $model->retrieveCasts();
            foreach ($keys as $key) {
                if ($model->hasGetMutator($key) || in_array($key, $datez) || array_key_exists($key, $castz)) {
                    $getterz[] = $key;
                }
            }
            self::$mutatorCache[$class] = $getterz;
        }
        $getterz = self::$mutatorCache[$class];
        $modelAttrib = $model->getAttributes();
        $result = array_intersect_key($modelAttrib, $meta);
        foreach ($keys as $key) {
            if (!isset($result[$key])) {
                $result[$key] = null;
            }
        }
        foreach ($getterz as $getter) {
            $result[$getter] = $model->$getter;
        }

        return $result;
    }
375519
private function getValue($item, $model)
    {
        if (is_string($item)) {
            if ($model instanceof Model) {
                if (isset($model->{$item})) {
                    return $model->{$item};
                }
                return $item;
            } else {
                if (isset($model[$item])) {
                    return $model[$item];
                }
                return $item;
            }
        } else if (is_callable($item)) {
            return call_user_func($item, $model);
        }
        return '';
    }
827133
public function get(AbstractModel $model)
    {
        if (! $this->repo->isModel($model)) {
            throw new InvalidArgumentException(
                sprintf('Model must be %s, was %s', $this->repo->getModelClass(), get_class($model))
            );
        }

        if ($this->map->contains($model)) {
            return $this->map[$model];
        } else {
            return $this->map[$model] = new Links($model);
        }
    }
535304
protected function getTableAndDatabase($model)
    {
        $table = $model->getConnection()->getTablePrefix() . $model->getTable();

        $database = null;

        if (strpos($table, '.')) {
            list($database, $table) = explode('.', $table);
        }

        return [$table, $database];
    }
993066
protected function getDiff($model)
    {
        $dirty = $model->getDirty();
        $fresh = $model->fresh() ? $model->fresh()->toArray() : []; 
        $after = json_encode($dirty);
        $before = json_encode(array_intersect_key($fresh, $dirty));

        return compact('before', 'after');
    }
252426
public function getNormalizedIdentifier($model)
    {
        $identifier = $this->baseModelManager->getNormalizedIdentifier($model);

        if ($identifier === null) {
            $identifierName = is_array($this->getModelIdentifier(get_class($model))) ? current($this->getModelIdentifier(get_class($model))) : $this->getModelIdentifier(get_class($model));

            return $model->{'get'.ucfirst($identifierName)}();
        }

        return $identifier;
    }
1016022
private function getId($model)
    {
        // Check to see if we can get an id via our defined methods
        foreach (self::$methods as $method) {
            if (method_exists($model, $method) && is_callable([$model, $method])) {
                return $model->$method();
            }
        }

        // Check to see if we can get an id via our defined properties
        foreach (self::$properties as $property) {
            if (isset($model->$property)) {
                return $model->$property;
            }
        }
    }
959569
protected function getReferenceFallback(Model $model)
    {
        // Use reference method if the model has one
        if (method_exists($model, 'getReferenceAttribute')) {
            return $model->reference;
        }

        if (method_exists($model, 'getReference')) {
            return $model->getReference();
        }

        return (string) $model->getKey();
    }
214014
protected function getEntityInstance($model)
    {
        if ($model === '*') {
            return '*';
        }

        if ( ! $model instanceof Model) {
            return new $model;
        }

        // Creating an ability for a non-existent model gives the authority that
        // ability on all instances of that model. If the developer passed in
        // a model instance that does not exist, it is probably a mistake.
        if ( ! $model->exists) {
            throw new InvalidArgumentException(
                'The model does not exist. To edit access to all models, use the class name instead'
            );
        }

        return $model;
    }
1000403
public function getModel($model)
    {
        if ($model instanceof Model) {
            return $model;
        }

        if (is_string($model) && class_exists($model)) {
            return $this->getModel(new $model());
        }

        throw new InvalidArgumentException("$model is not a valid model");
    }
860460
protected function _getOptionsFromModel($model)
    {
        $model = TableRegistry::get($model);

        if (method_exists($model, 'postType')) {
            $result = $model->postType();
            if ($result) {
                $result['table'] = $model->table();
            }
            return $result;
        }
        if (property_exists($model, 'postType')) {
            $result = $model->postType;
            if ($result) {
                $result['table'] = $model->table();
            }
            return $result;
        }
        return [];
    }