Introducción a Zend Framework

 Aprendiendo Zend Framework

Apéndice

 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

    21.6. Zend_Config_Yaml

    21.6.1. Overview

    YAML is a recursive acronym meaning "YAML Ain't Markup Language", and is intended as a "human friendly data serialization standard for all programming languages." It is often used for application configuration.

    Zend_Config_Yaml is a lightweight Zend_Config extension. It includes a parser capable of recognizing most common YAML syntax used for purposes of configuration, and allows specifying other parsers should you want more complex syntax (e.g., ext/syck, spyc, sfYaml, etc.).

    21.6.2. Quick Start

    The following is a YAML version of a standard application configuration.

    production:
      
    phpSettings:
        
    display_startup_errorsfalse
        display_errors
    false
      includePaths
    :
        
    libraryAPPLICATION_PATH/../library
      bootstrap
    :
        
    pathAPPLICATION_PATH/Bootstrap.php
        
    class: "Bootstrap"
      
    appnamespace"Application"
      
    resources:
        
    frontController:
          
    controllerDirectoryAPPLICATION_PATH/controllers
          moduleDirectory
    APPLICATION_PATH/modules
          params
    :
            
    displayExceptionsfalse
        modules
    :
        
    db:
          
    adapter"pdo_sqlite"
          
    params:
            
    dbnameAPPLICATION_PATH/../data/db/application.db
        layout
    :
          
    layoutPathAPPLICATION_PATH/layouts/scripts/

    staging:
      
    _extendsproduction

    testing
    :
      
    _extendsproduction
      phpSettings
    :
        
    display_startup_errorstrue
        display_errors
    true

    development
    :
      
    _extendsproduction
      phpSettings
    :
        
    display_startup_errorstrue
        display_errors
    true
      resources
    :
        
    frontController:
          
    params:
            
    displayExceptionstrue

    To utilize it, you simply instantiate Zend_Config_Yaml, pointing it to the location of this file and indicating the section of the file to load. By default, constant names found in values will be substituted with their appropriate values.

    $config = new Zend_Config_Yaml(
        
    APPLICATION_PATH '/configs/application.yaml',
        
    APPLICATION_ENV
    );

    Once instantiated, you use it as you would any other configuration object.

    $db Zend_Db::factory($config->resources->db);

    21.6.3. Configuration Options

    The following options may be passed as keys to the third, $options argument of the constructor.

    Zend_Config_Yaml Options

    allow_modifications

    The default behavior of Zend_Config is to mark the object as immutable once loaded. Passing this flag with a boolean true will enable modifications to the object.

    skip_extends

    By default, any time a section extends another, Zend_Config will merge the section with the section it extends. Speciying a boolean true value to this option will disable this feature, giving you only the configuration defined explicitly in that section.

    ignore_constants

    By default, Zend_Config_Yaml will replace constant names found in values with the defined constant value. You map pass a boolean true to this option to disable this functionality.

    yaml_decoder

    By default, Zend_Config_Yaml uses a built in decoder, Zend_Config_Yaml::decode(), to parse and process YAML files. You may specify an alternate callback to use in place of the built-in one using this option.

    21.6.4. Available Methods

    __construct($yaml, $section = null, $options = false);

    Constructor. $yaml should refer to a valid filesystem location containing a YAML configuration file. $section, if specified, indicates a specific section of the configuration file to use. $options is discussed in the options section.

    decode($yaml);

    Parses a YAML string into a PHP array.

    setIgnoreConstants($flag);

    This static function may be used to globally override the default settings for how constants found in YAML strings are handled. By default, constant names are replaced with the appropriate constant values; passing a boolean true value to this method will override that behavior. (You can override it per-instance via the ignore_constants option as well.)

    ignoreConstants();

    This static method gives you the current setting for the ignore_constants flag.

    21.6.5. Examples

    Ejemplo 21.6. Using Zend_Config_Yaml with sfYaml

    As noted in the options section, Zend_Config_Yaml allows you to specify an alternate YAML parser at instantiation.

    sfYaml is a Symfony component that implements a complete YAML parser in PHP, and includes a number of additional features including the ability to parse PHP expressions embedded in the YAML. In this example, we use the sfYaml::load() method as our YAML decoder callback. (Note: this assumes that the sfYaml class is either already loaded or available via autoloading.)

    $config = new Zend_Config_Yaml(
        
    APPLICATION_PATH '/configs/application.yaml',
        
    APPLICATION_ENV,
        array(
    'yaml_decoder' => array('sfYaml''load'))
    );

    digg delicious meneame google twitter technorati facebook

    Comentarios

    Loading...