[ Index ]
 

Code source de LifeType 1.2.4

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/class/net/ -> requestgenerator.class.php (source)

   1  <?php
   2  
   3      lt_include( PLOG_CLASS_PATH."class/config/config.class.php" );
   4  
   5      if ( !defined("CHECK_CONFIG_REQUEST_MODE") )
   6          define( "CHECK_CONFIG_REQUEST_MODE", 0 );
   7      if ( !defined("NORMAL_REQUEST_MODE") )
   8          define( "NORMAL_REQUEST_MODE", 1 );
   9      if ( !defined("SEARCH_ENGINE_FRIENDLY_MODE") )
  10          define( "SEARCH_ENGINE_FRIENDLY_MODE", 2 );
  11      if ( !defined("MODREWRITE_MODE") )
  12          define( "MODREWRITE_MODE", 3 );
  13      if ( !defined("CUSTOM_REQUEST_MODE") )
  14          define( "CUSTOM_REQUEST_MODE", 4 );    
  15  
  16      /** 

  17       * \ingroup Net

  18       *

  19       * Request generators are a way to allow the templates to generate links in an abstract manner regarding of the

  20       * current settings. Each request generator defines its own format for its URLs, and by using request generators 

  21       * we can easily change the format of our URLs without the need to alter our templates 

  22       * (and therefore, without the need to hardcode URLs in our templates)

  23       *

  24       * This is the class that implements the factory pattern to obtain the correct request generator, given

  25       * a BlogInfo object and optionally, a request generator type. If not type is given, then

  26       * the class will check the value of the <b>request_format_mode</b> configuration parameter.

  27       *

  28       * The four types of request generators supported as of pLog 1.0 are:

  29       *

  30       * - NORMAL_REQUEST_MODE

  31       * - SEARCH_ENGINE_FRIENDLY_MODE

  32       * - MODREWRITE_MODE

  33       * - CUSTOM_REQUEST_MODE

  34       *

  35       * The preferred way to obtain a request generator is:

  36       *

  37       * <pre>

  38       *  $rg =& RequestGenerator::getRequestGenerator( $blogInfo );

  39       *  ...

  40       *  $blogLink = $rg->blogLink();

  41       * </pre>

  42       *

  43       * In order to force the factory class to generate a specific request generator:

  44       *

  45       * <pre>

  46       *  $rg =& RequestGenerator::getRequestGenerator( $blogInfo, CUSTOM_REQUEST_MODE );

  47       * </pre>

  48       * 

  49       * However, in cases when we have a BlogInfo available it is even better to use the BlogInfo::getBlogRequestGenerator()

  50       * method:

  51       *

  52       * <pre>

  53       *  $rg = $blogInfo->getBlogRequestGenerator();

  54       *  ...

  55       *  $blogLink = $rg->blogLink();

  56       * </pre>

  57       *

  58       * In order to check which methods are available to request generators, please see the documentation of the

  59       * RequestGenerator proxy class.     

  60       */
  61      class RequestGenerator  
  62      {    
  63          var $_mode;
  64  
  65          function getRequestGenerator( $blogInfo = null, $mode = CHECK_CONFIG_REQUEST_MODE )
  66          {
  67              // check the mode

  68              if( $mode == CHECK_CONFIG_REQUEST_MODE ) {
  69                  $config =& Config::getConfig();
  70                  $mode   = $config->getValue( "request_format_mode" );
  71              }
  72  
  73              $this->_mode  = $mode;
  74  
  75              // load the correct generator, while doing some nice dynamic loading...

  76              if( $this->_mode == SEARCH_ENGINE_FRIENDLY_MODE ) {
  77                  lt_include( PLOG_CLASS_PATH."class/net/prettyrequestgenerator.class.php" );
  78                  $rg = new PrettyRequestGenerator( $blogInfo );
  79              } 
  80              elseif( $this->_mode == MODREWRITE_MODE ) {
  81                  lt_include( PLOG_CLASS_PATH."class/net/modrewriterequestgenerator.class.php" );
  82                  $rg = new ModRewriteRequestGenerator( $blogInfo );
  83              } 
  84              elseif( $this->_mode == CUSTOM_REQUEST_MODE ) {
  85                  lt_include( PLOG_CLASS_PATH."class/net/customrequestgenerator.class.php" );
  86                  $rg = new CustomRequestGenerator( $blogInfo );                
  87              } 
  88              else {
  89                  lt_include( PLOG_CLASS_PATH."class/net/rawrequestgenerator.class.php" );
  90                  $rg = new RawRequestGenerator( $blogInfo );
  91              }
  92  
  93              return $rg;
  94          }
  95      }
  96  ?>


Généré le : Mon Nov 26 21:04:15 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics