All Projects → contentful → Contentful.php

contentful / Contentful.php

Licence: mit
Official PHP SDK for the Content Delivery API

Labels

Projects that are alternatives of or similar to Contentful.php

Stellar Ios Mac Sdk
Stellar SDK for iOS & macOS - Swift, Stellar, Horizon, Soneso
Stars: ✭ 92 (-8.91%)
Mutual labels:  sdk
Opentok Ruby Sdk
OpenTok Server SDK for Ruby
Stars: ✭ 97 (-3.96%)
Mutual labels:  sdk
Easywechat
📦 一个 PHP 微信 SDK
Stars: ✭ 9,676 (+9480.2%)
Mutual labels:  sdk
Algoliasearch Client Android
Algolia Search API Client for Android
Stars: ✭ 92 (-8.91%)
Mutual labels:  sdk
Nim ios uikit
网易云信 iOS UI 组件,提供聊天界面,文本消息,图片消息,语音消息,视频消息,地理位置消息,自定义消息(阅后即焚)等消息示例。#推荐客户得比特币,首次推荐得0.02BTC,连续推荐得0.03BTC/单,上不封顶。点击参与https://yunxin.163.com/promotion/recommend
Stars: ✭ 1,326 (+1212.87%)
Mutual labels:  sdk
Applicationinsights Php
Azure Application Insights SDK for PHP
Stars: ✭ 98 (-2.97%)
Mutual labels:  sdk
Cpm8266
Z80-CP/M2.2 emulation on ESP8266 NONOS SDK + the NoSDK from cnlohr
Stars: ✭ 91 (-9.9%)
Mutual labels:  sdk
Applicationinsights Dotnet Logging
.NET Logging adaptors
Stars: ✭ 100 (-0.99%)
Mutual labels:  sdk
Netcorecli Fsc
[DEPRECATED] F# and .NET Core SDK working together
Stars: ✭ 97 (-3.96%)
Mutual labels:  sdk
Wxpay
微信支付 wxpay SDK for Go, 集成简单,功能完善,持续更新。
Stars: ✭ 99 (-1.98%)
Mutual labels:  sdk
Kanvas
Make canvas easier to use in Kotlin 😊
Stars: ✭ 93 (-7.92%)
Mutual labels:  sdk
Go Sdk
Stars: ✭ 94 (-6.93%)
Mutual labels:  sdk
Quickblox Javascript Sdk
JavaScript SDK of QuickBlox cloud backend platform
Stars: ✭ 98 (-2.97%)
Mutual labels:  sdk
Xr871 Old
XR871 SDK
Stars: ✭ 92 (-8.91%)
Mutual labels:  sdk
Ios Print Sdk
iOS Print SDK. Easily add print on demand functionality to your app within minutes! Print Postcards, Magnets, Photo Prints, Posters, Stickers, T-Shirts, PhotoBooks, etc.
Stars: ✭ 99 (-1.98%)
Mutual labels:  sdk
Fvm
Flutter Version Management: A simple CLI to manage Flutter SDK versions.
Stars: ✭ 1,293 (+1180.2%)
Mutual labels:  sdk
Go Tfe
Terraform Cloud/Enterprise API Client/SDK in Golang
Stars: ✭ 98 (-2.97%)
Mutual labels:  sdk
Invest Openapi Go Sdk
Stars: ✭ 101 (+0%)
Mutual labels:  sdk
Shopify Api Php
🚀 Shopify API Client for PHP
Stars: ✭ 100 (-0.99%)
Mutual labels:  sdk
Douyinsdk
抖音 SDK,数据采集,爬虫抓取不是梦
Stars: ✭ 99 (-1.98%)
Mutual labels:  sdk

PHP

Join Contentful Community Slack   Join Contentful Community Forum

contentful.php — Contentful PHP Delivery SDK

Packagist PHP version Packagist CircleCI

PHP SDK for the Contentful Content Delivery API and Content Preview API. It helps you to easily access your Content stored in Contentful with your PHP applications.

What is Contentful?

Contentful provides content infrastructure for digital teams to power websites, apps, and devices. Unlike a CMS, Contentful was built to integrate with the modern software stack. It offers a central hub for structured content, powerful management and delivery APIs, and a customizable web app that enable developers and content creators to ship their products faster.

Table of contents

Core Features

Getting started

In order to get started with the Contentful PHP SDK you'll need not only to install it, but also to get credentials which will allow you to have access to your content in Contentful. This package requires PHP 7.2 or higher.

Installation

Install the library using Composer:

composer require contentful/contentful

Your first request

The following code snippet is the most basic one you can use to get some content from Contentful with this SDK: All interactions with the SDK go through Contentful\Delivery\Client. To create a new client an access token and a space ID have to be passed to the constructor.

$client = new \Contentful\Delivery\Client(
    'b4c0n73n7fu1', # This is the access token for this space. Normally you get both ID and the token in the Contentful web app
    'cfexampleapi' # This is the space ID. A space is like a project folder in Contentful terms
);

