NYCPHP Meetup

NYPHP.org

[joomla] Adding custom libraries in Joomla

Gary Mort garyamort at gmail.com
Wed Dec 12 09:59:00 EST 2012


Hopefully I can fix my domain later today so I can publish my notes.  In
the meantime, I've been working on cleaning up some small plugins and
extensions so that they can be installed and used outside of the sites they
were built on.

This means moving classes to a common library, enabling the library, etc.

This dragged a bit as every time I thought it was done, I discovered
another little oddity in Joomla interactions.  As a first step to resolving
this, I've created an extremely simple demo package to use as a
model/skeleton for my real library.

An installable version of the package is located here:
https://github.com/garyamort/joomla-cms-hydra/raw/crafty-demo-library/package/package.tar.gz

And the entire source can be forked on Github:
https://github.com/garyamort/joomla-cms-hydra/tree/crafty-demo-library


The "library" consists of a single abstract class,
\crafty\demo\LibraryVersion which defines some class library version
related information as class constants - and then provides a few methods
for getting library information as strings.  It will be installed in the
libraries directory under crafty.demo

The plugin leverages JLoader exclusively - it uses JLoader to map the class
prefix \crafty\demo\ to the subdirectory libraries/crafty.demo.  NOTE: due
to deficiencies in the Joomla Plugin Helper the plugin class resides in the
global namespace.  Once installed, if the plugin is enabled the library is
available.  If the plugin is disabled, the library is unknown.

The module is simply used to show if the plugin is enabled or not. :-)  It
utilizes a call to class_exists to check for the
\crafty\demo\LibraryVersion class.  If it does not exist, a simple "class
does not exist" message is displayed.  If it does exist, then it will grab
some version information and display it to the user.

There is much that can be improved with this library, but rather than wait
for it to be "perfect" I figured I'd publish it now.   All code is under
the lesser GPL so others are free to fork it and extend it for their own
usage.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/joomla/attachments/20121212/fbc327a2/attachment.html>


More information about the Joomla mailing list