phpgt/cssxpath) bridges CSS selectors (common in frontend scraping, testing, or DOM manipulation) to XPath (useful for backend processing, XML/HTML parsing, or legacy systems). This is valuable for:
DOM and SimpleHTMLDom packages could leverage this for:
php-cs-fixer, phpunit, or guzzlehttp if used in scraping pipelines.SelectorTranslator facade for cleaner syntax:
use App\Facades\SelectorTranslator;
$xpath = SelectorTranslator::toXPath('div.content > p');
Query builder for dynamic XPath generation in Eloquent models (e.g., for XML-based databases like doctrine/dbal).button#submit → //button[@id='submit']).:nth-child), attribute selectors ([data-testid]), and namespace-aware XPath.:has() or :is() may not map cleanly to XPath 1.0 (default in DOMDocument). Requires XPath 2.0+ or manual fallbacks.strictMode flag to fail on unsupported queries.Illuminate\Support\Facades\Cache) or batch-process queries.composer.json as a private package or use require with replace to point to a local fork.div[class^="prefix-"])?Facebook/WebDriver’s built-in conversion)?Guzzle + Symfony\Component\DomCrawler.Laravel Dusk or Pest for cross-selector compatibility.spatie/array-to-xml or ext-dom for dynamic responses.doctrine/dbal with XPath queries).symfony/css-selector (similar functionality but Symfony-focused).php-cs-fixer for CSS selector linting.phpunit to assert XPath output matches expectations.$css = 'a[href^="https://"]';
$xpath = (new \Phpgt\CssXPath\CssXPath())->toXPath($css);
$this->assertEquals('//a[starts-with(@href, "https://")]', $xpath);
app/Services/SelectorTranslator.php) to abstract the package.// config/cssxpath.php
'supported_selectors' => ['class', 'id', 'attribute', 'pseudo-class'],
where clauses:
$posts = Post::whereCss('div.post > h2')->get(); // Translates to XPath
div, #id, .class), combinators (>, +), and attributes ([href]).:nth-child), pseudo-elements (::before), or :has() (may require XPath 2.0).DOMDocument).ext-xpath or sabberworm/PHP-XPath.AppServiceProvider:
public function register()
{
$this->app->singleton(\Phpgt\CssXPath\CssXPath::class, function () {
return new \Phpgt\CssXPath\CssXPath();
});
}
Laravel Debugbar).composer.json replace.var_dump($css, $xpath)How can I help you explore Laravel packages today?