Changeset 501
- Timestamp:
- 04/13/07 18:26:35 (2 years ago)
- Files:
-
- trunk/build/stubbles/build.xml (modified) (1 diff)
- trunk/src/main/php/net/stubbles/reflection/annotations/stubAbstractAnnotation.php (modified) (1 diff)
- trunk/src/main/php/net/stubbles/reflection/annotations/stubAnnotation.php (modified) (2 diffs)
- trunk/src/main/php/net/stubbles/reflection/annotations/stubAnnotationCache.php (modified) (1 diff)
- trunk/src/test/php/net/stubbles/reflection/annotations/stubAnnotationFactoryBuildTestCase.php (modified) (2 diffs)
- trunk/src/test/php/net/stubbles/reflection/annotations/stubAnnotationFactoryTestCase.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/build/stubbles/build.xml
r442 r501 93 93 94 94 <target name="test" description="run test suite"> 95 < delete file="${project.basedir}/../../lib/.cache" verbose="true"/>95 <phingcall target="test-preparation" /> 96 96 <mySimpletest testfile=""${project.basedir}/../../src/test/run.php"" exit="true" /> 97 97 </target> 98 98 99 99 <target name="test-integration"> 100 < delete file="${project.basedir}/../../lib/.cache" verbose="true"/>100 <phingcall target="test-preparation" /> 101 101 <mySimpletest testfile=""${project.basedir}/../../src/test/runIntegration.php"" exit="true" /> 102 102 </target> 103 104 <target name="test-preparation" description="Some preparations before running the tests."> 105 <delete file="${project.basedir}/../../lib/.cache" verbose="true"/> 106 <delete> 107 <fileset dir="${project.basedir}/../../cache"> 108 <include name="**/*.cache" /> 109 </fileset> 110 </delete> 111 </target> 103 112 </project> trunk/src/main/php/net/stubbles/reflection/annotations/stubAbstractAnnotation.php
r432 r501 40 40 return $this->annotationName; 41 41 } 42 43 /** 44 * assure that a clone clones all properties og type object as well 45 */ 46 public function __clone() 47 { 48 foreach (get_object_vars($this) as $name => $value) { 49 if (is_object($value) == true) { 50 $this->$name = clone $this->$name; 51 } 52 } 53 } 42 54 } 43 55 ?> trunk/src/main/php/net/stubbles/reflection/annotations/stubAnnotation.php
r432 r501 13 13 * @subpackage reflection_annotations 14 14 */ 15 interface stubAnnotation 15 interface stubAnnotation extends stubObject 16 16 { 17 17 /** … … 56 56 */ 57 57 public function getAnnotationTarget(); 58 59 /** 60 * assure that a clone clones all properties of type object as well 61 * 62 * @todo take comment away as soon as SimpleTests Mock::generate() supports __clone() 63 */ 64 #public function __clone(); 58 65 } 59 66 ?> trunk/src/main/php/net/stubbles/reflection/annotations/stubAnnotationCache.php
r432 r501 19 19 * Property to store annotations 20 20 * 21 * @var array 21 * @var array<string,array> 22 22 */ 23 private static $annotations = array( 24 stubAnnotation::TARGET_CLASS => array(), 25 stubAnnotation::TARGET_FUNCTION => array(), 26 stubAnnotation::TARGET_METHOD => array(), 27 stubAnnotation::TARGET_PROPERTY => array() 23 private static $annotations = array(stubAnnotation::TARGET_CLASS => array(), 24 stubAnnotation::TARGET_FUNCTION => array(), 25 stubAnnotation::TARGET_METHOD => array(), 26 stubAnnotation::TARGET_PROPERTY => array() 28 27 ); 29 28 30 29 /** 31 * Store an annotation in the cache 32 * 33 * @param int $target 34 * @param string $targetName 35 * @param string $annotationName 36 * @param stubAnnotation|null $annotation 30 * static initializer 37 31 */ 38 public static function put($target, $targetName, $annotationName, stubAnnotation $annotation = null) { 39 if (!isset(self::$annotations[$target][$targetName])) { 40 self::$annotations[$target][$targetName] = array(); 32 public static function __static() 33 { 34 if (file_exists(stubConfig::getCachePath() . '/annotations.cache') == true) { 35 self::$annotations = unserialize(file_get_contents(stubConfig::getCachePath() . '/annotations.cache')); 41 36 } 42 self::$annotations[$target][$targetName][$annotationName] = $annotation; 37 38 register_shutdown_function(array(__CLASS__, '__shutdown')); 43 39 } 44 40 45 41 /** 46 * Check, whether an annotation is available in the cache 42 * static shutdown 43 */ 44 public static function __shutdown() 45 { 46 file_put_contents(stubConfig::getCachePath() . '/annotations.cache', serialize(self::$annotations)); 47 } 48 49 /** 50 * flushes all contents from cache 51 */ 52 public static function flush() 53 { 54 self::$annotations = array(stubAnnotation::TARGET_CLASS => array(), 55 stubAnnotation::TARGET_FUNCTION => array(), 56 stubAnnotation::TARGET_METHOD => array(), 57 stubAnnotation::TARGET_PROPERTY => array() 58 ); 59 } 60 61 /** 62 * store an annotation in the cache 47 63 * 48 * @param int $target 49 * @param string $targetName 50 * @param string $annotationName 51 * @return boolean 64 * @param int $target target of the annotation 65 * @param string $targetName name of the target 66 * @param string $annotationName name of the annotation 67 * @param stubAnnotation $annotation optional the annotation to store 68 */ 69 public static function put($target, $targetName, $annotationName, stubAnnotation $annotation = null) { 70 if (isset(self::$annotations[$target][$targetName]) == false) { 71 self::$annotations[$target][$targetName] = array(); 72 } 73 74 if (null !== $annotation) { 75 $clone = clone $annotation; 76 self::$annotations[$target][$targetName][$annotationName] = $clone->getSerialized(); 77 } else { 78 self::$annotations[$target][$targetName][$annotationName] = null; 79 } 80 } 81 82 /** 83 * check, whether an annotation is available in the cache 84 * 85 * @param int $target target of the annotation 86 * @param string $targetName name of the target 87 * @param string $annotationName name of the annotation 88 * @return bool 52 89 */ 53 90 public static function has($target, $targetName, $annotationName) { 54 if ( !isset(self::$annotations[$target][$targetName])) {91 if (isset(self::$annotations[$target][$targetName]) == false) { 55 92 return false; 56 93 } 57 if (!isset(self::$annotations[$target][$targetName][$annotationName])) { 94 95 if (isset(self::$annotations[$target][$targetName][$annotationName]) == false) { 58 96 return false; 59 97 } 98 60 99 return true; 61 100 } 62 101 63 102 /** 64 * Fetch an annotation from the cache103 * fetch an annotation from the cache 65 104 * 66 * @param int $target67 * @param string $targetName68 * @param string $annotationName69 * @return stubAnnotation105 * @param int $target target of the annotation 106 * @param string $targetName name of the target 107 * @param string $annotationName name of the annotation 108 * @return stubAnnotation 70 109 */ 71 110 public static function get($target, $targetName, $annotationName) { 72 if (self::has($target, $targetName, $annotationName) ) {73 return self::$annotations[$target][$targetName][$annotationName];111 if (self::has($target, $targetName, $annotationName) == true) { 112 return clone self::$annotations[$target][$targetName][$annotationName]->getUnserialized(); 74 113 } 114 75 115 return null; 76 116 } trunk/src/test/php/net/stubbles/reflection/annotations/stubAnnotationFactoryBuildTestCase.php
r492 r501 8 8 */ 9 9 stubClassLoader::load('net.stubbles.reflection.annotations.stubAnnotationFactory'); 10 class stubMethodAnnotation implements stubAnnotation10 class stubMethodAnnotation extends stubAbstractAnnotation implements stubAnnotation 11 11 { 12 12 protected $foo; … … 30 30 public function getAnnotationTarget() {} 31 31 } 32 class stubPropertyAnnotation implements stubAnnotation32 class stubPropertyAnnotation extends stubAbstractAnnotation implements stubAnnotation 33 33 { 34 34 public $foo; trunk/src/test/php/net/stubbles/reflection/annotations/stubAnnotationFactoryTestCase.php
r492 r501 170 170 $this->assertEqual('bar', $anno2->foo); 171 171 $this->assertEqual('true', $anno2->argh); 172 $this->assertEqual(' tomato', $anno2->veggie);172 $this->assertEqual('cucumber', $anno2->veggie); 173 173 174 174 // fetch with a new stubAnnotationClass instance … … 179 179 $this->assertEqual('bar', $anno3->foo); 180 180 $this->assertEqual('true', $anno3->argh); 181 $this->assertEqual(' tomato', $anno3->veggie);181 $this->assertEqual('cucumber', $anno3->veggie); 182 182 } 183 183 }
