Download the PHP package zotenme/hyperf-ajax without Composer

On this page you can find all versions of the php package zotenme/hyperf-ajax. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package hyperf-ajax

Hyperf Ajax

PHP Version Hyperf Version [Tests]() [PHPStan]()

Hyperf Ajax is a Hyperf backend package compatible with the Larajax browser protocol. It lets a normal Hyperf page controller answer HTML-driven AJAX handlers such as data-request="onSave" without creating a separate JSON API route for every UI interaction.

This repository currently contains the first MVP implementation:

Installation

For local development:

Publish the frontend assets in a Hyperf application using Hyperf's vendor publish flow. The package exposes resources/dist as public/vendor/hyperfajax.

Frontend

Use either the existing npm package:

Or serve the published bundle:

framework-bundle.min.js starts the framework automatically. Do not call window.jax.start() with this bundle.

The published bundles are redistributed from Larajax 2.2.3. See Third-Party Notices for the upstream copyright and MIT license notice.

Controller Usage

The recommended low-friction entry point is HyperfAjaxController with ajaxPage(). The method renders a normal page for regular requests and dispatches onXxx handlers for AJAX requests.

ajaxPage() is the intentional public integration boundary. Call it explicitly from each page action that supports AJAX. The package does not install automatic middleware, attributes or AOP interception: Hyperf controllers may be long-lived, and keeping the concrete controller instance and request lifecycle explicit avoids hidden coroutine state. The render callback is lazy and is never called for an AJAX request.

Route:

View:

Minimal Browser Test

This example returns a tiny HTML page and a working onPing handler. It is the quickest way to verify a local path install inside a real Hyperf application.

See the copyable source in examples/HyperfAjaxTestController.php.

Route:

Request Input

Controllers using InteractsWithAjax do not need a $this->request property. The trait exposes request data from the active AJAX request:

Available helpers:

AJAX handler names follow one backend protocol grammar. Controller handlers use onEvent; component handlers use ComponentAlias::onEvent. Event must start with an uppercase ASCII letter, and names may otherwise contain ASCII letters, digits and underscores. Invalid handler names return an AJAX HTTP 400 response.

Handler signatures

Values passed in the ajaxPage(..., parameters: [...]) array may be positional or keyed by parameter name. Named values take priority over positional values and container injection. A single class or interface type can be resolved from the container; default values, nullable parameters and variadic parameters are supported. Pass a named variadic value as an array.

Union, intersection and enum parameters are supported when an explicit value of the correct PHP type is supplied. They are not guessed from the container or coerced from strings. A missing required parameter produces a diagnostic InvalidArgumentException instead of receiving an implicit null.

Request body and query values are deliberately not bound to method parameters. Read them through ajaxPost(), ajaxInput() or ajaxAll() so route/action parameters cannot silently conflict with submitted input.

To customize handler invocation, bind the typed invoker contract in config/autoload/dependencies.php:

The implementation receives the resolved controller/component callable and the explicit action parameters:

This contract replaces the former undocumented makeCallForAjax() method-name convention.

Validation

For inline, October-style validation, throw Hyperf Ajax's own validation exception. It accepts either a field error array or a validator/message-bag-like object.

Add data-request-validate to the form and place data-validate-for="field" where a field-level error should appear:

You can also throw field errors directly:

Components

HyperfAjaxController already implements AjaxControllerInterface, so a controller using components only needs to declare its component list:

Component aliases must be unique within one AJAX request. Duplicate aliases are rejected during registration instead of silently replacing an earlier component.

When applying InteractsWithAjax directly, the class must implement AjaxControllerInterface and provide the container accessor required by the trait:

Component:

HTML:

Flash messages

Flash messages are explicit response operations and do not depend on a Hyperf session integration:

Enable flash handling for the frontend request with data-request-flash (or the equivalent JavaScript flash: true option):

For Larajax 2.2.3 compatibility the frontend sends X-AJAX-FLASH, but the backend does not interpret that header or capture messages from session storage. It only returns flash operations explicitly added through AjaxResponse::flash(). Applications that need session-backed flash capture can implement it in their own handler or response adapter without making a session package mandatory.

Partials

The frontend distinguishes the current partial from the partials requested for rendering. A request originating inside data-ajax-partial sends its name in X-AJAX-PARTIAL. The backend exposes that context as $this->getAjaxRequest()?->partial, including to PartialRendererInterface. It does not render the current partial automatically.

Use _self when the originating partial should be refreshed:

As in Larajax 2.2.3, the frontend resolves _self to profile/card and includes that resolved name in X-AJAX-PARTIALS. The backend renders only this resolved list, keeping X-AJAX-PARTIAL as request context.

You can always return ready HTML without a renderer:

For automatic rendering of names sent in X-AJAX-PARTIALS, bind a PartialRendererInterface implementation in config/autoload/dependencies.php:

The renderer is framework-neutral and receives the controller, current AJAX request and explicit template data:

Set data during the AJAX handler. It is stored only in the current coroutine execution context:

Using hyperf/view

Install and configure hyperf/view and your chosen view engine, then implement the same contract with Hyperf\View\RenderInterface::getContents():

Complete examples for direct strings, plain PHP templates and hyperf/view are available in examples/PartialRendering.

A larger Blade example with a product catalog, category/minimum-price filters and “Show more” AJAX pagination is available in examples/ProductCatalog.

Tests

Run the PHPUnit suite:

The suite checks framework-neutral behavior. Full Hyperf integration tests remain in the local, ignored hyperf-app smoke environment.


All versions of hyperf-ajax with dependencies

PHP Build Version
Package Version
Requires php Version ^8.3
hyperf/context Version ^3.2
hyperf/contract Version ^3.2
hyperf/http-message Version ^3.2
hyperf/http-server Version ^3.2
psr/container Version ^1.1 || ^2.0
psr/http-message Version ^1.0 || ^2.0
psr/log Version ^1.1 || ^2.0 || ^3.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package zotenme/hyperf-ajax contains the following files

Loading the files please wait ...