Download the PHP package sphere/php-sdk without Composer

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

Composable Commerce PHP SDK

:warning: **This Composable Commerce PHP SDK is deprecated effective 1st September 2022., We recommend to use our PHP SDK V2.

Build Status Scrutinizer Scrutinizer Packagist Packagist

The PHP SDK allows developers to integrate with Composable Commerce APIs using PHP native interfaces, models and helpers instead of manually using the HTTP and JSON API.

You gain lots of IDE Auto-Completion, type checks on a literal API, Warnings, Object Mapping, i18n support etc.. The Client manages the OAuth2 security tokens, provides caches and interfaces for concurrent and asynchronous API calls.

The SDK is licensed under the permissive contribute!

Using the SDK

The PHP API documentation provides all the details you need in a searchable form (link points to latest stable release).

Install & Integrate the SDK into your Project

The SDK requires a PHP version of 5.6 or higher. The SDK tries to use the APC(u) as it's default cache. If you provide a PSR-6 or PSR-16 compliant cache adapter, APC(u) is not necessary. The cache/filesystem-adapter is tried to be used if no APC(u) is installed.

The curl extension is recommended but not strictly necessary because the SDK is using the Guzzle library library, which falls back to PHP stream wrappers if curl is not available. The intl extension is required to directly output Money objects as a String.

The recommended way to install the SDK is through Composer.

Next, run the Composer command to install the latest version of the SDK:

The SDK supports Guzzle6 as well as Guzzle5 as HTTP client. For Guzzle6:

When you want to use Guzzle5 you have to ensure react/promise at minimum version 2.2:

After installing, you need to require Composer's autoloader if that's not yet the case:

If you don't use Composer, just download a zip archive of the latest release, manually integrate it and configure your own autoloader.

The project follows the semantic versioning guidelines, i.e. everything but major version changes are backwards-compatible. This matches composer's default behavior.

With composer just run composer update commercetools/php-sdk to update to compatible versions. Edit your composer.json file to update to incompatible versions.

Please read the Changelog before updating in any case.

Getting started

To get up and running, create a free test Project on Composable Commerce. You can create your first API Client in The Merchant Center (Menu "Settings"->"Developer settings"->"Create new API client"). You need to select the template for the "Admin client".

If you prefer not to have a client with all admin rights, you need to explicitly include the client's permission scopes that you selected when creating the client, on the client's configuration:

In projects you will not put your API credentials directly into code but use a config file or your framework's config or dependency injection system for that.

Using the client factory

When using a Guzzle version of 6 or greater, it's also possible to use a preconfigured Guzzle client using the client factory. At the moment this is limited to client credentials authentication flow.

Synchronous execution

Asynchronous execution

The asynchronous execution will return a promise to fulfill the request.

Batch execution

By filling the batch queue and starting the execution all requests will be executed in parallel.

Using a logger

The client uses the PSR-3 logger interface for logging requests and deprecation notices. To enable logging provide a PSR-3 compliant logger (e.g. Monolog).

Using a cache adapter

The client will automatically request an OAuth token and store the token in the provided cache.

It's also possible to use a different cache adapter. The SDK provides a Doctrine, a Redis and an APCu cache adapter. By default the SDK tries to instantiate the APCu or a PSR-6 filesystem cache adapter if there is no cache given. E.g. Redis:

Using cache and logger

Middlewares

Adding middlewares to the clients for Composable Commerce as well for the authentication can be done using the config by setting client options.

For using a custom HandlerStack

For using an array of middlewares

Timeouts

The clients are configured to timeout by default after 60 seconds. This can be changed by setting the client options in the Config instance

Another option is to specify the timeout per request

Retrying

As a request can error in multiple ways it's possible to add a retry middleware to the client config. E.g.: Retrying in case of service unavailable errors

Using the phar distribution

Since version 1.6 the SDK is also released as a PHAR. You can find them in the releases section at Github.

Usage example:

Improve & Contribute to the SDK project

Mac OS X preparations:

assuming Homebrew is installed, do the following:

Linux preparations :

Windows preparations:

Start working:

Clone the develop branch of the repository (we're using the gitflow branching model, so master is for releases only):

Please follow the PSR-2 coding style, ideally via your IDE settings (see below for PhpStorm instructions).

Please make sure that exiting Unit and Integration tests don't fail and fully cover your new code with Unit Tests. You can run all tests locally:

Built In Test Server

You can use the docroot directory with the built-in PHP web server. Add to the docroot directory a file called "myapp.yml". Add following content and setup with your API credentials:

Then activate the php builtin web server

Now navigate to http://localhost:8000 in your browser.

PhpStorm configuration

To enable code style checks directly in PhpStorm you have to configure the path to the phpcs at Preferences > Languages & Frameworks > PHP > Code Sniffer. Now you can enable at Preferences > Editor > Inspections > PHP the "PHP code sniffer validation" with PSR-2 standard. Change the severity if needed.

Running integration tests

For running the integration tests you need an empty Project and have to create an API client using the commercetools Merchant Center with the scopes:

Local environment

Using docker

Running the test image:

Contribute

On bigger effort changes, please open a GitHub issue and ask if you can help or get help with your idea. For typos and documentation improvements just make a pull request.

Then:

  1. fork the repository on GitHub
  2. code and add tests that cover the created code. Your code should be warning-free.
  3. stick to PSR-2 and and don't reformat existing code.
  4. make a pull request. @jenschude will review it and pull or come back to you.

All versions of php-sdk with dependencies

PHP Build Version
Package Version
Requires php Version >=5.6
psr/log Version ^1.0 || ^2.0
guzzlehttp/guzzle Version ^7.0 || ^6.0 || ^5.3.3
guzzlehttp/psr7 Version ^1.7 || ^2.0
psr/cache Version ^1.0 || ^2.0 || ^3.0
psr/simple-cache Version ^1.0
cache/apcu-adapter Version ^1.0 || ^0.3 || ^0.2
paragonie/random_compat Version ^2.0 || ^1.0 || ^9.99
ext-intl 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 sphere/php-sdk contains the following files

Loading the files please wait ....