master

laravel/framework

Last updated at: 29/12/2023 09:22

Processor.php

TLDR

The Processor class in the file Processor.php is responsible for processing the results of various types of queries in the Illuminate Database Query Builder. It contains methods for processing select, insert-get-id, tables, views, types, columns, indexes, foreign keys, and column listing queries.

Methods

processSelect

This method processes the results of a "select" query and returns the results array as is.

processInsertGetId

This method processes an "insert get ID" query. It executes the query, retrieves the last inserted ID, and returns it as an integer if it is numeric; otherwise, it returns it as is.

processTables

This method processes the results of a tables query. It formats each result object in the results array into an associative array containing the name, schema, size, comment, collation, and engine of the table.

processViews

This method processes the results of a views query. It formats each result object in the results array into an associative array containing the name, schema, and definition of the view.

processTypes

This method processes the results of a types query and returns the results array as is.

processColumns

This method processes the results of a columns query and returns the results array as is.

processIndexes

This method processes the results of an indexes query and returns the results array as is.

processForeignKeys

This method processes the results of a foreign keys query and returns the results array as is.

processColumnListing

This method processes the results of a column listing query. It returns the results array as is.

END

<?php

namespace Illuminate\Database\Query\Processors;

use Illuminate\Database\Query\Builder;

class Processor
{
    /**
     * Process the results of a "select" query.
     *
     * @param  \Illuminate\Database\Query\Builder  $query
     * @param  array  $results
     * @return array
     */
    public function processSelect(Builder $query, $results)
    {
        return $results;
    }

    /**
     * Process an  "insert get ID" query.
     *
     * @param  \Illuminate\Database\Query\Builder  $query
     * @param  string  $sql
     * @param  array  $values
     * @param  string|null  $sequence
     * @return int
     */
    public function processInsertGetId(Builder $query, $sql, $values, $sequence = null)
    {
        $query->getConnection()->insert($sql, $values);

        $id = $query->getConnection()->getPdo()->lastInsertId($sequence);

        return is_numeric($id) ? (int) $id : $id;
    }

    /**
     * Process the results of a tables query.
     *
     * @param  array  $results
     * @return array
     */
    public function processTables($results)
    {
        return array_map(function ($result) {
            $result = (object) $result;

            return [
                'name' => $result->name,
                'schema' => $result->schema ?? null, // PostgreSQL and SQL Server
                'size' => isset($result->size) ? (int) $result->size : null,
                'comment' => $result->comment ?? null, // MySQL and PostgreSQL
                'collation' => $result->collation ?? null, // MySQL only
                'engine' => $result->engine ?? null, // MySQL only
            ];
        }, $results);
    }

    /**
     * Process the results of a views query.
     *
     * @param  array  $results
     * @return array
     */
    public function processViews($results)
    {
        return array_map(function ($result) {
            $result = (object) $result;

            return [
                'name' => $result->name,
                'schema' => $result->schema ?? null, // PostgreSQL and SQL Server
                'definition' => $result->definition,
            ];
        }, $results);
    }

    /**
     * Process the results of a types query.
     *
     * @param  array  $results
     * @return array
     */
    public function processTypes($results)
    {
        return $results;
    }

    /**
     * Process the results of a columns query.
     *
     * @param  array  $results
     * @return array
     */
    public function processColumns($results)
    {
        return $results;
    }

    /**
     * Process the results of an indexes query.
     *
     * @param  array  $results
     * @return array
     */
    public function processIndexes($results)
    {
        return $results;
    }

    /**
     * Process the results of a foreign keys query.
     *
     * @param  array  $results
     * @return array
     */
    public function processForeignKeys($results)
    {
        return $results;
    }

    /**
     * Process the results of a column listing query.
     *
     * @deprecated Will be removed in a future Laravel version.
     *
     * @param  array  $results
     * @return array
     */
    public function processColumnListing($results)
    {
        return $results;
    }
}