I was trying to create an extension for selecting a custom font for the entire forum from the administrator and replacing the default one, which is hard-coded (???) in the ClientView's constructor.
But I realized that there's no function for replacing or removing a string from the headStrings array.
Is there a workaround for this or should I add these functions to the class (removeHeadString, removeFootString, replaceHeadString and replaceFootString?
I believe @tobscure will revamp the ClientView class a bit, that should probably be considered...
@tobscure You asked which of the two APIs I like better:
~php
$view->getHead() // returns an Illuminate Collection
->push('value')
->put('key', 'value')
->forget('key');
~
or
~php
$view->addHeadHtml('key', 'value')
->removeHeadHtml('key', 'value');
// how far would we go with these methods?
// also keep in mind we'd need to add equivalent ones for foot as well
~
I'd go with the second. We control the interface (i.e. the method names define the contract of the class), it fits the "Tell, don't ask" principle, and the first one would violate the Law of Demeter.
(Plus, I was surprised that the methods you called on the collection mutate the collection directly - which doesn't fit very well with other methods that are immutable.)
Hmm, so it'd end up looking something like this:
$view->addHeadSnippet('key', 'value');
$view->removeHeadSnippet('key');
$view->getHeadSnippet('key'); // do we
$view->getHeadSnippets(); // need these?
$view->addFootSnippet('key', 'value');
$view->removeFootSnippet('key');
$view->getFootSnippet('key'); // do we
$view->getFootSnippets(); // need these?
What about giving items priorities so that they can be ordered?
It just seems to be a lot of functionality for the view class... all implemented twice (for head and foot).
What about an API like the JS ItemList class? That's kind of the exact functionality we want for this...
$view->getHeadItems()
->add('key', 'value', 10) // specify priorities
->remove('key');
I'm okay with a custom collection class.
if it does not make things complicated it's possible to store keys in a SplPriorityQueue
currently it's possible to remove/replace google font by $view->addHeadString('', 'font');