Skip to content

Core.What Pi Do When Request Received

linzongshu edited this page Mar 12, 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
    • Pi\Application\Bootstrap\Resource\RenderCache::checkPage() 1000
    • Pi\Application\Bootstrap\Resource\Module::setup() 999
    • Pi\Application\Bootstrap\Resource\i18n::loadTranslator()
    • Zend\Mvc\DispatchListener::onDispatch()
    • MVC EVENT_DISPATCH (trigger in onDispatch())
      • PI_CONTROLLER: Pi\Application\Bootstrap\Resource\Permission::checkAction() 99999
      • PI_CONTROLLER: Pi\Application\Bootstrap\Resource\RenderCache::checkAction() 999
      • Pi\Mvc\Controller\ActionController::onDispatch()
      • PI_CONTROLLER: Pi\Mvc\View\Http\ViewStrategyListener::canonizeActionResult() -70
      • Shared: Zend\Mvc\View\Http\CreateViewModelListener::createViewModelFromArray() -80
      • Shared: Zend\Mvc\View\Http\CreateViewModelListener::createViewModelFromNull() -80
      • PI_CONTROLLER: Pi\Mvc\View\Http\ErrorStrategy::prepareErrorViewModel() -85
      • PI_CONTROLLER: Pi\Mvc\View\Http\ViewStrategyListener::injectTemplate() -89
      • Shared: Zend\Mvc\View\Http\RouteNotFoundStrategy::prepareNotFoundViewModel -90
      • Shared: Zend\Mvc\View\Http\InjectTemplateListener::injectTemplate() -90
      • PI_CONTROLLER: Pi\Application\Bootstrap\Resource\RenderCache::saveAction() -91
      • Shared: Zend\Mvc\View\Http\InjectViewModelListener::injectViewModel() -100
    • Pi\Mvc\View\Http\ErrorStrategy::prepareErrorViewModel() -85
    • 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\ErrorStrategy::prepareErrorViewModel() 100
    • Pi\Mvc\View\Http\ViewStrategyListener::canonizeErrorResult() 10
    • Pi\Mvc\View\Http\ViewStrategyListener::canonizeThemeLayout() 5
    • Zend\Mvc\View\Http\DefaultRenderingStrategy::render() -10000
    • RENDER VIEW EVENT: EVENT_RENDERER (trigger in Zend\View\View::render())
      • Zend\View\Strategy\JsonStrategy::selectRenderer()
      • Zend\View\Strategy\PhpRendererStrategy::selectRenderer()
    • RENDER VIEW EVENT: EVENT_RESPONSE
      • Zend\View\Strategy\JsonStrategy::injectResponse()
      • Zend\View\Strategy\PhpRendererStrategy::injectResponse()
  • 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
    • Pi\Application\Bootstrap\Resource\RenderCache::savePage() -9000

Variables Hierarchy

  • Pi
    • $engine -> Pi\Application\Engine\Standard (Pi.php)
      • $application -> Pi\Mvc\Application (Pi\Mvc\Application::load())
        • $engine
        • $section (string)
        • $serviceManager -> Zend\ServiceManager\ServiceManager (Zend\Mvc\Application::__construct())
        • $events -> Zend\EventManager\EventManager (Zend\Mvc\Application::__construct())
          • $sharedManager -> Zend\EventManager\SharedEventManager (Zend\Mvc\Service\EventManagerFactory::createService())
          • $events -> Event method
        • $request -> Zend\Http\PhpEnvironment\Request
          • $envParams -> $_ENV (__construct())
          • $queryParams -> $_GET
          • $postParams -> $_POST
          • $fileParams -> $_FILE
          • $serverParams -> $_SERVER
          • $headers -> Zend\Http\Headers
        • $response -> Zend\Http\PhpEnvironment\Response
        • $event -> Zend\Mvc\MvcEvent (Zend\Mvc\Application::bootstrap())
          • $target -> Standard::$application
          • $application -> Standard::$application
          • $request -> Application::$request
          • $response -> Application::$response
          • $router -> Zend\Mvc\Router\Http\TreeRouteStack (Assign in bootstrap(), created in Resource\Router::boot())
            • $routes -> route data from db
          • $viewModel -> Zend\View\Model\ViewModel (Pi\Mvc\View\Http\ViewStrategyListener::prepareRootModel())
          • $routeMatch -> Matched route class (Zend\Mvc\RouteListener::onRoute())

Listener class variables hierarchy

  • Pi\Mvc\View\Http\ViewStrategyListener
    • $type -> json/feed/ajax/flash/none
  • Zend\Mvc\View\Http\ViewManager
    • $services -> Application::$serviceManager
    • $event -> Application::$event
    • $routeNotFoundStrategy -> Zend\Mvc\View\Http\RouteNotFoundStrategy
      • $notFoundTemplate
    • $exceptionStrategy -> Zend\Mvc\View\Http\ExceptionStrategy
      • $exceptionTemplate
    • $mvcRenderingStrategy -> Zend\Mvc\View\Http\DefaultRenderingStrategy
      • $layoutTemplate
      • $view -> Zend\View\View
        • $events -> Application::$events
        • $request -> Application::$request ($this->render())
        • $response -> Application::$response ($this->render())
    • $rendererStrategy -> Zend\View\Strategy\PhpRendererStrategy
      • $renderer -> Zend\Mvc\View\Http\ViewManager::$renderer
    • $helperManager -> Pi\Mvc\Service\ViewHelperManager
    • $resolver -> Zend\View\Resolver\AggregateResolver
    • $viewModel -> Application::$event::$viewModel
    • $renderer -> Zend\View\Renderer\PhpRenderer
      • $__hepler -> Zend\Mvc\View\Http\ViewManager::$helperManager
      • $__templateResolver -> Zend\Mvc\View\Http\ViewManager::$resolver
      • plugin('view_model') -> Zend\View\Helper\ViewModel
        • $root -> Application::$event::$viewModel

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