<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/class.yaf-dispatcher.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'en',
  ),
  'this' => 
  array (
    0 => 'yaf-dispatcher.dispatch.php',
    1 => 'Yaf_Dispatcher::dispatch',
    2 => 'Dispatch a request',
  ),
  'up' => 
  array (
    0 => 'class.yaf-dispatcher.php',
    1 => 'Yaf_Dispatcher',
  ),
  'prev' => 
  array (
    0 => 'yaf-dispatcher.disableview.php',
    1 => 'Yaf_Dispatcher::disableView',
  ),
  'next' => 
  array (
    0 => 'yaf-dispatcher.enableview.php',
    1 => 'Yaf_Dispatcher::enableView',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/yaf/yaf_dispatcher/dispatch.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="yaf-dispatcher.dispatch" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">Yaf_Dispatcher::dispatch</h1>
  <p class="verinfo">(Yaf &gt;=1.0.0)</p><p class="refpurpose"><span class="refname">Yaf_Dispatcher::dispatch</span> &mdash; <span class="dc-title">Dispatch a request</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-yaf-dispatcher.dispatch-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="modifier">function</span> <span class="methodname"><strong>Yaf_Dispatcher::dispatch</strong></span>(<span class="methodparam"><span class="type"><a href="class.yaf-request-abstract.php" class="type Yaf_Request_Abstract">Yaf_Request_Abstract</a></span> <code class="parameter">$request</code></span>): <span class="type"><span class="type"><a href="class.yaf-response-abstract.php" class="type Yaf_Response_Abstract">Yaf_Response_Abstract</a></span>|<span class="type"><a href="language.types.null.php" class="type null">null</a></span>|<span class="type"><a href="language.types.singleton.php" class="type false">false</a></span></span></div>

  <p class="simpara">
   This method does the heavy work of the
   <span class="classname"><a href="class.yaf-dispatcher.php" class="classname">Yaf_Dispatcher</a></span>. It takes a request object.
  </p>
  <p class="para">
   The dispatch process has three distinct events:
   <ul class="simplelist">
    <li>Routing</li>
    <li>Dispatching</li>
    <li>Response</li>
   </ul>
   Routing takes place exactly once, using the values in the request object
   when <span class="methodname"><strong>Yaf_Dispatcher::dispatch()</strong></span> is called.
   Dispatching takes place in a loop; a request may either indicate
   multiple actions to dispatch, or the controller or a plugin may reset
   the request object to force additional actions to dispatch (see
   <span class="classname"><a href="class.yaf-plugin-abstract.php" class="classname">Yaf_Plugin_Abstract</a></span>). When all is done, the
   <span class="classname"><a href="class.yaf-dispatcher.php" class="classname">Yaf_Dispatcher</a></span> returns a response.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-yaf-dispatcher.dispatch-parameters">
  <h3 class="title">Parameters</h3>
  <dl>
   
    <dt><code class="parameter">request</code></dt>
    <dd>
     <p class="simpara">
      A <span class="classname"><a href="class.yaf-request-abstract.php" class="classname">Yaf_Request_Abstract</a></span> instance to dispatch.
     </p>
    </dd>
   
  </dl>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-yaf-dispatcher.dispatch-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="simpara">
   The <span class="classname"><a href="class.yaf-response-abstract.php" class="classname">Yaf_Response_Abstract</a></span> instance on success,
   <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> on failure, or <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong> if the application is not initialized.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-yaf-dispatcher.dispatch-examples">
  <h3 class="title">Examples</h3>
  <div class="example" id="example-1">
   <p><strong>Example #1 <span class="methodname"><strong>Yaf_Dispatcher::dispatch()</strong></span> example</strong></p>
   <div class="example-contents">
<div class="phpcode"><pre><code style="color: #000000"><span style="color: #0000BB">&lt;?php
$app </span><span style="color: #007700">= new </span><span style="color: #0000BB">Yaf_Application</span><span style="color: #007700">(</span><span style="color: #0000BB">dirname</span><span style="color: #007700">(</span><span style="color: #0000BB">__FILE__</span><span style="color: #007700">) . </span><span style="color: #DD0000">"/conf/application.ini"</span><span style="color: #007700">);
</span><span style="color: #0000BB">$app</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">bootstrap</span><span style="color: #007700">();

</span><span style="color: #FF8000">// Build a request pointing at ProductController::detailAction and
// dispatch it manually.
</span><span style="color: #0000BB">$request </span><span style="color: #007700">= new </span><span style="color: #0000BB">Yaf_Request_Http</span><span style="color: #007700">(</span><span style="color: #DD0000">"/product/detail/id/42"</span><span style="color: #007700">);

</span><span style="color: #0000BB">$response </span><span style="color: #007700">= </span><span style="color: #0000BB">Yaf_Dispatcher</span><span style="color: #007700">::</span><span style="color: #0000BB">getInstance</span><span style="color: #007700">()-&gt;</span><span style="color: #0000BB">dispatch</span><span style="color: #007700">(</span><span style="color: #0000BB">$request</span><span style="color: #007700">);

if (</span><span style="color: #0000BB">$response </span><span style="color: #007700">instanceof </span><span style="color: #0000BB">Yaf_Response_Abstract</span><span style="color: #007700">) {
    </span><span style="color: #0000BB">$response</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">response</span><span style="color: #007700">();
}
</span><span style="color: #0000BB">?&gt;</span></code></pre></div>
   </div>

  </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-yaf-dispatcher.dispatch-seealso">
  <h3 class="title">See Also</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="methodname"><a href="yaf-application.run.php" class="methodname" rel="rdfs-seeAlso">Yaf_Application::run()</a> - Start Yaf_Application</span></li>
    <li><span class="classname"><a href="class.yaf-plugin-abstract.php" class="classname">Yaf_Plugin_Abstract</a></span></li>
   </ul>
  </p>
 </div>


</div><?php manual_footer($setup); ?>