relativizeFrom() public method

public relativizeFrom ( path $reference )
$reference path
Example #1
0
 protected function doRun()
 {
     $data = array();
     $srcDirectory = new atoum\fs\path($this->srcDirectory);
     foreach (new iterators\recursives\atoum\source($this->srcDirectory) as $file) {
         $file = new atoum\fs\path($file);
         $data[(string) $file->relativizeFrom($srcDirectory)] = file_get_contents($file);
     }
     $bootstrapFile = new atoum\fs\path($this->bootstrapFile);
     $bootstrapFile = $bootstrapFile->relativizeFrom($srcDirectory);
     $bootstrap = '<?php $directory = sys_get_temp_dir() . \'/\' . basename(__FILE__);';
     $bootstrap .= '$bootstrap = $directory . \'/' . $bootstrapFile . '\';';
     $bootstrap .= 'if (is_file($bootstrap) === false || filemtime(__FILE__) > filemtime($bootstrap))';
     $bootstrap .= '{';
     $bootstrap .= '$data = eval(substr(file_get_contents(__FILE__), __COMPILER_HALT_OFFSET__));';
     $bootstrap .= 'foreach ($data as $file => $contents)';
     $bootstrap .= '{';
     $bootstrap .= '$file = $directory . \'/\' . $file;';
     $bootstrap .= '@mkdir(dirname($file), 0777, true);';
     $bootstrap .= '@file_put_contents($file, $contents);';
     $bootstrap .= '}';
     $bootstrap .= '}';
     $bootstrap .= 'require $bootstrap;';
     $bootstrap .= '__halt_compiler();';
     if (file_put_contents($this->destinationFile, $bootstrap . 'return ' . var_export($data, true) . ';') === false) {
         throw new exceptions\runtime(sprintf($this->locale->_('Unable to write in file \'%s\''), $this->destinationFile));
     }
     return $this;
 }
Example #2
0
 /**
  * @param Path $path
  *
  * @return string
  */
 protected function getFileName(Path $path)
 {
     return ltrim((string) $path->relativizeFrom($this->sourceDirectory), './');
 }
Example #3
0
 public function testRelativizeFrom($path, $directorySeparator, $fromPath, $fromDirectorySeparator, $relativePath)
 {
     $this->if($path = new testedClass($path, $directorySeparator))->then->object($path->relativizeFrom(new testedClass($fromPath, $fromDirectorySeparator)))->isIdenticalTo($path)->toString->isEqualTo($relativePath);
 }
Example #4
0
 protected function makeSourceElement(score\coverage $coverage)
 {
     $sources = array();
     foreach ($coverage->getClasses() as $class => $file) {
         $path = new atoum\fs\path($file);
         $source = $this->adapter->file_get_contents((string) $path->resolve());
         $sources[] = array('name' => ltrim((string) $path->relativizeFrom($this->sourceDir), '.' . DIRECTORY_SEPARATOR), 'source' => $source, 'coverage' => $this->makeCoverageElement($coverage->getCoverageForClass($class)));
     }
     return $sources;
 }