Changeset 158

Show
Ignore:
Timestamp:
01/26/07 00:24:04 (2 years ago)
Author:
mikey
Message:

added possibility for classes to have a method static() which will be called when the class is loaded via net.stubbles.stubClassLoader

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/main/php/net/stubbles/stubClassLoader.php

    r97 r158  
    5555            self::$classNames[$nqClassName] = $fqClassName; 
    5656            require $dirName . '/' .  self::mapClassname($fqClassName); 
     57             
     58            if (method_exists($nqClassName, '__static') == true) { 
     59                call_user_func(array($nqClassName, '__static')); 
     60            } 
    5761        } 
    5862    } 
  • trunk/src/test/php/net/stubbles/stubClassLoaderTestCase.php

    r98 r158  
    11<?php 
    22/** 
    3  * Tests for stubClassLoader 
     3 * Tests for net.stubbles.stubClassLoader 
    44 * 
    55 * @author      Frank Kleine <mikey@stubbles.net> 
     
    88 */ 
    99/** 
    10  * Tests for stubClassLoader 
     10 * Tests for net.stubbles.stubClassLoader 
    1111 * 
    1212 * @package     stubbles 
     
    2424        $this->assertEqual(stubClassLoader::getNonQualifiedClassName('stubClassLoader'), 'stubClassLoader'); 
    2525    } 
     26     
     27    /** 
     28     * assert that __static is called, but only once 
     29     */ 
     30    public function testStatic() 
     31    { 
     32        $this->assertFalse(class_exists('WithStatic', false)); 
     33        stubClassLoader::load('_test.WithStatic'); 
     34        $this->assertEqual(WithStatic::getCalled(), 1); 
     35        $this->assertTrue(class_exists('WithStatic', false)); 
     36        $this->assertEqual(stubClassLoader::getFullQualifiedClassName('WithStatic'), '_test.WithStatic'); 
     37        $this->assertEqual(stubClassLoader::getNonQualifiedClassName('_test.WithStatic'), 'WithStatic'); 
     38        stubClassLoader::load('_test.WithStatic'); 
     39        $this->assertEqual(WithStatic::getCalled(), 1); 
     40    } 
    2641} 
    2742?>