At the risk of hijacking your thread could you show a simple example of this please.Plugins adhere to an API which gives them access to components in the pluggable system, and also allows the pluggable system to trigger calls in the plugins.
[TDD] Who wants to help me build an http request class?
Moderator: General Moderators
- Ollie Saunders
- DevNet Master
- Posts: 3179
- Joined: Tue May 24, 2005 6:01 pm
- Location: UK
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
You could look at my Swift source code but in pseudo terms it's like an observer-come-decorator with two-way coupling.ole wrote:At the risk of hijacking your thread could you show a simple example of this please.Plugins adhere to an API which gives them access to components in the pluggable system, and also allows the pluggable system to trigger calls in the plugins.
Code: Select all
<?php
interface PluginAPI
{
public function loadPluggable(APluggable $pluggable);
public function onSomeEvent();
}
class APlugin implements PluginAPI
{
protected $pluggable;
public function loadPluggable(APluggable $pluggable)
{
$this->pluggable = $pluggable;
}
public function onSomeEvent()
{
$this->pluggable->phrase = '<span style="size: 4em;">'.$this->pluggable->phrase.'</span>';
}
}
class APluggable
{
protected $pluginCollection = array();
//Certain items in our API either need to be public, or have accessors
public $phrase;
public function loadPlugin(PluginAPI $plugin, $name)
{
$this->pluginCollection[$name] = $plugin;
$plugin->loadPluggable($this);
}
public function runEvent($event)
{
$event = 'on'.ucfirst($event);
foreach ($this->pluginCollection as $plugin)
{
$plugin->$event();
}
}
public function speak($phrase)
{
$this->phrase = $phrase;
$this->runEvent('SomeEvent');
echo $this->phrase;
}
}
$speaker = new APlugabble();
$speaker->loadPlugin(new APlugin());
$speaker->speak("Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Nullam fringilla.");
//4x size of text prints out!! (I said speak, not SHOUT!)
?>- Ollie Saunders
- DevNet Master
- Posts: 3179
- Joined: Tue May 24, 2005 6:01 pm
- Location: UK
-
alex.barylski
- DevNet Evangelist
- Posts: 6267
- Joined: Tue Dec 21, 2004 5:00 pm
- Location: Winnipeg
What about a method which compares for identical keys between them and tries to see of someone is trying to hack your site by injecting information where it is unexpected. McGruff always talked about his request object searching for "alien" keys, including from the wrong input source.Hockey wrote: I can't see a reason why that information would ever be useful???
-
alex.barylski
- DevNet Evangelist
- Posts: 6267
- Joined: Tue Dec 21, 2004 5:00 pm
- Location: Winnipeg
How did I know someone would bring that up...sweatje wrote:What about a method which compares for identical keys between them and tries to see of someone is trying to hack your site by injecting information where it is unexpected. McGruff always talked about his request object searching for "alien" keys, including from the wrong input source.Hockey wrote: I can't see a reason why that information would ever be useful???
Fare enough, but my point is...it's over kill...people can spoof data no matter where it comes from GET, POST, COOKIE...So what difference does it make???
It's an extra step of un-essential processing, further slowing down my code for what? You couldn't use it as a replacement for actual data sanitization...
If anything, you could use it as logged data to indicate whether you had script kiddies trying to hack using GET instead of POST because they didn't have the know how to download a simple application which would let them carry out POST or COOKIE injection as well...
The only usefulness I see in it, is if you had a COOKIE with the same name as your POST, in which case, I'm not sure of the results...
In this case, I would argue that's bad convention and should be avoided anyways...
2 variables, same declaration and same namespace (super globals) = bad idea IMHO
Cheers
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
same as above, but also we are doing this completely from start to end of process - the goal is to get a class that works and is proven by TDD, we'll worry about the little extras after 
Perhaps when we have finished, this thread can be tidied up and submitted as a tutorial on UnitTest's and TDD?
btw - yes, cookie is also affected by magic quotes.. GPC = Get Post Cookie
Perhaps when we have finished, this thread can be tidied up and submitted as a tutorial on UnitTest's and TDD?
btw - yes, cookie is also affected by magic quotes.. GPC = Get Post Cookie
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia