Skip to content

Commit f4e28d8

Browse files
committed
fix: all directory path methods should return a relative path if there's no base path
1 parent c8652b2 commit f4e28d8

File tree

8 files changed

+135
-100
lines changed

8 files changed

+135
-100
lines changed

src/Project/Type/AbstractProjectType.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,17 @@ protected function getBaseFinder(string $projectDirectory): Finder
8686
->files();
8787
}
8888

89+
/**
90+
* Get the absolute or relative path to a given path.
91+
*
92+
* If the project directory is given, it will return the absolute path to the given path. Otherwise, it will
93+
* return the relative path.
94+
*/
95+
protected function getPath(string $path, string $projectDirectory = ''): string
96+
{
97+
return !empty($projectDirectory) ? rtrim($projectDirectory, '/').'/'.$path : $path;
98+
}
99+
89100
/**
90101
* Get a SplFileInfo object for a project file.
91102
*/
@@ -95,12 +106,12 @@ protected function getSplFileInfo(string $directory, string $path): SplFileInfo
95106
}
96107

97108
/**
98-
* Check if the given paths exist in the given directory.
109+
* Check if the given paths exist relative to the given project directory.
99110
*/
100-
protected function pathsExist(string $directory, array $paths): bool
111+
protected function pathsExist(string $projectDirectory, array $paths): bool
101112
{
102-
return $this->filesystem->exists(array_map(function (string $path) use ($directory) {
103-
return $directory.$path;
113+
return $this->filesystem->exists(array_map(function (string $path) use ($projectDirectory) {
114+
return $this->getPath($path, $projectDirectory);
104115
}, $paths));
105116
}
106117
}

src/Project/Type/AbstractWordPressProjectType.php

Lines changed: 40 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -57,37 +57,46 @@ public function getEnvironmentConfiguration(string $environment, array $baseConf
5757
}
5858

5959
/**
60-
* {@inheritdoc}
60+
* Get the path to the "mu-plugins" directory.
61+
*
62+
* If the project directory is given, it will return the absolute path to the "mu-plugins" directory. Otherwise, it
63+
* will return the relative path.
6164
*/
62-
public function getProjectFiles(string $projectDirectory): Finder
65+
public function getMustUsePluginsDirectoryPath(string $projectDirectory = ''): string
6366
{
64-
return parent::getProjectFiles($projectDirectory)
65-
->exclude(ltrim($this->getUploadsDirectoryPath(), '/'));
67+
return $this->getPath($this->getMustUsePluginsDirectory(), $projectDirectory);
6668
}
6769

6870
/**
69-
* Get the path to the "mu-plugins" directory.
71+
* Get the path to the "plugins" directory.
7072
*
71-
* If the directory is given, it will return the path to the "mu-plugins" directory in that directory. Otherwise, it
72-
* will return the relative path to the "mu-plugins" directory in the project.
73+
* If the project directory is given, it will return the absolute path to the "plugins" directory. Otherwise, it
74+
* will return the relative path.
7375
*/
74-
abstract public function getMustUsePluginsDirectoryPath(string $baseDirectory = ''): string;
76+
public function getPluginsDirectoryPath(string $projectDirectory = ''): string
77+
{
78+
return $this->getPath($this->getPluginsDirectory(), $projectDirectory);
79+
}
7580

7681
/**
77-
* Get the path to the "plugins" directory.
78-
*
79-
* If the directory is given, it will return the path to the "plugins" directory in that directory. Otherwise, it
80-
* will return the relative path to the "plugins" directory in the project.
82+
* {@inheritdoc}
8183
*/
82-
abstract public function getPluginsDirectoryPath(string $baseDirectory = ''): string;
84+
public function getProjectFiles(string $projectDirectory): Finder
85+
{
86+
return parent::getProjectFiles($projectDirectory)
87+
->exclude(ltrim($this->getUploadsDirectoryPath(), '/'));
88+
}
8389

8490
/**
8591
* Get the path to the "uploads" directory.
8692
*
87-
* If the directory is given, it will return the path to the "uploads" directory in that directory. Otherwise, it
88-
* will return the relative path to the "uploads" directory in the project.
93+
* If the project directory is given, it will return the absolute path to the "uploads" directory. Otherwise, it
94+
* will return the relative path.
8995
*/
90-
abstract public function getUploadsDirectoryPath(string $baseDirectory = ''): string;
96+
public function getUploadsDirectoryPath(string $projectDirectory = ''): string
97+
{
98+
return $this->getPath($this->getUploadsDirectory(), $projectDirectory);
99+
}
91100

92101
/**
93102
* Get the Finder object for finding all the required files in the given project directory.
@@ -151,4 +160,19 @@ protected function getWordPressCoreFiles(string $projectDirectory): Finder
151160
* Builds a regex pattern for a WordPress core path.
152161
*/
153162
abstract protected function buildWordPressCorePathPattern(string $path): string;
163+
164+
/**
165+
* Get the "mu-plugins" directory used by the project type.
166+
*/
167+
abstract protected function getMustUsePluginsDirectory(): string;
168+
169+
/**
170+
* Get the "plugins" directory used by the project type.
171+
*/
172+
abstract protected function getPluginsDirectory(): string;
173+
174+
/**
175+
* Get the "uploads" directory used by the project type.
176+
*/
177+
abstract protected function getUploadsDirectory(): string;
154178
}

src/Project/Type/BedrockProjectType.php

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -92,80 +92,80 @@ public function getInstallationMessage(): string
9292
/**
9393
* {@inheritdoc}
9494
*/
95-
public function getMustUsePluginsDirectoryPath(string $baseDirectory = ''): string
95+
public function getName(): string
9696
{
97-
return rtrim($baseDirectory, '/').'/web/app/mu-plugins';
97+
return 'Bedrock';
9898
}
9999

100100
/**
101101
* {@inheritdoc}
102102
*/
103-
public function getName(): string
103+
public function installIntegration(string $projectDirectory)
104104
{
105-
return 'Bedrock';
105+
$this->composerExecutable->require('ymirapp/wordpress-plugin', $projectDirectory);
106106
}
107107

108108
/**
109109
* {@inheritdoc}
110110
*/
111-
public function getPluginsDirectoryPath(string $baseDirectory = ''): string
111+
public function installProject(string $directory)
112112
{
113-
return rtrim($baseDirectory, '/').'/web/app/plugins';
113+
$this->composerExecutable->createProject('roots/bedrock', $directory);
114114
}
115115

116116
/**
117117
* {@inheritdoc}
118118
*/
119-
public function getUploadsDirectoryPath(string $baseDirectory = ''): string
119+
public function isEligibleForInstallation(string $directory): bool
120120
{
121-
return rtrim($baseDirectory, '/').'/web/app/uploads';
121+
return !(new \FilesystemIterator($directory))->valid();
122122
}
123123

124124
/**
125125
* {@inheritdoc}
126126
*/
127-
public function installIntegration(string $projectDirectory)
127+
public function isIntegrationInstalled(string $projectDirectory): bool
128128
{
129-
$this->composerExecutable->require('ymirapp/wordpress-plugin', $projectDirectory);
129+
return $this->composerExecutable->isPackageInstalled('ymirapp/wordpress-plugin', $projectDirectory);
130130
}
131131

132132
/**
133133
* {@inheritdoc}
134134
*/
135-
public function installProject(string $directory)
135+
public function matchesProject(string $projectDirectory): bool
136136
{
137-
$this->composerExecutable->createProject('roots/bedrock', $directory);
137+
return $this->pathsExist($projectDirectory, ['/web/app/', '/web/wp-config.php', '/config/application.php']);
138138
}
139139

140140
/**
141141
* {@inheritdoc}
142142
*/
143-
public function isEligibleForInstallation(string $directory): bool
143+
protected function buildWordPressCorePathPattern(string $path): string
144144
{
145-
return !(new \FilesystemIterator($directory))->valid();
145+
return sprintf('/^web\/wp\/%s/', $path);
146146
}
147147

148148
/**
149149
* {@inheritdoc}
150150
*/
151-
public function isIntegrationInstalled(string $projectDirectory): bool
151+
protected function getMustUsePluginsDirectory(): string
152152
{
153-
return $this->composerExecutable->isPackageInstalled('ymirapp/wordpress-plugin', $projectDirectory);
153+
return 'web/app/mu-plugins';
154154
}
155155

156156
/**
157157
* {@inheritdoc}
158158
*/
159-
public function matchesProject(string $projectDirectory): bool
159+
protected function getPluginsDirectory(): string
160160
{
161-
return $this->pathsExist($projectDirectory, ['/web/app/', '/web/wp-config.php', '/config/application.php']);
161+
return 'web/app/plugins';
162162
}
163163

164164
/**
165165
* {@inheritdoc}
166166
*/
167-
protected function buildWordPressCorePathPattern(string $path): string
167+
protected function getUploadsDirectory(): string
168168
{
169-
return sprintf('/^web\/wp\/%s/', $path);
169+
return 'web/app/uploads';
170170
}
171171
}

