Skip to content

Core.What Pi Do When Request Received

linzongshu edited this page Mar 9, 2015 · 12 revisions

Dispatch entrance script

  • match api/... -> www/api.php
  • match admin/... -> www/admin.php
  • match feed/... -> www/feed.php
  • else -> www/index.php

What do these scripts do:

  • Define engine class type
  • Enabled boot, make it as request process other than Pi APIs pro

Boot Initialization

  • Config var, lib, host path
  • Define namespace
  • Autoloader
  • System configuration
  • Code storage

Boot Start

  • Bootstrap (Pi\Application\Engine\AbstractEngine)
    • Services defined in configuration file
    • Resources defined in configuration file
      • Router Service (Zend\Mvc\Router\Http\TreeRouteStack)
    • Initialize application instance
      • ServiceManager
      • EventManager
      • Request
      • Response
    • Application boot (Zend\Mvc\Application)
      • Attach listeners @see Attach Events
      • MvcEvent
      • Trigger EVENT_BOOTSTRAP
  • Listeners
    • RouteListener -> Zend\Mvc\RouteListener
    • DispatchListener -> Zend\Mvc\DispatchListener
    • ViewManager -> Zend\Mvc\View\Http\ViewManager
    • SendResponseListener -> Zend\Mvc\SendResponseListener
    • ViewStrategyListener -> Pi\Mvc\View\Http\ViewStrategyListener

Bootstrap Run

  • onBootstrap
    • View service -> Zend\View\View
    • Renderer service -> Zend\View\Renderer\PhpRenderer
  • onRoute
  • onDispatch
    • Set controller instance, set controller EventManager
    • Set controller MvcEvent
    • Controller dispatch
      • Trigger MVC Dispatch
        • Call action method
    • Trigger EVENT_DISPATCH_ERROR if error

Attached Events

  • EVENT_BOOTSTRAP
    • Pi\Mvc\View\Http\ViewStrategyListener::prepareRequestType() 99999
    • Pi\Mvc\View\Http\ViewStrategyListener::prepareRootModel() 20000
    • Zend\Mvc\View\Http\ViewManager::onBootstrap() 10000
  • EVENT_ROUTE
    • Pi\Mvc\View\Http\ViewStrategyListener::initThemeAssemble() 10000
    • Zend\Mvc\RouteListener::onRoute()
    • Pi\Mvc\View\Http\ViewStrategyListener::prepareActionResult() -99999
  • EVENT_DISPATCH
    • Zend\Mvc\DispatchListener::onDispatch()
  • MVC EVENT_DISPATCH
    • Pi\Mvc\View\Http\ViewStrategyListener::canonizeActionResult() -70
    • Pi\Mvc\View\Http\ErrorStrategy::prepareErrorViewModel() -85
    • Pi\Mvc\View\Http\ViewStrategyListener::injectTemplate() -89
    • Zend\Mvc\View\Http\RouteNotFoundStrategy::prepareNotFoundViewModel -90
  • EVENT_DISPATCH_ERROR
    • Zend\Mvc\View\Http\RouteNotFoundStrategy::detectNotFoundError()
    • Zend\Mvc\View\Http\RouteNotFoundStrategy::prepareNotFoundViewModel()
    • Zend\Mvc\View\Http\ExceptionStrategy::prepareExceptionViewModel()
    • Zend\Mvc\View\Http\InjectViewModelListener::injectViewModel() -100
  • EVENT_RENDER
    • Pi\Mvc\View\Http\ViewStrategyListener::renderThemeAssemble() 10000
    • Pi\Mvc\View\Http\ViewStrategyListener::canonizeErrorResult() 10
    • Pi\Mvc\View\Http\ViewStrategyListener::canonizeThemeLayout() 5
    • Pi\Mvc\View\Http\ErrorStrategy::prepareErrorViewModel() 100
    • Zend\Mvc\View\Http\DefaultRenderingStrategy::render() -10000
  • EVENT_RENDER_ERROR
    • Pi\Mvc\View\Http\ViewStrategyListener::renderThemeAssemble() 10000
    • Zend\Mvc\View\Http\ExceptionStrategy::prepareExceptionViewModel()
    • Zend\Mvc\View\Http\InjectViewModelListener::injectViewModel() -100
    • Zend\Mvc\View\Http\DefaultRenderingStrategy::render() -10000
  • EVENT_FINISH
    • Pi\Mvc\View\Http\ViewStrategyListener::completeThemeAssemble() 10000

Services Created During Execution

  • Application -> Pi\Mvc\Service\ApplicationFactory -> Pi\Mvc\Application
  • Router -> Zend\Mvc\Router\Http\TreeRouteStack
  • EventManager -> Zend\Mvc\Service\EventManagerFactory -> Zend\EventManager\EventManager
  • Config -> Pi\Mvc\Service\Config
  • RouteNotFoundStrategy -> Zend\Mvc\View\Http\RouteNotFoundStrategy
  • ExceptionStrategy -> Zend\Mvc\View\Http\ExceptionStrategy
  • DefaultRenderingStrategy -> Zend\Mvc\View\Http\DefaultRenderingStrategy
  • View -> Zend\View\View
  • ViewPhpRendererStrategy -> Zend\View\Strategy\PhpRendererStrategy
  • ViewRenderer-> Zend\View\Renderer\PhpRenderer
  • ViewHelperManager -> Pi\Mvc\Service\ViewHelperManager
  • ViewResolver -> Zend\Mvc\Service\ViewResolverFactory -> Zend\View\Resolver\AggregateResolver

Additional Notes

  • Where to initialize header and footer
    • EVENT_ROUTE -> initThemeAssemble() -> Pi\View\Helper\ThemeAssemble::initStrategy()
      • Append head meta from config
      • Append footscript from config
      • Set global variables from config
Clone this wiki locally