Permalink
Browse files

Merge pull request #902 from eddieajau/docs

Updated auto-loader docs for new registerPrefix method.
  • Loading branch information...
2 parents 44c2f0c + 21aaa3e commit 99b335a2d284e198a8f28d6d4ee28536a82114fe @LouisLandry LouisLandry committed Feb 20, 2012
Showing with 33 additions and 1 deletion.
  1. +33 −1 docs/manual/en-US/chapters/classes/jloader.xml
View
34 docs/manual/en-US/chapters/classes/jloader.xml
@@ -42,12 +42,44 @@ JLoader::register('JDatabase', '/custom/path/database_driver.php', true);</progr
</section>
<section>
+ <title>Registering a Class Prefix</title>
+
+ <para>Since 12.1, there is the ability to register where the auto-loader will look based on a class prefix (previously only
+ the "J" prefix was supported, bound to the <filename>/libraries/joomla</filename> folder). This allows for several
+ scenarios:</para>
+
+ <simplelist>
+ <member>A developer can register the prefix of custom classes, and a root path to allow the auto-loader to find
+ them.</member>
+
+ <member>A developer can register an extra path for an existing prefix (for example, this allows the Joomla CMS to have
+ custom libraries but still using the "J" prefix).</member>
+
+ <member>A developer can register a force override for a prefix. This could be used to completely override the core classes
+ with a custom replacement.</member>
+ </simplelist>
+
+ <example>
+ <title>Using JLoader::registerPrefix</title>
+
+ <programlisting>// Tell the auto-loader to also look in the /libraries/cms folder for "J" prefixed classes.
+JLoader::registerPrefix('J', JPATH_PLATFORM . '/cms');
+
+// Tell the auto-loader to look for classes starting with "Foo" in a specific folder.
+JLoader::registerPrefix('Foo', '/path/to/custom/packages');
+
+// Tell the auto-loader to reset the "J" prefix and point it to a custom fork of the platform.
+JLoader::registerPrefix('J', '/my/platform/fork', true);</programlisting>
+ </example>
+ </section>
+
+ <section>
<title>Discovering Classes</title>
<para>Classes in a folder that follow a naming convention, but not one the auto-loader immediately recognises, can be
registered collectively with <classname>JLoader</classname>'s <methodname>discover</methodname> method. The discover method
looks at the file names in a folder and registers classes based on those names. Additional arguments can be used to update the
- class register and rescurse into sub-folders.</para>
+ class register and recurse into sub-folders.</para>
<example>
<title>Using JLoader::discover</title>

0 comments on commit 99b335a

Please sign in to comment.