Simple Cloud API for PHP

Zend just announced Simple Cloud API for PHP. This API aims to be an Abstraction Layer between PHP and a number of Cloud services (Azure, Amazon, Nirvanix, Rackspace). The current contributors to this project include Zend, Microsoft, IBM, Rackspace, Nirvanix, and GoGrid.

Go to simplecloud.org or check the announcement in Zend’s Developer Zone. The first version is already available to download (this is basically an alpha version, apparently the full version will be included in Zend Framework), and consists in three smaller APIs. The interfaces are:

File Storage API

/**
 * Simple interface for unstructured cloud storage.
 */
interface Zend_Cloud_StorageService
{
    /**
     * Get an item from the storage service.
     *
     * @param  string $path
     * @param  array $options
     * @return mixed
     */
    public function fetchItem($path, $options = null);
    
    /**
     * Store an item in the storage service.
     * WARNING: This operation overwrites any item that is located at 
     * $destinationPath.
     * @param mixed  $data
     * @param string $destinationPath
     * @param  array $options
     * @return void
     */
    public function storeItem($data,
                              $destinationPath,
                              $options = null);
    
    /**
     * Delete an item in the storage service.
     *
     * @param  string $path
     * @param  array $options
     * @return void
     */
    public function deleteItem($path, $options = null);
    
    /**
     * Copy an item in the storage service to a given path.
     * WARNING: This operation is *very* expensive for services that do not
     * support copying an item natively.
     *
     * @param  string $sourcePath
     * @param  string $destination path
     * @param  array $options
     * @return void
     */
    public function copyItem($sourcePath, $destinationPath, $options = null);
    
    /**
     * Move an item in the storage service to a given path.
     * WARNING: This operation is *very* expensive for services that do not
     * support moving an item natively.
     *
     * @param  string $sourcePath
     * @param  string $destination path
     * @param  array $options
     * @return void
     */
    public function moveItem($sourcePath, $destinationPath, $options = null);
    
    /**
     * Get a key/value array of metadata for the given path.
     *
     * @param  string $path
     * @param  array $options
     * @return array
     */
    public function fetchMetadata($path, $options = null);
    
    /**
     * Store a key/value array of metadata at the given path.
     * WARNING: This operation overwrites any metadata that is located at 
     * $destinationPath.
     *
     * @param  string $path
     * @param  array $options
     * @return void
     */
    public function storeMetadata($metadata, $destinationPath, $options = null);
    
    /**
     * Delete a key/value array of metadata at the given path.
     *
     * @param  string $path
     * @param  array $options
     * @return void
     */
    public function deleteMetadata($path);
}

Document Storage API

interface Zend_Cloud_DocumentService
{   
    /**
     * Create collection.
     *
     * @param  string $name
     * @param  array  $options
     * @return array
     */
    public function createCollection($name, $options = null);
    
    /**
     * Delete collection.
     *
     * @param  string $name
     * @param  array  $options
     * @return void
     */
    public function deleteCollection($name, $options = null);
    
   	/**
     * List collections.
     *
     * @param  array  $options
     * @return boolean
     */
    public function listCollections($options = null);
    
    /**
     * List documents. Returns a key=>value array of document names to document objects.
     *
     * @param  array $options
     * @return array
     */
    public function listDocuments($options = null);
    
    /**
     * Insert document
     * 
     * @param  Zend_Cloud_Document_Document $document
     * @param  array                 		$options
     * @return boolean
     */
    public function insertDocument($document, $options = null);
    
    /**
     * Update document. The new document replaces the existing document.
     * 
     * @param  Zend_Cloud_Document_Document $document
     * @param  array                 		$options
     * @return boolean
     */
    public function updateDocument($document, $options = null);
    
    /**
     * Delete document.
     * 
     * @param  mixed  $document Document ID or Document object.
     * @param  array  $options
     * @return void
     */
    public function deleteDocument($document, $options = null);
    
    /**
     * Query for documents stored in the document service. If a string is passed in
     * $query, the query string will be passed directly to the service.
     *
     * @param  mixed $query
     * @param  array $options
     * @return array
     */
    public function query($query, $options = null);
}

Simple Queues API

nterface Zend_Cloud_QueueService
{
    /**
     * Create a queue. Returns the URI of the created queue. It may take
     * some time to create the queue. Check your vendor's documentation for
     * details.
     *
     * @param  string $name
     * @param  array  $options
     * @return string
     */
    public function createQueue($name, $options = null);

    /**
     * Delete a queue. All messages in the queue will also be deleted.
     *
     * @param  string $name
     * @param  array  $options
     * @return void
     */
    public function deleteQueue($name, $options = null);
    
    /**
     * List all queues.
     *
     * @param  array $options
     * @return array
     */
    public function listQueues($options = null);
    
    /**
     * Get a key/value array of metadata for the given queue.
     *
     * @param  string $name
     * @param  array  $options
     * @return array
     */
    public function fetchQueueMetadata($name, $options = null);
    
    /**
     * Store a key/value array of metadata for the specified queue.
     * WARNING: This operation overwrites any metadata that is located at 
     * $destinationPath. Some adapters may not support this method.
     * 
     * @param  array  $metadata
     * @param  string $name
     * @param  array  $options
     * @return void
     */
    public function storeQueueMetadata($metadata, $name, $options = null);
    
    /**
     * Send a message to the specified queue.
     * 
     * @param  string $message
     * @param  string $name
     * @param  array  $options
     * @return void
     */
    public function sendMessage($message, $queueName, $options = null);
    
    /**
     * Recieve at most $max messages from the specified queue and return the
     * message ids for messages recieved.
     * 
     * @param  string $queueName
     * @param  int    $max
     * @param  array  $options
     * @return array
     */
    public function recieveMessages($queueName, $max = 1, $options = null);
    
    /**
     * Delete the specified message from the specified queue.
     * 
     * @param  string $id
     * @param  string $queueName
     * @param  array  $options
     * @return void
     */
    public function deleteMessage($id, $queueName, $options = null);
    
    /**
     * Peek at the specified message from the specified queue.
     * WARNING: This operation may block other receivers from recieving the
     * message until the message is released from the peeker for services
     * that do not natively support message peeking. This may impact
     * performance and/or introduce concurrency issues in your applications.
     * Check your cloud vendor's documentation for more details.
     *
     * @param  string $id
     * @param  string $queueName
     * @param  array  $options
     * @return void
     */
    public function peekMessage($id, $queueName, $options = null);
}

The full press release is here.


Posted

in

by

Comments

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from try {} except

Subscribe now to keep reading and get access to the full archive.

Continue reading