Skip to content

Início / Optitravel / Helpers / ScimHelper

parse(array $params, array $allowedColumns): array

The parse method is used to interpret SCIM query parameters and transform them into internal query conditions and options compatible with SQL-like syntax. It supports filtering, sorting, and pagination, while validating allowed fields to ensure safe and controlled access to data.

This method is typically used in SCIM-compliant endpoints to handle incoming search and listing requests.

Parameters

  • $params – (array) Required. The query parameters from the request (e.g., filter, sortBy, sortOrder, count, startIndex).

  • $allowedColumns – (array) Required. A list of column names that are allowed to be used for filtering or sorting. If a column is not in this list, an exception is thrown.

Returns

  • (array) Returns an associative array containing:

  • conditions: An array of filter conditions to be used in a database query.

  • options: Additional options like orderBy, limit, and offset for sorting and pagination.

Example

use \App\Utils\ScimHelper;

$params = [
    'filter' => 'userName eq "john.doe"',
    'sortBy' => 'created',
    'sortOrder' => 'descending',
    'count' => 10,
    'startIndex' => 1
];

$allowedColumns = ['username', 'create_time', 'status'];

$result = ScimHelper::parse($params, $allowedColumns);

Output:

[
  'conditions' => [
    ['username', '=', 'john.doe']
  ],
  'options' => [
    'orderBy' => 'create_time DESC',
    'limit' => 10,
    'offset' => 0
  ]
]

Notes

If an invalid filter syntax or unauthorized column is used, the method throws an exception.


(Última atualização: 14/05/2025)