/** * Get the container * * @return \Opis\Colibri\Container */ public function container() { if ($this->container === null) { $app = $this->app; $container = new Container(); foreach ($app->config()->read('collectors') as $type => $collector) { $container->alias($collector['interface'], $type); $container->singleton($collector['interface'], $collector['class']); } $this->container = $container; } return $this->container; }
/** * Include modules */ protected function includeCollectors() { if ($this->collectorsIncluded) { return; } $this->collectorsIncluded = true; $reader = new AnnotationReader(); foreach (app()->getModules() as $module) { if (!$module->isEnabled() || $module->collector() === false) { continue; } $instance = $this->container->make($module->collector()); $reflection = new ReflectionClass($instance); if (!$reflection->isSubclassOf(ModuleCollector::class)) { continue; } foreach ($reflection->getMethods(ReflectionMethod::IS_PUBLIC) as $method) { $name = $method->getShortName(); if (substr($name, 0, 2) === '__') { continue; } $annotation = $reader->getMethodAnnotation($method, CollectorAnnotation::class); if ($annotation == null) { $annotation = new CollectorAnnotation(); } if ($annotation->name === null) { $annotation->name = $name; } $callback = function ($collector) use($instance, $name) { $instance->{$name}($collector); }; $this->collectorTarget->handle(strtolower($annotation->name), $callback, $annotation->priority); } } }