This gist is a collection of classes and configurations that enable to have an entity as a "persistent" context in multiple controllers.
- ClientRoutePartHandler.php + Routes.yaml: these to handle the conversion of the route
- ClientContextAware.php: identifies a controller to be ClientContextAware
- ClientArgumentAspect.php: checks if the current controller ist ClientContextAware and adds the argument
client
to any url that is build without manual intervention - ClientContext.php: fetches the current client as a context, you can inject this class into anything where you might need the client to work with inside a ClientContextAware Controllercall.
- Package.php: Injects the current Request into the ClientContext
Example
Given you have a Client with a name acme
and a controller called ClientController that contains functions that all need a client to work. With these classes you can have urls like this:
http://foo.com/acme/client/index
That will automatically parse that /acme/
part into the matching client and you can inject the ClientContext into your ClientController, Services, ViewHelpers, etc to work with the current client, similar to the SecurityContext.
<?php
namespace My\Package\Controller;
use My\Package\Routing\ClientContext;
use Flowpack\Expose\Domain\Schema;
use TYPO3\Flow\Annotations as Flow;
use TYPO3\Flow\Mvc\Controller\ActionController;
use My\Package\Annotations as Foo;
/**
*
* @Foo\ClientContextAware
*/
class ClientController extends ActionController {
/**
* @Flow\Inject
* @var ClientContext
*/
protected $clientContext;
/**
*/
public function indexAction() {
$this->clientContext->getClient();
...
}
}