PHP code example of switon / context
1. Go to this page and download the library: Download switon/context library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
switon / context example snippets
use Switon\Core\Attribute\Autowired;
use Switon\Core\ContextAware;
use Switon\Core\ContextManagerInterface;
final class RequestStateContext
{
public array $vars = [];
}
final class RequestState implements ContextAware
{
#[Autowired] protected ContextManagerInterface $contextManager;
public function getContext(): RequestStateContext
{
return $this->contextManager->getContext($this);
}
public function remember(string $key, mixed $value): void
{
$this->getContext()->vars[$key] = $value;
}
}