RebelCode/sql-cqrs-resource-models-abstract

View on GitHub
src/SqlColumnNamesAwareTrait.php

Summary

Maintainability
A
0 mins
Test Coverage
<?php

namespace RebelCode\Storage\Resource\Sql;

use Dhii\Storage\Resource\Sql\EntityFieldInterface;
use Dhii\Util\String\StringableInterface as Stringable;

/**
 * Common functionality for objects that can provide SQL columns names from a field-column map.
 *
 * @since [*next-version*]
 */
trait SqlColumnNamesAwareTrait
{
    /**
     * Retrieves the names of the columns used in SQL SELECT queries.
     *
     * @since [*next-version*]
     *
     * @return string[]|Stringable[] A list of column names.
     */
    protected function _getSqlColumnNames()
    {
        return array_values($this->_getSqlFieldColumnMap());
    }

    /**
     * Retrieves the mapping of field names to table columns.
     *
     * @since [*next-version*]
     *
     * @return EntityFieldInterface[] A map of field names mapping to entity field instances.
     */
    abstract protected function _getSqlFieldColumnMap();
}