Closed mallorydxw closed 8 years ago
The first helper function we should add is one to get the URI of assets.
\Dxw\MyTheme\Helpers
which registers helper functions, and allows calling \Dxw\MyTheme\Helpers->myFunction()
app/load.php
so that we can do this: h()->myFunction()
We're using static methods in some places - we should replace those with this new helper system.
We need to be able to call code in a class from a template sometimes. At the moment, to call a method on an instance, you'd have to do
\Dxw\MyTheme\Registrar::getInstance()->di['Dxw\\MyTheme\\MyClass']->method()
which is a little too verbose.Here are my thoughts:
f('MyClass')->method($arg1, $arg2)
register()
function callsregisterHelperFunction('x', [$this, 'x']);
and then the template code looks likef('x', $arg1, $arg2)
The advantage of 1 is that it's very very simple and leverages existing code and is fairly sensible-looking.
The advantage of 2 is that it makes the author of a class think about which of their methods will need to be called by template code. But we would have to think about how to namespace the methods. And this also requires additional classes to make it happen.