Dump information about a variable.

This function decides what functions analyse the data
and acts as a hub.

@param Model $model
The variable we are analysing.

@return string
The generated markup.
548397
public function analysisHub(Model $model)
    {
        // Check memory and runtime.
        if ($this->pool->emergencyHandler->checkEmergencyBreak() === true) {
            return '';
        }

        $data = $model->getData();

        // String?
        if (is_string($data) === true) {
            return $this->processString->process($model);
        }

        // Integer?
        if (is_int($data) === true) {
            return $this->processInteger->process($model);
        }

        // Null?
        if ($data === null) {
            return $this->processNull->process($model);
        }

        // Handle the complex types.
        if (is_array($data) === true || is_object($data) === true) {
            // Up one nesting Level.
            $this->pool->emergencyHandler->upOneNestingLevel();
            // Handle the non simple types like array and object.
            $result = $this->handleNoneSimpleTypes($data, $model);
            // We are done here, down one nesting level.
            $this->pool->emergencyHandler->downOneNestingLevel();
            return $result;
        }

        // Boolean?
        if (is_bool($data) === true) {
            return $this->processBoolean->process($model);
        }

        // Float?
        if (is_float($data) === true) {
            return $this->processFloat->process($model);
        }

        // Resource?
        // The is_resource can not identify closed stream resource types.
        // And the get_resource_type() throws a warning, in case this is not a
        // resource.
        set_error_handler(function () {
            // Do nothing. We need to catch a possible warning.
        });
        if (get_resource_type($data) !== null) {
            restore_error_handler();
            return $this->processResource->process($model);
        }
        restore_error_handler();

        // Still here? Tell the dev that we can not analyse this one.
        return $this->processOther->process($model);
    }
52687
protected function saveColumns(Model $model)
    {
        /** @var \T4\Orm\Model $class */
        $class = get_class($model);
        $columns = $class::getColumns();
        $relations = $class::getRelations();
        $cols = [];
        $prep = [];
        $sets = [];
        $data = [];

        foreach ($columns as $column => $def) {
            if (isset($model->{$column}) && null === $model->{$column} && isset($def['default'])) {
                $cols[] = $this->quoteName($column);
                $prep[] = ':' . $column;
                $sets[] = '' . $this->quoteName($column) . '=:' . $column;
                $data[':' . $column] = $def['default'];
            } else {
                $cols[] = $this->quoteName($column);
                $prep[] = ':' . $column;
                $sets[] = '' . $this->quoteName($column) . '=:' . $column;
                switch ($def['type']) {
                    case 'boolean':
                        $data[':' . $column] = (int)$model->{$column};
                        break;
                    default:
                        $data[':' . $column] = $model->{$column};
                        break;
                }
            }
        }

        foreach ($relations as $rel => $def) {
            switch ($def['type']) {
                case $class::BELONGS_TO:
                    $column = $class::getRelationLinkName($def);
                    if (!in_array($column, $cols)) {
                        // @todo: test this!
                        // if (isset($model->{$column}) && !is_null($model->{$column})) {
                        if (isset($model->{$column})) {
                            $cols[] = $this->quoteName($column);
                            $prep[] = ':' . $column;
                            $sets[] = '' . $this->quoteName($column) . '=:' . $column;
                            $data[':' . $column] = $model->{$column};
                        } elseif (isset($model->{$rel}) && $model->{$rel} instanceof Model) {
                            $cols[] = $this->quoteName($column);
                            $prep[] = ':' . $column;
                            $sets[] = '' . $this->quoteName($column) . '=:' . $column;
                            $data[':' . $column] = $model->{$rel}->getPk();
                        }
                    }
                    break;
            }
        }

        $connection = $class::getDbConnection();
        if ($model->isNew()) {
            $sql = '
                INSERT INTO ' . $this->quoteName($class::getTableName()) . '
                (' . implode(', ', array_unique($cols)) . ')
                VALUES
                (' . implode(', ', array_unique($prep)) . ')
                RETURNING ' . $class::PK . '
            ';
            $res = $connection->query($sql, $data);
            $model->{$class::PK} = $res->fetch()[$class::PK];
        } else {
            $sql = '
                UPDATE ' . $this->quoteName($class::getTableName()) . '
                SET ' . implode(', ', array_unique($sets)) . '
                WHERE "' . $class::PK . '"=\'' . $model->{$class::PK} . '\'
            ';
            $connection->execute($sql, $data);
        }

        return $model;

    }
1268555
protected function getLinkForReferenceModel(Model $model)
    {
        $routeName = $this->getRouteHelper()->getRouteNameForModelClass(get_class($model), true);

        $action = $this->determineRouteAction($model);

        return route($routeName . '.' . $action, $model->getKey());
    }
1350709
protected function makeReferenceStrategy(Model $model)
    {
        // Get model information for the model
        $information = $this->getInformationRepository()->getByModel($model);

        // If the model is not part of the CMS, fall back
        if ( ! $information) return null;

        $strategy = $information->reference->strategy;

        if ( ! $strategy) {
            $strategy = config('cms-models.strategies.reference.default-strategy');
        }

        return $this->makeReferenceStrategyInstance($strategy);
    }
544134
public function dump($var, $mode = null)
    {
        if (null === $mode && class_exists('Zicht\Util\Debug')) {
            return htmlspecialchars(Debug::dump($var));
        } else {
            switch ($mode) {
                case 'export':
                    VarDumper::dump($var);
                    break;
                default:
                    var_dump($var);
                    break;
            }
        }
        return null;
    }
