Return an instance of a Model wrapped in a presenter object

@param  Model $model
@param  PresentableInterface $presenter

@return Model
502882
public function model(Model $model, PresentableInterface $presenter)
    {
        $object = clone $presenter;

        $object->set($model);

        return $object;
    }
18369
private function getVisibleAndEditAbleProperties(PaletteInterface $palette, ModelInterface $model)
    {
        return \array_intersect(
            \array_map(
                function (PropertyInterface $property) {
                    return $property->getName();
                },
                $palette->getVisibleProperties($model)
            ),
            \array_map(
                function (PropertyInterface $property) {
                    return $property->getName();
                },
                $palette->getEditableProperties($model)
            )
        );
    }
484903
protected function getArguments($presenter)
    {
        if (is_array($presenter)) {
            $r = new \ReflectionMethod($presenter[0], $presenter[1]);
        } elseif (is_object($presenter) && !$presenter instanceof \Closure) {
            $r = new \ReflectionObject($presenter);
            $r = $r->getMethod('__invoke');
        } else {
            $r = new \ReflectionFunction($presenter);
        }

        return $this->doGetArguments($presenter, $r->getParameters());
    }
372510
public function visitWritableBearer(WritableBearerInterface $writableBearer)
    {

        $template = 'writable-bearer/' . $writableBearer->getType() . '.twig';

        return $this
            ->loadTemplate($template)
            ->render(
                [
                    "id" => $writableBearer->getId(),
                    "classes" => $writableBearer->getClasses(),
                    "data" => $writableBearer->getData(),
                    "writables" => $writableBearer->getWritables(),
                ]
            );
    }
788274
public function present()
    {
        if (is_null($this->presenter)) {
            throw new \InvalidArgumentException('Presenter is not defined.');
        }

        return $this->getContainer()->make($this->presenter, array($this));
    }
109113
public function findPalette(ModelInterface $model = null, PropertyValueBag $input = null)
    {
        $matches = [];

        // Determinate the matching count for each palette.
        foreach ($this->palettes as $palette) {
            $condition = $palette->getCondition();

            if ($condition) {
                $count = $condition->getMatchCount($model, $input);

                if (false !== $count) {
                    $matches[$count][] = $palette;
                }
            }
        }

        // Sort by count.
        \ksort($matches);

        // Get palettes with highest matching count.
        $palettes = \array_pop($matches);

        if (1 !== \count($palettes)) {
            throw new DcGeneralInvalidArgumentException(\sprintf('%d matching palettes found.', \count($palettes)));
        }

        return $palettes[0];
    }
506890
private function searchParentOfInParentedMode(ModelInterface $model)
    {
        if ($this->defaultProviderName !== $model->getProviderName()) {
            throw new DcGeneralInvalidArgumentException(
                'Model originates from ' . $model->getProviderName() .
                ' but is expected to be from ' . $this->defaultProviderName .
                ' can not determine parent.'
            );
        }

        $condition = $this->relationships->getChildCondition($this->parentProviderName, $this->defaultProviderName);
        // This is pretty expensive, we fetch all models from the parent provider here.
        // This can be much faster by using the inverse condition if present.
        foreach ($this->parentProvider->fetchAll($this->parentProvider->getEmptyConfig()) as $candidate) {
            if ($condition->matches($candidate, $model)) {
                return $candidate;
            }
        }

        return null;
    }
818856
public function map($class, $presenter = null)
    {
        if (is_array($class)) {
            foreach ($class as $model => $present) {
                $this->mappings->put($model, $present);
            }
        } else {
            $this->mappings->put($class, $presenter);
        }
    }
1168677
protected function createPresenter($presenter)
    {
        if (false === strpos($presenter, '::')) {
            throw new TemplateEngineException(sprintf('Presenter must be in the format class|service::method', $presenter));
        }

        list($class, $method) = explode('::', $presenter, 2);
        $presenter = $this->applicationContext->object($class);

        if (!method_exists($presenter, $method)) {
            throw new TemplateEngineException(sprintf('Presenter "%s" does not have a "%s" method.', $class, $method));
        }

        return array($presenter, $method);
    }
