PHP code example of soulssoft / phraseanet-php-sdk
1. Go to this page and download the library: Download soulssoft/phraseanet-php-sdk library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
// 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);
$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
}
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())));
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));
$app = new Silex\Application();
$app->register(new PhraseanetSDK\PhraseanetSDKServiceProvider(), array(
// // 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
)
));