yepsua/jquery4php
jQuery4PHP is a PHP wrapper for jQuery and jQuery UI that lets you build JavaScript components, effects, and AJAX interactions using PHP objects and fluent APIs instead of writing raw JavaScript.
Aim to have the library running standalone before wiring it into any framework — this package has no first-party Laravel integration and its Symfony/Yii bundles are stale.
Install
composer require yepsua/jquery4php
If Packagist is unreachable or the version constraint fails on PHP 8+, add the repo directly:
"repositories": [{ "type": "vcs", "url": "https://github.com/oyepez003/jQuery4PHP" }],
"require": { "yepsua/jquery4php": "dev-master" }
Where to look first
src/Yepsua/jQuery/JQuery.php — the static entry point (JQuery::script(...), JQuery::onReady(...), singleton accessor).src/Yepsua/Sintax/JsSintax.php — the PHP→JS serializer (JsSintax::sintax($value)). Everything that ends up as a JS literal goes through here.src/Yepsua/jQuery/JQueryObject.php — the chainable selector object. Every DOM/effect/method call in the README maps onto a method here via __call.src/Yepsua/Html/ — HtmlTag and friends, for building markup with attached jQuery behavior.src/Yepsua/Sintax/JsFunction.php — wraps raw JS callbacks back into PHP objects.First use case
The canonical "hello world" is: build a selector chain, wrap it in an onReady, and echo it into your view.
use Yepsua\jQuery\JQuery;
use Yepsua\Sintax\JsSintax;
// PHP array → JS array literal
$items = JsSintax::sintax(['#a', '#b', '#c']); // "['#a','#b','#c']"
echo JQuery::script(
JQuery::getJQueryObject('#panel')
->addClass('active')
->find('.item')
->fadeIn()
);
That returns a <script>…</script> string you render alongside your HTML. The first useful mental model is: JQuery::script() produces the tag, JsSintax::sintax() produces the data, JQueryObject produces the jQuery chain.
1. Render server-side, execute client-side. The package never talks to a browser. It's a code generator: you produce a <script> string in a controller, Blade template, or service, and the browser executes it. Treat it like a templating layer for JS, not a front-end runtime.
2. Chaining is the primary workflow. Every jQuery method you know (hide, fadeIn, addClass, val, ajax, on, each) is exposed as a method on JQueryObject. Build the chain in PHP the way you'd write it in JS, then print it once:
$chain = JQuery::getJQueryObject('.row')
->on('click', '.delete', new JsFunction('return confirm("delete?")'))
->parent()
->addClass('pending');
echo JQuery::script($chain);
3. Bind data, not strings. Whenever a value is non-literal PHP (array, object, number, bool), pass it through JsSintax::sintax(). This is the intended data-bridging path and handles quoting/escaping for you. Avoid '"' . $string . '"' interpolation — it defeats the point of the library.
4. HTML helpers for event wiring. HtmlTag lets you construct markup and attach jQuery behavior in one PHP call, then emit both. This is the pattern the library was actually built for — "no JS file, all PHP." Useful in admin panels where you generate dynamic rows/lists and want the click handlers to follow them without a hand-written JS bundle.
5. Framework integration is DIY. Do not install the yepsua/jquery4php-bundle Symfony bundle or the Yii extension — they pin old jQuery/Symfony and will not resolve on modern stacks. Instead, wrap the emission in a Blade component or partial:
// resources/views/components/jquery.blade.php
{!! JQuery::script($chain) !!}
In Laravel, register a service provider that does nothing more than require the autoloader (Composer handles this once the package is a dependency).
6. Use it as a generator inside a test suite. A practical integration: snapshot the generated JS string in a unit test, then assert against it to catch accidental regressions in dynamically-built scripts. This works well because JQuery::script() is pure string output with no side effects.
7. Compose complex scripts by concatenation. Large scripts are usually assembled by repeatedly writing JQuery::script(...) chains into an array and implode("\n", …) at the end. There is no builder for multiple statements — that is the pattern.
License is the biggest gotcha. GPL-2.0 means anything you link this into and distribute must be GPL. In a proprietary Laravel SaaS this is a legal non-starter. Confirm with whoever owns compliance before adopting. If you only ever run it server-side and never ship the source, that's usually defensible — but it's an argument, not a safe harbor. Most teams should evaluate this package as an isolation tool (generate JS at runtime, never expose the library) rather than as a dependency to redistribute.
It is effectively unmaintained. Three stars, zero dependents, last meaningful activity ~2013–2015. Expect no PHP 8.0+ guarantees. On PHP 8.1+ you'll likely need error_reporting adjustments or small patches in JsSintax for null/false serialization. Budget a half-day for patch work if you actually adopt.
Case sensitivity bites. The namespace is Yepsua\ (capital Y, lowercase jQuery). On Linux CI the autoloader is case-sensitive; on macOS it isn't, so use Yepsua\jquery\JQuery will pass locally and explode in prod. Always spell Yepsua\jQuery.
JQuery::getInstance() is a singleton. If you hold it across requests (Octane, Swoole), chained state leaks between users. Prefer static factory methods (JQuery::getJQueryObject(...), JQuery::script(...)) over the instance accessor. If you must use the singleton, clone or reset it per request.
script() emits a raw <script> block. Anything you feed into selectors, callbacks, or JsSintax that originated from user input is a direct XSS vector. Always route dynamic strings through JsSintax::sintax(); never concatenate unescaped user input into a selector argument. Debug by var_dumping the generated string before it hits the view, not by staring at the browser.
onReady is not idempotent. Calling it multiple times produces multiple $(document).ready(...) wrappers. Compose once per page; if you need multiple entry points, put them all inside one onReady body.
Debugging strategy. There is no debug mode. When a generated script fails silently, echo the raw string, paste it into a browser console, and check it against JsSintax output. Most failures come from PHP values being serialized with the wrong type (e.g. "1" vs 1, or an array that should have been a JS object via JsSintax::sintax($obj, true) for "object" mode).
jQuery version skew. The library targets the 1.x API. If your app loads jQuery 3.x, most selectors still work, but .live()-style helpers and positional pseudoselectors will not. Pin jQuery 1.12 or audit each generated call.
Extension points.
JsSintax to override sintax() serialization (e.g. to support JsonSerializable, or to emit JSON.parse for special types).JQueryObject and register it via the factory if you need custom chains (e.g. a ->toast('msg') shorthand that expands into a repeated .show().delay().fadeOut() chain).JsFunction is the escape hatch for anything the fluent API can't express — pass a raw JS string; it is emitted verbatim, with no escaping, so treat it as eval()-grade.Config quirks.
type, nonce) aren't configurable — if you enforce CSP nonces, you must post-process the returned string or bypass script() and emit onReady() output inside your own tag wrapper.When not to use it. If your app already has a Blade/Alpine/Livewire stack, or you ship a compiled JS bundle, the value proposition is gone — you're paying GPL, stale-code, and XSS-safety costs purely to avoid writing $('#x').hide() in a .js file. The realistic niche is: legacy PHP admin panels with no build step, where you want all behavior expressed in PHP server-side and jQuery is already loaded globally.
How can I help you explore Laravel packages today?