359563
protected function getMetaModel(ModelInterface $model)
    {
        $filterSetting = $this->filterSettingFactory->createCollection($model->getProperty('fid'));

        return $filterSetting->getMetaModel();
    }
957954
public function render(string $name, string $presenter = null, array $bindings = [], bool $specialSidebar = false): ?string
    {
        if ($this->has($name)) {
            $instance = $this->instance($name);

            $this->callbacks->get($name)->each(function ($callback) use ($instance) {
                $reflectionParams = collect((new ReflectionFunction($callback))->getParameters());
                $reflectionParams->shift();

                collect($reflectionParams)->each(function ($param) use (&$params) {
                    $params[] = Route::current()->hasParameter($param->getName()) ? Route::current()->parameter($param->getName())
                        : (class_exists($param->getClass()->getName()) ? app($param->getClass()->getName()) : null);
                });

                $params ? $callback($instance, ...$params) : $callback($instance);
            });

            return $instance->setBindings($bindings)->render($presenter, $specialSidebar);
        }

        return null;
    }
651622
public function dropTable(ModelInterface $model)
    {
        $i = 0;

        $model->setConnection($this->connection);

        $builder = $this->getQueryBuilder();

//        $this->connection->executeUpdate($adapter->sqlCheckIntegrity(false, 'public', $model->tableName()));

        $schemaManager = $this->connection->getSchemaManager();
        foreach ($model->getMeta()->getManyToManyFields() as $field) {
            if (null === $field->through) {
                $fieldTable = TableNameResolver::getTableName($field->getTableName());
                if ($this->hasTable($fieldTable)) {
                    $schemaManager->dropTable($builder->getQuotedName($fieldTable));
                    $i += 1;
                }
            }
        }

        if ($this->hasTable($model->tableName())) {
            $schemaManager->dropTable($model->tableName());
            $i += 1;
        }

//        $this->connection->executeUpdate($adapter->sqlCheckIntegrity(true, 'public', $model->tableName()));

        return $i;
    }
502022
public function present($presenter = null)
    {
        if (! $presenter) {
            if (! $this->defaultPresenter) {
                throw new \BadMethodCallException('No presenter or default presenter passed to present()');
            }
            $presenter = $this->defaultPresenter;
        }

        $factory = new PresenterFactory();

        return $factory($this, $presenter);
    }
757459
protected function getHydratorForModel($model): Hydrator
    {
        if (null === $this->hydrator_factory) {
            throw UnresolvableHydratorException::forModel($model);
        }

        return $this->hydrator_factory->buildForModel($model);
    }
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;
    }
430775
public static function forge($presenter, $method = 'view', $auto_filter = null, $view = null)
	{
		// if no custom view is given, make it equal to the presenter name
		is_null($view) and $view = $presenter;

		// strip any extensions from the view name to determine the presenter to load
		$presenter = \Inflector::words_to_upper(str_replace(
			array('/', DS),
			'_',
			strpos($presenter, '.') === false ? $presenter : substr($presenter, 0, -strlen(strrchr($presenter, '.')))
		));

		// determine the presenter namespace from the current request context
		$namespace = \Request::active() ? ucfirst(\Request::active()->module) : '';

		// list of possible presenter classnames, start with the namespaced one
		$classes = array($namespace.'\\'.static::$ns_prefix.$presenter);

		// add the global version if needed
		empty($namespace) or $classes[] = static::$ns_prefix.$presenter;

		/**
		 * Add non prefixed classnames to the list, for BC reasons
		 *
		 * @deprecated 1.6
		 */
		$classes[] = $namespace.'\\'.$presenter;

		// and add the global version of that if needed
		empty($namespace) or $classes[] = $presenter;

		// check if we can find one
		foreach ($classes as $class)
		{
			if (class_exists($class))
			{
				return new $class($method, $auto_filter, $view);
			}
		}

		throw new \OutOfBoundsException('Presenter "'.reset($classes).'" could not be found.');
	}
1179870
public function orderUp(ModelConfigurationInterface $model, $id)
    {
        /** @var OrderableModel $instance */
        $instance = $model->getRepository()->find($id);
        $instance->moveUp();

        return back();
    }