/** * Executes the legacy hook if the Contao framework is booted. * * @param string $message * @param ContaoContext $context */ private function executeHook($message, ContaoContext $context) { if (null === $this->container || !$this->container->has('contao.framework')) { return; } $framework = $this->container->get('contao.framework'); if (!$framework->isInitialized() || !isset($GLOBALS['TL_HOOKS']['addLogEntry']) || !is_array($GLOBALS['TL_HOOKS']['addLogEntry'])) { return; } trigger_error('Using the addLogEntry hook has been deprecated and will no longer work in Contao 5.0.', E_USER_DEPRECATED); /** @var System $system */ $system = $framework->getAdapter(System::class); // Must create variables to allow modification-by-reference in hook $func = $context->getFunc(); $action = $context->getAction(); foreach ($GLOBALS['TL_HOOKS']['addLogEntry'] as $callback) { $system->importStatic($callback[0])->{$callback[1]}($message, $func, $action); } }
/** * Tests the setter and getter methods. */ public function testSettersAndGetters() { $context = new ContaoContext('foo'); $this->assertEquals('foo', $context->getFunc()); $this->assertNull($context->getAction()); $this->assertNull($context->getUsername()); $this->assertNull($context->getIp()); $this->assertNull($context->getBrowser()); $this->assertNull($context->getSource()); $context->setAction('action'); $context->setUsername('username'); $context->setIp('1.2.3.4'); $context->setBrowser('Mozilla'); $context->setSource('Foo::bar()'); $this->assertEquals(json_encode(['func' => 'foo', 'action' => 'action', 'username' => 'username', 'ip' => '1.2.3.4', 'browser' => 'Mozilla']), (string) $context); }
/** * Sets the source. * * @param ContaoContext $context */ private function updateSource(ContaoContext $context) { if (null !== $context->getSource()) { return; } $context->setSource($this->isBackendScope() ? 'BE' : 'FE'); }