diff --git a/reference/yaf/yaf_loader/registerlocalnamespace.xml b/reference/yaf/yaf_loader/registerlocalnamespace.xml index 8c07c4846ebc..2dce52fc7297 100644 --- a/reference/yaf/yaf_loader/registerlocalnamespace.xml +++ b/reference/yaf/yaf_loader/registerlocalnamespace.xml @@ -10,13 +10,14 @@ &reftitle.description; - public voidYaf_Loader::registerLocalNamespace - mixedprefix + public Yaf_LoaderfalseYaf_Loader::registerLocalNamespace + stringarraynamespace + stringpath - Register local class prefix name, Yaf_Loader search + Register local class prefix name, Yaf_Loader searches classes in two library directories, the one is configured via application.library.directory(in + linkend="configuration.yaf.directory">application.library.directory (in application.ini) which is called local library directory; the other is configured via yaf.library (in php.ini) which is called global library directory, since it can be shared @@ -27,17 +28,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. - - 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. - - But if you want your Yaf application be strong, then always register your - own classes as local classes. - + + 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. + + + For a more robust Yaf application, always register the application's own + classes as local classes. + @@ -46,32 +48,43 @@ &reftitle.parameters; - prefix + namespace - - 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 prefixes. A prefix only matches at + an underscore or backslash boundary: registering Baidu + makes Baidu_Name and Baidu local, + but not BaiduName. A leading backslash is ignored, and + backslashes are handled like underscores. + + + path + + A &string; of path, it is better to use absolute path here for performance. + + &reftitle.returnvalues; - - bool - + + Returns the Yaf_Loader instance on success&return.falseforfailure;. + &reftitle.examples; - <function>Yaf_Loader::registerLocalNamespace</function>example + <function>Yaf_Loader::registerLocalNamespace</function> example registerLocalNamespace("Baidu"); $loader->registerLocalNamespace(array("Sina", "Weibo")); diff --git a/reference/yaf/yaf_loader/registernamespace.xml b/reference/yaf/yaf_loader/registernamespace.xml index 03457640eb85..8f9094ae6fcf 100644 --- a/reference/yaf/yaf_loader/registernamespace.xml +++ b/reference/yaf/yaf_loader/registernamespace.xml @@ -4,27 +4,27 @@ Yaf_Loader::registerNamespace - Register namespace with searching path + Registers a namespace with searching path &reftitle.description; - public boolYaf_Loader::registerNamespace - stringarraynamespaces + public Yaf_LoaderfalseYaf_Loader::registerNamespace + stringarraynamespace stringpath Register a namespace with searching path, Yaf_Loader - searchs classes under this namespace in path, the one is also could be - configureded via - application.library.directory.namespace(in application.ini); + searches classes under this namespace in path, which can also be + configured via + application.library.namespace (in application.ini). - - Yaf still think underline as folder separator. - + + Yaf still thinks underscore as folder separator. + @@ -36,16 +36,18 @@ namespace - a string of namespace, or an array of namespaces with paths. + A &string; of namespace, or an &array; of namespaces with paths. path - - a string of path, it is better to use abosolute path here for performance - + + A &string; of path, it is better to use absolute path here for performance. + Ignored when namespace is an &array;; in that case + each path is given as the value of its namespace key. + @@ -53,28 +55,30 @@ &reftitle.returnvalues; - - bool - + + Returns the Yaf_Loader instance on success,&return.falseforfailure;. + &reftitle.examples; - <function>Yaf_Loader::registerNamespace</function>example + <function>Yaf_Loader::registerNamespace</function> example 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' ?> ]]> diff --git a/reference/yaf/yaf_route_regex/construct.xml b/reference/yaf/yaf_route_regex/construct.xml index 5ae1ae00038e..c3045d285de6 100644 --- a/reference/yaf/yaf_route_regex/construct.xml +++ b/reference/yaf/yaf_route_regex/construct.xml @@ -15,10 +15,14 @@ arrayroute arraymap arrayverify - stringreverse + arraynullmap&null; + arraynullverify&null; + stringnullreverse&null; - - + + Constructs a Yaf_Route_Regex route, which routes a + request URI matching a regular expression to a module, controller and action. + @@ -28,33 +32,33 @@ match - - 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, Yaf_Route_Regex will return &false;. - + route - When the match pattern matches the request uri, + When the match pattern matches the request URI, Yaf_Route_Regex will use this to decide which - m/c/a to routed. - - - either of m/c/a in this array is optional, if you don't assign a - specific value, it will be routed to default. + m/c/a to be routed. + + Each of m/c/a in this &array; is optional, if no specific value is + assigned, it will be routed to default. + map - - An array to assign name to the captures in the match result. - + + An &array; to assign name to the captures in the match result. + @@ -69,11 +73,11 @@ reverse - a string, used to assemble url, see + A &string;, used to assemble URL, see Yaf_Route_Regex::assemble. - this parameter is introduced in 2.3.0 + This parameter is introduced in 2.3.0 @@ -96,22 +100,23 @@ 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", ) - ); -?> + ) +); ]]> @@ -120,22 +125,23 @@ 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", ) - ); -?> + ) +); ]]> @@ -144,22 +150,22 @@ getRouter()->addRoute("name", - new Yaf_Route_Regex( - "#^/product/(?[^/]+)/([^/])+#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/(?[^/]+)/([^/])+#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", ) - ); -?> + ) +); ]]> @@ -168,25 +174,27 @@ 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) +); ]]>