@@ -55,7 +55,38 @@ public function getComposerCommand()
55
55
*/
56
56
public function validatePath ($ path )
57
57
{
58
- // TODO: Implement validatePath() method.
58
+ $ absPath = $ this ->getAbsolutePath ($ path );
59
+ $ absPathParts = explode (DIRECTORY_SEPARATOR , $ absPath );
60
+ $ nSteps = count ($ absPathParts );
61
+
62
+ $ tmpPath = $ absPathParts [0 ];
63
+ $ prevReadable = false ;
64
+ $ prevWritable = false ;
65
+
66
+ for ($ i = 1 ; $ i < $ nSteps ; $ i ++) {
67
+ $ tmpPath .= DIRECTORY_SEPARATOR . $ absPathParts [$ i ];
68
+
69
+ if (file_exists ($ tmpPath )) {
70
+ if (!is_dir ($ tmpPath )) {
71
+ if (is_link ($ tmpPath )) {
72
+ $ linkPath = readlink ($ tmpPath );
73
+ if (false === $ linkPath || !is_dir ($ linkPath )) {
74
+ return false ;
75
+ }
76
+ $ tmpPath = $ linkPath ;
77
+ } else {
78
+ return false ;
79
+ }
80
+ }
81
+
82
+ $ prevReadable = is_readable ($ tmpPath );
83
+ $ prevWritable = is_writable ($ tmpPath );
84
+ } else {
85
+ return ($ prevReadable && $ prevWritable );
86
+ }
87
+ }
88
+
89
+ return true ;
59
90
}
60
91
61
92
/**
@@ -64,7 +95,13 @@ public function validatePath($path)
64
95
*/
65
96
public function ensurePath ($ path )
66
97
{
67
- // TODO: Implement ensurePath() method.
98
+ $ absPath = $ this ->getAbsolutePath ($ path );
99
+
100
+ if (!file_exists ($ absPath ) && false === mkdir ($ absPath , 0755 , true )) {
101
+ throw new \RuntimeException ('Unable to create the specified directory ( ' . $ absPath . '). ' );
102
+ }
103
+
104
+ return $ absPath ;
68
105
}
69
106
70
107
/**
@@ -73,7 +110,7 @@ public function ensurePath($path)
73
110
*/
74
111
protected function isAbsolutePath ($ path )
75
112
{
76
- // TODO: Implement isAbsolutePath() method.
113
+ return preg_match ( ' /^[a-z]\:/i ' , $ path ) === 1 ;
77
114
}
78
115
79
116
/**
@@ -82,6 +119,11 @@ protected function isAbsolutePath($path)
82
119
*/
83
120
protected function getAbsolutePath ($ path )
84
121
{
85
- // TODO: Implement getAbsolutePath() method.
122
+ $ path = $ this ->isAbsolutePath ($ path ) ? $ path : (getcwd () . DIRECTORY_SEPARATOR . $ path );
123
+
124
+ // Normalise directory separators
125
+ $ path = preg_replace ('/[\/ \\\\]/u ' , DIRECTORY_SEPARATOR , $ path );
126
+
127
+ return $ path ;
86
128
}
87
129
}
0 commit comments