SitePoint Sponsor |
|
User Tag List
Results 101 to 125 of 384
-
Jul 12, 2005, 16:05 #101
- Join Date
- Jun 2004
- Location
- Copenhagen, Denmark
- Posts
- 6,157
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by Ezku
-
Jul 12, 2005, 16:30 #102
- Join Date
- Nov 2001
- Location
- Bath, UK
- Posts
- 2,498
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by kyberfabrikken
Originally Posted by kyberfabrikken
DouglasHello World
-
Jul 12, 2005, 17:22 #103
- Join Date
- May 2005
- Location
- Finland
- Posts
- 608
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by kyberfabrikken
-
Jul 13, 2005, 00:12 #104
- Join Date
- Jun 2004
- Location
- Copenhagen, Denmark
- Posts
- 6,157
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by kyberfabrikken
(Well, actually I was reading the wact sources, and they do this.)
Originally Posted by Ezku
-
Jul 13, 2005, 03:42 #105
- Join Date
- May 2005
- Location
- Finland
- Posts
- 608
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by kyberfabrikken
I can't think of a situation where you would need that option.
Except maybe that we could use it to apply some lazy-loading.PHP Code:/**
* Calls a method on an object upon invocation
*
* @author Ezku (dmnEe0@gmail.com)
* @since Jul 12, 2005
*/
class Delegate implements IDelegate
{
protected $subordinate = NULL;
protected $method = NULL;
public function __construct($subordinate, $method)
{
$this->subordinate = $subordinate;
$this->method = $method;
}
public function invoke($args = NULL)
{
$callback = array($this->subordinate, $this->method);
return call_user_func_array($callback, (array) $args);
}
}
class EventHandler
{
/**
* @var array 2-dimensional IDelegate map
*/
protected $listeners = array();
/**
* Register listener for event
* @param object IDelegate
*/
public function register($event, IDelegate $delegate)
{
$this->listeners[$event][] = $delegate;
}
/**
* Trigger event listeners
* @param string event
*/
public function trigger($event)
{
if (isset($this->listeners[$event]) && is_array($this->listeners[$event]))
{
foreach($this->listeners[$event] as $delegate)
{
$delegate->invoke();
}
}
}
}
-
Jul 13, 2005, 04:42 #106
- Join Date
- Mar 2004
- Location
- Sweden
- Posts
- 180
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by Ezku
-
Jul 13, 2005, 04:48 #107
- Join Date
- May 2005
- Location
- Finland
- Posts
- 608
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by Overunner
-
Jul 13, 2005, 06:06 #108
- Join Date
- Jun 2004
- Location
- Copenhagen, Denmark
- Posts
- 6,157
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by Ezku
Originally Posted by Ezku
-
Jul 13, 2005, 06:46 #109
- Join Date
- May 2005
- Location
- Finland
- Posts
- 608
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by kyberfabrikken
Regarding Context: wouldn't it be a nice place to store Session objects and the like? I was about to start stuffing Session, Cookie etc. to the Request when I realized that Context would probably be where they really belong. Context could also be used as a messaging service between layers (along the lines of $context->data->set('errors', $logger->getMessages());). It would prevent cluttering both Request and Response. Is this A Bad Idea (TM)?
-
Jul 13, 2005, 07:54 #110
- Join Date
- Jun 2004
- Location
- Copenhagen, Denmark
- Posts
- 6,157
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I recieved a PM from tharos, but since I think it's relevant to the discussion, I'll reply here.
Originally Posted by tharos
I reckon we could rely on the ConfigReader classes from the skeleton-thread.
Originally Posted by tharos
PHP Code:class MySubmitHandler
{
var $redirect = "?page=afterform"; // or whatever
function execute(&$request, &$response) {
$model =& new Model();
$model->import($request);
$response->setRedirect($this->redirect);
}
}
class MyForm extends FormController
{
function MyForm() {
parent::FormController(
new ServerPage("page/forminit.php"), // handler to handle state=init
new ServerPage("page/forminvalid.php"), // handler to handle state=invalid
new MySubmitHandler() // handler to handle state=valid
);
// rules to be met in order to become valid
$this->addRule(new Rule_Required("foo"));
$this->addRule(new Rule_Email("foo"));
}
}
Originally Posted by tharos
-
Jul 13, 2005, 08:11 #111
- Join Date
- Jun 2004
- Location
- Copenhagen, Denmark
- Posts
- 6,157
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by Ezku
Originally Posted by Ezku
I won't rule out a Context as a ServiceLocator alltogether, but I'd rather wait to implement it when we actually need it. And I don't think we do quite yet.
flowcontroller0.4.zip
Here's a minor update to the code, which removes the context-object again, and places the errorLogger in the respose-object.
I also renamed InputController to InputProcessor as agreed.
I have updated tests and added a test for DataSpace. Still need to port the tests for rules (if we decide to stay with the Logger ...)
Lastly I added magic-fix back to the Request code in the way that DougBTX suggested (copy&paste from WACT)
About the naming. Since InputController have been renamed to InputProcessor, maybe we should rename FlowController to InputController ? Would that make sense ?
-
Jul 13, 2005, 14:28 #112
- Join Date
- Jun 2003
- Location
- Melbourne, Australia
- Posts
- 440
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by kyberfabrikken
With WACT, it gets better than that. The handlers inside delegates need not be instantiated objects, but so-called 'Handles'. If the particular Delegate wrapping that Handle is invoked, the Handle is instantiated as the handler object.
I'm in awe of Selkirk for creating this most elegant mechanism!Zealotry is contingent upon 100 posts and addiction 200?
-
Jul 13, 2005, 16:58 #113
- Join Date
- Dec 2004
- Location
- ljubljana, slovenia
- Posts
- 684
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by kyberfabrikken
-
Jul 13, 2005, 18:05 #114
- Join Date
- May 2005
- Location
- Finland
- Posts
- 608
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by dbevfat
auricle: My thoughts exactly. As for my relating code above, I was just guessing based on the description at WACT. It's probably quite different in reality.
-
Jul 14, 2005, 09:41 #115
Originally Posted by Ezku
-
Jul 14, 2005, 10:05 #116
- Join Date
- May 2005
- Location
- Finland
- Posts
- 608
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by 33degrees
A possiblity would be to rename the object to something more inclusive, like Context, and within it place the Request, Cookies, Sessions, etc.. passing it around in the handlers.
I'm starting to believe we really need a Context container that collects data together and encapsulates common data used throughout the system (Encapsulate Context, Allan Kelly).
-
Jul 14, 2005, 10:55 #117
- Join Date
- Jun 2004
- Location
- Copenhagen, Denmark
- Posts
- 6,157
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by Ezku
The thing which I don't like about having a Context-object is that it makes it harder for newcomers to understand the codebase. The benefits of such a container lies in the scalability of the system, but it's at the price of simplicity. Depending on the system you are building with it this may be good or bad.
-
Jul 14, 2005, 11:41 #118
- Join Date
- May 2005
- Location
- Finland
- Posts
- 608
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by kyberfabrikken
-
Jul 14, 2005, 11:47 #119
Originally Posted by kyberfabrikken
Originally Posted by kyberfabrikken
-
Jul 14, 2005, 14:37 #120
- Join Date
- May 2005
- Location
- Finland
- Posts
- 608
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by Ezku
Context, I understand, is already generally agreed on? Assuming I refactor my code to Context+Response, where do Logger or the error messages go?Last edited by Ezku; Jul 14, 2005 at 17:03.
-
Jul 14, 2005, 17:17 #121
Originally Posted by Ezku
-
Jul 15, 2005, 02:16 #122
- Join Date
- Jun 2004
- Location
- Copenhagen, Denmark
- Posts
- 6,157
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by Ezku
Originally Posted by 33degrees
I'd want to have either one Context object or a Request + a Response.
Originally Posted by Ezku
-
Jul 15, 2005, 02:45 #123
- Join Date
- May 2005
- Location
- Finland
- Posts
- 608
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by kyberfabrikken
Off Topic:
I should really learn to think before posting
Why the sudden loss in interest?Last edited by Ezku; Jul 15, 2005 at 07:12.
-
Jul 15, 2005, 11:44 #124
- Join Date
- May 2005
- Location
- Finland
- Posts
- 608
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Here's some code.
PHP Code:/**
* Context containing Request-related objects
*
* @author Ezku (dmnEe0@gmail.com)
* @since Jul 15, 2005
*/
class Request
{
/**
* @var object HttpRequest
*/
protected $http = NULL;
/**
* @var object FILES DataSpace
*/
protected $files = NULL;
/**
* @var object COOKIE DataSpace
*/
protected $cookie = NULL;
/**
* @var object SERVER DataSpace
*/
protected $server = NULL;
public function __construct()
{
$this->http = new HttpRequest;
$this->files = new DataSpace($_FILES);
$this->cookie = new DataSpace($_COOKIE);
$this->server = new DataSpace($_SERVER);
}
public function & __get($name)
{
return isset($this->$name) ? $this->$name : NULL;
}
}
PHP Code:/**
* HTTP request data: GET and POST
*
* @author Ezku (dmnEe0@gmail.com)
* @since Jul 15, 2005
*/
class HttpRequest extends DataSpace
{
/**
* Request method is GET
*/
const METHOD_GET = 'GET';
/**
* Request method is POST
*/
const METHOD_POST = 'POST';
/**
* @var int Request method
*/
protected $method = NULL;
/**
* @var object GET DataSpace
*/
public $GET = NULL;
/**
* @var object POST DataSpace
*/
public $POST = NULL;
/**
* Request constructor
* @param int request method, optional
*/
public function __construct()
{
$this->method = (strcasecmp($_SERVER['REQUEST_METHOD'], 'POST') == 0) ? self::METHOD_POST : self::METHOD_GET;
$this->data = $_REQUEST;
$this->GET = new DataSpace($_GET);
$this->POST = new DataSpace($_POST);
}
public function getMethod()
{
return $this->method;
}
public function isPost()
{
return (self::METHOD_POST == $this->method);
}
/**
* Cleans arrays ruined by MagicQuotes=On.
*/
static public function fixMagicQuotes($aList, $aIsTopLevel = true)
{
$gpcList = array();
$isMagic = self::$magic;
foreach ($aList as $key => $value)
{
if (is_array($value))
{
$decodedKey = ($isMagic && !$aIsTopLevel)?stripslashes($key):$key;
$decodedValue = self::fixMagicQuotes($value, false);
}
else
{
$decodedKey = stripslashes($key);
$decodedValue = ($isMagic)?stripslashes($value):$value;
}
$gpcList[$decodedKey] = $decodedValue;
}
return $gpcList;
}
static public $magic = NULL;
}
/**
* Fix magicquotes
*/
if (HttpRequest::$magic = get_magic_quotes_gpc())
{
$_REQUEST = HttpRequest::fixMagicQuotes($_REQUEST);
$_POST = HttpRequest::fixMagicQuotes($_POST);
$_GET = HttpRequest::fixMagicQuotes($_GET);
$_COOKIE = HttpRequest::fixMagicQuotes($_COOKIE);
}
PHP Code:/**
* Context containing Response-related objects
*
* @author Ezku (dmnEe0@gmail.com)
* @since Jul 15, 2005
*/
class Response
{
/**
* @var object HttpResponse
*/
protected $http = NULL;
/**
* @var object LogManager
*/
protected $logs = NULL;
public function __construct()
{
$this->http = new HttpResponse;
$this->logs = new LogManager;
}
public function & __get($name)
{
return isset($this->$name) ? $this->$name : NULL;
}
}
PHP Code:/**
* HTTP response data: headers, status, redirection, content.
*
* @author Ezku (dmnEe0@gmail.com)
* @since Jul 15, 2005
*/
class HttpResponse
{
protected $headers = array();
protected $redirect = NULL;
protected $status = NULL;
protected $content = NULL;
public function setHeader($key, $value=NULL) { $this->headers[$key] = $value; }
public function getHeaders() { return $this->headers; }
public function setRedirect($url) { $this->redirect = $url; }
public function getRedirect() { return $this->redirect; }
public function setStatus($status) { $this->status = $status; }
public function getStatus() { return $this->status; }
public function setContent($content) { $this->content = $content; }
public function getContent() { return $this->content; }
public function out()
{
if($this->redirect)
{
header('Location: '.$this->redirect);
die;
}
else
{
if ($this->status)
{
header('HTTP/1.1 '.$this->status);
}
foreach ($this->headers as $key => $value)
{
header($key.': '.rawurlencode($value));
}
echo $this->content;
}
}
}
PHP Code:/**
* A container for Loggers.
*
* @author Ezku (dmnEe0@gmail.com)
* @since Jul 15, 2005
*/
class LogManager
{
/**
* @var array ILogger storage
*/
protected $logs = array();
/**
* Set Logger by a name.
* @param string Logger name
* @param object ILogger
*/
public function __set($key, ILogger $logger)
{
$this->logs[$key] = $logger;
}
/**
* Get Logger. If one doesn't exist, a basic Logger will be created by the given name and returned.
* @param string Logger name
*/
public function & __get($key)
{
if(!isset($this->logs[$key]))
{
$this->logs[$key] = new Logger;
}
return $this->logs[$key];
}
}
I need your thoughts!
-
Jul 16, 2005, 02:51 #125
- Join Date
- Jun 2004
- Location
- Copenhagen, Denmark
- Posts
- 6,157
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
While I can't really conjure up rational arguments, I'm still not keen on changing the signature of IHandler->execute()
Regarding you latest post, I think the LogManager may be overkill. Why would we need multiple logs ?
If we are going to pass all sort of stuff (such as $_FILES, $_SERVER and LogManager) around, I'd prefer a single ServiceLocator (Context) rather than split it into two. For example, the Loggers are output to some scripts, but input to others, which makes them odd to put in the right spot. (Though Response is possible better than Request)
Maybe we could give it a rest and bring it back up in a while ?
I'd be much more interested in peeking into a form-factory class as the one tharos was calling for. For a start, I suppose that we could just extend the FormController class ?
Bookmarks