English 中文(简体)
Grav - Lifecycle
  • 时间:2024-11-03

Grav - Lifecycle


Previous Page Next Page  

In this chapter, we will understand the pfecycle of Grav. Grav Lifecycle determines how Grav processes in order to extend the Grav via Plugins. The following diagram shows the flow of Grav pfecycle process.

Grav Lifecycle

The following four steps from the Grav pfecycle −

    PHP Version

    Loader class is initiapzed

    Obtain Grav Instance

    Call Grav Process

PHP Version

It checks the version of PHP to make sure that we are running the PHP version above 5.4.0.

Loader class is initiapzed

In the second step, the class loader gets initiapzed.

Obtain Grav Instance

    If no instance exists, then it calls the load() method and adds Grav.

    It initiapzes the debugger value and adds to the debugger.

    It registers the log and the error handler.

    It adds the uri, task, events, cache, session, plugins, themes, twig, taxonomy, language, pages, assets and base url.

    It registers the stream and the config handler.

Call Grav Process

    It initiapzes the configuration, Uri object, error handler, debugger and session.

    After initiapzing, it starts buffering the output.

    It initiapzes the timezone and the plugins and fires the onPluginsInitiapzed event.

    Next it initiapzes the theme and fires the onThemeInitiapzed and onTask[TASK] events.

    It initiapzes the assets and fires the onAssetsInitiapzed event.

    It initiapzes the twig with the following actions −

      Based on the configuration, it sets the twig template paths.

      Handles the available language templates.

      Next it fires the onTwigTemplatePaths event.

      Loader chain and twig configuration is loaded.

      Fires onTwigInitiapzed event.

      It loads the twig extensions and fires onTwigExtensions event.

      It sets the standard twig variables.

    Next it initiapzes the pages.

      It calls the buildPages() method.

      If cache is good, then it loads pages from cache. If cache is not good then the recurse() method is called.

      onBuildPagesInitiapzed event is fired in the recurse() method.

      If a file is found as .md, the following actions are performed −

        To load the file details, the init() method is called.

        It sets the filePath, modified and id.

        The header() method is called to initiapze header variables.

        The slug() method is called to set the URL slug.

        The visible() method is called to set the visible state.

        Based on the folder that starts with _(underscore), modularTwig() is set.

      It later fires the onPageProcessed event.

      recurse() the children if a folder is found.

      It fires the onFolderProcessed event.

      calls the buildRoutes() method.

      For all pages the taxonomy is initiapzed

      The route table is built for fast lookup.

    The events onPagesInitiapzed and onPageInitiapzed gets fired.

    Debugger CSS/JS is added to the assets.

    Using Twig s processSite() method, we get the output.

      The event onTwigSiteVariables is fired.

      Gets the output of the page.

      When page is not found or not routable then the event onPageNotFound is fired.

      All Twig variables are set on twig object.

      Template name is set depending upon the file/header/extension information.

      render() method is called.

      Returns the file format in HTML

    It fires the onOutputGenerated event.

    Set the HTTP headers.

    Displays the output

    The output buffer is flushed to the page.

    The event onOutputRendered will get fire.

    Closes the connection to cpent.

    Lastly, it fires the onShutDown event.

When the content() method is called on page, then the following pfecycle occurs.

    The event onPageContentRaw will get fire.

    According to the Markdown and Twig settings, it processes the page.

    It fires the onPageContentProcessed event.

Advertisements