/**
  * {@inheritDoc}
  * @return FileConversionClient
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     /** @var \Detail\FileConversion\Options\ModuleOptions $moduleOptions */
     $moduleOptions = $serviceLocator->get('Detail\\FileConversion\\Options\\ModuleOptions');
     $clientOptions = $moduleOptions->getClient();
     /** @var \Detail\FileConversion\Client\Job\JobBuilder $jobBuilder */
     $jobBuilder = $serviceLocator->get('Detail\\FileConversion\\Client\\Job\\JobBuilder');
     return FileConversionClient::factory($clientOptions->toArray(), $jobBuilder);
 }
예제 #2
0
<?php

use Detail\FileConversion\Client\FileConversionClient;
$config = (require '../bootstrap.php');
$imageUrl = isset($_GET['image_url']) ? $_GET['image_url'] : null;
if (!$imageUrl) {
    throw new RuntimeException('Missing or invalid parameter "image_url"');
}
$imageSize = isset($_GET['image_size']) ? $_GET['image_size'] : 200;
$image = new SplFileInfo($imageUrl);
$imageName = $image->getBasename();
$getConfig = function ($optionName) use($config) {
    if (!isset($config[$optionName])) {
        throw new RuntimeException(sprintf('Missing configuration option "%s"', $optionName));
    }
    return $config[$optionName];
};
$client = FileConversionClient::factory($config);
/** @var \Detail\FileConversion\Client\Job\JobBuilder $jobBuilder */
$jobBuilder = $client->getJobBuilder();
$jobBuilder->setDefaultOption('action.save', array('type' => 's3', 'params' => array('bucket' => $getConfig('s3bucket'))));
$job = $jobBuilder->createJob()->setSourceUrl($imageUrl)->addAction($jobBuilder->createAction()->setName('thumbnail')->setParams(array('size' => $imageSize))->setSaveOptions(array('identifier' => $imageName, 'params' => array('key' => $getConfig('s3path') . '/' . $imageName . '-' . $imageSize . '_dfw-fileconversion.jpg'))));
try {
    $job->addNotification($jobBuilder->createNotification()->setParams(array('url' => $getConfig('notification_url'))));
} catch (RuntimeException $e) {
    // Do nothing when no notification URL is provided (job will be created without notification)
}
$response = $client->submitJob($job);
var_dump($response->getResult());
 public function testJobBuilderCanBeSet()
 {
     $client = FileConversionClient::factory();
     $this->assertInstanceOf(JobBuilder::CLASS, $client->getJobBuilder());
     $jobBuilder = new JobBuilder();
     $this->assertEquals($client, $client->setJobBuilder($jobBuilder));
     $this->assertEquals($jobBuilder, $client->getJobBuilder());
 }