try {
    $entry = $client->getEntry('nyancat');
} catch (\Contentful\Core\Exception\NotFoundException $exception) {
    // Entry does not exist
}

Using this SDK with the Preview API

This SDK can also be used with the Preview API. In order to do so, you need to use the Preview API access token, available on the same page where you get the Delivery API token, and tell the client to use the different API:

$options = \Contentful\Delivery\ClientOptions::create()
    ->usingPreviewApi();
$client = new \Contentful\Delivery\Client($accessToken, $spaceId, $environmentId, $options);

You can find all available methods of our client in our reference documentation.

Authentication

To get your own content from Contentful, an app should authenticate with an OAuth bearer token.

You can create API keys using the Contentful web interface. Go to the app, open the space that you want to access (top left corner lists all the spaces), and navigate to the APIs area. Open the API Keys section and create your first token. Done.

Don't forget to also get your Space ID.

For more information, check the Contentful REST API reference on Authentication.

Documentation & References

Configuration

The ClientOptions class allows you to configure the client in a variety of different ways:

$options = \Contentful\Delivery\ClientOptions::create()
    ->usingPreviewApi()
    ->withDefaultLocale(string $defaultLocale = null)
    ->withHost(string $host)
    ->withLogger(Psr\Log\LoggerInterface $logger)
    ->withCache(Psr\Cache\CacheItemPoolInterface $cache, bool $autoWarmup = false, bool $cacheContent = false)
    ->withHttpClient(GuzzleHttp\Client $client)
    ->withoutMessageLogging()
;

$client = new \Contentful\Delivery\Client(
    string $accessToken,
    string $spaceId,
    string $environmentId = 'master',
    ClientOptions $options = null
);
Client parameter Default Description
$accessToken Required. Your access token
$spaceId Required. Your space ID
$environmentId 'master' Your environment ID
$options null A ClientOptions object
ClientOptions method Parameters Description
usingPreviewApi() - Use the Preview API host (preview.contentful.com)
withDefaultLocale() string $locale Set a locale to be automatically used for all requests
withHost() string $host A string to override the default Contentful API URL, useful if you have a proxy between your application and the Contentful API
withLogger() Psr\Log\LoggerInterface $logger A PSR-3 logger. Two types of logs are written: a generic one using either the INFO or ERROR level (depending on the response status code) with a brief summary, and a complete dump of request and response using the DEBUG level. We suggest to configure the logger minimum level according to your needs.
withCache() Psr\Cache\CacheItemPoolInterface $cache A PSR-6 cache item pool. This will be used to stored data such as content types and locales, which are always needed but don't change often
withCache() bool $autoWarmup = false When using a cache pool, set this to true to automatically fill the cache during regular use
withCache() bool $cacheContent = false When using a cache pool with $autoWarmup set to true, se this to true to fill the cache with entries and assets during runtime. This may speed up execution when calling $client->getEntry($entryId) and $client->getAsset($assetId), but not when calling the getEntries() and getAssets() methods, as the client can't reliably know which entries or assets will be returned by the API, and for this reason the cache can't intercept the call.
withHttpClient() GuzzleHttp\Client $client A Guzzle client instance, which can be configured with custom middleware
withoutMessageLogging() - Do not store API requests and responses (which can use a lot of memory). If messages are not stored, they will not be retrievable from Client::getMessages() for debugging and inspection purposes

Reference documentation

The PHP SDK reference documents what objects and methods are exposed by this library, what arguments they expect and what kind of data is returned.

Most methods also have examples which show you how to use them.

Tutorials & other resources

  • This library is a wrapper around our Contentful Delivery REST API. Some more specific details such as search parameters and pagination are better explained on the REST API reference, and you can also get a better understanding of how the requests look under the hood.
  • Check the Contentful for PHP page for Tutorials, Demo Apps, and more information on using PHP with Contentful.

Upgrade

For details about how to upgrade from version 3.x to version 4, please check the changelog entry for version 4.0.0 and the upgrade to version 4 guide.

For details about how to upgrade from version 2.x to version 3, please check the changelog entry for version 3.0.0 and the upgrade to version 3 guide.

Reach out to us

You have questions about how to use this library?

  • Reach out to our community forum: Contentful Community Forum
  • Jump into our community slack channel: Contentful Community Slack

You found a bug or want to propose a feature?

  • File an issue here on GitHub: File an issue. Make sure to remove any credential from your code before sharing it.

You need to share confidential information or have other questions?

  • File a support ticket at our Contentful Customer Support: File support ticket

Get involved

PRs Welcome

License

This repository is published under the MIT license.

Code of Conduct

We want to provide a safe, inclusive, welcoming, and harassment-free space and experience for all participants, regardless of gender identity and expression, sexual orientation, disability, physical appearance, socioeconomic status, body size, ethnicity, nationality, level of experience, age, religion (or lack thereof), or other identity markers.

Read our full Code of Conduct.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].