svn: /pear/peardoc/trunk/en/package/networking/net-url-mapper/ example.xml examples/blog-router.php examples/dynamic-routing.php examples/generate-url.php examples/init.php examples/static-routing.php examples/wildcard-routing.php examples/zf-router.php features.xml

[email protected] (Christian Weiske)
Newsgroups php.pear.doc
Message-ID <[email protected]>
cweiske                                  Mon, 05 Oct 2009 17:41:05 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=289225

Log:
fix php parse errors in examples; move examples into single files, make xml nice

Changed paths:
    U   pear/peardoc/trunk/en/package/networking/net-url-mapper/example.xml
    A   pear/peardoc/trunk/en/package/networking/net-url-mapper/examples/
    A   pear/peardoc/trunk/en/package/networking/net-url-mapper/examples/blog-router.php
    A   pear/peardoc/trunk/en/package/networking/net-url-mapper/examples/dynamic-routing.php
    A   pear/peardoc/trunk/en/package/networking/net-url-mapper/examples/generate-url.php
    A   pear/peardoc/trunk/en/package/networking/net-url-mapper/examples/init.php
    A   pear/peardoc/trunk/en/package/networking/net-url-mapper/examples/static-routing.php
    A   pear/peardoc/trunk/en/package/networking/net-url-mapper/examples/wildcard-routing.php
    A   pear/peardoc/trunk/en/package/networking/net-url-mapper/examples/zf-router.php
    U   pear/peardoc/trunk/en/package/networking/net-url-mapper/features.xml
svn-diffs-289225.txt (text/x-diff, 14.6 KB)
Modified: pear/peardoc/trunk/en/package/networking/net-url-mapper/example.xml
===================================================================
--- pear/peardoc/trunk/en/package/networking/net-url-mapper/example.xml	2009-10-05 17:05:35 UTC (rev 289224)
+++ pear/peardoc/trunk/en/package/networking/net-url-mapper/example.xml	2009-10-05 17:41:05 UTC (rev 289225)
@@ -8,11 +8,13 @@
  </info>

  <para>
-  The following examples assume/need the following setup:
+  The coming examples assume/need the following setup:
  </para>

  <example>
