[ Index ] |
|
Code source de Symfony 1.0.0 |
1 <?php 2 /** 3 * $Id: PHPUnit2Util.php 3076 2006-12-18 08:52:12Z fabien $ 4 * 5 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 6 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 7 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 8 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 9 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 10 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 11 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 12 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 13 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 14 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 15 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 16 * 17 * This software consists of voluntary contributions made by many individuals 18 * and is licensed under the LGPL. For more information please see 19 * <http://phing.info>. 20 */ 21 22 /** 23 * Various utility functions 24 * 25 * @author Michiel Rook <michiel.rook@gmail.com> 26 * @version $Id: PHPUnit2Util.php 3076 2006-12-18 08:52:12Z fabien $ 27 * @package phing.tasks.ext.phpunit2 28 * @since 2.1.0 29 */ 30 class PHPUnit2Util 31 { 32 protected static $definedClasses = array(); 33 34 /** 35 * Returns the package of a class as defined in the docblock of the class using @package 36 * 37 * @param string the name of the class 38 * @return string the name of the package 39 */ 40 static function getPackageName($classname) 41 { 42 $reflect = new ReflectionClass($classname); 43 44 if (preg_match('/@package[\s]+([\.\w]+)/', $reflect->getDocComment(), $matches)) 45 { 46 return $matches[1]; 47 } 48 else 49 { 50 return "default"; 51 } 52 } 53 54 /** 55 * Derives the classname from a filename. 56 * Assumes that there is only one class defined in that particular file, and that 57 * the naming follows the dot-path (Java) notation scheme. 58 * 59 * @param string the filename 60 * @return string the name fo the class 61 */ 62 static function getClassFromFileName($filename) 63 { 64 $filename = basename($filename); 65 66 $rpos = strrpos($filename, '.'); 67 68 if ($rpos != -1) 69 { 70 $filename = substr($filename, 0, $rpos); 71 } 72 73 return $filename; 74 } 75 76 /** 77 * @param string the filename 78 * @param Path optional classpath 79 * @return array list of classes defined in the file 80 */ 81 static function getDefinedClasses($filename, $classpath = NULL) 82 { 83 $filename = realpath($filename); 84 85 if (!file_exists($filename)) 86 { 87 throw new Exception("File '" . $filename . "' does not exist"); 88 } 89 90 if (isset(self::$definedClasses[$filename])) 91 { 92 return self::$definedClasses[$filename]; 93 } 94 95 Phing::__import($filename, $classpath); 96 97 $declaredClasses = get_declared_classes(); 98 99 foreach ($declaredClasses as $classname) 100 { 101 $reflect = new ReflectionClass($classname); 102 103 self::$definedClasses[$reflect->getFilename()][] = $classname; 104 105 if (is_array(self::$definedClasses[$reflect->getFilename()])) 106 { 107 self::$definedClasses[$reflect->getFilename()] = array_unique(self::$definedClasses[$reflect->getFilename()]); 108 } 109 } 110 111 if (isset(self::$definedClasses[$filename])) 112 { 113 return self::$definedClasses[$filename]; 114 } 115 else 116 { 117 return array(); 118 } 119 } 120 } 121 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Fri Mar 16 22:42:14 2007 | par Balluche grâce à PHPXref 0.7 |