5.2.0-git
2014-07-25
Last Modified 2008-04-03 by Chuck Hagenbuch
  • Message
    This page is locked by 107.20.109.52 for 10 Minutes.
RampageFramework Reload Page

Horde on the Rampage

Rampage Libraries

These are PHP 5.2+ libraries, in some cases PHP 5.3+, that are E_STRICT compliant, that will be part of Horde 4 and the Rampage framework:

  • Horde/Argv
  • Horde/Feed
  • Horde/Http_Client
  • Horde/Lens
  • Horde/Log
  • Horde/Pdf
  • Horde/Rdo
  • Horde/Routes
  • Horde/Text_Rst
  • Horde/Text_Textile
  • Horde/View
  • Horde/Xml_Element
  • Horde/Yaml

General ideas

RampageInstallation

Lightweight component architecture

Take a look at the Horde_Block system. Take a look at the *_View objects in Kronolith and a few other apps. Come up with something that unifies them into a lightweight way to encapsulate content in an easy-to-reuse, easy-to-render elsewhere package.

Structure

New structure for views/commands:

/do/App/Command
/get/App/View

AJAX built-in
webservices
Context object?
see ruby on rails and DB_DataObject pdf

  • all config in a sqlite core db - not sure about this
  • next-gen DataTree - RDO. Need a seperate tree/hierarchy solution
  • Controller patterns - not necessarily a front controller, files already are that. unified /path/app/item/id would be good.
  • integrate w/ existing Horde
  • one database, pear installed files, one VFS space - have just one installed set of libs for multiple sites. do with HORDE_BASE or something similar?
  • differentiate between rampage app core (replace giapeto?) and libraries. try to go with more libraries than monolithic framework?
  • Context::appname::method($params) - this doesn't work, Rampage::app->method would. Already implemented in Registry class.
  • Session object for managing data we expect to find in $_SESSION
  • base Rampage on: ulaform, giapeto, wicked, should replace those ... ? jonah?
  • Iterators! Only loop through data once!
  • Page/URL design: the back button should work where possible
  • use POST for anything that's an edit or delete. really.
  • Make use of stream wrappers for easy fopen/fwrite/fgets with data sources. VFS wrappers at least.

Encapsulated globals in Rampage:: namespace. Goal to avoid global $conf, $prefs, etc. variables and to do lazy-loading of conf and prefs so they're not loaded when they're not needed. Maybe encapsulate prefs in a User object/namespace?

everything else pear installable
- apps - Horde/Rampage/App/Appname, or Apps?
- blocks - Horde/Rampage/Block/, or Horde/Block?
- libs

Each app has:
Views/
Forms/
Objects/
Methods/
Pages/?
Config/?
xml files

Dir structure for distributable apps:

www.sitename.tld
cron/
htdocs/
.htaccess
themes/
screen.css
graphics/
sounds/
javascript/
index.php
includes/
pear/ ?
logs/
scripts/
templates/

Use .phar (php archive) files for installing rampage sites?

Rampage::log() - just for admin messages
Rampage::message() or Rampage::notify()
For user level notification - html alerts, ajax, send email, jabber, etc. Can be triggered by an Observer but doesn't implement object relationshps. What should? Workflow...

RDO

Data dictionary - description of fields, basis for validation? required, etc... pull some from database, some from object hardcoded metadata?

no set/get
just pass it a $form object
commands come in somewhere
Builder: http://www.javaworld.com/javaworld/jw-01-2004/jw-0102-toolbox-p2.html
http://www.javaworld.com/javaworld/jw-08-2003/jw-0801-toolbox.html - Listing 0.1.Elim... !

take interfaces that implement Iterator wherever possible

need basic classes for each backend (SQL, LDAP, Kolab, IMSP, etc) that provide a unified api
try hard not to use more than that api; write specific adapters when necessary (Whups with encapsulated specialized Mapper objects, etc.).

Should be a way to cache table meta data

Need a way to specify which fields to load (for example like Turba only loads fields being displayed). When this is done, the rest should be lazy-loaded.

Should be possible to greedy-load related objects (lazy is the default).

