WsdlToPhp\PackageGenerator\Generator\Utils::resolveCompletePath PHP Method

resolveCompletePath() public static method

public static resolveCompletePath ( string $origin, string $destination ) : string
$origin string
$destination string
return string
    public static function resolveCompletePath($origin, $destination)
    {
        $resolvedPath = $destination;
        if (!empty($destination) && strpos($destination, 'http://') === false && strpos($destination, 'https://') === false && !empty($origin)) {
            if (substr($destination, 0, 2) === './') {
                $destination = substr($destination, 2);
            }
            $destinationParts = explode('/', $destination);
            $fileParts = pathinfo($origin);
            $fileBasename = is_array($fileParts) && array_key_exists('basename', $fileParts) ? $fileParts['basename'] : '';
            $parts = parse_url(str_replace('/' . $fileBasename, '', $origin));
            $scheme = is_array($parts) && array_key_exists('scheme', $parts) ? $parts['scheme'] : '';
            $host = is_array($parts) && array_key_exists('host', $parts) ? $parts['host'] : '';
            $path = is_array($parts) && array_key_exists('path', $parts) ? $parts['path'] : '';
            $path = str_replace('/' . $fileBasename, '', $path);
            $pathParts = explode('/', $path);
            $finalPath = implode('/', $pathParts);
            foreach ($destinationParts as $locationPart) {
                if ($locationPart == '..') {
                    $finalPath = substr($finalPath, 0, strrpos($finalPath, '/', 0));
                } else {
                    $finalPath .= '/' . $locationPart;
                }
            }
            $port = is_array($parts) && array_key_exists('port', $parts) ? $parts['port'] : '';
            /**
             * Remote file
             */
            if (!empty($scheme) && !empty($host)) {
                $resolvedPath = str_replace('urn', 'http', $scheme) . '://' . $host . (!empty($port) ? ':' . $port : '') . str_replace('//', '/', $finalPath);
            } elseif (empty($scheme) && empty($host) && count($pathParts)) {
                /**
                 * Local file
                 */
                if (is_file($finalPath)) {
                    $resolvedPath = $finalPath;
                }
            }
        }
        return $resolvedPath;
    }

Usage Example

Ejemplo n.º 1
0
 /**
  *
  */
 public function testResolveCompletePath()
 {
     $dirname = __DIR__;
     $this->assertSame(sprintf('%s/../resources/aukro.wsdl', $dirname), Utils::resolveCompletePath(sprintf('%s/../resources/ebaySvc.wsdl', $dirname), './folder/../aukro.wsdl'));
     $this->assertSame(sprintf('%s/../resources/aukro.wsdl', $dirname), Utils::resolveCompletePath(sprintf('%s/../resources/ebaySvc.wsdl', $dirname), 'folder/../aukro.wsdl'));
     $this->assertSame(sprintf('%s/../resources/aukro.wsdl', $dirname), Utils::resolveCompletePath(sprintf('%s/../resources/ebaySvc.wsdl', $dirname), 'folder/../toto/../aukro.wsdl'));
     $this->assertSame(sprintf('%s/../resources/aukro.wsdl', $dirname), Utils::resolveCompletePath(sprintf('%s/../resources/ebaySvc.wsdl', $dirname), 'aukro.wsdl'));
 }
All Usage Examples Of WsdlToPhp\PackageGenerator\Generator\Utils::resolveCompletePath