PHPackages                             phraseanet/php-sdk - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. phraseanet/php-sdk

ActiveLibrary[API Development](/categories/api)

phraseanet/php-sdk
==================

A library to interact with Phraseanet API

7.0.1(5y ago)819.4k15[2 PRs](https://github.com/alchemy-fr/Phraseanet-PHP-SDK/pulls)1MITPHPPHP ^7.2CI failing

Since Mar 11Pushed 1y ago10 watchersCompare

[ Source](https://github.com/alchemy-fr/Phraseanet-PHP-SDK)[ Packagist](https://packagist.org/packages/phraseanet/php-sdk)[ RSS](/packages/phraseanet-php-sdk/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (5)Versions (60)Used By (1)

Phraseanet API PHP-SDK
======================

[](#phraseanet-api-php-sdk)

[![License](https://camo.githubusercontent.com/243f7c7cfc3ecc764139ecc4072fe01cfa1e88457b7e0deb065c7050e7e834f4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f706872617365616e65742f7068702d73646b2e7376673f7374796c653d666c61742d737175617265)](https://github.com/alchemy-fr/Phraseanet-PHP-SDK/LICENSE)[![Packagist](https://camo.githubusercontent.com/b8fd4b3fd2c88315c98f6e9ce5c8318b23881324fd77a5b4a1e281b3a446c320/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f706872617365616e65742f7068702d73646b2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/phraseanet/php-sdk)[![Travis](https://camo.githubusercontent.com/e013e030f02382d2ba4e5d2ffb498d1af1a7a3fb624f4169a9f1664a13166192/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f616c6368656d792d66722f506872617365616e65742d5048502d53444b2e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/alchemy-fr/Phraseanet-PHP-SDK)[![Scrutinizer Coverage](https://camo.githubusercontent.com/e40ce63ace81fa9dc4d26be6708801da2212150afe4edd762b98b9d22a8ea80b/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f616c6368656d792d66722f506872617365616e65742d5048502d53444b2e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/alchemy-fr/Phraseanet-PHP-SDK/?branch=master)[![Scrutinizer](https://camo.githubusercontent.com/3aa442bb36fe5861b09fcd7c341c02488cb94ae11b489353bc5df1137f32ecd7/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f616c6368656d792d66722f506872617365616e65742d5048502d53444b2e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/alchemy-fr/Phraseanet-PHP-SDK/)[![Packagist](https://camo.githubusercontent.com/80dcb16cc5d8632fc5626488441f2d171be9f1ce528147bde81d4fa6ddc3a2cd/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f706872617365616e65742f7068702d73646b2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/phraseanet/php-sdk/stats)

The Phraseanet PHP SDK is an OO library to interact with [Phraseanet API](https://docs.phraseanet.com/Devel).

Install
-------

[](#install)

The recommended way to install Phraseanet PHP SDK is [through composer](http://getcomposer.org).

```
composer require phraseanet/php-sdk:^0.9
```

Basic Usage
-----------

[](#basic-usage)

### Create the application

[](#create-the-application)

Here is the minimum to create the Phraseanet SDK Application ; please note that client `client-id`, `url` and `secret` a required. Please refer to the [online documentation](https://docs.phraseanet.com/3.7/en/Devel/ApplicationDeveloper.html)to get more more information about generating those.

```
$app = PhraseanetSDK\Application::create(array(
    'client-id' => '409ee2762ff49ce936b2ca6e5413607a',
    'secret'    => 'f53ea9b0da92e45f9bbba67439654ac3',
    'url'       => 'https://your.phraseanet-install.com/', // Phraseanet install URI
));
```

### Getting an oauth token

[](#getting-an-oauth-token)

Once the application is created, a token is required to query the API. There are two ways :

#### Developer token

[](#developer-token)

The developer token can be retrieved from Phraseanet developer application panel (My account &gt; developer &gt; applications).

#### OAuth2 authentication flow

[](#oauth2-authentication-flow)

Phraseanet SDK provides a convenient way to retrieve an oauth token. Use the OAuth2Connector for that :

- Redirect the end user to the Phraseanet authorization URL :

```
// Must be identical to the redirect URI set in your Oauth application configuration in Phraseanet.
$redirectUri = 'http://myhost.dev/oauth-callback-endpoint/';
$connector = $app->getOauth2Connector();
$url = $connector->getAuthorizationUrl($redirectUri);
```

Note that extra parameters can be passed to the `getAuthorizationUrl` method. Please refer to the [online documentation](https://docs.phraseanet.com/Devel)about available parameters.

- Retrieve an access token in your application callback :

```
$connector = $app->getOauth2Connector();
$token = $connector->retrieveAccessToken($code, $redirectUri);
```

Once you have the token, you can use the `EntityManager`.

### Use the EntityManager

[](#use-the-entitymanager)

The `EntityManager` is the entry point to retrieve Phraseanet entities.

```
$em = $app->getEntityManager($token);

$query = $em->getRepository('Record')->search(array(
    'query'        => 'animals',
    'offset_start' => 0,
    'per_page'     => 20,
    'bases'        => array(1, 4),
    'record_type'  => 'image'
));

echo $query->getTotalResults() . " items found in " . $query->getQueryTime() . " seconds\n";

foreach($query->getResults() as $record) {
    echo "Record " . $record->getTitle() . "\n".
    foreach ($record->getSubdefs() as $subdef) {
        echo "subdef ". $subdef->getName() ." has URL " . $subdef->getPermalink()->getUrl() . "\n";
    }
}
```

### Uploading files to Phraseanet

[](#uploading-files-to-phraseanet)

Files can be uploaded to Phraseanet using the uploader instance exposed via the `Application` object:

```
$uploader = $app->getUploader($token);

$result = $uploader->upload('/path/to/file.jpg', $base_id);

if ($result instanceof PhraseanetSDK\Entity\Record) {
    // record has been created
} elseif ($result instanceof PhraseanetSDK\Entity\Quarantine) {
    // record has been quarantined
}
```

`$base_id` can be either a `base_id` value or a `PhraseanetSDK\Entity\DataboxCollection`entity.

Please note that you can force the behavior with the third argument and pass a Phraseanet record status (binary string) as fourth argument :

```
$result = $loader->upload('/path/to/file.jpg', $base_id, $behavior, '1011000');
```

Behavior can be either :

- 0 to force record
- 1 to force quarantine
- null to let Phraseanet check (default behavior)

Configuration
-------------

[](#configuration)

### Extended API Response format

[](#extended-api-response-format)

The Phraseanet API (v1.4.1) can provide extended Response format for Record Object.

In this case all relations to Record object (permalink, sub-definitions, caption, status) are included in the response.

The result is that with this feature you need only one request to populate a whole Record object instead of five.

The time to hydrate record object is slightly higher but is ridiculously tiny compared to the time spent over HTTP protocol to fetch relations data.

```
$app = PhraseanetSDK\Application::create(array(
    'client-id' => '409ee2762ff49ce936b2ca6e5413607a',
    'secret'    => 'f53ea9b0da92e45f9bbba67439654ac3',
    'url'       => 'https://your.phraseanet-install.com/'
));

$token = '899ee278736b2an6bs786e541ajk8';

// activate globally
$app->getAdapter()->setExtended(true);

// activate for current entity manager
$em = $app->getEntityManager($token);
$em->getAdapter()->setExtended(true);
```

### Log

[](#log)

Request can be logged for monitor or debug purpose by setting a PSR Logger in the configuration. See

See  for log plugin configuration

```
use Psr\Log\LoggerInterface;

class QueryLogger extends LoggerInterface
{
    ...
}
```

```
use PhraseanetSDK\Application;
use Guzzle\Log\PsrLogAdapter;
use Guzzle\Plugin\Log\LogPlugin;

$client = Application::create(array(
    'client-id' => '409ee2762ff49ce936b2ca6e5413607a',
    'secret'    => 'f53ea9b0da92e45f9bbba67439654ac3',
    'url'       => 'https://your.phraseanet-install.com/'
), array(new LogPlugin(new PsrLogAdapter(new QueryLogger())));
```

### Cache

[](#cache)

For performance, it is strongly recommended to use a cache system. This can be easily done using the following configuration.

See  for cache plugin configuration.

```
use PhraseanetSDK\Application;
use Doctrine\Common\Cache\FilesystemCache;
use Guzzle\Cache\DoctrineCacheAdapter;
use Guzzle\Plugin\Cache\CachePlugin;
use Guzzle\Plugin\Cache\DefaultCacheStorage;

$cachePlugin = new CachePlugin(array(
    'storage' => new DefaultCacheStorage(
        new DoctrineCacheAdapter(
            new FilesystemCache('/path/to/cache/files')
        )
    )
));

$client = Application::create(
    array(
        'client-id' => '409ee2762ff49ce936b2ca6e5413607a',
        'secret'    => 'f53ea9b0da92e45f9bbba67439654ac3',
        'url'       => 'https://your.phraseanet-install.com/',
    ), array($cachePlugin));
```

Silex Provider
--------------

[](#silex-provider)

A [Silex](http://silex.sensiolabs.org/) provider is bundled within this package.

### Basic usage

[](#basic-usage-1)

```
$app = new Silex\Application();
$app->register(new PhraseanetSDK\PhraseanetSDKServiceProvider(), array(
    // required
    'sdk.config' => array(
        'client-id' => $clientId, // Your client id
        'secret'    => $secret, // You client secret
        'url'       => $url, // The ur of the phraseanet instance where you have created your application
    ),
    // optional
    'cache.config' => array(
        'type' => 'array', // can be 'array', 'memcache' or 'memcached'. Default value is 'array'.
        // options for memcache(d) cache type
        'options' => array(
            'host' => '127.0.0.1',
            'port' => '11211'
        )
        'ttl'  => '3600', // cache TTL in seconds. Default value is '3600'.
        'revalidation' => null, // cache re-validation strategy can be null, 'skip' or 'deny' or an object that implements 'Guzzle\Plugin\Cache\RevalidationInterface'
                                // Default value is null.
                                // skip : never performs cache re-validation and just assumes the request is still ok
                                // deny : never performs cache re-validation and just assumes the request is invalid
                                // The default strategy if null is provided is to follow HTTP RFC. see https://tools.ietf.org/html/draft-ietf-httpbis-p4-conditional-26
                                // and https://tools.ietf.org/html/draft-ietf-httpbis-p6-cache-26
        'can_cache' => null,    // can cache strategy can be null or an object that implements 'Guzzle\Plugin\Cache\CanCacheStrategyInterface'
        'key_provider' => null, // key provider strategy can be null or an object that implements 'Guzzle\Plugin\Cache\CacheKeyProviderInterface'
    ),
    'recorder.enabled' => false, // Enabled recorder
    'recorder.config' => array(
        'type' => 'file', // specified type of storage can be 'file', 'memcache' or 'memcached'. Default value is file
        'options' => array(
            'file' => '/path/to/file', // specified path to the file to write data, if specified type is file
            'host' => '127.0.0.1', // specified host to the memcache(d) server , if specified type is memcache or memcached
            'port' => '33', // specified port to the memcache(d) server, if specified type is memcache or memcached
        ),
        'limit' => 1000, // specified limit of request to store
    )
));
```

Record / Play requests
----------------------

[](#record--play-requests)

### Recorder

[](#recorder)

Recorder can be enabled per requests through service provider using the following code :

```
$app = new Silex\Application();
$app->register(new PhraseanetSDK\PhraseanetSDKServiceProvider(), array(
    'sdk.config' => array(
        'client-id' => $clientId,
        'secret'    => $secret,
        'url'       => $url,
    ),
    'recorder.enabled' => true,
    'recorder.config' => array(
        'type' => 'memcached',
        'options' => array(
            'host' => 'localhost',
            'port' => 11211,
        ),
        'limit' => 5000 // record up to 5000 requests
    ),
));
```

Requests can be store either in `memcache`, `memcached` or `file`. To use file, configuration should look like :

```
$app = new Silex\Application();
$app->register(new PhraseanetSDK\PhraseanetSDKServiceProvider(), array(
    'recorder.config' => array(
        'type' => 'memcached',
        'options' => array(
            'host' => '127.0.0.1',
            'port' => '/path/to/file',
        ),
        'limit' => 5000 // record up to 5000 requests
    ),
));
```

### Player

[](#player)

To replay stored requests, use the player

```
$player = $app['phraseanet-sdk.player.factory']($token);
$player->play();
```

Please note that, in order to play request without using cache (to warm it for example), you must use the `deny` cache re-validation strategy :

```
$app->register(new PhraseanetSDK\PhraseanetSDKServiceProvider(), array(
    'sdk.config' => array(
        'client-id' => $clientId,
        'secret' => $secret,
        'url' => $url,
    ),
    'cache.config' = array(
        'revalidation' => 'deny',  // important
    )
));
```

Monitor
-------

[](#monitor)

SDK provides a tool to monitor Phraseanet :

```
$monitor = $app->getMonitor($token);
$scheduler = $monitor->getScheduler();

echo sprintf("Scheduler state is %s", $scheduler->getState());
```

License
-------

[](#license)

Phraseanet SDK is released under the MIT license.

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance27

Infrequent updates — may be unmaintained

Popularity33

Limited adoption so far

Community27

Small or concentrated contributor base

Maturity72

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~76 days

Recently: every ~241 days

Total

55

Last Release

676d ago

Major Versions

0.10.10 → 1.0.02021-01-18

1.0.0 → 6.0.02021-02-16

1.x-dev → 6.0.12021-02-23

6.0.1 → 7.x-dev2021-02-24

PHP version history (6 changes)0.1.0PHP &gt;=5.3.2

0.5.0PHP &gt;5.3.3

0.8.0PHP &gt;5.4

0.9.0PHP &gt;=5.5

1.x-devPHP ^7.1

7.x-devPHP ^7.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/3c264f69af4c60cb9cc98a522b4663f4b6a2708629cabc14409478ab6fc35348?d=identicon)[romain](/maintainers/romain)

![](https://www.gravatar.com/avatar/1065e5ef9f8a67da432f1edbb8302b5e19c246102892534f1a2e524559b083a4?d=identicon)[nlegoff](/maintainers/nlegoff)

---

Top Contributors

[![romainneutron](https://avatars.githubusercontent.com/u/137574?v=4)](https://github.com/romainneutron "romainneutron (152 commits)")[![nlegoff](https://avatars.githubusercontent.com/u/511494?v=4)](https://github.com/nlegoff "nlegoff (142 commits)")[![aztech-dev](https://avatars.githubusercontent.com/u/93562568?v=4)](https://github.com/aztech-dev "aztech-dev (30 commits)")[![bburnichon](https://avatars.githubusercontent.com/u/2437286?v=4)](https://github.com/bburnichon "bburnichon (19 commits)")[![xrousset78800](https://avatars.githubusercontent.com/u/3024133?v=4)](https://github.com/xrousset78800 "xrousset78800 (13 commits)")[![aynsix](https://avatars.githubusercontent.com/u/35221835?v=4)](https://github.com/aynsix "aynsix (5 commits)")[![nmaillat](https://avatars.githubusercontent.com/u/1225962?v=4)](https://github.com/nmaillat "nmaillat (2 commits)")[![csaoh](https://avatars.githubusercontent.com/u/2509916?v=4)](https://github.com/csaoh "csaoh (2 commits)")[![chmeliuk](https://avatars.githubusercontent.com/u/1220015?v=4)](https://github.com/chmeliuk "chmeliuk (1 commits)")

---

Tags

Phraseanet

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/phraseanet-php-sdk/health.svg)

```
[![Health](https://phpackages.com/badges/phraseanet-php-sdk/health.svg)](https://phpackages.com/packages/phraseanet-php-sdk)
```

###  Alternatives

[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M651](/packages/sylius-sylius)[tencentcloud/tencentcloud-sdk-php

TencentCloudApi php sdk

3731.2M42](/packages/tencentcloud-tencentcloud-sdk-php)[ec-cube/ec-cube

EC-CUBE EC open platform.

78527.0k1](/packages/ec-cube-ec-cube)[thenbsp/wechat

微信公众平台第三方 SDK 开发包，优雅、健壮，可扩展，遵循 PSR 开发规范。

9408.2k](/packages/thenbsp-wechat)[dsc/mercado-livre

Client para integração com API do Mercado Livre

8138.7k](/packages/dsc-mercado-livre)[mapado/rest-client-sdk

Rest Client SDK for hydra API

1125.9k2](/packages/mapado-rest-client-sdk)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
