mageekguy\atoum\fs\path::relativizeFrom PHP Method

relativizeFrom() public method

public relativizeFrom ( path $reference )
$reference path
    public function relativizeFrom(path $reference)
    {
        $this->resolve();
        $resolvedReferencePath = $reference->getResolvedPath();
        $this->drive = null;
        switch (true) {
            case $this->components === '/':
                $this->components = '.' . $this->components;
                break;
            case $this->components === $resolvedReferencePath->components:
                $this->components = '.';
                break;
            case $this->isSubPathOf($resolvedReferencePath):
                $this->components = './' . ltrim(substr($this->components, strlen($resolvedReferencePath->components)), '/');
                break;
            default:
                $relativePath = '';
                while ($this->isNotSubPathOf($resolvedReferencePath)) {
                    $relativePath .= '../';
                    $resolvedReferencePath = $resolvedReferencePath->getParentDirectoryPath();
                }
                $this->components = static::getComponents($relativePath) . '/' . ltrim(substr($this->components, strlen($resolvedReferencePath->components)), '/');
        }
        return $this;
    }

Usage Example

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;
 }
All Usage Examples Of mageekguy\atoum\fs\path::relativizeFrom