Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions reference/yaf/yaf_loader/registerlocalnamespace.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<modifier>public</modifier> <type class="union"><type>Yaf_Loader</type><type>false</type><type>null</type></type><methodname>Yaf_Loader::registerLocalNamespace</methodname>
<methodparam><type>string|array</type><parameter>namespace</parameter></methodparam>
<methodparam choice="opt"><type>string</type><parameter>path</parameter><initializer>null</initializer></methodparam>
<modifier>public</modifier> <type class="union"><type>Yaf_Loader</type><type>false</type></type><methodname>Yaf_Loader::registerLocalNamespace</methodname>
<methodparam><type class="union"><type>string</type><type>array</type></type><parameter>namespace</parameter></methodparam>
<methodparam choice="opt"><type>string</type><parameter>path</parameter><initializer>&null;</initializer></methodparam>
</methodsynopsis>
Comment thread
mmalferov marked this conversation as resolved.
<simpara>Register a local namespace. Classes whose prefix belongs to a local namespace are looked up under the given path (or the local library directory when no path is given) instead of the global one.</simpara>
<simpara>This lets you place your own classes into the local library directory, while shared classes live in the global library directory (see the <literal>yaf.library</literal> ini setting).</simpara>
Expand All @@ -25,6 +25,7 @@
<term><parameter>namespace</parameter></term>
<listitem>
<simpara>A namespace prefix string, or an array of prefix/path pairs (when the value is a path string) or prefix strings.</simpara>
<simpara>A prefix only matches at an underscore or backslash boundary: registering <literal>Models</literal> makes <literal>Models_User</literal> and <literal>Models</literal> itself local, but not <literal>ModelsUser</literal>. A leading backslash is ignored, and a class name written with backslashes is looked up as if they were underscores.</simpara>
</listitem>
</varlistentry>
Comment thread
mmalferov marked this conversation as resolved.
<varlistentry>
Expand Down
8 changes: 4 additions & 4 deletions reference/yaf/yaf_loader/registernamespace.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<modifier>public</modifier> <type class="union"><type>Yaf_Loader</type><type>false</type><type>null</type></type><methodname>Yaf_Loader::registerNamespace</methodname>
<methodparam><type>string|array</type><parameter>name_prefix</parameter></methodparam>
<methodparam choice="opt"><type>string</type><parameter>path</parameter><initializer>null</initializer></methodparam>
<modifier>public</modifier> <type class="union"><type>Yaf_Loader</type><type>false</type></type><methodname>Yaf_Loader::registerNamespace</methodname>
<methodparam><type class="union"><type>string</type><type>array</type></type><parameter>namespace</parameter></methodparam>
<methodparam choice="opt"><type>string</type><parameter>path</parameter><initializer>&null;</initializer></methodparam>
</methodsynopsis>
<simpara>Alias of <methodname>Yaf_Loader::registerLocalNamespace</methodname>.</simpara>
</refsect1>
Expand All @@ -21,7 +21,7 @@
&reftitle.parameters;
<variablelist>
<varlistentry>
<term><parameter>name_prefix</parameter></term>
<term><parameter>namespace</parameter></term>
<listitem>
<simpara>A namespace prefix string, or an array of prefix/path pairs (when the value is a path string) or prefix strings.</simpara>
</listitem>
Expand Down
204 changes: 111 additions & 93 deletions reference/yaf/yaf_route_regex/construct.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@
<modifier>public</modifier> <methodname>Yaf_Route_Regex::__construct</methodname>
<methodparam><type>string</type><parameter>match</parameter></methodparam>
<methodparam><type>array</type><parameter>route</parameter></methodparam>
<methodparam choice="opt"><type>array</type><parameter>map</parameter></methodparam>
<methodparam choice="opt"><type>array</type><parameter>verify</parameter></methodparam>
<methodparam choice="opt"><type>string</type><parameter>reverse</parameter></methodparam>
<methodparam choice="opt"><type class="union"><type>array</type><type>null</type></type><parameter>map</parameter><initializer>&null;</initializer></methodparam>
<methodparam choice="opt"><type class="union"><type>array</type><type>null</type></type><parameter>verify</parameter><initializer>&null;</initializer></methodparam>
<methodparam choice="opt"><type class="union"><type>string</type><type>null</type></type><parameter>reverse</parameter><initializer>&null;</initializer></methodparam>
</constructorsynopsis>
<para>
</para>
<simpara>
Constructs a <classname>Yaf_Route_Regex</classname> route, which routes a
request URI matching a regular expression to a module, controller and action.
</simpara>

