Permalink
Browse files

Revised README file.

  • Loading branch information...
1 parent f0c4a39 commit 00ac458c5753cd7d0f648cdd65ea85d454fc54c4 unknown committed Feb 14, 2012
Showing with 94 additions and 72 deletions.
  1. +4 −0 .gitignore
  2. +0 −24 README
  3. +90 −48 lib/example.php → README.markdown
View
4 .gitignore
@@ -0,0 +1,4 @@
+
+/.buildpath
+/.project
+/phpdoc.ini
View
24 README
@@ -1,24 +0,0 @@
-PHP Object Storage client
-
--. Overview
-PHP client
--. Install
-Unzip the files and make sure to include Swift/Util.php once somewhere your script
-
-- Requirements
- Mandatory
- PHP version > 5.2
- Optional
- Zend Framework (for HTTP Client)
- CURL
-
-- Doc
-Documents are generated by PHPDocumentor. See docs directory for details.
-
-- Tests
-The test cases are run using phpunit version PHPUnit 3.5.13
-To run a test, provide your object storage credentials in test/BaseTest.php file.
-
-- Examples
-
-See lib/example.php and test cases.
View
138 lib/example.php → README.markdown
@@ -1,4 +1,30 @@
-<?php
+SoftLayer Object Storage PHP Client
+====================================
+PHP bindings for SoftLayer Object Storage
+
+
+# Install
+Unzip the files and make sure to include Swift/Util.php once somewhere your script
+
+# Requirements
+ * Mandatory
+ * PHP version > 5.2
+ * Optional
+ * Zend Framework (for HTTP Client)
+ * CURL
+
+# Documents
+Documents are generated by PHPDocumentor. See docs directory for details.
+
+# Tests
+The test cases are run using phpunit version PHPUnit 3.5.13
+To run a test, provide your object storage credentials in test/BaseTest.php file.
+
+# Examples
+
+## Configuring Object Storage
+
+```php
// If you want to cache ObjectStorage authentication token:
$tokenStore = ObjectStorage_TokenStore::factory('file', array('ttl' => 3600, 'path' => '/tmp/objectStorage'));
@@ -7,8 +33,11 @@
// If no adapter option is provided, CURL will be used.
$options = array('adapter' => ObjectStorage_Http_Client::SOCKET, 'timeout' => 10);
$objectStorage = new ObjectStorage($host, $username, $password, $options);
+```
+
+## Basic CRUD
-// Basic CRUD
+```php
$shallowContainer = $objectStorage->with('example_container');
$newContainer = $shallowContainer->create();
@@ -27,22 +56,57 @@
// If you wanted, you can do this all one line.
// Most functions return itself so you can chain method calls except delete method which returns a boolean value.
-$result = $objectStorage->with('example_container')->create()->setMeta('Description', 'Adding a meta data')->update()->get()->delete();
+$result = $objectStorage->with('example_container')
+ ->create()
+ ->setMeta('Description', 'Adding a meta data')
+ ->update()
+ ->get()
+ ->delete();
// When you create a new container or an object, ObjectStorage_Abstract will return itself, not the newly created container or object.
// If you wish to reload the data from ObjectStorage cluster, use ObjectStorage_Abstract::get or ObjectStorage_Abstract::reload methods.
// It will fetch the container info from ObjectStorage and reload $newContainer object with it.
$newContainer = $objectStorage->with('example_container')->create()->reload();
+```
+## CDN operations
+```php
// To create a CDN enabled container
$objectStorage->with('cdn_container')->enableCdn()->create();
// To update an existing container to a CDN enabled container
$objectStorage->with('another_container')->enableCdn()->setTtl(3600)->update();
-// You can traverse container or objects like this:
-$container = $objectStorage->with('another_container')->get();
+// You want to see CDN URLs?
+$cdnUrls = $container->getCdnUrls();
+
+// CDN purge cache. (In case you modified an object and need to refresh CDN cache.)
+$objectStorage05->with('cdn_container/object')->purgeCache();
+
+// CDN load cache
+$objectStorage05->with('cdn_container/object')->loadCache();
+
+// If you want to compress *text* files served via CDN.
+$results = $objectStorage05->with('')->setContext('cdn')
+ ->setRequestHeader('X-CDN-COMPRESSION', 'true') // Set to "false" to turn off compression
+ ->setRequestHeader('X-CDN-COMPRESSION-MIME', 'text/plain,text/html,text/css,application/x-javascript,text/javascript')
+ ->update();
+
+// If you want to add a custom CDN CNAME. (
+// You can add a CNAME to a container level as well. To do so, pass an appropriate container name to with() method
+// Keep in mind you can have only one custom CNAME per container
+// To find your CNAME endpoint, use "dig" command on your existing CDN host. For example,
+// $ dig 1234.http.dal05.cdn.softlayer.net
+$results = $objectStorage05->with('')->setContext('cdn')
+ ->setRequestHeader('X-CDN-CNAME-Action', 'add') // Use "delete" if you wish to delete a CNAME
+ ->setRequestHeader('X-Cdn-CNAME', 'cdn.mysite.com')
+ ->update();
+```
+
+## Traversing containers or objects
+```php
+$container = $objectStorage->with('another_container')->get();
if (count($container->objects) > 0) {
foreach ($results->objects as $shallowObject) {
$object = $shallowObject->get();
@@ -51,68 +115,46 @@
echo $object->getBody();
}
}
+```
+
+## Copy an object to another Object Storage
-// Copy an object to another Object Storage
+```php
$objectStorage01 = new ObjectStorage($host01, $username01, $password01);
$objectStorage02 = new ObjectStorage($host02, $username02, $password02);
$object = $objectStorage01->with('container/object')->get();
$objectStorage02->create($object);
+```
-// Search
+## Search
+```php
$objectOrContainer = $objectStorage05->with('')
->setContext('search')
->setFilter('type', 'container')
->setFilter('q', $searchKeyword)
->setMime('json')
->get();
+```
-// CDN purge cache. (In case you modified an object and need to refresh CDN cache.)
-$objectStorage05->with('cdn_container/object')->purgeCache();
-// CDN load cache
-$objectStorage05->with('cdn_container/object')->loadCache();
+## Notes
+ObjectStorage_Abstract has many properties but these three are the major componets
+* $objectStorage: holds reference to a ObjectStorage object (optional)
+* $request: HTTP request object is consisted of headers and body
+* $response: HTTP response object is consisted of headers and body
-// If you want to compress *text* files served via CDN.
-$results = $objectStorage05->with('')->setContext('cdn')
- ->setRequestHeader('X-CDN-COMPRESSION', 'true') // Set to "false" to turn off compression
- ->setRequestHeader('X-CDN-COMPRESSION-MIME', 'text/plain,text/html,text/css,application/x-javascript,text/javascript')
- ->update();
-
-// If you want to add a custom CDN CNAME. (
-// You can add a CNAME to a container level as well. To do so, pass an appropriate container name to with() method
-// Keep in mind you can have only one custom CNAME per container
-// To find your CNAME endpoint, use "dig" command on your existing CDN host. For example,
-// $ dig 1234.http.dal05.cdn.softlayer.net
-$results = $objectStorage05->with('')->setContext('cdn')
- ->setRequestHeader('X-CDN-CNAME-Action', 'add') // Use "delete" if you wish to delete a CNAME
- ->setRequestHeader('X-Cdn-CNAME', 'cdn.mysite.com')
- ->update();
-
-// ObjectStorage_Abstract has many properties but these three are the major componets
-// * $objectStorage: holds reference to a ObjectStorage object (optional)
-// * $request: HTTP request object is consisted of headers and body
-// * $response: HTTP response object is consisted of headers and body
-
-// You can access to HTTP request or response object using ObjectStorage_Abstract::getRequest or ObjectStorage_Abstract::getResponse.
-// You can also use convenience getter and setters. These can help you avoid doing like this:
+You can access to HTTP request or response object using ObjectStorage_Abstract::getRequest or ObjectStorage_Abstract::getResponse.
+You can also use convenience getter and setters. These can help you avoid doing like this:
+```php
$container->getResponse()->setMeta('description', 'example meta');
$container->getRequest()->getBody();
+```
-// and you can do this instead:
+But you can do this instead:
+```php
$container->setMeta('description', 'example meta');
$container->getBody();
+```
-// Simple idea is that you *set* data to HTTP request and *get* data from HTTP response.
-
-// Sets data to HTTP request object
-// * ObjectStorage_Abstract::setHeader
-// * ObjectStorage_Abstract::setHeasers
-// * ObjectStorage_Abstract::setMeta
-// * ObjectStorage_Abstract::setBody
-
-// Gets data from HTTP response object
-// * ObjectStorage_Abstract::getHeader
-// * ObjectStorage_Abstract::getHeaders
-// * ObjectStorage_Abstract::getMeta
-// * ObjectStorage_Abstract::getBody
+The idea is that you *set* data to HTTP request and *get* data from HTTP response.

0 comments on commit 00ac458

Please sign in to comment.