Installation guide
'Body' => fopen($file, 'r'),
));
echo "\nCreated a new object: {$result['ObjectURL']}\n";
You can also mount the facades into a namespace other than the global namespace. For example, if you wanted to
make the client facades available in the "Services" namespace, then you could do the following:
Aws::factory('/path/to/my_config.php')->enableFacades('Services');
$result = Services\DynamoDb::listTables();
The client facades that are available are determined by what is in your service builder configuration (see Configuring
the SDK). If you are extending the SDK's default configuration file or not providing one at all, then all of the clients
should be accessible from the service builder instance and client facades (once enabled) by default.
Based on the following excerpt from the default configuration file (located at
src/Aws/Common/Resources/aws-config.php):
's3' => array(
'alias' => 'S3',
'extends' => 'default_settings',
'class' => 'Aws\S3\S3Client'
),
The 'class' key indicates the client class that the static client facade will proxy to, and the 'alias' key
indicates what the client facade will be named. Only entries in the service builder config that have both the
'alias' and 'class' keys specified will be mounted as static client facades. You can potentially update or add
to your service builder config to alter or create new or custom client facades.
Testing Code that Uses Client Facades
With the static client facades in the SDK, even though you are calling static classes, all of the method calls are
proxied to method calls on actual client instances — the ones stored in the service builder. This means that they can
be mocked during tests, which removes one of the general disadvantages to using static classes in object-oriented
programming.
To mock a client facade for a test, you can explicitly set a mocked client object for the key in the service builder that
would normally contain the client referenced by the client facade. Here is a complete, but contrived, PHPUnit test
showing how this is done:
<?php
use Aws\Common\Aws;
use Guzzle\Service\Resource\Model;
use YourApp\Things\FileBrowser;
class SomeKindOfFileBrowserTest extends PHPUnit_Framework_TestCase
{
private $serviceBuilder;
public function setUp()
{
$this->serviceBuilder = Aws::factory();
$this->serviceBuilder->enableFacades();
}
public function testCanDoSomethingWithYourAppsFileBrowserClass()
{
// Mock the ListBuckets method of S3 client
$mockS3Client = $this->getMockBuilder('Aws\S3\S3Client')
->disableOriginalConstructor()
->getMock();
$mockS3Client->expects($this->any())
Static Client Facades
41