For Developers
Add a Fact
This example will show you how to add a custom fact that looks up some environment variables.
-
Add your own FactProvider
Your fact provider has to extend the abstract class
Leuchtfeuer\
. The value of theLocate\ Fact Provider\ Abstract Fact Provider PROVIDER_
constant has to match the TypoScript key you will use for your fact.NAME class Environment extends AbstractFactProvider { const PROVIDER_NAME = 'environment'; public function getBasename(): string { return self::PROVIDER_NAME; } public function process(): self { foreach (GeneralUtility::getIndpEnv('_ARRAY') as $key => $value) { $this->facts[$this->getFactPropertyName($key)] = $value; } return $this; } public function isGuilty($prosecution): bool { $subject = array_keys($prosecution); $subject = array_shift($subject); $value = $prosecution[$subject]; LocateUtility::mainstreamValue($subject); return ($this->getSubject()[$subject] ?? false) == $value; } }
Copied! -
Register fact via TypoScript:
Next, you need to register this PHP class as a fact in TypoScript.
config.tx_locate.facts { environment = Leuchtfeuer\Locate\FactProvider\Environment }
Copied! -
Setup a Judge
Now you are all set and use your fact in a judge. Here is an example that will redirect the user to the english page if the HTTP host matches
www.
:Leuchtfeuer. com config.tx_locate.judges { 10 = Leuchtfeuer\Locate\Judge\Condition 100 { verdict = redirectToPageEN fact = environment prosecution { HTTP_HOST = www.Leuchtfeuer.com } } }
Copied!
Add a Verdict
This example will show you how to add a custom verdict that adds some data to the user session.
-
Add your own verdict class
Your verdict has to extend the abstract class
Leuchtfeuer\
.Locate\ Verdict\ Abstract Verdict class StoreSessionData extends AbstractVerdict { public function execute(): ?ResponseInterface { $sessionStore = new \Leuchtfeuer\Locate\Store\SessionStore('dummy'); $sessionStore->set('foo', $this->configuration['foo']); return null; } }
Copied! -
Register the verdict in TypoScript
Now you can register this verdict in your TypoScript setup and add a configuration key
foo
that contains the data that should be stored in the session.config.tx_locate.verdicts { storeSessionData = Vendor\Extension\Verdict\StoreSessionData storeSessionData { foo = bar } }
Copied!