Exemple #1
0
 /**
  * @param string the filename
  * @param Path optional classpath
  * @return array list of classes defined in the file
  */
 static function getDefinedClasses($filename, $classpath = NULL)
 {
     $filename = realpath($filename);
     if (!file_exists($filename)) {
         throw new Exception("File '" . $filename . "' does not exist");
     }
     if (isset(self::$definedClasses[$filename])) {
         return self::$definedClasses[$filename];
     }
     Phing::__import($filename, $classpath);
     $declaredClasses = get_declared_classes();
     foreach ($declaredClasses as $classname) {
         $reflect = new ReflectionClass($classname);
         self::$definedClasses[$reflect->getFilename()][] = $classname;
         if (is_array(self::$definedClasses[$reflect->getFilename()])) {
             self::$definedClasses[$reflect->getFilename()] = array_unique(self::$definedClasses[$reflect->getFilename()]);
         }
     }
     if (isset(self::$definedClasses[$filename])) {
         return self::$definedClasses[$filename];
     } else {
         return array();
     }
 }
 /**
  * Import a path, supporting the following conventions:
  * - PEAR style (@link http://pear.php.net/manual/en/standards.naming.php)
  * - PSR-0 (@link https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md)
  * - dot-path
  *
  * @param string $dotPath   Path
  * @param mixed  $classpath String or object supporting __toString()
  *
  * @return string         The unqualified classname (which can be instantiated).
  *
  * @throws BuildException - if cannot find the specified file
  */
 public static function import($dotPath, $classpath = null)
 {
     if (strpos($dotPath, '.') !== false) {
         $classname = StringHelper::unqualify($dotPath);
     } else {
         $classname = $dotPath;
         $dotPath = '';
         $shortClassName = $classname;
         if ($lastNsPos = strripos($shortClassName, '\\')) {
             $namespace = substr($shortClassName, 0, $lastNsPos);
             $shortClassName = substr($shortClassName, $lastNsPos + 1);
             $dotPath = str_replace('\\', '.', $namespace) . '.';
         }
         $dotPath .= str_replace('_', '.', $shortClassName);
     }
     // first check to see that the class specified hasn't already been included.
     // (this also handles case where this method is called w/ a classname rather than dotpath)
     if (class_exists($classname)) {
         return $classname;
     }
     $dotClassname = basename($dotPath);
     $dotClassnamePos = strlen($dotPath) - strlen($dotClassname);
     // 1- temporarily replace escaped '.' with another illegal char (#)
     $tmp = str_replace('\\.', '##', $dotClassname);
     // 2- swap out the remaining '.' with DIR_SEP
     $tmp = strtr($tmp, '.', DIRECTORY_SEPARATOR);
     // 3- swap back the escaped '.'
     $tmp = str_replace('##', '.', $tmp);
     $classFile = $tmp . ".php";
     $path = substr_replace($dotPath, $classFile, $dotClassnamePos);
     Phing::__import($path, $classpath);
     return $classname;
 }
Exemple #3
0
 /**
  * Import a dot-path notation class path.
  * @param string $dotPath
  * @param mixed $classpath String or object supporting __toString()
  * @return string The unqualified classname (which can be instantiated).
  * @throws BuildException - if cannot find the specified file
  */
 public static function import($dotPath, $classpath = null)
 {
     /// check if this is a PEAR-style path (@link http://pear.php.net/manual/en/standards.naming.php)
     if (strpos($dotPath, '.') === false && strpos($dotPath, '_') !== false) {
         $classname = $dotPath;
         $dotPath = str_replace('_', '.', $dotPath);
     } else {
         $classname = StringHelper::unqualify($dotPath);
     }
     // first check to see that the class specified hasn't already been included.
     // (this also handles case where this method is called w/ a classname rather than dotpath)
     if (class_exists($classname)) {
         return $classname;
     }
     $dotClassname = basename($dotPath);
     $dotClassnamePos = strlen($dotPath) - strlen($dotClassname);
     // 1- temporarily replace escaped '.' with another illegal char (#)
     $tmp = str_replace('\\.', '##', $dotClassname);
     // 2- swap out the remaining '.' with DIR_SEP
     $tmp = strtr($tmp, '.', DIRECTORY_SEPARATOR);
     // 3- swap back the escaped '.'
     $tmp = str_replace('##', '.', $tmp);
     $classFile = $tmp . ".php";
     $path = substr_replace($dotPath, $classFile, $dotClassnamePos);
     Phing::__import($path, $classpath);
     return $classname;
 }
 function main()
 {
     $files = $this->getFilenames();
     $this->log("Setting up coverage database for " . count($files) . " files");
     $props = new Properties();
     foreach ($files as $file) {
         $fullname = $file['fullname'];
         $filename = $file['key'];
         $props->setProperty($filename, serialize(array('fullname' => $fullname, 'coverage' => array())));
     }
     $dbfile = new PhingFile($this->database);
     $props->store($dbfile);
     $this->project->setProperty('coverage.database', $dbfile->getAbsolutePath());
     foreach ($files as $file) {
         $fullname = $file['fullname'];
         xdebug_start_code_coverage(XDEBUG_CC_UNUSED);
         Phing::__import($fullname, $this->classpath);
         $coverage = xdebug_get_code_coverage();
         xdebug_stop_code_coverage();
         CoverageMerger::merge($this->project, array($coverage));
     }
 }
Exemple #5
0
 /**
  * Import a dot-path notation class path.
  * @param string $dotPath
  * @param mixed $classpath String or object supporting __toString()
  * @return string The unqualified classname (which can be instantiated).
  * @throws BuildException - if cannot find the specified file
  */
 public static function import($dotPath, $classpath = null)
 {
     // first check to see that the class specified hasn't already been included.
     // (this also handles case where this method is called w/ a classname rather than dotpath)
     $classname = StringHelper::unqualify($dotPath);
     if (class_exists($classname, false)) {
         return $classname;
     }
     $dotClassname = basename($dotPath);
     $dotClassnamePos = strlen($dotPath) - strlen($dotClassname);
     $classFile = strtr($dotClassname, '.', DIRECTORY_SEPARATOR) . ".php";
     $path = substr_replace($dotPath, $classFile, $dotClassnamePos);
     Phing::__import($path, $classpath);
     return $classname;
 }