/** * @param array $options * @return Profiler * * @throws \RuntimeException * @throws AccessException * @throws UndefinedOptionsException * @throws MissingOptionsException * @throws InvalidOptionsException * @throws NoSuchOptionException * @throws OptionDefinitionException */ public function create(array $options = []) { $options = $this->resolveOptions($options); if (!$options[self::OPTION_ENABLE]) { return new NullProfiler(); } if ($options[self::OPTION_ENVIRONMENT] !== null) { Profiler::$environment = $options[self::OPTION_ENVIRONMENT]; } $profiler = new Profiler(); switch ($options[self::OPTION_DATASOURCE_CLASS]) { default: case File::class: $datasource = new File($options[self::OPTION_DATASOURCE_PROFILES_FOLDER]); break; case Memory::class: $datasource = new Memory(); } $profiler->setDataSource($datasource); $profiler->registerCollectorClasses($options[self::OPTION_COLLECTORS]); $dispatcher = $profiler->getContext()->getProcess()->getDispatcher(); $className = $options['logger']; $logger = new $className(); $logger->setDispatcher($dispatcher); $profiler->setLogger($logger); $profiler->setTimeline(new TimelineComponent($dispatcher)); return $profiler; }
protected function setUp() { parent::setUp(); Profiler::$environment = 'cli'; $this->profiler = new Profiler(); $this->profiler->setDataSource(new Memory()); }
public function testContext() { Profiler::$environment = 'http'; $this->profiler = ProfilerFactory::build([]); $this->assertInstanceOf(ContextInterface::class, $this->profiler->getContext()); $this->assertInstanceOf(Http::class, $this->profiler->getContext()); $this->profiler->getContext()->sendDebugIds(); }