* @copyright Copyright (c) 2013 - 2019, TechFuze. (http://techfuze.net) */ class TracyComponent implements iComponent { /** * Whether Tracy is enabled or not * * @var bool $enableTracy */ protected $enableTracy = true; public function getName(): string { return 'TracyComponent'; } public function getClasses(): array { return []; } public function onAddComponent(Configurator $configurator){} /** * Enables Tracy when requested to do so. Disables FuzeWorks Logger. * * @param Factory $container * @throws Exception\EventException */ public function onCreateContainer(Factory $container) { // If Tracy should not be enabled, escape if ($this->enableTracy == false) { Logger::logInfo("TracyComponent added but not enabled."); return; } // Disable screenLog Events::addListener(function($event){ $event->setCancelled(true); }, 'screenLogEvent'); // Enable Tracy. Use DEVELOPMENT mode when logger is enabled if ($container->logger->isEnabled() == true) Debugger::enable(Debugger::DEVELOPMENT, realpath(Core::$logDir)); else Debugger::enable(Debugger::PRODUCTION, realpath(Core::$logDir)); // Disable FuzeWorks Logger $container->logger->disable(); // Enable bridges GitTracyBridge::register(); LoggerTracyBridge::register(); } /** * Calls a static method in the Debugger class * * @param $method * @param $arguments * @return mixed * @throws InvalidArgumentException */ public function __call($method, $arguments) { if (!method_exists('\Tracy\Debugger', $method)) throw new InvalidArgumentException("Could not invoke call on Tracy\Debugger. Method '".$method."' does not exist."); return call_user_func_array(['\Tracy\Debugger', $method], $arguments); } /** * Gets a property from the Debugger class * * @param $name * @return mixed * @throws InvalidArgumentException */ public function __get($name) { if (!property_exists('\Tracy\Debugger', $name)) throw new InvalidArgumentException("Could not get property of Tracy\Debugger. Property does not exist."); return Debugger::$$name; } /** * Sets a property in the Debugger class * * @param $name * @param $value * @throws InvalidArgumentException */ public function __set($name, $value) { if (!property_exists('\Tracy\Debugger', $name)) throw new InvalidArgumentException("Could not get property of Tracy\Debugger. Property does not exist."); Debugger::$$name = $value; } /** * Enable Tracy * * Has no effect after container is created */ public function enableTracy() { $this->enableTracy = true; } /** * Disable Tracy * * Has no effect after container is created */ public function disableTracy() { $this->enableTracy = false; } /** * Check whether Tracy will be enabled or not * * @return bool */ public function isEnabled(): bool { return $this->enableTracy; } }