Re: [PHPTAL] Custom modifiers - any callback function

2010-11-03 Thread Kornel Lesiński

On 03-11-2010 at 07:46:29 Anton Andriyevskyy x.meg...@gmail.com wrote:


http://phptal.org/manual/en/split/custom-modifiers.html

Hey, lets add to PHPTAL a way to use standard php callbacks to define  
custom modifiers.


Currently it is so:

phptal_tales_mymodifier

It would be nice to use something like this:

$phptalInstance-setModifier('modifierName', phpStandardCallback)

This will allow to better integrate PHPTAL into pure OOP frameworks like
Kohana, CI and others.


Is it only because functions are not OO, or do you actually need to define  
modifiers with same name, but different implementation, in different parts  
of same PHP program?



PHPTAL does have object-oriented method for defining custom modifiers:

PHPTAL_TalesRegistry::getInstance()-registerPrefix('modifierName',  
phpStandardCallback)


but it doesn't solve any problems over simple function definition, which  
is why I don't recommend it.


--
regards, Kornel

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] Custom modifiers - any callback function

2010-11-03 Thread Kornel Lesiński

On 03-11-2010 at 12:26:14 Anton Andriyevskyy x.meg...@gmail.com wrote:


Thanks for hinting to that method.

Actually it can be just right way to follow fully-OOP framework like  
Kohana.


Please don't do it. OOP just for sake of OOP is pointless.


but...
PHPTAL_TalesRegistry::getInstance()

as I understand it will affect ALL phptal object instances available in
runtime?
What about concrete phptal instance, is it possible to affect only one of
them somehow?


It's not possible. Singletons, despite OO, have all the downsides of  
global functions.


However, so far I haven't found this to be a problem in real-world  
applications, so fixing this is far down on my list. I'm happy to accept  
patches fixing this.


If you were to write setModifier() function, I suggest naming it  
setModifierCompiler() or similar. That should make it clearer to new users  
that modifiers generate PHP code, rather than returning value immediately.


Callback could take object that has -compileTalesExpresssion() rather  
than $nothrow argument like it does now. That would eliminate another  
global dependency on phptal_tales().


--
regards, Kornel

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] Custom modifiers - any callback function

2010-11-03 Thread Anton Andriyevskyy
Thanks for your detailed explanations. It all makes sense.


2010/11/3 Kornel Lesiński kor...@aardvarkmedia.co.uk

 On 03-11-2010 at 12:26:14 Anton Andriyevskyy x.meg...@gmail.com wrote:

  Thanks for hinting to that method.

 Actually it can be just right way to follow fully-OOP framework like
 Kohana.


 Please don't do it. OOP just for sake of OOP is pointless.


  but...
 PHPTAL_TalesRegistry::getInstance()

 as I understand it will affect ALL phptal object instances available in
 runtime?
 What about concrete phptal instance, is it possible to affect only one of
 them somehow?


 It's not possible. Singletons, despite OO, have all the downsides of global
 functions.

 However, so far I haven't found this to be a problem in real-world
 applications, so fixing this is far down on my list. I'm happy to accept
 patches fixing this.

 If you were to write setModifier() function, I suggest naming it
 setModifierCompiler() or similar. That should make it clearer to new users
 that modifiers generate PHP code, rather than returning value immediately.

 Callback could take object that has -compileTalesExpresssion() rather than
 $nothrow argument like it does now. That would eliminate another global
 dependency on phptal_tales().


 --
 regards, Kornel

 ___
 PHPTAL mailing list
 PHPTAL@lists.motion-twin.com
 http://lists.motion-twin.com/mailman/listinfo/phptal

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal