contentful / contentful
SDK for the Contentful Content Delivery API
Installs: 2 861 320
Dependents: 15
Suggesters: 0
Security: 0
Stars: 114
Watchers: 33
Forks: 63
Open Issues: 5
Requires
- php: ^8.0
- contentful/core: ^4.0
- contentful/rich-text: ^4.0
- psr/cache: ^2.0|^3.0
- psr/log: ^1.0|^2.0|^3.0
- symfony/cache: ^5.0|^6.0|^7.0
- symfony/console: ~2.7|~3.0|~4.0|^5.0|^6.0|^7.0
- symfony/filesystem: ~2.7|~3.0|~4.0|~5.0|^6.0|^7.0
Requires (Dev)
- covergenius/phpunit-testlistener-vcr: 3.3.1
- php-vcr/php-vcr: ^1.6.3
- phpstan/phpstan: ^1.9
- phpunit/phpunit: ^8.5
- roave/backward-compatibility-check: ^7.1|^8.0
- dev-master
- v7.1.0
- v7.0.2
- 7.0.1
- v7.0.0
- 6.4.0
- 6.3.0
- 6.2.0
- 6.1.0
- 6.0.5
- 6.0.4
- 6.0.3
- 6.0.2
- 6.0.1
- 6.0.0
- 5.0.2
- 5.0.0
- 4.1.4
- 4.1.3
- 4.1.2
- 4.1.1
- 4.1.0
- 4.0.2
- 4.0.1
- 4.0.0
- 3.4.0
- 3.3.0
- 3.2.3
- 3.2.2
- 3.2.1
- 3.2.0
- 3.1.0
- 3.0.2
- 3.0.1
- 3.0.0
- 3.0.0-beta1
- 2.4.1
- 2.4.0
- 2.3.0
- 2.2.0
- 2.1.0
- 2.0.1
- 2.0.0
- 1.2.0
- 1.1.0
- 1.0.0
- 0.8.1-beta
- 0.8.0-beta
- 0.7.0-beta
- 0.6.5-beta
- 0.6.4-beta
- 0.6.3-beta
- 0.6.2-beta
- 0.6.1-beta
- 0.6.0-beta
- dev-add-catalog-info
- dev-lint-fix
- dev-Fix-NotWorkingCacheItem
- dev-6.2.0-bc-break-fix
- dev-php8-support
- dev-fix/php-stan-suggested-fixes
- dev-fix/php-134-circleci-badge
- dev-fix/PHP-130-self-reference-edge-cases
- dev-feature/php74-support
- dev-281-bump-up-requrired-rich-text-version
- dev-PHP-123-decrement-max-depth-for-separate-calls
- dev-PHP-52-replace-travis-with-circle
- dev-fix/270-build-entry-with-locale-fallback
- dev-fix/cs-fixer
- dev-fix/PHP-97-incorrect-merge
- dev-fix/unix-timestamp
This package is auto-updated.
Last update: 2024-10-09 09:56:33 UTC
README
contentful.php — Contentful PHP Delivery Library
PHP library 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
- contentful.php — Contentful PHP Delivery library
- What is Contentful?
- Core Features
- Getting started
- Installation
- Your first request
- Using this library with the Preview API
- Authentication
- Documentation & References
- Configuration
- Reference documentation
- Tutorials & other resources
- Upgrade
- Reach out to us
- You have questions about how to use this library?
- You found a bug or want to propose a feature?
- You need to share confidential information or have other questions?
- Get involved
- License
- Code of Conduct
Core Features
- Content retrieval through the Content Delivery API and Content Preview API.
- Synchronization
- Localization support
- Link resolution
Getting started
In order to get started with the Contentful PHP library 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 or PHP 8.0 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 library:
All interactions with the library 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 library with the Preview API
This library 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() ->withQueryCache(Psr\Cache\CacheItemPoolInterface $queryCacheItemPool, int $queryCacheLifetime = 0) ; $client = new \Contentful\Delivery\Client( string $accessToken, string $spaceId, string $environmentId = 'master', ClientOptions $options = null );
Reference documentation
The PHP library 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?
You found a bug or want to propose a feature?
- File an issue here on GitHub: . Make sure to remove any credential from your code before sharing it.
You need to share confidential information or have other questions?
Get involved
Important: Right now, the API has php-vcr
as a development dependency, which does not officially support PHP8 yet. If you want to develop on PHP8, you will need to install the dependencies with composer install --ignore-platform-reqs
to overwrite this requirement.
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.