Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extract Protected Request Response from AWS SDK for PHP

I'm working with the new Amazon ElasticTranscoder service, and am new to working with the AWS-SDK. I have a successful script created that runs a createJob request, transcoding an Amazon S3 file from one format to another.

The problem is, I can't seem to access the response $data that is returned when the request is made. I can see it, and it contains the information I need, but I receive this error when I attempted to store it:

Fatal error: Cannot access protected property Guzzle\Service\Resource\Model::$data

Here's what my request looks like:

<?php
// Include the SDK
require 'aws.phar';
use Aws\ElasticTranscoder\ElasticTranscoderClient;

// Setup the trancoding service tool(s)
$client = ElasticTranscoderClient::factory( array(
    'key' => 'XXXXXXXXX',
    'secret' => 'XXXXXXXXX',
    'region' => 'us-east-1'
) );

// Create a new transcoding job
$file_name = '1362761118382-lqg0CvC1Z1.mov';
$file_name_explode = explode( '.', $file_name );

$webm_transcode_request = $client->createJob( array(
    'PipelineId' => '1362759955061-7ad779',
    'Input' => array(
        'Key' => $file_name,
        'FrameRate' => 'auto',
        'Resolution' => 'auto',
        'AspectRatio' => 'auto',
        'Interlaced' => 'auto',
        'Container' => 'auto',
    ),
    'Output' => array(
        'Key' => $file_name_explode[0] . '.webm',
        'ThumbnailPattern' => $file_name_explode[0] . '-thumb-{resolution}-{count}',
        'Rotate' => '0',
        'PresetId' => '1363008701532-b7d529' // BenchFly MP4
    )
) );

// Print the response data
echo '<pre>';
var_dump( $webm_transcode_request->data );
echo '</pre>';
?>

I've been banging my head against the wall trying to find some documentation on handling response requests with PHP and the AWS SDK, any help is very much appreciated.

like image 281
Kevin Leary Avatar asked Mar 21 '13 17:03

Kevin Leary


1 Answers

You have two options:

  1. Use the toArray() method, listed under "Methods inherited from Guzzle\Common\Collection" in the docs.

    e.g.

    $webm_transcode_request->toArray();
    
  2. Just directly access indexes of the $data property as if they were indexes of the response object. This works because the Guzzle\Service\Resource\Model class implements PHP's magic ArrayAccess interface to make array-like access operate on the $data property.

    e.g.

    $response = $ec2Client->describeInstances();
    
    // Gets the value of the 'Reservations' key of the protected `$data` property
    // of `$response`
    var_dump($response['Reservations']);
    
like image 191
iPhoney Avatar answered Nov 07 '22 13:11

iPhoney