-  <info><title>.htaccess</title></info>
+  <info>
+   <title>.htaccess</title>
+  </info>
   <programlisting><![CDATA[
 DirectoryIndex router.php
 RewriteEngine On
@@ -23,57 +25,57 @@
  </example>

  <example>
-  <info><title>init.php</title></info>
-  <programlisting role="php"><![CDATA[
-require_once 'Net/URL/Mapper.php';
-$m = Net_URL_Mapper::getInstance();
-  ]]></programlisting>
+  <info>
+   <title>init.php</title>
+  </info>
+  <programlisting role="php">
+    <xi:include parse="text"
+     xmlns:xi="http://www.w3.org/2001/XInclude"
+     href="&package.networking.net-url-mapper.examples.init.php;"
+    >
+     <xi:fallback>FIXME:MISSING XINCLUDE CONTENT</xi:fallback>
+    </xi:include>
+  </programlisting>
  </example>

  <phd:toc phd:element="package.networking.net-url-mapper.example"/>

- <para>
-  The following examples use <literal>.htaccess</literal> and <literal>init.php</literal> as a base.
- </para>

  <section
   xml:id="package.networking.net-url-mapper.example.blog"
   phd:chunk="false"
  >
+  <info>
+   <title>Blog routing</title>
+  </info>

-  <info><title>Blog routing</title></info>
-
   <para>
    The following snippets maps a couple blog URLs.
   </para>

   <example>
-   <info><title>router.php</title></info>
+   <info>
+    <title>blog-router.php</title>
+   </info>
    <programlisting role="php">
-     <![CDATA[
-require 'init.php';
-
-$m->connect('blog', array('page' => 'frontpage.php'));
-$m->connect('blog/feed/:type', array('page' => 'feed.php', 'type' => 'rss'));
-$m->connect('blog/archives/:year/:month', array('page' => 'archive.php', 'year' => date('Y'), 'month' => date('m'));
-
-$route = $m->match($_SERVER['REQUEST_URI']);
-if ($route === null) { // no match
-    $route = array(
-        'page' => 'frontpage.php',
-    );
-}
-include dirname(__FILE__) . '/inc/' . $route['page'];
-     ]]>
+    <xi:include parse="text"
+     xmlns:xi="http://www.w3.org/2001/XInclude"
+     href="&package.networking.net-url-mapper.examples.blog-router.php;"
+    >
+     <xi:fallback>FIXME:MISSING XINCLUDE CONTENT</xi:fallback>
+    </xi:include>
    </programlisting>
   </example>
  </section>

+
  <section
   xml:id="package.networking.net-url-mapper.example.zf"
   phd:chunk="false"
  >
-  <info><title>Zend Framework routing</title></info>
+  <info>
+   <title>Zend Framework routing</title>
+  </info>

   <para>
    A really simple example for Zend Framework-style URL routing. ;-) This is not
@@ -82,71 +84,45 @@
   </para>

   <example>
-   <info><title>router.php</title></info>
+   <info>
+    <title>zf-router.php</title>
+   </info>
    <programlisting role="php">
-     <![CDATA[
-require 'init.php';
-
-$path     = '/:module/:controller/:action';
-$defaults = array(
-    'module'     => 'default',
-    'controller' => 'index',
-    'action'     => 'index',
-);
-
-$m->connect($path, $defaults);
-
-$route = $m->match($_SERVER['REQUEST_URI']);
-
-// Fix the controller's name to adhere to ZF's standard, FooController
-$controllerClass  = ucfirst(strtolower($route['controller'])) . 'Controller';
-
-// Fix the action's name to adhere to ZF's standard, barAction()
-$controllerAction = strtolower($route['action']) . 'Action';
-
-// load the controller class
-require 'app/modules/' . $route['module'] . '/' . $class . '.php';
-
-$controllerObj = new $controllerClass;
-call_user_func(array($controllerObj, $controllerAction)); // pseudo dispatcher
-     ]]>
+    <xi:include parse="text"
+     xmlns:xi="http://www.w3.org/2001/XInclude"
+     href="&package.networking.net-url-mapper.examples.zf-router.php;"
+    >
+     <xi:fallback>FIXME:MISSING XINCLUDE CONTENT</xi:fallback>
+    </xi:include>
    </programlisting>
   </example>
  </section>

+
  <section
   xml:id="package.networking.net-url-mapper.example.generate"
   phd:chunk="false"
  >
+  <info>
+   <title>Generate a URL</title>
+  </info>

-  <info><title>Generate a URL</title></info>
-
   <para>
-   The following snippet explains how to generate a fancy URL.
+   The following snippet explains how to generate a fancy URL
+   automatically from the defined routes.
   </para>

   <example>
-   <info><title>router.php</title></info>
+   <info>
+    <title>generate-url.php</title>
+   </info>
    <programlisting role="php">
-     <![CDATA[
-require 'init.php';
-
-$m->connect('blog', array('page' => 'frontpage.php'));
-$m->connect('blog/feed/:type', array('page' => 'feed.php', 'type' => 'rss'));
-$m->connect('blog/archives/:year/:month', array('page' => 'archive.php', 'year' => date('Y'), 'month' => date('m'));
-
-$m->generate(array(
-    'page' => 'feed.php',
-    'type' => 'atom',
-)); // blog/feed/atom
-
-$m->generate(array(
-    'page'  => 'archive.php',
-    'year'  => '2008',
-    'month' => '06',
-)); // blog/archives/2008/06
-
-     ]]>
+    <xi:include parse="text"
+     xmlns:xi="http://www.w3.org/2001/XInclude"
+     href="&package.networking.net-url-mapper.examples.generate-url.php;"
+    >
+     <xi:fallback>FIXME:MISSING XINCLUDE CONTENT</xi:fallback>
+    </xi:include>
    </programlisting>
   </example>
  </section>

Added: pear/peardoc/trunk/en/package/networking/net-url-mapper/examples/blog-router.php
===================================================================
--- pear/peardoc/trunk/en/package/networking/net-url-mapper/examples/blog-router.php	                        (rev 0)
+++ pear/peardoc/trunk/en/package/networking/net-url-mapper/examples/blog-router.php	2009-10-05 17:41:05 UTC (rev 289225)
@@ -0,0 +1,26 @@
+<?php
+require 'init.php';
+
+$m->connect('blog', array('page' => 'frontpage.php'));
+$m->connect(
+    'blog/feed/:type',
+    array('page' => 'feed.php', 'type' => 'rss')
+);
+$m->connect(
+    'blog/archives/:year/:month',
+    array(
+        'page' => 'archive.php',
+        'year' => date('Y'),
+        'month' => date('m')
+    )
+);
+
+$route = $m->match($_SERVER['REQUEST_URI']);
+if ($route === null) {
+    // no match
+    $route = array(
+        'page' => 'frontpage.php',
+    );
+}
+include dirname(__FILE__) . '/inc/' . $route['page'];
+?>
\ No newline at end of file

Added: pear/peardoc/trunk/en/package/networking/net-url-mapper/examples/dynamic-routing.php
===================================================================
--- pear/peardoc/trunk/en/package/networking/net-url-mapper/examples/dynamic-routing.php	                        (rev 0)
+++ pear/peardoc/trunk/en/package/networking/net-url-mapper/examples/dynamic-routing.php	2009-10-05 17:41:05 UTC (rev 289225)
@@ -0,0 +1,7 @@
+<?php
+require_once 'Net/URL/Mapper.php';
+
+$m = Net_URL_Mapper::getInstance();
+$m->connect('news/:id', array('controller' => 'news', 'action' => 'read'));
+var_dump($m->match($_SERVER['REQUEST_URI']));
+?>
\ No newline at end of file

Added: pear/peardoc/trunk/en/package/networking/net-url-mapper/examples/generate-url.php
===================================================================
--- pear/peardoc/trunk/en/package/networking/net-url-mapper/examples/generate-url.php	                        (rev 0)
+++ pear/peardoc/trunk/en/package/networking/net-url-mapper/examples/generate-url.php	2009-10-05 17:41:05 UTC (rev 289225)
@@ -0,0 +1,29 @@
+<?php
+require 'init.php';
+
+$m->connect('blog', array('page' => 'frontpage.php'));
+$m->connect(
+    'blog/feed/:type',
+    array('page' => 'feed.php', 'type' => 'rss')
+);
+$m->connect(
+    'blog/archives/:year/:month',
+    array(
+        'page' => 'archive.php',
+        'year' => date('Y'),
+        'month' => date('m')
+    )
+);
+
+$url1 = $m->generate(array(
+    'page' => 'feed.php',
+    'type' => 'atom',
+)); // blog/feed/atom
+
+$url2 = $m->generate(array(
+    'page'  => 'archive.php',
+    'year'  => '2008',
+    'month' => '06',
+)); // blog/archives/2008/06
+
+?>
\ No newline at end of file

Added: pear/peardoc/trunk/en/package/networking/net-url-mapper/examples/init.php
===================================================================
--- pear/peardoc/trunk/en/package/networking/net-url-mapper/examples/init.php	                        (rev 0)
+++ pear/peardoc/trunk/en/package/networking/net-url-mapper/examples/init.php	2009-10-05 17:41:05 UTC (rev 289225)
@@ -0,0 +1,4 @@
+<?php
+require_once 'Net/URL/Mapper.php';
+$m = Net_URL_Mapper::getInstance();
+?>
\ No newline at end of file

Added: pear/peardoc/trunk/en/package/networking/net-url-mapper/examples/static-routing.php
===================================================================
--- pear/peardoc/trunk/en/package/networking/net-url-mapper/examples/static-routing.php	                        (rev 0)
+++ pear/peardoc/trunk/en/package/networking/net-url-mapper/examples/static-routing.php	2009-10-05 17:41:05 UTC (rev 289225)
@@ -0,0 +1,7 @@
+<?php
+require_once 'Net/URL/Mapper.php';
+
+$m = Net_URL_Mapper::getInstance();
+$m->connect('home', array('controller' => 'index', 'action' => 'index'));
+var_dump($m->match($_SERVER['REQUEST_URI']));
+?>
\ No newline at end of file

Added: pear/peardoc/trunk/en/package/networking/net-url-mapper/examples/wildcard-routing.php
===================================================================
--- pear/peardoc/trunk/en/package/networking/net-url-mapper/examples/wildcard-routing.php	                        (rev 0)
+++ pear/peardoc/trunk/en/package/networking/net-url-mapper/examples/wildcard-routing.php	2009-10-05 17:41:05 UTC (rev 289225)
@@ -0,0 +1,15 @@
+<?php
+require_once 'Net/URL/Mapper.php';
+
+$m = Net_URL_Mapper::getInstance();
+
+$path     = 'content/*(section)';
+$defaults = array(
+    'controller' => 'content',
+    'action'     => 'display',
+    'section'    => '#toc',
+);
+
+$m->connect($path, $defaults);
+var_dump($m->match($_SERVER['REQUEST_URI']));
+?>
\ No newline at end of file

Added: pear/peardoc/trunk/en/package/networking/net-url-mapper/examples/zf-router.php
===================================================================
--- pear/peardoc/trunk/en/package/networking/net-url-mapper/examples/zf-router.php	                        (rev 0)
+++ pear/peardoc/trunk/en/package/networking/net-url-mapper/examples/zf-router.php	2009-10-05 17:41:05 UTC (rev 289225)
@@ -0,0 +1,24 @@
+require 'init.php';
+
+$path     = '/:module/:controller/:action';
+$defaults = array(
+    'module'     => 'default',
+    'controller' => 'index',
+    'action'     => 'index',
+);
+
+$m->connect($path, $defaults);
+
+$route = $m->match($_SERVER['REQUEST_URI']);
+
+// Fix the controller's name to adhere to ZF's standard, FooController
+$controllerClass  = ucfirst(strtolower($route['controller'])) . 'Controller';
+
+// Fix the action's name to adhere to ZF's standard, barAction()
+$controllerAction = strtolower($route['action']) . 'Action';
+
+// load the controller class
+require 'app/modules/' . $route['module'] . '/' . $class . '.php';
+
+$controllerObj = new $controllerClass;
+call_user_func(array($controllerObj, $controllerAction)); // pseudo dispatcher

Modified: pear/peardoc/trunk/en/package/networking/net-url-mapper/features.xml
===================================================================
--- pear/peardoc/trunk/en/package/networking/net-url-mapper/features.xml	2009-10-05 17:05:35 UTC (rev 289224)
+++ pear/peardoc/trunk/en/package/networking/net-url-mapper/features.xml	2009-10-05 17:41:05 UTC (rev 289225)
@@ -19,60 +19,65 @@
   keys provided could be called anything and are not mandatory.
  </para>

+
  <section
   xml:id="package.networking.net-url-mapper.features.static"
   phd:chunk="false"
  >
+  <info>
+   <title>Static path parts</title>
+  </info>

-  <info><title>Static path parts</title></info>
-
   <para>
    The following code snippet maps the URL <literal>/home</literal>:
   </para>

   <example>
    <programlisting role="php">
-     <![CDATA[
-require_once 'Net/URL/Mapper.php';
-
-$m = Net_URL_Mapper::getInstance();
-$m->connect('home', array('controller' => 'index', 'action' => 'index'));
-var_dump($m->match($_SERVER['REQUEST_URI']));
-
-     ]]>
+    <xi:include parse="text"
+     xmlns:xi="http://www.w3.org/2001/XInclude"
+     href="&package.networking.net-url-mapper.examples.static-routing.php;"
+    >
+     <xi:fallback>FIXME:MISSING XINCLUDE CONTENT</xi:fallback>
+    </xi:include>
    </programlisting>
   </example>
  </section>

+
  <section
   xml:id="package.networking.net-url-mapper.features.dynamic"
   phd:chunk="false"
  >
-  <info><title>Dynamic path parts</title></info>
+  <info>
+   <title>Dynamic path parts</title>
+  </info>

   <para>
    The following code snippet maps a URL such as <literal>/news/1</literal>,
    <literal>/news/2</literal> to a designated controller and action.
   </para>
+
   <example>
    <programlisting role="php">
-     <![CDATA[
-require_once 'Net/URL/Mapper.php';
-
-$m = Net_URL_Mapper::getInstance();
-$m->connect('news/:id', array('controller' => 'news', 'action' => 'read'));
-var_dump($m->match($_SERVER['REQUEST_URI']));
-
-     ]]>
+    <xi:include parse="text"
+     xmlns:xi="http://www.w3.org/2001/XInclude"
+     href="&package.networking.net-url-mapper.examples.dynamic-routing.php;"
+    >
+     <xi:fallback>FIXME:MISSING XINCLUDE CONTENT</xi:fallback>
+    </xi:include>
    </programlisting>
   </example>
  </section>

+
  <section
   xml:id="package.networking.net-url-mapper.features.wildcard"
   phd:chunk="false"
  >
-  <info><title>Wildcard path parts</title></info>
+  <info>
+   <title>Wildcard path parts</title>
+  </info>

   <para>
    The following code snippet maps all URLs with <literal>/content</literal> to a
@@ -80,24 +85,15 @@
    display</literal>. Optionally, we'll determine the section on the page using a
    wildcard. The default for section is <literal>#toc</literal> (Table Of Contents).
   </para>
+
   <example>
    <programlisting role="php">
-     <![CDATA[
-require_once 'Net/URL/Mapper.php';
-
-$m = Net_URL_Mapper::getInstance();
-
-$path     = 'content/*(section)';
-$defaults = array(
-    'controller' => 'content',
-    'action'     => 'display',
-    'section'    => '#toc',
-);
-
-$m->connect($path, $defaults);
-var_dump($m->match($_SERVER['REQUEST_URI']));
-
-     ]]>
+    <xi:include parse="text"
+     xmlns:xi="http://www.w3.org/2001/XInclude"
+     href="&package.networking.net-url-mapper.examples.wildcard-routing.php;"
+    >
+     <xi:fallback>FIXME:MISSING XINCLUDE CONTENT</xi:fallback>
+    </xi:include>
    </programlisting>
   </example>
  </section>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.