国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

首頁(yè) php教程 PHP開(kāi)發(fā) Zend Framework教程之Application用法實(shí)例詳解

Zend Framework教程之Application用法實(shí)例詳解

Dec 27, 2016 pm 02:19 PM
zend framework

本文實(shí)例講述了Zend Framework教程之Application用法。分享給大家供大家參考,具體如下:

Zend_Application是Zend Framework的核心組件。Zend_Application為Zend Framework應(yīng)用程序提供基本功能,是程序的入口點(diǎn)。它的主要功能有兩個(gè):裝載配置PHP環(huán)境(包括自動(dòng)加載),并引導(dǎo)應(yīng)用程序。

通常情況下,通過(guò)配置選項(xiàng)配置Zend_Application構(gòu)造器,但也可以完全使用自定義方法配置。以下是兩個(gè)使用用例。

Zend_Application配置選項(xiàng)

構(gòu)造函數(shù):

/**
 * Constructor
 *
 * Initialize application. Potentially initializes include_paths, PHP
 * settings, and bootstrap class.
 *
 * @param string          $environment
 * @param string|array|Zend_Config $options String path to configuration file, or array/Zend_Config of configuration options
 * @throws Zend_Application_Exception When invalid options are provided
 * @return void
 */
public function __construct($environment, $options = null)
{
  $this->_environment = (string) $environment;
  require_once 'Zend/Loader/Autoloader.php';
  $this->_autoloader = Zend_Loader_Autoloader::getInstance();
  if (null !== $options) {
    if (is_string($options)) {
      $options = $this->_loadConfig($options);
    } elseif ($options instanceof Zend_Config) {
      $options = $options->toArray();
    } elseif (!is_array($options)) {
      throw new Zend_Application_Exception('Invalid options provided; must be location of config file, a config object, or an array');
    }
    $this->setOptions($options);
  }
}

Zend_Application配置方法

1.使用配置文件
2.使用配置數(shù)組

常見(jiàn)配置選項(xiàng)

QQ圖片20161227132413.png

注意:

選項(xiàng)名稱不區(qū)分大小寫。

Zend_Application的方法

QQ圖片20161227132413.png

QQ圖片20161227132413.png

QQ圖片20161227132413.png

配置舉例:

默認(rèn):

// Create application, bootstrap, and run
$application = new Zend_Application(
  APPLICATION_ENV,
  APPLICATION_PATH . '/configs/application.ini'
);
$application->bootstrap()
      ->run();

源代碼

