Download the PHP package ghayma/sdk without Composer

On this page you can find all versions of the php package ghayma/sdk. 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 sdk

ghayma/sdk

PHP client for the Ghayma platform. Two entry classes over the two published contracts:

Requires PHP 8.2+.

Install

The SDK talks HTTP through the PSR-18 / PSR-17 interfaces and never hard-depends on a client. It discovers any installed implementation via php-http/discovery. If your app doesn't already ship one, add Guzzle and nyholm:

You can also pass your own client and factories explicitly (see Bring your own HTTP client).

Admin client (Ghayma)

Authenticate with a project API key from Project → Settings → API keys.

->auth, ->storage and ->databases return typed, immutable DTOs (Ghayma\Sdk\Model\*). See examples/admin.php.

Credentials: your site's own

->databases->credentials() and ->storage->credentials() answer a site's key (the GHAYMA_API_KEY in the site's variables) with that site's own connection credential, the one its runtime already carries in DATABASE_URL / MONGODB_URI or STORAGE_*, at the connection's level (read-only/connect for a database, read/read-write for a bucket); credential is always connection. A database's own login and a bucket's owner key are never handed out.

Answer status / errorCode Exception
The connection has no credential of its own yet; retry in a few minutes 409 no_own_credential GhaymaException
The bucket is still being provisioned 409 credentials_not_ready GhaymaException
A project-wide key has no connection of its own 403 site_key_required ForbiddenException
The site is not connected to that database or bucket 403 not_connected ForbiddenException
An account token instead of a site key: a database's own login and a bucket's owner key are shown to no one 410 shared_credentials_retired GhaymaException

From your laptop, reach a database with ghayma connect --local, and a bucket with ghayma env pull (your site's STORAGE_* variables; the S3 endpoint is public). A system outside Ghayma gets a credential of its own: ghayma access add database <name> --name <principal> (or bucket).

End-user auth client (GhaymaAuth)

GhaymaAuth holds no session state — a PHP request is stateless, so the caller passes the accessToken (or refreshToken) it stored. There is no token storage, no auto-refresh timer.

login() returns a LoginResult (LoginSuccess | TwoFaRequired | TwoFaEnrollmentRequired); register() returns a RegisterResult (RegisterSuccess | VerificationRequired). Match with instanceof. See examples/auth.php.

Server key and client IP

When you construct GhaymaAuth with a server key, pass the real end-user IP so the auth service applies its rate limits to that user rather than to your server. The key and the IP travel together or not at all (a forwarded IP is only honoured from a caller that proves itself with the key), and the IP is validated as a literal before it is sent:

On Ghayma, the visitor's IP is in X-Real-IP, which the platform's edge overwrites; if your server is also reachable another way (another host, your own proxy), make sure that path overwrites it too, or don't forward it.

clientIp is accepted on the rate-limited entry points: register, login, verify2fa, refresh, forgotPassword, resetPassword, verifyResetToken, resendVerification, exchangeCode, signInWithIdToken. Never expose the server key to a browser — build GhaymaAuth in server code only.

OAuth

Build a provider sign-in URL for a login page, then redirect the browser to it:

Complete a native or PKCE sign-in server-side:

The redirect_uri must match one of the app's Allowed Origins, and native client IDs must be registered under Native client IDs, both in the console. See the mobile OAuth guide: https://docs.ghayma.cloud/guides/oauth-mobile.

signInWithIdToken() refuses a Google account whose email address Google has not verified: a 403 ForbiddenException with errorCode email_not_verified, through the usual error mapping.

Second factor on OAuth sign-in

When the app's 2FA policy applies to the user, exchangeCode() and signInWithIdToken() create no session and throw a TwoFactorRequiredException. Its result is the same pending step login() returns, finished the same way:

$e->errorCode is two_fa_required or two_fa_enrollment_required, and $e->status is 200. The exception extends GhaymaException, so a broad catch (GhaymaException $e) still stops the sign-in; catch TwoFactorRequiredException first to offer the second factor.

Errors

Every failure is a Ghayma\Sdk\Exception\GhaymaException carrying status, errorCode and (on a 429) retryAfter. Catch the base type broadly, or a subclass to branch:

Exception Raised when
UnauthorizedException 401 — missing, malformed or expired credentials
ForbiddenException 403 — valid credentials, not entitled to the route or action
NotFoundException 404 — no such resource for these credentials
RateLimitedException 429 — too many requests; retryAfter holds the cooldown in seconds when known
InvalidGrantException an expired or already-spent token/code (code: invalid_grant)
InvalidTokenException a token that failed verification (code: invalid_token)
NetworkException a transport failure before any HTTP status (status 0)
TwoFactorRequiredException an OAuth sign-in stopped at the second factor (status 200); result holds the pending step, see Second factor on OAuth sign-in

Bring your own HTTP client

The constructors accept an optional PSR-18 client and PSR-17 request/stream factories; when omitted, they are discovered:

Laravel

No facade or companion package is required — bind the clients in a service provider:

Then type-hint Ghayma or GhaymaAuth anywhere the container resolves. Laravel's Guzzle satisfies the PSR-18/17 discovery. Forward the visitor's IP with $request->header('X-Real-IP').

Contracts and conformance

Every wire shape comes from the two vendored OpenAPI contracts in Prism mock of each and runs the SDK against them; tool/sync-spec.sh refreshes the vendored copies from the served documents.

License

MIT © Throct


All versions of sdk with dependencies

PHP Build Version
Package Version
Requires php Version >=8.2
psr/http-client Version ^1.0
psr/http-factory Version ^1.0
psr/http-message Version ^2.0
php-http/discovery Version ^1.19
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 ghayma/sdk contains the following files

Loading the files please wait ...