Improvements to SimpleComponent

5 views
Skip to first unread message

Mike Reich

unread,
May 10, 2012, 8:54:34 AM5/10/12
to cum...@googlegroups.com
One of the first pieces of feedback I've received is that the SimpleComponent is too complex (ironically), and is going to be hard to use for first-timers. The observation was that putting things in a config hash hides the possible values and abstracts out what is happening - you have to know both what to define and how it works behind the scenes.

The suggestion for improvement was to wrap most of the functionality in an easy to understand (and find) public API.  This makes it clear both how to accomplish a task and what the expected/required values are.

So, here's what I'd propose for the SimpleComponent.

Creating DataProviders
We define an API for specifying DataProviders:
$this->addDataProvider("someAlias", "\Some\Classname", array("apiKey" => "someKey"));
Or, possibly
$this->addDataProvider("someDP", "\Some\Classname");
$this->someDP->apiKey = "SomeKey";

Accessing DataProviders
DataProviders become class instance variables.  So, to access a DataProvider, you use the $this-> syntax:
$this->someDP->process("do something with this text");

Creating Routes
Same would go for routes:
$this->addRoute("index");
or 
$this->addRoute("index", "someFunc");

Binding to DataProvider Events
Same approach:
$this->bindEvent("someDP", "load", function() {
  ....
});

I'm less sure about this one - might be a good idea to leave it as: $this->someDP->bind("load", function() {...});


Thoughts?
Reply all
Reply to author
Forward
0 new messages