Perry Rylance

Personal & Professional blog

PSR-4, REST Cache and DataTables

PSR-4 autoloading is the standard mechanism by which Laravel loads classes. I hit a few stumbling blocks as a relative newcomer to PSR-4, I’ve now got a good hold on this and have my Laravel powered WordPress REST Cache plugin loading both my DOMDocument library and my new DataTable library.

There are quite a lot of existing DataTable libraries but they all appear to be exclusively server side. My library provides client side code to make creating datatables very straightforward. To use the library, one only needs to implement the abstract methods on a subclass to specify the table name and API route, from there everything including searching, sorting and pagination works out of the box.

I also learned how to add my own custom classes to my Laravel application and get them loaded up with PSR-4, this facilitates instantiating the record and rule tables, which are based on the DataTables library.

This DataTables library is available on Packagist, and will be used in my REST cache to show a table of cache records and caching rules.

Now that I have this in place, the rest should follow quite easily, I’m hopeful to wrap the cache up this week, if not sooner!

I’m considering sitting this course within the month if time permits, my REST cache exercise has been a very good way to learn, but I would like to do something more comprehensive, even if it doesn’t provide a practical application at the end of the process.