Re: [Template] Design issues

From: Date: Sat, 12 Jun 2004 15:14:29 +0000
Subject: Re: [Template] Design issues
References: 1 2 3 4 5 6 7 8 9 10 11  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-30567@lists.php.net to get a copy of this message
Paul M Jones wrote:
On Jun 12, 2004, at 9:51 AM, Philippe Jausions wrote:
Hummm... Why not doing something like that, we avoid an inheritance without losing performance... or may be even better... class Template { <snip> function _output() {
       // Previous output() method
} function output() {
      // Any registered filters?
      if ($this->filters) {
          if (is_a($r = $this->toString(), 'PEAR_Error') {
              return $r;
          }
          foreach ($this->filters ...) {
          ...
          }
      } else {
        return $this->_output();
      }
} function toString() {
       ob_start();
       if (is_a($r = $this->_output(), 'PEAR_Error')) {
           ob_end_clean();
           return $r;
       }
       if (function_exists('ob_get_clean')) {
           return ob_get_clean();
       } else {
           $data = ob_get_contents();
           ob_end_clean();
           return $data;
       }
} </snip> }
I can live with that very easily. Alan?
Altough, I realize that toString() is not filtered... We need to rework that with _output() and _outputFiltered() and branch in both output() AND toString()... I'd prefer to wait for the package to be in CVS before continuing posting code... or use the wiki... code change in e-mail is not really top solution here...
Two notes: If we stay with PEAR_Error, we'll need a strtolower() on the is_a(). Howeer, I think we ought to move to PEAR_ErrorStack if at all possible.
Agreed on both. I'd have to look seriously at PEAR_ErrorStack, is it out of beta yet? BTW: the case-folding of class name in PHP is really something that bothers me... I'd also like to rework that debug() method by using PEAR::Log instead. Mixing output and debug output will actually really make things difficult. Imagine trying to debug a image template engine with echo() in output... hahahaha! Something like: function debug($string) { if (!$this->option['debug']) {
        return;
} elseif (is_null($this->_log)) {
        if (is_object($this->option['debug'])) {
             // To allow the user to pass existing log object
             $this->_log =& $this->option['debug'];
        } else {
             // Not fully worked out yet...
             $this->_log =& Log::Singleton($this->option['debug']->type, $this->option['debug']->conf);
        }
} $this->_log->log($string); } Or, we could just simply ask for a Log object in the "debug" option... even easier for us and open... That object would just need a "log()" method... -Philippe

« previous php.pear.dev (#30567) next »