- π¦πΊAustralia kim.pepper πββοΈπ¦πΊSydney, Australia
This would be useful for π Allow validators passed to file_validate to use callable syntax Closed: outdated
- Status changed to Needs review
over 1 year ago 8:01am 12 April 2023 - π¦πΊAustralia kim.pepper πββοΈπ¦πΊSydney, Australia
I made quite a few changes to address some of the feedback.
- Move the
is_callable()
check to the top for quick exit. - Removed the reflection to just rely on the class resolver and is_callable()
- Removed the
invokeFromDefinition()
method - Removed the dependency on the container
One side effect is that the error messages are a bit more generic without the extra service container lookups. Not sure whether that is a worthwhile trade off?
- Move the
- π¦πΊAustralia kim.pepper πββοΈπ¦πΊSydney, Australia
I think invoking the callbacks should be out of scope. Having a look at how we use them, they are pretty simple wrappers around DoTrustedCallbackTrait that are specific to Renderer etc. I think we want to keep this more generic.
- π¦πΊAustralia kim.pepper πββοΈπ¦πΊSydney, Australia
Updating IS with remaining tasks.
- π¬π§United Kingdom joachim
It's been ages since I looked at this.
Was there a resolution to the problem of how to deal with the 'Class::method' syntax, where different systems currently handle that in different ways?
- π¦πΊAustralia kim.pepper πββοΈπ¦πΊSydney, Australia
Pretty sure its just
::
is for static or instance method. The class resolver takes care of creating new instances for us. - π¬π§United Kingdom joachim
> Pretty sure its just :: is for static or instance method.
That's the thing though -- in some systems, Class::method means a static call, and in others, it means instantiate the class and call $object->method.
- π¦πΊAustralia kim.pepper πββοΈπ¦πΊSydney, Australia
Re: #78 Not sure it matters? Calling
is_callable()
on the string'\Drupal\Tests\Core\Utility\NoInstantiationMockStaticCallable::staticMethod'
returns true if it's a static method. If not, it drops down to where we instantiate an object. - π¦πΊAustralia Sam152
That's the thing though -- in some systems, Class::method means a static call, and in others, it means instantiate the class and call $object->method.
Pre PHP 8 is_callable would return true for public methods that required instantiation, but this changed: https://3v4l.org/d93fd
Hence the reflection is no longer required and false from is_callable can accurately signal the need for instantiation or the container.
- π¦πΊAustralia kim.pepper πββοΈπ¦πΊSydney, Australia
Changed ControllerResolver to use CallableResolver and added a CR.
- π¦πΊAustralia kim.pepper πββοΈπ¦πΊSydney, Australia
Hence the reflection is no longer required and false from is_callable can accurately signal the need for instantiation or the container.
Whew! π
- π¦πΊAustralia kim.pepper πββοΈπ¦πΊSydney, Australia
So this looks like a genuine fail for
Drupal\Tests\ckeditor5\FunctionalJavascript\MediaTest
.When embedding a media item into a ckeditor5 field, I get the following error in logs:
NOTICE: PHP message: Uncaught PHP Exception ReflectionException: "Function \Drupal\media\Controller\MediaFilterController::formatUsesMediaEmbedFilter() does not exist" at /data/app/core/lib/Drupal/Component/Utility/ArgumentsResolver.php line 122
\Drupal\media\Controller\MediaFilterController::formatUsesMediaEmbedFilter()
does existIs there something we are missing to handle static methods in:
protected function getReflector(callable $callable) { return is_array($callable) ? new \ReflectionMethod($callable[0], $callable[1]) : new \ReflectionFunction($callable); }
?
- π¦πΊAustralia kim.pepper πββοΈπ¦πΊSydney, Australia
Confirmed! Added a check for a string static method callable with "::" syntax.
- π¦πΊAustralia kim.pepper πββοΈπ¦πΊSydney, Australia
Here's a test-only patch for the ArgumentsResolver to show that callables that are static methods in string "::" format aren't currently supported.
- π¬π§United Kingdom joachim
> Pre PHP 8 is_callable would return true for public methods that required instantiation, but this changed: https://3v4l.org/d93fd - created this snippet 24h ago because I was similarly confused π
Oh that's NICE!
It works for this too:
$callable = Foo::class . '::bar';
The last submitted patch, 87: 2982949-87-test-only.patch, failed testing. View results β
- Status changed to Needs work
over 1 year ago 9:06am 13 April 2023 - π¬π§United Kingdom joachim
The change in PHP 8 is documented here BTW: https://www.php.net/manual/en/migration80.incompatible.php
- Status changed to Needs review
over 1 year ago 9:35am 13 April 2023 - π¦πΊAustralia kim.pepper πββοΈπ¦πΊSydney, Australia
Tests passed so needs review.
- Status changed to Needs work
over 1 year ago 10:07am 13 April 2023 - π¦πΊAustralia larowlan π¦πΊπ.au GMT+10
Left some comments on the MR - looking great - some solid test coverage too
Re #64 I don't think moving the trait into this service is needed. Traits should be reused, so I don't see the harm in there being N classes that use it.
However I do think we should be using this in
\Drupal\Core\Security\DoTrustedCallbackTrait::doTrustedCallback
I think to enable that we'd need a $callableResolver property in that trait and ::getCallableResolver method that first checked the property, and if it wasn't set reached out to the \Drupal singleton. That way classes using the trait can use DI to the property eventually, but if they don't, the class will be fetched from the container. We'd have to update the usages of the trait in core to set that property.
- π«π·France andypost
Addressed mostly all feedback in MR, leaving NW for #92 and
- https://git.drupalcode.org/project/drupal/-/merge_requests/338#note_166660
- https://git.drupalcode.org/project/drupal/-/merge_requests/338#note_166667 - Status changed to Needs review
over 1 year ago 9:14pm 13 April 2023 - π¦πΊAustralia kim.pepper πββοΈπ¦πΊSydney, Australia
All feedback has been addressed or at least commented on.
- π¦πΊAustralia kim.pepper πββοΈπ¦πΊSydney, Australia
Should we split static methods in strings '::' into arrays first? That we we can do the ArgumentResolver change in a follow up.
- π¬π§United Kingdom joachim
Ah, the change to ArgumentResolver is so that it can handle getting the method reflector for a method given in 'Class::method' form? That makes sense now :)
I'd keep it in.
- π«π·France andypost
Re #95 there's interesting numbers - #3274867-21: Add TrustedCallback attribute β
TL'DR callable as array faster ~50% vs string
- π¦πΊAustralia kim.pepper πββοΈπ¦πΊSydney, Australia
#97 are you saying we should split by "::" first up?
- π¦πΊAustralia kim.pepper πββοΈπ¦πΊSydney, Australia
@andypost I'm not sure how much of a micro-optimisation that is? Currently static methods in "::" string format will be returned by the first line:
if (is_callable($definition)) { return $definition; }
- Status changed to RTBC
over 1 year ago 11:03am 15 April 2023 - π«π·France andypost
@kim.pepper no need to change it as PHP internals will do that on call, I see no reason in changing callable as the most performant case is first-class callable but it's just preemptive optimization ATM
Looks ready to go
- last update
over 1 year ago 29,225 pass - π§πͺBelgium dieterholvoet Brussels
I noticed service notation without specifying a method name (with an
__invoke
method) is missing from the documentation/tests. Is this supported yet? If not, do you think it should be supported? It seems potentially useful to me. - Status changed to Needs work
over 1 year ago 8:56pm 17 April 2023 - last update
over 1 year ago 29,307 pass - last update
over 1 year ago 29,307 pass - Status changed to Needs review
over 1 year ago 1:12am 18 April 2023 - π«π·France andypost
Added test and docs for service with
__invoke()
PS: rebased and merge commits are gone, /cc @kim.pepper
- Status changed to RTBC
over 1 year ago 12:22am 13 May 2023 - πΊπΈUnited States smustgrave
Seems this was already previously reviewed.
Point #101 appears to have been addressed so remarking this for ya.
- last update
over 1 year ago 29,412 pass - Open on Drupal.org βEnvironment: PHP 8.1 & MySQL 5.7last update
over 1 year ago Waiting for branch to pass - last update
over 1 year ago 29,412 pass - last update
over 1 year ago 29,405 pass, 2 fail - last update
over 1 year ago 29,412 pass - Open on Drupal.org βEnvironment: PHP 8.1 & MySQL 5.7last update
over 1 year ago Waiting for branch to pass 12:02 6:15 Running- last update
over 1 year ago 29,423 pass - π¦πΊAustralia larowlan π¦πΊπ.au GMT+10
There's an unresolved comment on the MR about whether we should be using this in a few places
\Drupal\Core\Render\Renderer::doCallback
\Drupal\Core\Menu\MenuLinkTree::transform (and \Drupal\toolbar\Menu\ToolbarMenuLinkTree which subclasses it)
\Drupal\Core\Routing\RouteBuilder::rebuild
\Drupal\Core\Access\CustomAccessCheck::access
\Drupal\user\PermissionHandler::buildPermissionsYaml instead of the controller resolver?Can we get follow up issues created for that?
- last update
over 1 year ago 29,423 pass - π¦πΊAustralia kim.pepper πββοΈπ¦πΊSydney, Australia
Created follow up issues:
- π Use CallableResolver for \Drupal\Core\Render\Renderer::doCallback() Needs work
- π Use CallableResolver for \Drupal\Core\Menu\MenuLinkTree::transform() Fixed
- π Use CallableResolver for \Drupal\Core\Routing\RouteBuilder::rebuild Needs work
- π Use CallableResolver for \Drupal\Core\Access\CustomAccessCheck::access() Fixed
- π Use CallableResolver for \Drupal\user\PermissionHandler::buildPermissionsYaml() instead of the controller resolver Fixed
- First commit to issue fork.
- Open on Drupal.org βEnvironment: PHP 8.1 & MySQL 5.7last update
over 1 year ago Not currently mergeable. - Open on Drupal.org βEnvironment: PHP 8.1 & MySQL 5.7last update
over 1 year ago Not currently mergeable. - Open on Drupal.org βEnvironment: PHP 8.1 & MySQL 5.7last update
over 1 year ago Not currently mergeable. - Open on Drupal.org βEnvironment: PHP 8.1 & MySQL 5.7last update
over 1 year ago Not currently mergeable. - Open on Drupal.org βEnvironment: PHP 8.1 & MySQL 5.7last update
over 1 year ago Not currently mergeable. - Open on Drupal.org βEnvironment: PHP 8.1 & MySQL 5.7last update
over 1 year ago Not currently mergeable. - Status changed to Needs work
over 1 year ago 12:05am 5 June 2023 - last update
over 1 year ago Custom Commands Failed - last update
over 1 year ago 29,438 pass - Status changed to Needs review
over 1 year ago 7:02am 5 June 2023 - π¦πΊAustralia kim.pepper πββοΈπ¦πΊSydney, Australia
Rebased on 11.x
- π¦πΊAustralia kim.pepper πββοΈπ¦πΊSydney, Australia
Hiding patch as it makes it look like the MR is failing when its not.
- Status changed to RTBC
over 1 year ago 8:44am 5 June 2023 - last update
over 1 year ago 29,440 pass - last update
over 1 year ago 29,459 pass - last update
over 1 year ago 29,460 pass - π«π·France andypost
There's some measurements of different types of callables https://gist.github.com/donquixote/85efcca90056111e967dd14cb1f9de9c
Which means we should try re-use a callable as possible
- last update
over 1 year ago 29,467 pass - last update
over 1 year ago 29,473 pass - π¦πΊAustralia kim.pepper πββοΈπ¦πΊSydney, Australia
The last MR comment can be resolved.
- last update
over 1 year ago 29,522 pass - last update
over 1 year ago 29,522 pass, 1 fail - last update
over 1 year ago 29,528 pass -
larowlan β
committed c4cf5949 on 11.x
Issue #2982949 by kim.pepper, Sam152, andypost, FatherShawn, elber,...
-
larowlan β
committed c4cf5949 on 11.x
- Status changed to Fixed
over 1 year ago 6:17am 22 June 2023 - π¦πΊAustralia larowlan π¦πΊπ.au GMT+10
Committed to 11.x and published the change record.
The child issues are now good to go.
- π¦πΊAustralia larowlan π¦πΊπ.au GMT+10
I also added an extra CR announcing the new feature - https://www.drupal.org/node/3368504 β please review and amend if appropriate
- πΊπΈUnited States fathershawn New York
Grateful and excited to see this committed. I'll rebase the work I started on π Limit what can be called by a callback in form arrays Needs work onto 11.x-dev and update it in light of this work.
Automatically closed - issue fixed for 2 weeks with no activity.