Display and templates, Views and Components

  • views/components should be nestable
  • need a concept of "slots" - where can a view put sub-views
  • copy java's layout managers? or is that too heavy? want to keep it simple
  • How much effort should be put into formats other than XHTML? probably different for data vs. components. Data should be available as a pdf, as rss feeds, in export formats. Components will still be xhtml, maybe wml for mobile device support, maybe php-gtk - more limited set.
  • Fields
  • html/xhtml/xml renderers

What's good about Horde_Template

  • simple

What's bad about Horde_Template

  • does not result in valid XML templates because of nested < inside tags (<a href="<tag:url>" />)
  • hard to debug
  • actually not so fast
  • no built-in support for htmlspecialchars(), so the code using the template has to know what to encode

Replace with:

ViewBuilder/PageBuilder custom views
Web services, command line, GET/web layout should be identical
App/Method/Params?

RSS

FeedBuilder - strategy interface for building multiple kinds of feeds (atom, rss versions, etc.) Takes any object that implements a Feedable interface, or a result set that implements FeedableCollection. Should RDO_Result implement that? Or should we use a more general Describable interface, like below?

FormBuilder

Interface with different form building implementations.
takes an RDO_ResultSet or a single RDO object and builds a form based on that (array is for row based renderers, etc). Or use a more general Describable interface. Need anything besides describe()? Have a DescribableCollection, too, and have RDO_ResultSet implement that?

RampageObject
DescribableObject
|- describe()

Example Applications

  • tagging/category-based bookmarks & blog apps?

Things to remember

MVC is 30 years old

A rant on installing software: http://www.lastcraft.com/blog/index.php?p=11
Top Ten website mistakes: http://www.useit.com/alertbox/990502.html

double orderTotal;
Money amount = ...;
...
orderTotal += amount.getValue();
orderTotal must be in dollars

The problem with this approach is that the foregoing code makes a big assumption about how the Money class is implemented (that the "value" is stored in a double). Code that makes implementation assumptions breaks when the implementation changes. If, for example, you need to internationalize your application to support currencies other than dollars, then getValue() returns nothing meaningful. You could add a getCurrency(), but that would make all the code surrounding the getValue() call much more complicated, especially if you persist in using the getter/setter strategy to get the information you need to do the work. A typical (flawed) implementation might look like this:

Money amount = ...;
...
value = amount.getValue();
currency = amount.getCurrency();
conversion = CurrencyTable.getConversionFactor( currency, USDOLLARS );
total += value * conversion;
...

This change is too complicated to be handled by automated refactoring. Moreover, you would have to make these sorts of changes everywhere in your code.

The business-logic-level solution to this problem is to do the work in the object that has the information required to do the work. Instead of extracting the "value" to perform some external operation on it, you should have the Money class do all the money-related operations, including currency conversion. A properly structured object would handle the total like this:

Money total = ...;
Money amount = ...;

total.increaseBy( amount );

In the Strategy pattern, you create a Strategy interface (LayoutManager) implemented by several Concrete Strategy classes (FlowLayout, GridLayout, etc.). You then tell a Context object (a Container) how to do something by passing it a Strategy object. (You pass a Container a LayoutManager that defines a layout strategy.)

Frameworks

A discussion of fragile base classes would be incomplete without a mention of framework-based programming. Frameworks such as Microsoft Foundation Classes (MFC) have become a popular way of building class libraries. Though MFC itself is blessedly fading away, MFC's structure has been ingrained in countless Microsoft shops where programmers assumed that the Microsoft way was the best way.

A framework-based system typically starts with a library of half-baked classes that don't do everything they need to do, but rather rely on a derived class to provide missing functionality. A good example in Java is the Component's paint() method, which is effectively a place holder; a derived class must provide the real version.

You can get away with this sort of thing in moderation, but an entire class framework that depends on derivation-based customization is brittle in the extreme. The base classes are too fragile. When I programmed in MFC, I had to rewrite all my applications every time Microsoft released a new version. The code would often compile, but then not work because some base-class method changed.

All Java packages work quite well out of the box. You don't need to extend anything to make them function. This works-out-of-the-box structure is better than a derivation-based framework. It's easier to maintain and use, and doesn't put your code at risk if a Sun Microsystems-supplied class changes its implementation.