src/Project/Type/RadicleProjectType.php

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -85,66 +85,66 @@ public function getEnvironmentConfiguration(string $environment, array $baseConf
8585
/**
8686
* {@inheritdoc}
8787
*/
88-
public function getMustUsePluginsDirectoryPath(string $baseDirectory = ''): string
88+
public function getName(): string
8989
{
90-
return rtrim($baseDirectory, '/').'/public/content/mu-plugins';
90+
return 'Radicle';
9191
}
9292

9393
/**
9494
* {@inheritdoc}
9595
*/
96-
public function getName(): string
96+
public function installIntegration(string $projectDirectory)
9797
{
98-
return 'Radicle';
98+
$this->composerExecutable->require('ymirapp/wordpress-plugin', $projectDirectory);
99+
$this->composerExecutable->require('ymirapp/laravel-bridge', $projectDirectory);
99100
}
100101

101102
/**
102103
* {@inheritdoc}
103104
*/
104-
public function getPluginsDirectoryPath(string $baseDirectory = ''): string
105+
public function isIntegrationInstalled(string $projectDirectory): bool
105106
{
106-
return rtrim($baseDirectory, '/').'/public/content/plugins';
107+
return $this->composerExecutable->isPackageInstalled('ymirapp/laravel-bridge', $projectDirectory)
108+
&& $this->composerExecutable->isPackageInstalled('ymirapp/wordpress-plugin', $projectDirectory);
107109
}
108110

109111
/**
110112
* {@inheritdoc}
111113
*/
112-
public function getUploadsDirectoryPath(string $baseDirectory = ''): string
114+
public function matchesProject(string $projectDirectory): bool
113115
{
114-
return rtrim($baseDirectory, '/').'/public/content/uploads';
116+
return $this->pathsExist($projectDirectory, ['/public/content/', '/public/wp-config.php', '/bedrock/application.php']);
115117
}
116118

117119
/**
118120
* {@inheritdoc}
119121
*/
120-
public function installIntegration(string $projectDirectory)
122+
protected function buildWordPressCorePathPattern(string $path): string
121123
{
122-
$this->composerExecutable->require('ymirapp/wordpress-plugin', $projectDirectory);
123-
$this->composerExecutable->require('ymirapp/laravel-bridge', $projectDirectory);
124+
return sprintf('/^public\/wp\/%s/', $path);
124125
}
125126

126127
/**
127128
* {@inheritdoc}
128129
*/
129-
public function isIntegrationInstalled(string $projectDirectory): bool
130+
protected function getMustUsePluginsDirectory(): string
130131
{
131-
return $this->composerExecutable->isPackageInstalled('ymirapp/laravel-bridge', $projectDirectory)
132-
&& $this->composerExecutable->isPackageInstalled('ymirapp/wordpress-plugin', $projectDirectory);
132+
return 'public/content/mu-plugins';
133133
}
134134

135135
/**
136136
* {@inheritdoc}
137137
*/
138-
public function matchesProject(string $projectDirectory): bool
138+
protected function getPluginsDirectory(): string
139139
{
140-
return $this->pathsExist($projectDirectory, ['/public/content/', '/public/wp-config.php', '/bedrock/application.php']);
140+
return 'public/content/plugins';
141141
}
142142

143143
/**
144144
* {@inheritdoc}
145145
*/
146-
protected function buildWordPressCorePathPattern(string $path): string
146+
protected function getUploadsDirectory(): string
147147
{
148-
return sprintf('/^public\/wp\/%s/', $path);
148+
return 'public/content/uploads';
149149
}
150150
}

