Updated: Comment #0
Problem/Motivation
Drupal 7 had the useful function drupal_parse_dependency to parse dependencies declared in the "example (>7.x-2.3)" format.
This was useful for contrib and was used in Libraries API as libraries use the same mechanism to declare dependencies.
In Drupal 8 the parsing is now done in the protected function \Drupal\Core\Extension\ModuleHandler::parseDependency(). The function is therefore inaccessible to contrib and would have to be copied. This is a regression in DX.
Proposed resolution
Make \Drupal\Core\Extension\ModuleHandler::parseDependency()
public.
Since it is a utility function and does not access object state at all, tstoeckler proposes that it be made static as well. This is what we do with other utility methods (see \Drupal\(Core/Component)\Utility) and so should not offend OO purists any more than existing code. I am also open to moving this method to a separate utility class in case people find that this would be "tainting" ModuleHandler.
API changes
Before:
drupal_parse_dependency($dependency)
After:
use Drupal\Core\Extension\ModuleHandler;
ModuleHandler::parseDependency($dependency)
Note that there is currently no change notice for the removal of drupal_parse_dependency() :-/
Comment | File | Size | Author |
---|---|---|---|
#1 | drupal8.parse-dependency-public.2068797-1.patch | 1.18 KB | tstoeckler |
Comments
Comment #1
tstoecklerHere we go.
Comment #3
tstoeckler#1: drupal8.parse-dependency-public.2068797-1.patch queued for re-testing.
I think this is a random error: SearchMatchTest.php, l. 30
Comment #4
dawehnerThis would also make it easier to unit test it later!
Comment #5
catchCommitted/pushed to 8.x, thanks!
Comment #6
tstoecklerAdded a change notice.
https://drupal.org/node/2090931
Comment #7
tstoecklerCreated #2090939: Unit test \Drupal\Core\ModuleHandler::parseDependency() per #4.
Comment #8
fubhy CreditAttribution: fubhy commentedSorry, but why did we make this public instead of moving it to 'Components\Utility". It has basically 0 to do with ModuleHandler as a service except that it uses it.
Comment #9
fubhy CreditAttribution: fubhy commentedJust read this:
So, yes, it's "tainting" ModuleHandler. I will just post a quick follow-up patch right here to move it to a utility component. Any suggestions for good name for that class?
Comment #10
fubhy CreditAttribution: fubhy commentedI opened #2098521: Move extension/version handling logic to a Utility class.
Comment #11
xjmUntagging. Please remove the "Needs change notification" tag when the change notice task is complete.