Zend Framework 框架解析【一】

先從入口文件開始分析php

index.phpweb


<?php

error_reporting(E_ALL);
ini_set("display_errors",1);
chdir(dirname(__DIR__));
// Decline static file requests back to the PHP built-in webserver
if (php_sapi_name() === 'cli-server' && is_file(__DIR__ . parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH))) {
    return false;
}
// Setup autoloading
//初始化自動加載類
require 'init_autoloader.php';

// Run the application!
//運行應用程序
Zend\Mvc\Application::init(require 'config/application.config.php')->run();

?>
api


init_autoloader.php文件的功能主要以下,app

一、會先檢查是否有vendor/autoload.php文件,並設置ZF框架文件的主目錄框架

二、若是沒有verdor/autoload.php文件,使用自動加載工廠類,加載標準加載器ui


if ($zf2Path) {
    if (isset($loader)) {
        $loader->add('Zend', $zf2Path);
    } else {
        include $zf2Path . '/Zend/Loader/AutoloaderFactory.php';
        Zend\Loader\AutoloaderFactory::factory(array(
            'Zend\Loader\StandardAutoloader' => array(
                'autoregister_zf' => true
            )
        ));
    }
}
url


調用Zend\Loader\AutoloaderFactory::factory方法,主要功能以下spa

一、引用'Zend\Loader\StandardAutoloader' 並初始化code

二、註冊namespace Zendserver

三、調用Zend\Loader\StandAutoloader類的autoload方法載入spl__autoload

相關文章
相關標籤/搜索