112484
protected function showModifier(Model $model)
    {
        $name = $this->manager->getClassName($model);

        $this->title("Modifier of Model {$name}: ");

        $modifiers = [
            'mutators' => $this->manager->getMutators($model),
            'accessors' => $this->manager->getAccessors($model),
            'scopes' => $this->manager->getScopes($model),
        ];

         $rows = [];

        foreach (max($modifiers) as $modifier) {
            foreach (['mutator', 'accessor', 'scope'] as $type) {
                $$type = '';
                $types = &$modifiers[Str::plural($type)];

                if ($types->count() > 0) {
                    $$type = $this->paintString($types->first()->getName(), 'brown');
                    unset($types[0]);
                }
            }

            $rows[] = [$mutator, $accessor, $scope];
        }

        $headers = ['mutator', 'accessor', 'scope'];

        $this->table($headers, $rows);
        
    }
824966
public function save(Model $model)
    {
        $saved = $model->save();

        if ($saved) {
            app('cache')->flush();
        }

        return $saved;
    }
589661
public function onPreviewHtmlReport(Model $model)
    {
        $this->onReportsHistory();
        Breadcrumbs::register('logger-reports-preview-' . $model->id, function($breadcrumbs) use($model) {
            $breadcrumbs->parent('logger-reports-history');
            $breadcrumbs->push('Preview report ' . $model->name, handles('antares::logger/view/' . $model->id));
        });
        view()->share('breadcrumbs', Breadcrumbs::render('logger-reports-preview-' . $model->id));
    }
1133841
protected function getCleanLog(Model $Model)
	{
		$ds = $Model->getDataSource();
		$queries = array();

		if (method_exists($ds, 'getLog')) {
			$log = $ds->getLog(false, false);
			$diff = Set::diff($log['log'], $this->cachedQueries);

			$this->cachedQueries = $log['log'];

			foreach ($diff as $entry) {
				if (empty($entry['affected'])) {
					continue;
				}

				$queries[] = $entry['query'];
			}
		}

		return $queries;
	}
116587
public function getMemory($model)
    {
        if (empty($model['memory'])) {
            return null;
        }

        return [
            sprintf('%.2f MB', $model['memory'] / 1048576),
            $model['memory'] / ($this->panel->memory / 100)
        ];
    }
1111196
protected function getModelPrimaryKeyString($model)
    {
        return is_array($model->getPrimaryKey()) ? implode('-', $model->getPrimaryKey()) : $model->getPrimaryKey();
    }
324946
protected function getModel($model) {
		$args = func_get_args();
		array_shift($args);
		require 'app/models/' . $model . '.php';
       	$class = 'Tadpole\model\\' . $model;
		if(!empty($args)) {
			$modData = new ReflectionClass($class);
			$returnMod = $modData->newInstanceArgs($args);
			return $returnMod;
		} else {
        	$returnMod = new $class;
			return $returnMod;
		}
	}
932375
public function getTableName($model = null)
    {
        $model = $model ?? $this->model;

        if ($model instanceof Model) {
            return $model->getTable();
        } elseif ($model instanceof EloquentBuilder) {
            return $model->getModel()->getTable();
        }

        return $model->from;
    }
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();
    }
1323938
protected function serializeModel($model)
    {
        if ($this->request->getIsHead()) {
            return null;
        }

        [$fields, $expand] = $this->getRequestedFields();
        return $model->toArray($fields, $expand);
    }
224381
protected function getReference(Model $model)
    {
        $reference = $this->getReferenceValue($model);

        return $this->wrapWithLink($reference, $this->getLinkForReferenceModel($model));
    }
543664
public function process(Model $model)
    {
        $ref = new \ReflectionFunction($model->getData());

        $result = array();

        // Adding comments from the file.
        $result[static::META_COMMENT] =  $this->pool
            ->createClass('Brainworxx\\Krexx\\Analyse\\Comment\\Functions')
            ->getComment($ref);

        // Adding the sourcecode
        $highlight = $ref->getStartLine() -1;
        $result[static::META_SOURCE] = $this->pool->fileService->readSourcecode(
            $ref->getFileName(),
            $highlight,
            $highlight - 3,
            $ref->getEndLine() -1
        );

        // Adding the place where it was declared.
        $result[static::META_DECLARED_IN] = $this->pool->fileService->filterFilePath($ref->getFileName()) . "\n";
        $result[static::META_DECLARED_IN] .= 'in line ' . $ref->getStartLine();

        // Adding the namespace, but only if we have one.
        $namespace = $ref->getNamespaceName();
        if (empty($namespace) === false) {
            $result[static::META_NAMESPACE] = $namespace;
        }

        // Adding the parameters.
        $paramList = '';

        foreach ($ref->getParameters() as $key => $reflectionParameter) {
            ++$key;
            $paramList .=  $result[static::META_PARAM_NO . $key] = $this->pool
                ->codegenHandler
                ->parameterToString($reflectionParameter);
            // We add a comma to the parameter list, to separate them for a
            // better readability.
            $paramList .= ', ';
        }

        return $this->pool->render->renderExpandableChild(
            $model->setType(static::TYPE_CLOSURE)
                ->setNormal(static::UNKNOWN_VALUE)
                // Remove the ',' after the last char.
                ->setConnectorParameters(trim($paramList, ', '))
                ->setDomid($this->generateDomIdFromObject($model->getData()))
                ->setConnectorType(Connectors::METHOD)
                ->addParameter(static::PARAM_DATA, $result)
                ->injectCallback(
                    $this->pool->createClass('Brainworxx\\Krexx\\Analyse\\Callback\\Iterate\\ThroughMethodAnalysis')
                )
        );
    }