</refsect1>

Expand All @@ -28,52 +30,60 @@
<varlistentry>
<term><parameter>match</parameter></term>
<listitem>
<para>
A complete Regex pattern, will be used to match a request uri, if
doesn't matched, <classname>Yaf_Route_Regex</classname> will return
&false;.
</para>
<simpara>
A complete regular expression pattern, used to match the request URI.
When it does not match, <methodname>Yaf_Route_Regex::route</methodname>
returns &false; and the router moves on to the next route.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>route</parameter></term>
<listitem>
<para>
When the match pattern matches the request uri,
<classname>Yaf_Route_Regex</classname> will use this to decide which
m/c/a to routed.
</para>
<para>
either of m/c/a in this array is optional, if you don't assign a
specific value, it will be routed to default.
</para>
<simpara>
When the pattern matches the request URI, this &array; determines the
module, controller and action to route to.
</simpara>
<simpara>
Each of the three entries is optional; when one is not given, the
default is used. An entry whose value starts with <literal>:</literal>
is resolved against the parameters produced by
<parameter>map</parameter>.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>map</parameter></term>
<listitem>
<para>
An array to assign name to the captures in the match result.
</para>
<simpara>
An &array; mapping capture group indexes to parameter names. Only the
captures listed here become request parameters; a numeric capture that
is not listed is discarded.
</simpara>
<simpara>
Named capture groups are always added under their own name and do not
need to be listed.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>verify</parameter></term>
<listitem>
<para>

</para>
<simpara>
Accepted and stored on the route, but not used: the current
implementation never consults it while routing.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>reverse</parameter></term>
<listitem>
<para>
a string, used to assemble url, see
A &string;, used to assemble URL, see
<methodname>Yaf_Route_Regex::assemble</methodname>.
<note>
<simpara>
this parameter is introduced in 2.3.0
This parameter is introduced in 2.3.0
</simpara>
</note>
</para>
Expand All @@ -84,108 +94,114 @@

<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>

</para>
<simpara>No value is returned.</simpara>
</refsect1>

