calvinalkan / better-wordpress-hooks Goto Github PK
View Code? Open in Web Editor NEWHome Page: https://packagist.org/packages/calvinalkan/better-wordpress-hooks
License: MIT License
Home Page: https://packagist.org/packages/calvinalkan/better-wordpress-hooks
License: MIT License
Assuming the following 2 Listener.
NewAppointment::class => [
SendStaffBookingConfirmationEmail::class,
StaffBookingCustomerSync::class,
],
do not implement __invoke
but use the default handleEvent
method the ListenerFactory
will throw an exception. This happens because for the second listener the "alias" is an integer with value 1. This value needs to be normalized before creating the listener.
It would be create to have one listener class listen to any dispatched event that has a specific interface.
Sometimes EventObjects are pure data classes for one variable and the listener is not interested in the event object but only the variable. It would be good to have some sort of payload
method on event objects which allows dictating the payload passed to the listeners when the event gets dispatched.
WordPress has the very unfortunate behaviour of passing an empty string as the first payload parameter for several hooks including the init
hook. This forces us right now to accept an additional argument for the listener callback.
Currently mapped events are not loaded from the service container. In fact, they don't even go through the dispatcher flow at all. Instead, they are directly going through the WP hook API.
Create an option to pass an optional argument to mapped events to also resolve them from the service container
Allow Filterable events to define a default message that can optionally adjust the returned payload if the filtered value is either the same as the payload or if the filtered value is null or did not respect the API and return value of a filter.
The FakeDispatcher will need a reference to the original dispatcher to dynamically forward non event-dispatching methods
Right now it's possible to attach many listeners two one event. The inverse is also very useful in many situations.
Replace the reflects callable trait with the ReflectionPayload
class from another project of mine. This would allow to handle certain edge cases better and build the hook payload using the container by combining type-checks and parameter names. Right now the payload is passed by order into the listener which may cause a problem with certain edge cases with for example the init hook where WP-passes an empty string as the first argument.
https://github.com/calvinalkan/wp-mvc/blob/master/src/Support/ReflectionPayload.php
Right now when we use an event object and customize the payload to be something different then the object itself we won't be able to use features later on in the dispatch()
method that rely on the payload to be an event object.
public function swapDispatcher(Dispatcher $new_dispatcher)
{
// The dispatcher needs to be swapped also in the service container.
$this->dispatcher = $new_dispatcher;
}
Right now it's not possible to create an event listener and bind it to an interface.
The dispatcher will flag it as an invalid listener since it's neither a closure nor an instance nor a callable.
Right now it's only possible to either fake all or some events. But not all except some
Using the following configuration:
$listeners => [
BookingCreated::class => [
NotifyOwner::class,
NotifyAttendee::class
]
].
Both Listeners rely on the event object. This setup requires set NotifyOwner::class MUST return the received event which is weird. If the first listener does not return the event php NotifyAttendee::class
will receive null
due to WordPress resetting the value here.
The fix is easy. In the WordpressApi
class that is the bridge to WP we just need a conditional check and use do_action
instead of apply_filters
respectively.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.