Added support for using PHP array callbacks. Refactored get_mapped_mvc_call#32
Added support for using PHP array callbacks. Refactored get_mapped_mvc_call#32niktest wants to merge 4 commits into10quality:v3.0from
Conversation
…c_call Adding support for using PHP array Callbacks / Callables to add_action, add_filter, add_shortcode, remove_action, remove_filter. Simplified the preg_match call with a stripos to optimize performance.
src/psr4/Bridge.php
Outdated
| $type_prefix = stripos( $call, 'view@' ) !== false ? '_v_' : '_c_'; | ||
| $return_prefix = $return ? 'return_' : 'void_'; | ||
|
|
||
| return $type_prefix . $return_prefix . $call; |
There was a problem hiding this comment.
To optimize performance and improve memory allocation, we want to avoid instantiating variables unless is highly necessary. Please do the concatenation directly, the same as the original code that was refactored, and remove all the variables that are only used once.
src/psr4/Bridge.php
Outdated
| $call = str_replace( $class_prefix, '', implode( '@', $call ) ); | ||
| } | ||
|
|
||
| $type_prefix = stripos( $call, 'view@' ) !== false ? '_v_' : '_c_'; |
There was a problem hiding this comment.
Follow the regex pattern added in the original, this is not covering the original functionality.
There was a problem hiding this comment.
Sure, no worries. I had restored original code and styling
src/psr4/Bridge.php
Outdated
| . ( $return ? 'return_' : 'void_' ) | ||
| . $call; | ||
| if ( is_array( $call ) ) { | ||
| $class_prefix = $this->config->get( 'namespace' ) . '\\Controllers\\'; |
There was a problem hiding this comment.
How do you that /Controllers/ will always be the route?, take into consideration that the path can be changed at config/app.php, so this PR is not covering all case scenarios.
There was a problem hiding this comment.
You are right. I've rewritten this controversial solution.
src/psr4/Bridge.php
Outdated
| return ( preg_match( '/[vV]iew\@/', $call ) ? '_v_' : '_c_' ) | ||
| . ( $return ? 'return_' : 'void_' ) | ||
| . $call; | ||
| if ( is_array( $call ) ) { |
There was a problem hiding this comment.
Any new feature like this requires unit testing.
There was a problem hiding this comment.
I've extended the tests along with the new functionality
…remove a Controller hardcoded path. Nikita Alekseev 6 minutes ago
Adding support for using PHP array Callbacks / Callables to add_action, add_filter, add_shortcode, remove_action, remove_filter. Simplified the preg_match call with a
striposto optimize performance.This will allow using the below approach, which can offer better modules dependencies and their methods tracking in the popular IDE's