src/Project/Type/WordPressProjectType.php

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,6 @@ public function getInstallationMessage(): string
7171
return 'Downloading WordPress using WP-CLI';
7272
}
7373

74-
/**
75-
* {@inheritdoc}
76-
*/
77-
public function getMustUsePluginsDirectoryPath(string $baseDirectory = ''): string
78-
{
79-
return rtrim($baseDirectory, '/').'/wp-content/mu-plugins';
80-
}
81-
8274
/**
8375
* {@inheritdoc}
8476
*/
@@ -87,14 +79,6 @@ public function getName(): string
8779
return 'WordPress';
8880
}
8981

90-
/**
91-
* {@inheritdoc}
92-
*/
93-
public function getPluginsDirectoryPath(string $baseDirectory = ''): string
94-
{
95-
return rtrim($baseDirectory, '/').'/wp-content/plugins';
96-
}
97-
9882
/**
9983
* {@inheritdoc}
10084
*/
@@ -110,14 +94,6 @@ public function getProjectFiles(string $projectDirectory): Finder
11094
return $projectFiles;
11195
}
11296

113-
/**
114-
* {@inheritdoc}
115-
*/
116-
public function getUploadsDirectoryPath(string $baseDirectory = ''): string
117-
{
118-
return rtrim($baseDirectory, '/').'/wp-content/uploads';
119-
}
120-
12197
/**
12298
* {@inheritdoc}
12399
*/
@@ -201,4 +177,28 @@ protected function buildWordPressCorePathPattern(string $path): string
201177
{
202178
return sprintf('/^%s/', $path);
203179
}
180+
181+
/**
182+
* {@inheritdoc}
183+
*/
184+
protected function getMustUsePluginsDirectory(): string
185+
{
186+
return 'wp-content/mu-plugins';
187+
}
188+
189+
/**
190+
* {@inheritdoc}
191+
*/
192+
protected function getPluginsDirectory(): string
193+
{
194+
return 'wp-content/plugins';
195+
}
196+
197+
/**
198+
* {@inheritdoc}
199+
*/
200+
protected function getUploadsDirectory(): string
201+
{
202+
return 'wp-content/uploads';
203+
}
204204
}

0 commit comments

Comments
 (0)