Introducción a Zend Framework

 Aprendiendo Zend Framework


 Referencia de Zend Framework

  • Zend_Gdata
  • Zend_Http
  • Zend_InfoCard
  • Zend_Json
  • Zend_Layout
  • Zend_Ldap
  • Zend_Loader
  • Zend_Locale
  • Zend_Log
  • Zend_Mail
  • Zend_Markup
  • Zend_Measure
  • Zend_Memory
  • Zend_Mime
  • Zend_Navigation
  • Zend_Oauth
  • Zend_OpenId
  • Zend_Paginator
  • Zend_Pdf
  • Zend_ProgressBar
  • Zend_Queue
  • Zend_Reflection
  • Zend_Registry
  • Zend_Rest

  • Zend_Search_Lucene
  • Zend_Serializer
  • Zend_Server
  • Zend_Service
  • Zend_Session
  • Zend_Soap
  • Zend_Tag
  • Zend_Test
  • Zend_Text
  • Zend_TimeSync
  • Zend_Tool
  • Zend_Tool_Framework
  • Zend_Tool_Project
  • Zend_Translate
  • Zend_Uri
  • Zend_Validate
  • Zend_Version
  • Zend_View
  • Zend_Wildfire
  • Zend_XmlRpc
  • ZendX_Console_Process_Unix
  • ZendX_JQuery
  • Traducción al 26.9% - Actualizado el 2011-11-16 - Revisión 24249 - Versión ZF 1.11.x

    19.3. StorageService Introduction

    The storage service in the Simple Cloud API implements a basic interface for file storage on the cloud. The files have no internal structure as far as the service is concerned, and are identified by a string key that is analogous to a filepath on a filesystem.

    19.3.1. StorageService Adapters

    The interface Zend_Cloud_StorageService_Adapter defines methods that each concrete storage service adapter must implement. The following adapters are shipped with the Simple Cloud API:

    To create the service object, call the static method Zend_Cloud_StorageService_Factory::getAdapter(), which accepts either an array or a Zend_Config object. The key named storage_adapter should specify the concrete adapter class. Adapter-specific keys may also be passed in this configuration parameter.

    Ejemplo 19.27. Using the StorageService Factory

    $storage Zend_Cloud_StorageService_Factory::getAdapter(array(
    Zend_Cloud_StorageService_Factory::STORAGE_ADAPTER_KEY => 'Zend_Cloud_StorageService_Adapter_S3',
    Zend_Cloud_StorageService_Adapter_S3::AWS_ACCESS_KEY   => $amazonKey,
    Zend_Cloud_StorageService_Adapter_S3::AWS_SECRET_KEY   => $amazonSecret,
    )); StorageService Adapter Options

    Tabla 19.7. Zend_Cloud_StorageService_Adapter_S3 options

    Option key Description Used in Required Default
    aws_accesskey Amazon AWS access key Constructor Yes None
    aws_secretkey Amazon AWS secret key Constructor Yes None
    bucket_name The name of the S3 bucket for this item Used in the constructor to set the default bucket for the instantiated service. This option can also be specified in any of the item access operations. Yes None
    bucket_as_domain Indicates that the bucket name is part of the domain name Used in constructor to set the default behavior for the instantiated service. This option can also be specified in any of the item access operations. No False
    metadata Array of metadata to associate with the item storeItem() No None
    fetch_stream Indicates whether the response is stream, and not a string
    [Nota] Nota

    See the Zend_Service_Amazon_S3 documentation for more about handling streamed responses)

    fetchItem() No False
    http_adapter HTTP adapter to use in all access operations Constructor No Zend_Http_Client_Adapter_Socket

    Tabla 19.8. Zend_Cloud_StorageService_Adapter_WindowsAzure options

    Option key Description Used in Required Default
    storage_accountname Windows Azure account name Constructor Yes None
    storage_accountkey Windows Azure account key Constructor Yes None
    storage_container Container to use for this storage object Constructor Yes None
    storage_host Windows Azure access host Constructor Yes
    storage_proxy_host Proxy hostname Constructor No None
    storage_proxy_port Proxy port Constructor No 8080
    storage_proxy_credentials Proxy credentials Constructor No None
    http_adapter HTTP adapter to use in all access operations Constructor No Zend_Http_Client_Adapter_Socket
    returntype How to return the results.
    • For fetchItem():


      Return the data as strings.


      save data on disk in temp file, return path name


      Default: Return the data as stream

    • For listItems():


      return the list of item names (default)


      return the list of WindowsAzure objects

    fetchItem(), listItems() No RETURN_STREAM for fetchItem(); RETURN_NAMES for listItems()
    return_path Return path. This is the URL that can be used to access the item after it has been uploaded. fetchItem() No System tmp directory
    return_openmode fopen() mode used to open the file for saving data fetchItem() No 'r'

    Tabla 19.9. Zend_Cloud_StorageService_Adapter_Nirvanix options

    Option key Description Used in Required Default
    auth_username Nirvanix user name Constructor Yes None
    auth_password Nirvanix password Constructor Yes None
    auth_accesskey Nirvanix access key Constructor Yes None
    http_adapter HTTP adapter to use in all access operations Constructor No Zend_Http_Client_Adapter_Socket
    remote_directory Nirvanix directory to use Constructor (mandatory) Yes None

    Tabla 19.10. Zend_Cloud_StorageService_Adapter_Filesystem options

    Option key Description Used in Required Default
    local_directory Local directory where the files will be stored Constructor No System tmp directory

    19.3.2. Basic concepts

    Different cloud storage services use their own unique terminology to refer to document storage concepts. The SimpleCloud API defines a number of common concepts that are shared among all major providers.

    The storage service identifies files by string keys, which may be URL paths or another service-specific identifier. The items can be stored and retrieved using this key. Each item can have metadata associated with it. These metadata carry service-specific information about the item, such as size, type, permissions, etc. as defined in the adapter for that provider.

    19.3.3. Exceptions

    If some error occurs inside the storage service, a Zend_Cloud_StorageService_Exception is thrown. If the exception was caused by underlying service driver, you can use the getClientException() method to retrieve the original exception.

    Since different cloud providers implement different sets of services, some adapters do not implement certain features. In this case, the Zend_Cloud_OperationNotAvailableException exception is thrown.

    19.3.4. Store an item

    storeItem() method is used to upload or otherwise add files to the storage provider.

    Ejemplo 19.28. Storing an item

    $data file_get_contents('/my/local/dir/picture.jpg');
    $returnedData $storage->storeItem('/my/remote/path/picture.jpg'$data);

    An optional third parameter describes service-specific options.

    Ejemplo 19.29. Storing an item with options

    $data file_get_contents("/my/local/dir/picture.jpg");

    // Use S3 bucket: myBucket
    // Make this item publicly readable
    $returnedData $storage->storeItem(
    Zend_Cloud_StorageService_Adapter_S3::BUCKET_NAME => "myBucket",
    Zend_Cloud_StorageService_Adapter_S3::METADATA    => array(
    Zend_Service_Amazon_S3::S3_ACL_HEADER => Zend_Service_Amazon_S3::S3_ACL_PUBLIC_READ,

    For service adapters that support streaming, data can also be a PHP stream (i.e. opened file).

    19.3.5. Fetch an item

    The fetchItem() operation retrieves an item from the storage.

    Ejemplo 19.30. Fetching an item

    $returnedData $storage->fetchItem("/my/remote/path/picture.jpg");

    19.3.6. Delete an item

    The deleteItem() operation removes an item from the storage service.

    Ejemplo 19.31. Deleting an item


    19.3.7. Copy an item

    The copyItem() operation creates a copy of the item in the storage.

    [Nota] Nota

    Not all services support copying natively. If this is the case, the adapter will simulate the operation, fetching the item and storing it under the target path.

    Ejemplo 19.32. Copying an item


    19.3.8. Move an item

    The moveItem() operation moves an item from one key (or directory) to another.

    [Nota] Nota

    Not all services support moving natively. If this is the case the adapter will simulate the operation, fetching the item, storing it under the target path, then deleting the original file.

    Ejemplo 19.33. Moving an item


    19.3.9. Rename an item

    The renameItem() operation changes the item name. For some services, this operation may be equivalent to moving to its original directory with a new name.

    Ejemplo 19.34. Renaming an item


    19.3.10. List items

    To list the items stored in the specified path, use the listItems() method. The method returns a list of names identifying matching remote items.

    Ejemplo 19.35. List items

    $objects $storage->listItems('/my/remote/path/');
    foreach (
    $objects as $objname) {
    "Found: $objname\n";

    19.3.11. Fetching metadata

    Some services store a set of key-value pairs along with the item as metadata. Use the fetchMetadata() method to retrieve an item's metadata.

    Ejemplo 19.36. Fetching metadata

    $data $storage->fetchMetadata('/my/remote/path/picture.jpg');
    foreach (
    $data as $key => $value) {
    "Metadata $key$value\n";

    19.3.12. Store metadata

    Depending on the service, metadata can be supplied either when storing the item or with a separate request. In the latter case, use storeMetadata() to add or update this metadata.

    Ejemplo 19.37. Storing metadata

    $data $storage->storeMetadata('/my/remote/path/picture.jpg', array(
    'type'     => 'JPEG',
    'category' => 'Portrait',

    19.3.13. Delete metadata

    The deleteMetadata() method removes all user-supplied metadata from an item.

    [Nota] Nota

    Not all services support removing metadata.

    Ejemplo 19.38. Deleting metadata


    19.3.14. Accessing concrete adapters

    Sometimes it is necessary to retrieve the concrete adapter for the service that the Storage API is working with. This can be achieved by using the getAdapter() method.

    [Nota] Nota

    Accessing the underlying adapter breaks portability among services, so it should be reserved for exceptional circumstances only.

    Ejemplo 19.39. Using a concrete adapter

    // the Simple Cloud Storage API doesn't support "clean bucket" operation
    // the concrete adapter can be used to access this feature
    $s3 $storage->getClient();

    digg delicious meneame google twitter technorati facebook