Skip to content

Commit 65b31ad

Browse files
committed
feat!: harden 4.0 runtime validation, docs, and CI coverage
1 parent 94480d8 commit 65b31ad

22 files changed

Lines changed: 873 additions & 367 deletions

.github/workflows/ci.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ jobs:
1515
name: PHP ${{ matrix.php }} / ${{ matrix.driver }} / ${{ matrix.search_build }}
1616
runs-on: ubuntu-22.04
1717
timeout-minutes: 30
18-
continue-on-error: ${{ matrix.search_build == 'SPHINX3' }}
1918
permissions:
2019
contents: read
2120
packages: read
@@ -101,8 +100,11 @@ jobs:
101100
docker logs searchd || true
102101
exit 1
103102
103+
- name: Validate composer metadata
104+
run: composer validate --strict --no-check-publish
105+
104106
- name: Install dependencies
105-
run: composer update --prefer-dist --no-interaction
107+
run: composer install --prefer-dist --no-interaction --no-progress
106108

107109
- name: Prepare autoload
108110
run: composer dump-autoload

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
* Updated CI PHP matrix to 8.2 and 8.3
44
* Restored runtime-level driver normalization for PDO/MySQLi scalar fetch values
55
* Normalized MySQLi driver exception handling for modern PHP `mysqli_sql_exception` behavior
6+
* Hardened runtime validation for `SphinxQL`, `Facet`, `Helper`, and `Percolate` input contracts (fail-fast exceptions for invalid query-shape input)
7+
* Standardized driver exception message prefixes for better diagnostics (`[mysqli][...]`, `[pdo][...]`)
8+
* Expanded helper runtime API coverage (`SHOW WARNINGS`, `SHOW STATUS`, `SHOW INDEX STATUS`, `FLUSH RAMCHUNK`, `FLUSH RTINDEX`, `OPTIMIZE INDEX`, UDF lifecycle checks)
9+
* Added and stabilized Sphinx 3 compatibility coverage while preserving Sphinx 2 and Manticore test behavior
10+
* Migrated CI to GitHub Actions-only validation with strict composer metadata checks
11+
* Updated documentation and added a dedicated `MIGRATING-4.0.md` guide
612

713
#### 3.0.2
814
* Dropped support for PHP 7.3 and lower

MIGRATING-4.0.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Migrating to 4.0
2+
3+
This guide covers migration from the 3.x line to the 4.0 line.
4+
5+
## Baseline Requirements
6+
7+
- PHP 8.2+
8+
- `mysqli` or `pdo_mysql` extension
9+
10+
## Major Behavioral Changes
11+
12+
4.0 introduces strict runtime validation for query builder and helper input.
13+
Invalid query-shape arguments now fail fast with `Foolz\SphinxQL\Exception\SphinxQLException`.
14+
15+
### SphinxQL builder strict validation
16+
17+
The following now throw on invalid input:
18+
19+
- `setType()` unknown query type
20+
- `compile()` with no selected query type
21+
- `from()` with empty or invalid index input
22+
- `facet()` with non-`Facet` argument
23+
- `orderBy()` / `withinGroupOrderBy()` invalid direction (must be `ASC` or `DESC`)
24+
- `limit()` / `offset()` negative or invalid integer values
25+
- `groupNBy()` non-positive values
26+
- `where()` / `having()` invalid filter value shape for `IN`/`NOT IN`/`BETWEEN`
27+
- `into()`, `columns()`, `values()`, `value()`, `set()` invalid/empty input
28+
- `setQueuePrev()` non-`SphinxQL` argument
29+
30+
### Facet strict validation
31+
32+
- empty `facet()` input
33+
- empty function/params in `facetFunction()` and `orderByFunction()`
34+
- invalid direction in `orderBy()` / `orderByFunction()`
35+
- negative or invalid `limit()` / `offset()`
36+
37+
### Helper strict validation
38+
39+
Helper methods now validate required identifiers and argument shapes:
40+
41+
- `showTables()`, `describe()`, `showIndexStatus()`, `flushRtIndex()`,
42+
`truncateRtIndex()`, `optimizeIndex()`, `flushRamchunk()`, etc.
43+
- `setVariable()` validates variable names and array values
44+
- `callSnippets()` and `callKeywords()` validate required arguments
45+
- `createFunction()` validates return type (`INT`, `UINT`, `BIGINT`, `FLOAT`, `STRING`)
46+
47+
### Percolate strict validation
48+
49+
Percolate input now rejects invalid payload types earlier instead of relying on
50+
implicit coercion, and string sanitization paths are null-safe.
51+
52+
## Exception Message Format
53+
54+
Driver-level connection/query exceptions now include a source prefix:
55+
56+
- `[mysqli][connect]...`
57+
- `[mysqli][query]...`
58+
- `[pdo][connect]...`
59+
- `[pdo][query]...`
60+
61+
If your code matches exact exception strings, update those checks to match
62+
message fragments or exception classes.
63+
64+
## Migration Tips
65+
66+
1. Validate user input before passing it to query builder methods.
67+
2. Replace implicit coercions with explicit typing/casting in your app layer.
68+
3. Prefer exception-class checks over exact message equality.
69+
4. Run your integration tests against your target engine (`Sphinx2`, `Sphinx3`, `Manticore`).

