Aspects (Was: Re: [PECL-DEV] superglobals)
| From: | Jackson Miller | Date: | Mon, 12 Apr 2004 16:20:05 +0000 |
| Subject: | Aspects (Was: Re: [PECL-DEV] superglobals) | ||
| References: | 1 2 3 | Groups: | php.pecl.dev |
| Request: | Send a blank email to pecl-dev+get-546@lists.php.net to get a copy of this message | ||
Implementing aspects has come up in the development of "CEP" which aims to be
an application framework for enterprise applications. CEP stands for "Core
Enterprise PHP", or in true gnu fashion "CEP Extends PEAR". It is licensed
under the PHP license and is available at sourceforge.net
(http://sourceforge.net/projects/cep).
I am pretty sure that aspects could be of benefit to other PHP development
frameworks, and adding aspect functionality to PECL could provide a way for
the multiple frameworks to work together, or at least share the
implementation of aspects. So it does have the possibility to be widely used
by the (small) subset of PHP developers creating large OOP apps. Hence the
involvement of PECL.
AspectJ is the package that provides aspects to Java. Their homepage is:
http://eclipse.org/aspectj
From the homepage:
AspectJ enables the clean modularization of crosscutting concerns such as:
error checking and handling, synchronization, context-sensitive behavior,
performance optimizations, monitoring and logging, debugging support,
multi-object protocols.
The important thing about aspects is that they are "crosscutting concerns" in
your apps that are woven through the different pages/modules/etc. "Clean" is
an important word in the definition.
Aspects aim to solve the problem of disparate code throughout your app to
handle the same task over and over again. Error checking/handling, caching,
and logging are prime examples. But those are examples that are often
handled by the lauguage or the framework. By using aspects you can easily
change the functionality system wide. An example might be to move from
logging to a flat-file to logging via web-services.
I know from this explaination aspects sould like they can easily be
accomplished with objects. "Getting Started with Aspects" (http://
dev.eclipse.org/viewcvs/indextech.cgi/~checkout~/aspectj-home/doc/progguide/
starting.html) describes some of the more important elements of aspects that
diferentiate them from objects. The three that are important to PHP are
"Join Points", "Pointcuts", and "Advice".
We are still working out the syntax for implementing join points, pointcuts,
and advice in PHP aspects, but my first step was to implement an $_ASPECT
superglobal so that the aspects could be available from all the parts of the
application.
I would like the second step to be to create a PHP keyword for creating
aspects with something like the following:
$log = new aspect Log::singleton(...);
or
aspect $log = new Log::singleton(...);
which would be accessible via:
$_ASPECT['log']
I would like to see the aspect keyword do something like create a new class
that extends the passed class (in this case PEAR::Log). The new class would
have some methods for adding pointcuts to this aspect. Then it would return
an object of this new class.
The hope is that we can create a very basic implementation of aspects similar
to how objects entered PHP. It needs to be more than just an automatic
global reference, but it doesn't need to be much more for now.
$_ASPECT['log'] is much cleaner than $GLOBALS['log'] or
$GLOBALS['aspect']
['log'].
In CEP we are working with the idea of CLAMs (Components, Libraries, Aspects,
and Modules). An entire application can be written out of CLAMs on CEP, but
we need to implement aspects in order to be complete.
So far I have created an $_ASPECT superglobal be editing the PHP source. Now
we are working on making an extension (hopefully for PECL) that will do the
same.
-Jackson