composer package updates
[openemr.git] / vendor / zendframework / zend-uri / src / File.php
blob141d3c7935728e2215426d65650b1a4324259c32
1 <?php
2 /**
3 * @see https://github.com/zendframework/zend-uri for the canonical source repository
4 * @copyright Copyright (c) 2005-2018 Zend Technologies USA Inc. (https://www.zend.com)
5 * @license https://github.com/zendframework/zend-uri/blob/master/LICENSE.md New BSD License
6 */
8 namespace Zend\Uri;
10 /**
11 * File URI handler
13 * The 'file:...' scheme is loosely defined in RFC-1738
15 class File extends Uri
17 protected static $validSchemes = ['file'];
19 /**
20 * Check if the URI is a valid File URI
22 * This applies additional specific validation rules beyond the ones
23 * required by the generic URI syntax.
25 * @return bool
26 * @see Uri::isValid()
28 public function isValid()
30 if ($this->query) {
31 return false;
34 return parent::isValid();
37 /**
38 * User Info part is not used in file URIs
40 * @see Uri::setUserInfo()
41 * @param string $userInfo
42 * @return File
44 public function setUserInfo($userInfo)
46 return $this;
49 /**
50 * Fragment part is not used in file URIs
52 * @see Uri::setFragment()
53 * @param string $fragment
54 * @return File
56 public function setFragment($fragment)
58 return $this;
61 /**
62 * Convert a UNIX file path to a valid file:// URL
64 * @param string $path
65 * @return File
67 public static function fromUnixPath($path)
69 $url = new static('file:');
70 if (substr($path, 0, 1) == '/') {
71 $url->setHost('');
74 $url->setPath($path);
75 return $url;
78 /**
79 * Convert a Windows file path to a valid file:// URL
81 * @param string $path
82 * @return File
84 public static function fromWindowsPath($path)
86 $url = new static('file:');
88 // Convert directory separators
89 $path = str_replace(['/', '\\'], ['%2F', '/'], $path);
91 // Is this an absolute path?
92 if (preg_match('|^([a-zA-Z]:)?/|', $path)) {
93 $url->setHost('');
96 $url->setPath($path);
97 return $url;