<refsect1 role="examples">
&reftitle.examples;
<example>
<title><classname>Yaf_Route_Regex</classname> example</title>
<title><classname>Yaf_Route_Regex</classname> via <methodname>Yaf_Router::addRoute</methodname></title>
<programlisting role="php">
<![CDATA[
<?php
/**
* Add a regex route to Yaf_Router route stack
*/
Yaf_Dispatcher::getInstance()->getRouter()->addRoute("name",
new Yaf_Route_Regex(
"#^/product/([^/]+)/([^/])+#", //match request uri leading "/product"
array(
'controller' => "product", //route to product controller,
),
array(
1 => "name", // now you can call $request->getParam("name")
2 => "id", // to get the first captrue in the match pattern.
)

/**
* Add a regex route to the Yaf_Router route stack
*/
Yaf_Dispatcher::getInstance()->getRouter()->addRoute(
"name",
new Yaf_Route_Regex(
"#^/product/([^/]+)/([^/]+)#", // match a URI leading "/product"
array(
'controller' => "product", // route to the product controller
),
array(
1 => "name", // $request->getParam("name") holds the first capture
2 => "id", // and $request->getParam("id") the second
)
);
)
);
?>
]]>
</programlisting>
</example>
<example>
<title><classname>Yaf_Route_Regex</classname> (as of 2.3.0) example</title>
<title><classname>Yaf_Route_Regex</classname> using a capture as the controller name</title>
<programlisting role="php">
<![CDATA[
<?php
/**
* Use match result as MVC name
*/
Yaf_Dispatcher::getInstance()->getRouter()->addRoute("name",
new Yaf_Route_Regex(
"#^/product/([^/]+)/([^/])+#i", //match request uri leading "/product"
array(
'controller' => ":name", // route to :name, which is $1 in the match result as controller name
),
array(
1 => "name", // now you can call $request->getParam("name")
2 => "id", // to get the first captrue in the match pattern.
)

/**
* Use a capture as the controller name
*/
Yaf_Dispatcher::getInstance()->getRouter()->addRoute(
"name",
new Yaf_Route_Regex(
"#^/product/([^/]+)/([^/]+)#i", // match a URI leading "/product"
array(
'controller' => ":name", // the "name" capture (see map) becomes the controller
),
array(
1 => "name", // $request->getParam("name") holds the first capture
2 => "id", // and $request->getParam("id") the second
)
);
)
);
?>
]]>
</programlisting>
</example>
<example>
<title><classname>Yaf_Route_Regex</classname> and named capture group (as of 2.3.0) example</title>
<title><classname>Yaf_Route_Regex</classname> using a named capture group</title>
<programlisting role="php">
<![CDATA[
<?php
/**
* Use match result as MVC name
*/
Yaf_Dispatcher::getInstance()->getRouter()->addRoute("name",
new Yaf_Route_Regex(
"#^/product/(?<name>[^/]+)/([^/])+#i", //match request uri leading "/product"
array(
'controller' => ":name", // route to :name,
// which is named capture group 'name' in the match result as controller name
),
array(
2 => "id", // to get the first captrue in the match pattern.
)

/**
* Use a named capture group as the controller name
*/
Yaf_Dispatcher::getInstance()->getRouter()->addRoute(
"name",
new Yaf_Route_Regex(
"#^/product/(?<name>[^/]+)/([^/]+)#i", // match a URI leading "/product"
array(
'controller' => ":name", // the "name" capture becomes the controller
),
array(
2 => "id", // group 1 is named, only group 2 needs a map entry
)
);
)
);
?>
]]>
</programlisting>
</example>
<example>
<title><classname>Yaf_Route_Regex</classname> example</title>
<title><classname>Yaf_Route_Regex</classname> via <methodname>Yaf_Router::addConfig</methodname></title>
<programlisting role="php">
<![CDATA[
<?php
/**
* Add a regex route to Yaf_Router route stack by calling addconfig
*/
$config = array(
"name" => array(
"type" => "regex", //Yaf_Route_Regex route
"match" => "#(.*)#", //match arbitrary request uri
"route" => array(
'controller' => "product", //route to product controller,
'action' => "dummy", //route to dummy action
),
"map" => array(
1 => "uri", // now you can call $request->getParam("uri")
),

/**
* Add a regex route to the Yaf_Router route stack through a config array
*/
$config = array(
"name" => array(
"type" => "regex", // a Yaf_Route_Regex route
"match" => "#(.*)#", // match any request URI
"route" => array(
'controller' => "product", // route to the product controller
'action' => "dummy", // and to the dummy action
),
);
Yaf_Dispatcher::getInstance()->getRouter()->addConfig(
new Yaf_Config_Simple($config));
"map" => array(
1 => "uri", // $request->getParam("uri") holds the matched URI
),
),
);

Yaf_Dispatcher::getInstance()->getRouter()->addConfig(
new Yaf_Config_Simple($config)
);
?>
]]>
</programlisting>
Expand All @@ -195,6 +211,8 @@
<refsect1 role="seealso">
&reftitle.seealso;
<simplelist>
<member><methodname>Yaf_Route_Regex::route</methodname></member>
<member><methodname>Yaf_Route_Regex::assemble</methodname></member>
<member><methodname>Yaf_Router::addRoute</methodname></member>
<member><methodname>Yaf_Router::addConfig</methodname></member>
<member><classname>Yaf_Route_Static</classname></member>
Expand Down