Re: [PHPTAL] How to add customized namespace-attribute out of the Phptal repository

2012-09-25 Thread Hisateru Tanaka
Loading your own namespace would not prevent PHPTAL's built in attributes, I 
think.

But note that registering namespace costs much to load PHPTAL's parser engine.

So I'm using pre-filter mechanism to load my namespace classes because
PHPTAL_PreFilter class is very small and not related to other parts of PHPTAL.

When I already have parsed template in my cache dir, it does never cost to load
parser engine and namespaces. Then the filter() method would be ignored
instead cached code would be used.  I can pay to just only PHPTAL_PreFilter :)


On 2012/09/20, at 23:31, Clouts wrote:

 I've added my own namespace using:
 PHPTAL_Dom_Defs::getInstance()-registerNamespace(new MyNewNS());
 
 And defined the NS class as:
 /* 
 *
 */ /* * */
 class MyNewNS extends PHPTAL_Namespace_Builtin
 {
 /* 
 *
 */ /* * */
public function __construct(){
parent::__construct('MyNewNS', 'http://ctrlogic.net/tpl/phptal/ns');
$this-addAttribute(new PHPTAL_NamespaceAttributeSurround('att', 4));
}
 }
 
 And defined the Attribute class as:
 /* 
 *
 */ /* * */
 class PHPTAL_Php_Attribute_MyNewNS_att extends PHPTAL_Php_Attribute
 {
 /* 
 *
 */ /* * */
public function before(PHPTAL_Php_CodeWriter $codewriter)
{
 $code = code
 Some php code here
 code;
$codewriter-pushCode($code);
}
 /* 
 *
 */ /* * */
public function after(PHPTAL_Php_CodeWriter $codewriter)
{
}
 }
 
 Is there any way not having this attribute class inside the PHPTAL installed 
 repository?
 
 I want to have it outside the PHPTAL installed repository...
 
 Would preloading it prevent PHPTAL from searching the class inside its own 
 installed repository?
 
 
 ___
 PHPTAL mailing list
 PHPTAL@lists.motion-twin.com
 http://lists.motion-twin.com/mailman/listinfo/phptal

-- 
Hisateru Tanaka
tanakahisat...@gmail.com


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


Re: [PHPTAL] How to add customized namespace-attribute out of the Phptal repository

2012-09-25 Thread Robert Goldsmith
Your class can be called whatever you wish and can be either manually required 
before first use or loaded using any available autoloader. You can put it 
wherever you like :)

We work heavily with Zend Framework and so use autoloaders and Symphony has a 
similar system but feel free to keep things simple and require the class 
manually as long as you do so before the point you call 
'PHPTAL_Dom_Defs::getInstance()-registerNamespace(new MyNewNS());'

Robert
-
Robert Goldsmith
rgoldsm...@names.co.uk


 I've added my own namespace using:
 PHPTAL_Dom_Defs::getInstance()-registerNamespace(new MyNewNS());
 
 And defined the NS class as:
 /* 
 *
 */ /* * */
 class MyNewNS extends PHPTAL_Namespace_Builtin
 {
 /* 
 *
 */ /* * */
   public function __construct(){
   parent::__construct('MyNewNS', 'http://ctrlogic.net/tpl/phptal/ns');
   $this-addAttribute(new PHPTAL_NamespaceAttributeSurround('att', 4));
   }
 }
 
 And defined the Attribute class as:
 /* 
 *
 */ /* * */
 class PHPTAL_Php_Attribute_MyNewNS_att extends PHPTAL_Php_Attribute
 {
 /* 
 *
 */ /* * */
   public function before(PHPTAL_Php_CodeWriter $codewriter)
   {
 $code = code
 Some php code here
 code;
   $codewriter-pushCode($code);
   }
 /* 
 *
 */ /* * */
   public function after(PHPTAL_Php_CodeWriter $codewriter)
   {
   }
 }
 
 Is there any way not having this attribute class inside the PHPTAL installed 
 repository?
 
 I want to have it outside the PHPTAL installed repository...
 
 Would preloading it prevent PHPTAL from searching the class inside its own 
 installed repository?
 


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