<?php
class Zend_Application
{  /**
   * Constructor
   *
   * Initialize application. Potentially initializes include_paths, PHP
   * settings, and bootstrap class.
   *
   * @param string          $environment
   * @param string|array|Zend_Config $options String path to configuration file, or array/Zend_Config of configuration options
   * @throws Zend_Application_Exception When invalid options are provided
   * @return void
   */
  public function __construct($environment, $options = null)
  {
    $this->_environment = (string) $environment;
    require_once &#39;Zend/Loader/Autoloader.php&#39;;
    $this->_autoloader = Zend_Loader_Autoloader::getInstance();
    if (null !== $options) {
      if (is_string($options)) {
        $options = $this->_loadConfig($options);
      } elseif ($options instanceof Zend_Config) {
        $options = $options->toArray();
      } elseif (!is_array($options)) {
        throw new Zend_Application_Exception(&#39;Invalid options provided; must be location of config file, a config object, or an array&#39;);
      }
      $this->setOptions($options);
    }
  }
  /**
   * Retrieve current environment
   *
   * @return string
   */
  public function getEnvironment()
  {
    return $this->_environment;
  }
  /**
   * Retrieve autoloader instance
   *
   * @return Zend_Loader_Autoloader
   */
  public function getAutoloader()
  {
    return $this->_autoloader;
  }
  /**
   * Set application options
   *
   * @param array $options
   * @throws Zend_Application_Exception When no bootstrap path is provided
   * @throws Zend_Application_Exception When invalid bootstrap information are provided
   * @return Zend_Application
   */
  public function setOptions(array $options)
  {
    if (!empty($options[&#39;config&#39;])) {
      if (is_array($options[&#39;config&#39;])) {
        $_options = array();
        foreach ($options[&#39;config&#39;] as $tmp) {
          $_options = $this->mergeOptions($_options, $this->_loadConfig($tmp));
        }
        $options = $this->mergeOptions($_options, $options);
      } else {
        $options = $this->mergeOptions($this->_loadConfig($options[&#39;config&#39;]), $options);
      }
    }
    $this->_options = $options;
    $options = array_change_key_case($options, CASE_LOWER);
    $this->_optionKeys = array_keys($options);
    if (!empty($options[&#39;phpsettings&#39;])) {
      $this->setPhpSettings($options[&#39;phpsettings&#39;]);
    }
    if (!empty($options[&#39;includepaths&#39;])) {
      $this->setIncludePaths($options[&#39;includepaths&#39;]);
    }
    if (!empty($options[&#39;autoloadernamespaces&#39;])) {
      $this->setAutoloaderNamespaces($options[&#39;autoloadernamespaces&#39;]);
    }
    if (!empty($options[&#39;autoloaderzfpath&#39;])) {
      $autoloader = $this->getAutoloader();
      if (method_exists($autoloader, &#39;setZfPath&#39;)) {
        $zfPath  = $options[&#39;autoloaderzfpath&#39;];
        $zfVersion = !empty($options[&#39;autoloaderzfversion&#39;])
              ? $options[&#39;autoloaderzfversion&#39;]
              : &#39;latest&#39;;
        $autoloader->setZfPath($zfPath, $zfVersion);
      }
    }
    if (!empty($options[&#39;bootstrap&#39;])) {
      $bootstrap = $options[&#39;bootstrap&#39;];
      if (is_string($bootstrap)) {
        $this->setBootstrap($bootstrap);
      } elseif (is_array($bootstrap)) {
        if (empty($bootstrap[&#39;path&#39;])) {
          throw new Zend_Application_Exception(&#39;No bootstrap path provided&#39;);
        }
        $path = $bootstrap[&#39;path&#39;];
        $class = null;
        if (!empty($bootstrap[&#39;class&#39;])) {
          $class = $bootstrap[&#39;class&#39;];
        }
        $this->setBootstrap($path, $class);
      } else {
        throw new Zend_Application_Exception(&#39;Invalid bootstrap information provided&#39;);
      }
    }
    return $this;
  }
  /**
   * Retrieve application options (for caching)
   *
   * @return array
   */
  public function getOptions()
  {
    return $this->_options;
  }
  /**
   * Is an option present?
   *
   * @param string $key
   * @return bool
   */
  public function hasOption($key)
  {
    return in_array(strtolower($key), $this->_optionKeys);
  }
  /**
   * Retrieve a single option
   *
   * @param string $key
   * @return mixed
   */
  public function getOption($key)
  {
  }
  /**
   * Merge options recursively
   *
   * @param array $array1
   * @param mixed $array2
   * @return array
   */
  public function mergeOptions(array $array1, $array2 = null)
  {
    if (is_array($array2)) {
      foreach ($array2 as $key => $val) {
        if (is_array($array2[$key])) {
          $array1[$key] = (array_key_exists($key, $array1) && is_array($array1[$key]))
                 ? $this->mergeOptions($array1[$key], $array2[$key])
                 : $array2[$key];
        } else {
          $array1[$key] = $val;
        }
      }
    }
    return $array1;
  }
  /**
   * Set PHP configuration settings
   *
   * @param array $settings
   * @param string $prefix Key prefix to prepend to array values (used to map . separated INI values)
   * @return Zend_Application
   */
  public function setPhpSettings(array $settings, $prefix = &#39;&#39;)
  {
    foreach ($settings as $key => $value) {
      $key = empty($prefix) ? $key : $prefix . $key;
      if (is_scalar($value)) {
        ini_set($key, $value);
      } elseif (is_array($value)) {
        $this->setPhpSettings($value, $key . &#39;.&#39;);
      }
    }
    return $this;
  }
  /**
   * Set include path
   *
   * @param array $paths
   * @return Zend_Application
   */
  public function setIncludePaths(array $paths)
  {
    $path = implode(PATH_SEPARATOR, $paths);
    set_include_path($path . PATH_SEPARATOR . get_include_path());
    return $this;
  }
  /**
   * Set autoloader namespaces
   *
   * @param array $namespaces
   * @return Zend_Application
   */
  public function setAutoloaderNamespaces(array $namespaces)
  {
    $autoloader = $this->getAutoloader();
    foreach ($namespaces as $namespace) {
      $autoloader->registerNamespace($namespace);
    }
    return $this;
  }
  /**
   * Set bootstrap path/class
   *
   * @param string $path
   * @param string $class
   * @return Zend_Application
   */
  public function setBootstrap($path, $class = null)
  {
    // setOptions() can potentially send a null value; specify default
    // here
    if (null === $class) {
      $class = &#39;Bootstrap&#39;;
    }
    if (!class_exists($class, false)) {
      require_once $path;
      if (!class_exists($class, false)) {
        throw new Zend_Application_Exception(&#39;Bootstrap class not found&#39;);
      }
    }
    $this->_bootstrap = new $class($this);
    if (!$this->_bootstrap instanceof Zend_Application_Bootstrap_Bootstrapper) {
      throw new Zend_Application_Exception(&#39;Bootstrap class does not implement Zend_Application_Bootstrap_Bootstrapper&#39;);
    }
    return $this;
  }
  /**
   * Get bootstrap object
   *
   * @return Zend_Application_Bootstrap_BootstrapAbstract
   */
  public function getBootstrap()
  {
    if (null === $this->_bootstrap) {
      $this->_bootstrap = new Zend_Application_Bootstrap_Bootstrap($this);
    }
    return $this->_bootstrap;
  }
  /**
   * Bootstrap application
   *
   * @param null|string|array $resource
   * @return Zend_Application
   */
  public function bootstrap($resource = null)
  {
    $this->getBootstrap()->bootstrap($resource);
    return $this;
  }
  /**
   * Run the application
   *
   * @return void
   */
  public function run()
  {
    $this->getBootstrap()->run();
  }
  /**
   * Load configuration file of options
   *
   * @param string $file
   * @throws Zend_Application_Exception When invalid configuration file is provided
   * @return array
   */
  protected function _loadConfig($file)
  {
    $environment = $this->getEnvironment();
    $suffix   = pathinfo($file, PATHINFO_EXTENSION);
    $suffix   = ($suffix === &#39;dist&#39;)
           ? pathinfo(basename($file, ".$suffix"), PATHINFO_EXTENSION)
           : $suffix;
    switch (strtolower($suffix)) {
      case &#39;ini&#39;:
        $config = new Zend_Config_Ini($file, $environment);
        break;
      case &#39;xml&#39;:
        $config = new Zend_Config_Xml($file, $environment);
        break;
      case &#39;json&#39;:
        $config = new Zend_Config_Json($file, $environment);
        break;
      case &#39;yaml&#39;:
      case &#39;yml&#39;:
        $config = new Zend_Config_Yaml($file, $environment);
        break;
      case &#39;php&#39;:
      case &#39;inc&#39;:
        $config = include $file;
        if (!is_array($config)) {
          throw new Zend_Application_Exception(&#39;Invalid configuration file provided; PHP file does not return array value&#39;);
        }
        return $config;
        break;
      default:
        throw new Zend_Application_Exception(&#39;Invalid configuration file provided; unknown config type&#39;);
    }
    return $config->toArray();
  }
}

希望本文所述對(duì)大家PHP程序設(shè)計(jì)有所幫助。

更多Zend Framework教程之Application用法實(shí)例詳解相關(guān)文章請(qǐng)關(guān)注PHP中文網(wǎng)!

本站聲明
本文內(nèi)容由網(wǎng)友自發(fā)貢獻(xiàn),版權(quán)歸原作者所有,本站不承擔(dān)相應(yīng)法律責(zé)任。如您發(fā)現(xiàn)有涉嫌抄襲侵權(quán)的內(nèi)容,請(qǐng)聯(lián)系admin@php.cn

熱AI工具

Undress AI Tool

Undress AI Tool

免費(fèi)脫衣服圖片

Undresser.AI Undress

Undresser.AI Undress

人工智能驅(qū)動(dòng)的應(yīng)用程序,用于創(chuàng)建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用于從照片中去除衣服的在線人工智能工具。

Clothoff.io

Clothoff.io

AI脫衣機(jī)

Video Face Swap

Video Face Swap

使用我們完全免費(fèi)的人工智能換臉工具輕松在任何視頻中換臉!

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費(fèi)的代碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

功能強(qiáng)大的PHP集成開(kāi)發(fā)環(huán)境

Dreamweaver CS6

Dreamweaver CS6

視覺(jué)化網(wǎng)頁(yè)開(kāi)發(fā)工具

SublimeText3 Mac版

SublimeText3 Mac版

神級(jí)代碼編輯軟件(SublimeText3)

在PHP中使用Zend Framework:快速入門指南 在PHP中使用Zend Framework:快速入門指南 Jun 21, 2023 am 08:58 AM

在PHP中使用ZendFramework:快速入門指南ZendFramework是一個(gè)開(kāi)源的、基于PHP的Web應(yīng)用程序框架,它是一個(gè)功能強(qiáng)大且易于擴(kuò)展的框架。ZendFramework包含了許多好用的組件,這些組件可以幫助你構(gòu)建高效的Web應(yīng)用程序。本文將介紹如何在PHP中使用ZendFramework,幫助你快速入門。安裝ZendFramewo

Zend Framework中間件:實(shí)現(xiàn)全文搜索和分頁(yè)功能 Zend Framework中間件:實(shí)現(xiàn)全文搜索和分頁(yè)功能 Jul 30, 2023 pm 08:49 PM

ZendFramework是一個(gè)功能強(qiáng)大的開(kāi)發(fā)框架,可以幫助開(kāi)發(fā)人員快速構(gòu)建高性能、可擴(kuò)展的PHP應(yīng)用程序。其中,中間件是ZendFramework中的一個(gè)重要概念,它可以幫助我們實(shí)現(xiàn)全文搜索和分頁(yè)功能。本文將介紹如何在ZendFramework中使用中間件來(lái)實(shí)現(xiàn)這兩個(gè)功能,并提供代碼示例。一、全文搜索功能全文搜索是現(xiàn)代應(yīng)用程序中常見(jiàn)的功能之一。

通過(guò)Zend Framework中間件實(shí)現(xiàn)高效的數(shù)據(jù)庫(kù)查詢 通過(guò)Zend Framework中間件實(shí)現(xiàn)高效的數(shù)據(jù)庫(kù)查詢 Jul 28, 2023 pm 01:13 PM

通過(guò)ZendFramework中間件實(shí)現(xiàn)高效的數(shù)據(jù)庫(kù)查詢引言在開(kāi)發(fā)過(guò)程中,數(shù)據(jù)庫(kù)查詢是不可避免的一部分。一個(gè)高效的數(shù)據(jù)庫(kù)查詢可以大大提高系統(tǒng)的性能和用戶體驗(yàn)。ZendFramework是一個(gè)使用廣泛的PHP框架,擁有強(qiáng)大的數(shù)據(jù)庫(kù)操作功能。本文將介紹如何通過(guò)ZendFramework中間件來(lái)實(shí)現(xiàn)高效的數(shù)據(jù)庫(kù)查詢,并提供相應(yīng)的代碼示例。一、了解ZendF

Zend Framework中間件:為應(yīng)用程序添加OAuth和OpenID登錄支持 Zend Framework中間件:為應(yīng)用程序添加OAuth和OpenID登錄支持 Jul 28, 2023 pm 01:09 PM

ZendFramework中間件:為應(yīng)用程序添加OAuth和OpenID登錄支持在當(dāng)今的互聯(lián)網(wǎng)應(yīng)用程序中,用戶認(rèn)證是一個(gè)關(guān)鍵的功能。為了提供更好的用戶體驗(yàn)和安全性,許多應(yīng)用程序選擇集成第三方登錄服務(wù),如OAuth和OpenID。在ZendFramework中,我們可以通過(guò)中間件來(lái)輕松地為應(yīng)用程序添加OAuth和OpenID登錄支持。首先,我們需要安裝Ze

Zend Framework中間件:提供郵件通知和消息推送的功能 Zend Framework中間件:提供郵件通知和消息推送的功能 Jul 29, 2023 pm 08:29 PM

ZendFramework中間件:提供郵件通知和消息推送的功能引言:隨著互聯(lián)網(wǎng)的發(fā)展和智能手機(jī)的普及,郵件通知和消息推送已經(jīng)成為了現(xiàn)代軟件開(kāi)發(fā)中常用的功能之一。在ZendFramework中,我們可以使用中間件來(lái)實(shí)現(xiàn)郵件通知和消息推送的功能。本文將介紹如何利用ZendFramework中間件來(lái)實(shí)現(xiàn)郵件通知和消息推送,并提供相應(yīng)的代碼示例。一、準(zhǔn)備工作在

Zend Framework中間件:為Web應(yīng)用程序添加社交登錄功能 Zend Framework中間件:為Web應(yīng)用程序添加社交登錄功能 Jul 28, 2023 pm 07:21 PM

ZendFramework是一個(gè)基于PHP的開(kāi)源框架,提供了許多功能強(qiáng)大的工具和組件,用于構(gòu)建可擴(kuò)展的Web應(yīng)用程序。本文將介紹如何使用ZendFramework的中間件來(lái)為Web應(yīng)用程序添加社交登錄功能。中間件是一種在請(qǐng)求進(jìn)入應(yīng)用程序之前或之后執(zhí)行的代碼。它允許開(kāi)發(fā)人員在處理請(qǐng)求的過(guò)程中進(jìn)行定制和擴(kuò)展。ZendFramework提供了一種靈活的方式來(lái)

CodeIgniter vs Zend Framework:哪個(gè)框架更適合開(kāi)發(fā)ERP系統(tǒng)? CodeIgniter vs Zend Framework:哪個(gè)框架更適合開(kāi)發(fā)ERP系統(tǒng)? Jun 19, 2023 am 08:53 AM

當(dāng)你決定開(kāi)發(fā)ERP系統(tǒng)時(shí),選擇一個(gè)適合的框架是至關(guān)重要的。這里我們將比較CodeIgniter和ZendFramework這兩個(gè)PHP框架,幫助你找到更適合你的ERP系統(tǒng)開(kāi)發(fā)的框架。CodeIgniter和ZendFramework是頗受歡迎的PHP框架。它們都提供了許多功能,并具有擴(kuò)展性和可維護(hù)性。然而,這兩個(gè)框架在某些方面存在明顯不同,更適合于某些應(yīng)

Zend Framework中間件:為應(yīng)用程序添加支付寶和微信支付功能 Zend Framework中間件:為應(yīng)用程序添加支付寶和微信支付功能 Jul 28, 2023 pm 08:01 PM

ZendFramework中間件:為應(yīng)用程序添加支付寶和微信支付功能引言:隨著移動(dòng)支付的普及,支付寶和微信支付已經(jīng)成為了許多應(yīng)用程序中必不可少的支付方式。本文將介紹如何使用ZendFramework中間件來(lái)為應(yīng)用程序添加支付寶和微信支付功能。通過(guò)本文的學(xué)習(xí),您將了解到如何使用中間件來(lái)簡(jiǎn)化支付流程,并且可以運(yùn)用到您的實(shí)際項(xiàng)目當(dāng)中。一、準(zhǔn)備工作在開(kāi)始之前,您

See all articles