README.md

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ Query Builder for SphinxQL
88

99
## About
1010

11-
This is a SphinxQL Query Builder used to work with SphinxQL, a SQL dialect used with the Sphinx search engine and it's fork Manticore. It maps most of the functions listed in the [SphinxQL reference](http://sphinxsearch.com/docs/current.html#SphinxQL-reference) and is generally [faster](http://sphinxsearch.com/blog/2010/04/25/sphinxapi-vs-SphinxQL-benchmark/) than the available Sphinx API.
11+
This is a query builder for SphinxQL/ManticoreQL, the SQL dialect used by
12+
Sphinx Search and Manticore Search. It maps most common query-builder use cases
13+
and supports both `mysqli` and `PDO` drivers.
1214

1315
This Query Builder has no dependencies except PHP 8.2 or later, `\MySQLi` extension, `PDO`, and [Sphinx](http://sphinxsearch.com)/[Manticore](https://manticoresearch.com).
1416

@@ -24,22 +26,22 @@ If any feature is unreachable through this library, open a new issue or send a p
2426

2527
The majority of the methods in the package have been unit tested.
2628

27-
The only methods that have not been fully tested are the Helpers, which are mostly simple shorthands for SQL strings.
29+
Helper methods and engine compatibility scenarios are covered by the test suite.
2830

2931
## How to Contribute
3032

3133
### Pull Requests
3234

3335
1. Fork the SphinxQL Query Builder repository
3436
2. Create a new branch for each feature or improvement
35-
3. Submit a pull request from each branch to the **master** branch
37+
3. Submit a pull request from each branch to the repository default branch
3638

3739
It is very important to separate new features or improvements into separate feature branches, and to send a pull
3840
request for each branch. This allows me to review and pull in new features or improvements individually.
3941

4042
### Style Guide
4143

42-
All pull requests must adhere to the [PSR-2](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md) standard.
44+
All pull requests should follow PSR-12-compatible formatting.
4345

4446
### Unit Testing
4547

@@ -80,6 +82,19 @@ We support the following database connection drivers:
8082
* Foolz\SphinxQL\Drivers\Mysqli\Connection
8183
* Foolz\SphinxQL\Drivers\Pdo\Connection
8284

85+
### Engine Compatibility Matrix
86+
87+
| Engine | Query Builder | Helper APIs | Notes |
88+
| --- | --- | --- | --- |
89+
| Sphinx 2.x | Supported | Supported | Full CI lane |
90+
| Sphinx 3.x | Supported | Supported with engine-specific assertions | Full CI lane |
91+
| Manticore | Supported | Supported + Percolate | Full CI lane |
92+
93+
### Migration to 4.0
94+
95+
See [`MIGRATING-4.0.md`](MIGRATING-4.0.md) for the complete migration checklist,
96+
including strict runtime validation behavior introduced in the 4.0 line.
97+
8398
### Connection
8499

85100
* __$conn = new Connection()__
@@ -118,10 +133,6 @@ There are cases when an input __must__ be escaped in the SQL statement. The foll
118133

119134
Returns the escaped value. This is processed with the `\MySQLi::real_escape_string()` function.
120135

121-
* __$sq->quoteIdentifier($identifier)__
122-
123-
Adds backtick quotes to the identifier. For array elements, use `$sq->quoteIdentifierArray($arr)`.
124-
125136
* __$sq->quote($value)__
126137

127138
Adds quotes to the value and escapes it. For array elements, use `$sq->quoteArr($arr)`.
@@ -136,6 +147,15 @@ There are cases when an input __must__ be escaped in the SQL statement. The foll
136147

137148
_Refer to `$sq->match()` for more information._
138149

150+
#### Strict Validation in 4.0
151+
152+
4.0 performs fail-fast validation for invalid query-shape input. Examples:
153+
154+
* invalid `setType()` values
155+
* invalid `ORDER BY` direction values
156+
* negative `limit()`/`offset()`
157+
* invalid value shapes for `IN`/`BETWEEN`
158+
139159
#### SELECT
140160

141161
* __$sq = (new SphinxQL($conn))->select($column1, $column2, ...)->from($index1, $index2, ...)__

composer.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22
"name": "foolz/sphinxql-query-builder",
33
"replace": {"foolz/sphinxql": "self.version"},
44
"type": "library",
5-
"description": "A PHP query builder for SphinxQL. Uses MySQLi to connect to the Sphinx server.",
5+
"description": "A PHP query builder for SphinxQL and ManticoreQL with MySQLi and PDO drivers.",
66
"keywords": ["database", "sphinxql", "sphinx", "search", "SQL", "query builder"],
7-
"homepage": "http://www.foolz.us",
7+
"homepage": "https://github.com/FoolCode/SphinxQL-Query-Builder",
88
"license": "Apache-2.0",
99
"authors": [{"name": "foolz", "email": "support@foolz.us"}],
1010
"support": {
11-
"email": "support@foolz.us",
12-
"irc": "irc://irc.irchighway.net/fooldriver"
11+
"issues": "https://github.com/FoolCode/SphinxQL-Query-Builder/issues",
12+
"source": "https://github.com/FoolCode/SphinxQL-Query-Builder",
13+
"docs": "https://github.com/FoolCode/SphinxQL-Query-Builder/tree/master/docs"
1314
},
1415
"require": {
1516
"php": "^8.2"

docs/config.rst

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
Configuration
44
=============
55

6-
Obtaining a Connection
7-
----------------------
6+
Creating a Connection
7+
---------------------
88

9-
You can obtain a SphinxQL Connection with the `Foolz\\SphinxQL\\Drivers\\Mysqli\\Connection` class.
9+
Use one of the supported drivers:
1010

1111
.. code-block:: php
1212
@@ -15,33 +15,37 @@ You can obtain a SphinxQL Connection with the `Foolz\\SphinxQL\\Drivers\\Mysqli\
1515
use Foolz\SphinxQL\Drivers\Mysqli\Connection;
1616
1717
$conn = new Connection();
18-
$conn->setparams(array('host' => '127.0.0.1', 'port' => 9306));
19-
20-
.. warning::
21-
22-
The existing PDO driver written is considered experimental as the behaviour changes between certain PHP releases.
18+
$conn->setParams(array(
19+
'host' => '127.0.0.1',
20+
'port' => 9306,
21+
));
2322
24-
Connection Parameters
25-
---------------------
23+
You can also use the PDO driver:
2624

27-
The connection parameters provide information about the instance you wish to establish a connection with. The parameters required is set with the `setParams($array)` or `setParam($key, $value)` methods.
25+
.. code-block:: php
2826
29-
.. describe:: host
27+
<?php
3028
31-
:Type: string
32-
:Default: 127.0.0.1
29+
use Foolz\SphinxQL\Drivers\Pdo\Connection;
3330
34-
.. describe:: port
31+
$conn = new Connection();
32+
$conn->setParams(array(
33+
'host' => '127.0.0.1',
34+
'port' => 9306,
35+
));
3536
36-
:Type: int
37-
:Default: 9306
37+
Connection Parameters
38+
---------------------
3839

39-
.. describe:: socket
40+
``setParams()`` and ``setParam()`` accept:
4041

41-
:Type: string
42-
:Default: null
42+
- ``host`` (string, default ``127.0.0.1``)
43+
- ``port`` (int, default ``9306``)
44+
- ``socket`` (string|null, default ``null``)
45+
- ``options`` (array, driver-specific client options)
4346

44-
.. describe:: options
47+
Strict Validation Notes
48+
-----------------------
4549

46-
:Type: array
47-
:Default: null
50+
The query builder validates critical inputs at runtime in 4.0.
51+
Prefer explicit values over implicit coercion.

docs/contribute.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ Pull Requests
66

77
1. Fork `SphinxQL Query Builder <https://github.com/FoolCode/SphinxQL-Query-Builder>`_
88
2. Create a new branch for each feature or improvement
9-
3. Submit a pull request with your branch against the master branch
9+
3. Submit a pull request with your branch against the default branch
1010

1111
It is very important that you create a new branch for each feature, improvement, or fix so that may review the changes and merge the pull requests in a timely manner.
1212

1313
Coding Style
1414
------------
1515

16-
All pull requests must adhere to the `PSR-2 <https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md>`_ standard.
16+
All pull requests should follow modern PHP style conventions (PSR-12 compatible formatting).
1717

1818
Testing
1919
-------

0 commit comments

Comments
 (0)