Download the PHP package castle/castle-php without Composer

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

PHP SDK for Castle

Specs Lint Latest Stable Version

Castle analyzes user behavior in web and mobile apps to stop fraud before it happens.

Usage

See the documentation for how to use this SDK with the Castle APIs

Requirements

PHP 7.2 or newer, with the curl and json extensions. The library is tested against PHP 7.2 through 8.5.

Getting started

Install the latest version with Composer:

Then load Composer's autoloader and configure the library with your Castle API secret:

Namespaces

As of 4.0 the library lives under the Castle\ namespace, e.g. Castle\Castle, Castle\Webhook, Castle\RequestContext, Castle\ApiError. This is the canonical API:

Backward compatibility

The historic global class names (Castle, Castle_*, RestModel) are kept as aliases of their namespaced counterparts, so existing integrations keep working without changes. Castle_ApiError and Castle\ApiError are the same class, so instanceof checks and catch blocks work with either name:

New code should prefer the namespaced names; the global aliases are retained for compatibility.

Optional Configurations

Set the per-request timeout in milliseconds (applied to both connection and transfer). Defaults to 1000:

Set the failover strategy used when a risk or filter request cannot be completed (see Failover):

Set a specified list of request headers to include with event context (optional, not recommended):

Request context

By default, Castle extracts all the necessary information, such as IP and request headers, from the PHP globals in order to build and send the requests to the Castle API. However in some cases you want to track data to Castle from a context where these globals are not available, eg. when tracking async in a background worker. In this case you can build the request context manually.

Origin IP Address

By default, the SDK extracts the contextual client IP address from headers in the following priority:

  1. X-Forwarded-For
  2. X-Real-Ip
  3. REMOTE_ADDR

If the true client IP address is not specified in the above headers, you can manually set the IP address like so:

Lists

Manage lists and their items:

List items:

Privacy

Request or delete the data Castle stores for a user:

Failover

When a risk or filter request cannot be completed because of a network error, timeout or a 5xx response from the Castle API, the SDK returns a synthetic decision instead of throwing, so your authentication flow keeps working. The decision is controlled by the failover strategy:

A failed-over response carries failover => true and a failover_reason:

Successful responses include failover => false. Client errors (4xx, such as 422 invalid_request_token) are never failed over and always raise.

Do-not-track

Disable outbound tracking calls, for example in staging or test environments. While disabled, risk, filter and log return an allow response without contacting the API:

Events (enterprise)

Query event data:

Webhooks

Verify the authenticity of incoming Castle webhooks. By default the raw body is read from php://input and the signature from the X-Castle-Signature header:

The body and signature can also be passed explicitly:

Errors

Whenever something unexpected happens, an exception is thrown to indicate what went wrong.

Name Description
Castle_Error A generic error
Castle_RequestError A request failed. Probably due to a network error
Castle_ApiError An unexpected error for the Castle API
Castle_InternalServerError The Castle API returned a 5xx response (triggers failover)
Castle_ConfigurationError The Castle secret API key has not been set
Castle_UnauthorizedError Wrong Castle API secret key
Castle_PaymentRequiredError HTTP 402 response
Castle_BadRequest The request was invalid. For example if a challenge is created without the user having MFA enabled.
Castle_ForbiddenError The user has entered the wrong code too many times and a new challenge has to be requested.
Castle_NotFoundError The resource requestd was not found. For example if a session has been revoked.
Castle_InvalidParametersError One or more of the supplied parameters are incorrect. Check the response for more information.
Castle_InvalidRequestTokenError The request token parameter is missing or invalid
Castle_WebhookVerificationError An incoming webhook could not be verified against the X-Castle-Signature header

Running test suite

Install the dev dependencies and run the suite with:


All versions of castle-php with dependencies

PHP Build Version
Package Version
Requires php Version >=7.2
ext-curl Version *
ext-json Version *
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 castle/castle-php contains the following files

Loading the files please wait ...