master

laravel/framework

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

MySqlProcessor.php

TLDR

This file contains the MySqlProcessor class, which extends the Processor class. It includes several methods for processing the results of various types of queries.

Methods

processColumnListing($results)

This method processes the results of a column listing query. It takes an array of results and returns an array of column names. It is deprecated and will be removed in a future Laravel version.

processColumns($results)

This method processes the results of a columns query. It takes an array of results and returns an array of columns with their associated details such as name, type, nullable, default value, etc.

processIndexes($results)

This method processes the results of an indexes query. It takes an array of results and returns an array of indexes with their associated details such as name, columns, type, uniqueness, etc.

processForeignKeys($results)

This method processes the results of a foreign keys query. It takes an array of results and returns an array of foreign keys with their associated details such as name, columns, foreign table, foreign columns, actions on update and delete, etc.

<?php

namespace Illuminate\Database\Query\Processors;

class MySqlProcessor extends Processor
{
    /**
     * 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 array_map(function ($result) {
            return ((object) $result)->column_name;
        }, $results);
    }

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

            return [
                'name' => $result->name,
                'type_name' => $result->type_name,
                'type' => $result->type,
                'collation' => $result->collation,
                'nullable' => $result->nullable === 'YES',
                'default' => $result->default,
                'auto_increment' => $result->extra === 'auto_increment',
                'comment' => $result->comment,
            ];
        }, $results);
    }

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

            return [
                'name' => $name = strtolower($result->name),
                'columns' => explode(',', $result->columns),
                'type' => strtolower($result->type),
                'unique' => (bool) $result->unique,
                'primary' => $name === 'primary',
            ];
        }, $results);
    }

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

            return [
                'name' => $result->name,
                'columns' => explode(',', $result->columns),
                'foreign_schema' => $result->foreign_schema,
                'foreign_table' => $result->foreign_table,
                'foreign_columns' => explode(',', $result->foreign_columns),
                'on_update' => strtolower($result->on_update),
                'on_delete' => strtolower($result->on_delete),
            ];
        }, $results);
    }
}