Skip to content
Open
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
29 changes: 16 additions & 13 deletions reference/yaf/yaf_loader/registerlocalnamespace.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<modifier>public</modifier> <type>void</type><methodname>Yaf_Loader::registerLocalNamespace</methodname>
<modifier>public</modifier> <type class="union"><type>Yaf_Loader</type><type>false</type></type><methodname>Yaf_Loader::registerLocalNamespace</methodname>
<methodparam><type>mixed</type><parameter>prefix</parameter></methodparam>
</methodsynopsis>
<para>
Register local class prefix name, <classname>Yaf_Loader</classname> search
Register local class prefix name, <classname>Yaf_Loader</classname> searches
classes in two library directories, the one is configured via <link
linkend="configuration.yaf.library">application.library.directory</link>(in
linkend="configuration.yaf.library">application.library.directory</link> (in
application.ini) which is called local library directory; the other is
configured via <link linkend="ini.yaf.library">yaf.library</link> (in
php.ini) which is called global library directory, since it can be shared
Expand All @@ -27,17 +27,18 @@
determine which library directory should be searched in by examining the prefix
name of the missed classname.

If the prefix name is registered as a localnamespack then look for it in
If the prefix name is registered as a local namespace then look for it in
local library directory, otherwise look for it in global library directory.
<note>
<para>
If yaf.library is not configured, then the global library directory is
assumed to be the local library directory. in that case, all autoloading
will look for local library directory.

<simpara>
If <literal>yaf.library</literal> is not configured, then the global library directory is
assumed to be the local library directory. In that case, all autoloading
will look for local library directory.
</simpara>
<simpara>
But if you want your Yaf application be strong, then always register your
own classes as local classes.
</para>
</simpara>
</note>
</para>
</refsect1>
Expand All @@ -49,8 +50,8 @@
<term><parameter>prefix</parameter></term>
<listitem>
<para>
a string or an array of class name prefix.
all class prefix with these prefix will be loaded in local library path.
A &string; or an &array; of class name prefix.
All class prefix with these prefix will be loaded in local library path.
</para>
</listitem>
</varlistentry>
Expand All @@ -60,7 +61,7 @@
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
bool
Returns the <classname>Yaf_Loader</classname> instance on success,&return.falseforfailure;.
</para>
</refsect1>

Expand All @@ -71,7 +72,9 @@
<programlisting role="php">
<![CDATA[
<?php

$loader = Yaf_Loader::getInstance('/local/library/', '/global/library');

$loader->registerLocalNamespace("Baidu");
$loader->registerLocalNamespace(array("Sina", "Weibo"));

Expand Down
26 changes: 14 additions & 12 deletions reference/yaf/yaf_loader/registernamespace.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<modifier>public</modifier> <type>bool</type><methodname>Yaf_Loader::registerNamespace</methodname>
<methodparam><type class="union"><type>string</type><type>array</type></type><parameter>namespaces</parameter></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></methodparam>
</methodsynopsis>
<para>
Register a namespace with searching path, <classname>Yaf_Loader</classname>
searchs classes under this namespace in path, the one is also could be
configureded via <link linkend="configuration.yaf.library.namespace">
application.library.directory.namespace</link>(in application.ini);
searches classes under this namespace in path, the one is also could be
configured via <link linkend="configuration.yaf.library.namespace">
application.library.namespace</link> (in <literal>application.ini</literal>).
</para>
<para>
<note>
<para>
Yaf still think underline as folder separator.
Yaf still think underscore as folder separator.
</para>
</note>
</para>
Expand All @@ -36,15 +36,15 @@
<term><parameter>namespace</parameter></term>
<listitem>
<para>
a string of namespace, or an array of namespaces with paths.
A &string; of namespace, or an &array; of namespaces with paths.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>path</parameter></term>
<listitem>
<para>
a string of path, it is better to use abosolute path here for performance
A &string; of path, it is better to use abosolute path here for performance.
</para>
</listitem>
</varlistentry>
Expand All @@ -54,7 +54,7 @@
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
bool
Returns the <classname>Yaf_Loader</classname> instance on success,&return.falseforfailure;.
</para>
</refsect1>

Expand All @@ -65,16 +65,18 @@
<programlisting role="php">
<![CDATA[
<?php

$loader = Yaf_Loader::getInstance();

$loader->registerNamespace("\Vendor\PHP", "/var/lib/php");
$loader->registerNamespace(array(
"\Vendor\ASP" => "/var/lib/asp",
"\Vendor\JSP" => "/usr/lib/vendor/",
));

$loader->autoload("\Vendor\PHP\Dummy"); //load '/var/lib/php/Dummy.php'
$loader->autoload("\Vendor\PHP\Foo_Bar"); //load '/var/lib/php/Foo/Bar.php'
$loader->autoload("\Vendor\JSP\Dummy"); //load '/usr/lib/vendor/Dummy.php'
$loader->autoload("\Vendor\PHP\Dummy"); // Load '/var/lib/php/Dummy.php'
$loader->autoload("\Vendor\PHP\Foo_Bar"); // Load '/var/lib/php/Foo/Bar.php'
$loader->autoload("\Vendor\JSP\Dummy"); // Load '/usr/lib/vendor/Dummy.php'

?>
]]>
Expand Down
144 changes: 74 additions & 70 deletions reference/yaf/yaf_route_regex/construct.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<term><parameter>match</parameter></term>
<listitem>
<para>
A complete Regex pattern, will be used to match a request uri, if
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>
Expand All @@ -39,12 +39,12 @@
<term><parameter>route</parameter></term>
<listitem>
<para>
When the match pattern matches the request uri,
When the match pattern matches the request URI,
<classname>Yaf_Route_Regex</classname> will use this to decide which
m/c/a to routed.
m/c/a to be routed.
</para>
<para>
either of m/c/a in this array is optional, if you don't assign a
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>
</listitem>
Expand All @@ -53,7 +53,7 @@
<term><parameter>map</parameter></term>
<listitem>
<para>
An array to assign name to the captures in the match result.
An &array; to assign name to the captures in the match result.
</para>
</listitem>
</varlistentry>
Expand All @@ -69,11 +69,11 @@
<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>
<para>
this parameter is introduced in 2.3.0
This parameter is introduced in 2.3.0
</para>
</note>
</para>
Expand All @@ -96,22 +96,23 @@
<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 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", // The first capture in the match pattern is now available via $request->getParam("name")
2 => "id",
)
);
?>
)
);
]]>
</programlisting>
</example>
Expand All @@ -120,22 +121,23 @@
<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 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", // The first capture in the match pattern is now available via $request->getParam("name")
2 => "id",
)
);
?>
)
);
]]>
</programlisting>
</example>
Expand All @@ -144,22 +146,22 @@
<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 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",
)
);
?>
)
);
]]>
</programlisting>
</example>
Expand All @@ -168,25 +170,27 @@
<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 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
),
);
Yaf_Dispatcher::getInstance()->getRouter()->addConfig(
new Yaf_Config_Simple($config));
?>
"map" => array(
1 => "uri", // The URI is now available via $request->getParam("uri")
),
),
);

Yaf_Dispatcher::getInstance()->getRouter()->addConfig(
new Yaf_Config_Simple($config)
);
]]>
</programlisting>
</example>
Expand Down