This repository was archived by the owner on Apr 18, 2024. It is now read-only.
Code-level changes #68
ostark
started this conversation in
Show and tell
Replies: 4 comments
What to start with?
|
0 replies
|
The current CachePurgeInterface is probably okay, but I would avoid the abstract class and use a decorator instead, which is a bit more flexible. What about something like this?: <?php
class Purger implements CachePurgeInterface
{
private CachePurgeInterface $actual;
public configure(PurgerConfig $config) {
$this->actual = resolve($config->className);
$this->actual->configure($config);
}
public function purgeUrls(array $urls): bool {
// SOMETHING BEFORE
$result = $this->actual->purgeUrls($urls);
// SOMETHING AFTER
return $result;
}
public function purgeAll(array $urls): bool {
// SOMETHING BEFORE
$result = $this->actual->purgeAll();
// SOMETHING AFTER
return $result;
}
} |
0 replies
|
There is no need for CacheControlBehavior to be a Behavior. Instead, it could be a simple class that interacts with <?php
class CacheControl
{
public function __construct(private HeaderCollection $headers) {}
} |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Design goals & principles
The Hollywood_principle / IoC
Relying on the Service Locator leads to spaghetto, because it makes it very easy to access everything from everywhere.
Only the main plugin class should be the glue between Craft and the code we own. As well our code should be designed with low coupling and clear separation of concerns in mind.
Tests
Writing tests should be fun! If it feels hard, most likely the principle above wasn't applied. Don't be afraid to change the actual code to make tests easier.
Each unit should be covered by tests, but don't be fanatic about 100% coverage.
Start with the happy path, but don't forget to cover edge cases.
All reactions