inpsyde / modularity

A PSR-11 implementation for WordPress Plugins, Themes or Libraries.
https://inpsyde.github.io/modularity/
GNU General Public License v2.0
46 stars 4 forks source link

Use `PATHINFO_BASENAME` for interoperability #42

Open widoz opened 8 months ago

widoz commented 8 months ago

The usage of the flag PATHINFO_FILENAME might strip part of the name of the project.

One case might be a theme having a dot as part of the name, for instance when we want to differentiate the different versions of a theme we have in our installation.

Please check if the PR fulfills these requirements

What kind of change does this PR introduce? (Bug fix, feature, docs update, ...) Bug fix

What is the current behavior? (You can also link to an open issue here) The project base name is stripping part of the name when defining the baseName property

What is the new behavior (if this is a feature change)? The part after the dot (.) character is no longer stripped off.

Does this PR introduce a breaking change? (What changes might users need to make in their application due to this PR?) No

Other information:

widoz commented 8 months ago

I see some tests failing because of the changes, it might make sense to override the BaseProperties::sanitizeBaseName within the ThemeProperties instead?

gmazzap commented 8 months ago

@widoz I think we need to change a bit how it works.

The line substr_count($name, '/') and $name = dirname($name); in BaseProperties::sanitizeBaseName() is something that makes sense for plugins. In fact, for plugin we pass the result of plugin_basename() that with return the-folder/the-file.php when the plguin is in a folder, but the-file.php when the plugin is made of a single file. So I think we should move the entire code of BaseProperties::sanitizeBaseName() to PluginProperties.

So, when we have $this->pluginBaseName = plugin_basename($pluginMainFile); we should do something alomng the lines of:

$basename = plugin_basename($pluginMainFile);
substr_count($basename, '/') and $basename = dirname($name);
$this->pluginBaseName = strtolower(pathinfo($name, PATHINFO_FILENAME));

This way, we should cover all cases for plugin, and it will also be backward compatible for plugins and libraries (which do not use files/directories at all, but Composer name).

At that point, BaseProperties::sanitizeBaseName() could probably removed at all, or maybe just strtolower($name).