Skip to content

Commit 891e2d9

Browse files
committed
feat: add capability discovery and feature-gated helper APIs
1 parent f797beb commit 891e2d9

11 files changed

Lines changed: 454 additions & 6 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* Expanded helper runtime API coverage (`SHOW WARNINGS`, `SHOW STATUS`, `SHOW INDEX STATUS`, `FLUSH RAMCHUNK`, `FLUSH RTINDEX`, `OPTIMIZE INDEX`, UDF lifecycle checks)
99
* Added fluent boolean grouping APIs (`orWhere`, `whereOpen/whereClose`, `orHaving`, `havingOpen/havingClose`) and JOIN builders (`join`, `innerJoin`, `leftJoin`, `rightJoin`, `crossJoin`)
1010
* Added `orderByKnn()` and broader helper wrappers for operational and Manticore-oriented commands (`SHOW PROFILE/PLAN/THREADS/VERSION/PLUGINS`, table status/settings/indexes, flush/reload/kill, suggest family)
11+
* Added capability discovery and feature-gating APIs (`Capabilities`, `getCapabilities()`, `supports()`, `requireSupport()`) with `UnsupportedFeatureException` for unsupported command families
1112
* Added capability-aware runtime tests for optional engine features (`supportsCommand`, Buddy-gated checks)
1213
* Added and stabilized Sphinx 3 compatibility coverage while preserving Sphinx 2 and Manticore test behavior
1314
* Migrated CI to GitHub Actions-only validation with strict composer metadata checks

MIGRATING-4.0.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ Helper methods now validate required identifiers and argument shapes:
4343
- `setVariable()` validates variable names and array values
4444
- `callSnippets()` and `callKeywords()` validate required arguments
4545
- `createFunction()` validates return type (`INT`, `UINT`, `BIGINT`, `FLOAT`, `STRING`)
46+
- capability-aware APIs are available via `getCapabilities()`/`supports()`
47+
- feature-gated methods may throw `UnsupportedFeatureException` when unsupported
4648

4749
### Percolate strict validation
4850

@@ -67,3 +69,4 @@ message fragments or exception classes.
6769
2. Replace implicit coercions with explicit typing/casting in your app layer.
6870
3. Prefer exception-class checks over exact message equality.
6971
4. Run your integration tests against your target engine (`Sphinx2`, `Sphinx3`, `Manticore`).
72+
5. Prefer `supports($feature)` checks before engine-specific helper calls.

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,18 @@ Remember to `->execute()` to get a result.
440440

441441
Takes the pairs from a SHOW command and returns an associative array key=>value
442442

443+
* __$helper->getCapabilities()__
444+
445+
Returns a `Capabilities` object with detected engine/version and feature flags.
446+
447+
* __$helper->supports($feature)__
448+
449+
Checks whether a named feature is supported by the current backend/runtime.
450+
451+
* __$helper->requireSupport($feature, $context = '')__
452+
453+
Throws `UnsupportedFeatureException` when the requested feature is not available.
454+
443455
The following methods return a prepared `SphinxQL` object. You can also use `->enqueue($next_object)`:
444456

445457
```php

docs/helper.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,15 @@ Available Methods
5757
- ``flushLogs()``
5858
- ``reloadPlugins()``
5959
- ``kill($queryId)``
60+
- ``getCapabilities()``
61+
- ``supports($feature)``
62+
- ``requireSupport($feature, $context = '')``
6063

6164
Validation Notes
6265
----------------
6366

6467
In 4.0, helper methods validate required identifiers and input shapes and throw
6568
``SphinxQLException`` on invalid arguments.
69+
70+
Feature-gated helper methods may throw ``UnsupportedFeatureException`` when the
71+
current engine/runtime does not support that command family.

docs/query-builder.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,11 @@ JOIN and KNN Ordering
8383
Vector-oriented ordering is available through:
8484

8585
- ``orderByKnn($field, $k, array $vector, $direction = 'ASC')``
86+
87+
Capability Introspection
88+
------------------------
89+
90+
``SphinxQL`` exposes runtime capability helpers for connection-aware behavior:
91+
92+
- ``getCapabilities()``
93+
- ``supports($feature)``

src/Capabilities.php

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?php
2+
3+
namespace Foolz\SphinxQL;
4+
5+
/**
6+
* Describes detected engine/runtime capabilities.
7+
*/
8+
class Capabilities
9+
{
10+
/**
11+
* @var string
12+
*/
13+
private $engine;
14+
15+
/**
16+
* @var string
17+
*/
18+
private $version;
19+
20+
/**
21+
* @var array<string,bool>
22+
*/
23+
private $features;
24+
25+
/**
26+
* @param string $engine
27+
* @param string $version
28+
* @param array<string,bool> $features
29+
*/
30+
public function __construct($engine, $version, array $features)
31+
{
32+
$this->engine = strtoupper((string) $engine);
33+
$this->version = (string) $version;
34+
$this->features = $features;
35+
}
36+
37+
/**
38+
* @return string
39+
*/
40+
public function getEngine()
41+
{
42+
return $this->engine;
43+
}
44+
45+
/**
46+
* @return string
47+
*/
48+
public function getVersion()
49+
{
50+
return $this->version;
51+
}
52+
53+
/**
54+
* @return array<string,bool>
55+
*/
56+
public function getFeatures()
57+
{
58+
return $this->features;
59+
}
60+
61+
/**
62+
* @param string $feature
63+
*
64+
* @return bool
65+
*/
66+
public function supports($feature)
67+
{
68+
return !empty($this->features[$feature]);
69+
}
70+
71+
/**
72+
* @return array<string,mixed>
73+
*/
74+
public function toArray()
75+
{
76+
return array(
77+
'engine' => $this->engine,
78+
'version' => $this->version,
79+
'features' => $this->features,
80+
);
81+
}
82+
}
83+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
namespace Foolz\SphinxQL\Exception;
4+
5+
class UnsupportedFeatureException extends SphinxQLException
6+
{
7+
8+
}
9+

0 commit comments

Comments
 (0)