Monitor calls made to get configuration during a request

{@inheritDoc}
339118
public function get($class, $name = null, $excludeMiddleware = 0)
    {
        $result = parent::get($class, $name, $excludeMiddleware);

        // Only track not empty values by default
        if ($result || $this->trackEmpty) {
            if (!isset(self::$configCalls[$class][$name])) {
                self::$configCalls[$class][$name] = [
                    'calls' => 0,
                    'result' => null
                ];
            }
            self::$configCalls[$class][$name]['calls']++;
            self::$configCalls[$class][$name]['result'] = $result;
        }

        return $result;
    }
955001
private function callConfiguration() {
		$container = Container::getInstance();
		$className = $this->getConfig('namespace', self::CONF_PROJECT) . 'Configuration';
		if ($container->has($className)) {
			$clazz = $container->get($className);
			$methods = (new ReflectionClass($clazz))->getMethods();
			foreach ($methods as $method) {
				if (strpos($method->name, 'set') !== 0) {
					continue;
				}
				$params = $method->getParameters();
				$init_params = [];
				foreach ($params as $param) {
					$type = $param->getType();
					if (class_exists('ReflectionNamedType') && $type instanceof \ReflectionNamedType) {
						$typeName = $type->getName();
					} else {
						$typeName = $type->__toString();
					}
					if ($type->isBuiltin()) {
						$value = null;
						settype($value, $typeName);
						$init_params[] = $value;
					} else {
						$init_params[] = $container->get($typeName);
					}
				}
				$method->invokeArgs($clazz, $init_params);
			}
		}
	}
517179
public function eventTypeConfig()
    {
        $this->request->allowMethod(['post', 'put', 'patch']);

        $response = [
            'success' => false,
            'data' => [],
            'errors' => [],
        ];

        $data = $this->request->getData();

        try {
            $config = ObjectFactory::getConfig(null, 'Event', $data['event_type']);

            if (!empty($config)) {
                $response['success'] = true;
                $response['data'] = $config;
            }
        } catch (Exception $e) {
            $response['errors'][] = $e->getMessage();
            throw $e;
        }

        $this->set(compact('response'));
        $this->set('_serialize', 'response');
    }
220463
public function getInitial(): JsonResponse
    {
        $service = $this->getConfigService();

        if ($service->isAuthorized()) {
            return $this->response->success('OK', $service->getUserConfig());
        }

        return $this->response->success('OK', $service->getGuestConfig());
    }
1099958
protected function handleGET()
    {
        $scriptable = $this->request->getParameterAsBool('scriptable');

        \Log::info('Building event map');

        $eventMap = [];
        if (!empty($serviceName = $this->request->getParameter('service'))) {
            if (Session::allowsServiceAccess($serviceName)) {
                try {
                    if (!empty($service = ServiceManager::getService($serviceName))) {
                        if (!empty($map = $service->getEventMap())) {
                            $eventMap[$serviceName] = $map;
                        }
                    }
                } catch (\Exception $ex) {
                    Log::info("Failed to build event map for service $serviceName. {$ex->getMessage()}");
                }
            }
        } else {
            foreach (ServiceManager::getServiceNames() as $serviceName) {
                if (Session::allowsServiceAccess($serviceName)) {
                    try {
                        if (!empty($service = ServiceManager::getService($serviceName))) {
                            if (!empty($map = $service->getEventMap())) {
                                $eventMap[$serviceName] = $map;
                            }
                        }
                    } catch (\Exception $ex) {
                        Log::info("Failed to build event map for service $serviceName. {$ex->getMessage()}");
                    }
                }
            }
        }

        \Log::info('Event map build process complete');

        $allEvents = [];
        foreach ($eventMap as $serviceKey => $paths) {
            foreach ($paths as $path => $operations) {
                if (empty($type = array_get($operations, 'type'))) {
                    $type = 'service';
                    $eventMap[$serviceKey][$path]['type'] = $type;
                }
                if (!empty($endpoints = (array)array_get($operations, 'endpoints', $path))) {
                    if ($scriptable) {
                        $temp = [];
                        foreach ($endpoints as $endpoint) {
                            $temp[] = $endpoint;
                            switch ($type) {
                                case 'api':
                                    // add pre_process, post_process
                                    $temp[] = "$endpoint.pre_process";
                                    $temp[] = "$endpoint.post_process";
                                    break;
                                case 'service':
                                    break;
                            }
                            // add queued
                            $temp[] = "$endpoint.queued";
                        }
                        $endpoints = $temp;
                        $eventMap[$serviceKey][$path]['endpoints'] = $temp;
                    }
                    $allEvents = array_merge($allEvents, $endpoints);
                }
            }
        }

        if (!$this->request->getParameterAsBool(ApiOptions::AS_LIST)) {
            return $eventMap;
        }

        return ResourcesWrapper::cleanResources(array_values(array_unique($allEvents)));
    }
1038769
def ensure_configured(func):
    """"""
    @functools.wraps(func)
    def wrapper(*args, **kwargs):
        if len(logging.root.handlers) == 0:
            basicConfig()
        return func(*args, **kwargs)
    return wrapper
493104
def _read_config(self):
        """"""

        try:
            self.config = self.componentmodel.find_one(
                {'name': self.uniquename})
        except ServerSelectionTimeoutError:  # pragma: no cover
            self.log("No database access! Check if mongodb is running "
                     "correctly.", lvl=critical)
        if self.config:
            self.log("Configuration read.", lvl=verbose)
        else:
            self.log("No configuration found.", lvl=warn)
800720
public function beforeCompile(): void
	{
		// Breaks at other mode then CLI
		if (PHP_SAPI !== 'cli') return;

		$builder = $this->getContainerBuilder();

		// Verify that we have http.request
		if (!$builder->hasDefinition('http.request')) {
			throw new RuntimeException('Service http.request is needed');
		}

		$config = $this->validateConfig($this->defaults);
		$builder->getDefinition('http.request')
			->setFactory(Request::class, [
				new Statement(UrlScript::class, [$config['url']]),
				$config['query'],
				$config['post'],
				$config['files'],
				$config['cookies'],
				$config['headers'],
				$config['method'],
				$config['remoteAddress'],
				$config['remoteHost'],
				$config['rawBodyCallback'],
			]);
	}
78876
public function index($request)
    {
        $suite = 'check';

        if ($name = $request->param('Suite')) {
            $suite = $name;
        }

        $checker = new EnvironmentChecker($suite, 'Environment status');
        $checker->setRequest($request);
        $checker->init($this->config()->permission);

        return $checker;
    }
745793
protected function configChanged() {
    if (self::$logger->isDebugEnabled()) {
      self::$logger->debug("Configuration is changed");
    }
    if (ObjectFactory::isConfigured()) {
      if (self::$logger->isDebugEnabled()) {
        self::$logger->debug("Emitting change event");
      }
      ObjectFactory::getInstance('eventManager')->dispatch(ConfigChangeEvent::NAME,
              new ConfigChangeEvent());
    }
  }
554576
public function ensureProductionSettings() : void
    {
        $queryCacheImpl = $this->getQueryCacheImpl();

        if (! $queryCacheImpl) {
            throw QueryCacheNotConfigured::create();
        }

        if ($queryCacheImpl instanceof ArrayCache) {
            throw QueryCacheUsesNonPersistentCache::fromDriver($queryCacheImpl);
        }

        $metadataCacheImpl = $this->getMetadataCacheImpl();

        if (! $metadataCacheImpl) {
            throw MetadataCacheNotConfigured::create();
        }

        if ($metadataCacheImpl instanceof ArrayCache) {
            throw MetadataCacheUsesNonPersistentCache::fromDriver($metadataCacheImpl);
        }

        if ($this->getProxyManagerConfiguration()->getGeneratorStrategy() instanceof EvaluatingGeneratorStrategy) {
            throw ProxyClassesAlwaysRegenerating::create();
        }
    }
581085
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
    {
        // Read the configuration settings.
        if (file_exists(Webtrees::CONFIG_FILE)) {
            $config = parse_ini_file(Webtrees::CONFIG_FILE);

            // Store the configuration settings as request attributes.
            foreach ($config as $key => $value) {
                $request = $request->withAttribute($key, $value);
            }

            return $handler->handle($request);
        }

        // No configuration file? Run the setup wizard to create one.
        return $this->setup_controller->setup($request);
    }
818050
public function detectConfig(): ConfigurationInterface
    {
        if (file_exists($file = $this->rootDir.'/config/sculpin_site_'.$this->environment.'.yml')) {
            return $this->getConfigFile($file);
        }

        if (file_exists($file = $this->rootDir.'/config/sculpin_site.yml')) {
            return $this->getConfigFile($file);
        }

        return new Configuration();
    }
789187
function configureFetch(init) {
  // If the user only provided a query string
  if (typeof init === 'string') {
    var request = {
      method: init.method || 'POST',
      headers: init.headers || {
        'Content-Type': 'application/json',
        Accept: 'application/json'
      },
      body: JSON.stringify({
        query: init
      })
    };

    // If the user provided an actual configuration object
  } else {
    var request = {
      method: init.method || 'POST',
      headers: init.headers || {
        'Content-Type': 'application/json',
        Accept: 'application/json'
      },
      body:
        init.body ||
        JSON.stringify({
          query: init.fields,
          variables: init.variables
        }),
      mode: init.mode,
      credentials: init.credentials,
      cache: init.cache,
      redirect: init.redirect,
      referrer: init.referrer,
      referrerPolicy: init.referrerPolicy,
      integrity: init.integrity,
      keepalive: init.keepalive,
      signal: init.signal
    };
  }

  return request;
}
802514
protected function configureCorsIfEnabled(): void
    {
        $reflection = new \ReflectionClass($this);
        $reader = new AnnotationReader();

        $annotation = $reader->getClassAnnotation($reflection, CORS::class);

        if (empty($annotation)) {
            return;
        }

        $corsConfig = [
            'Access-Control-Allow-Origin' => $annotation->origins ?? '*',
            'Access-Control-Allow-Methods' => $annotation->methods ?? 'GET, POST, PUT, DELETE, OPTIONS',
            'Access-Control-Allow-Headers' => $annotation->headers ?? '*',
            'Access-Control-Allow-Credentials' => $annotation->credentials ?? true,
            'Access-Control-Allow-Max-Age' => $annotation->maxAge ?? 3600
        ];

        foreach ($corsConfig as $key => $value) {
            $this->getResponse()->headers->set($key, $value);
        }
    }
101110
private function getRequest() {

        $token = $this->getParam('token');

        if (empty($token)) {
            throw new ConfigurationException(__CLASS__ . ' is not configured properly. Please set "token" parameter properly.');
        }

        $request = new Request();
        $request->setUri($this->url);
        $request->setMethod(Request::METHOD_POST);

        $request->getHeaders()->addHeaders(array(
          'accept' => 'application/json',
          'content-type' => 'application/json',
          'authorization' => 'Basic ' . $token
        ));

        return $request;
    }
1146427
function processShorthandPropertyConfiguration () {

  // Fetch extensions implementing .processShorthandPropertyConfiguration(...) method
  let extensions = _.filter(this.extensions, (extension) => {
    return extension.implemented.processShorthandPropertyConfiguration;
  });

  // Create a proxy .processShorthandPropertyConfiguration(...) method
  this.processShorthandPropertyConfiguration =  (propertyConfiguration) => {
    // Execute all extensions' .processShorthandPropertyConfiguration(...) method and update configuration
    _.forEach(extensions, (extension) => {
      propertyConfiguration = extension.processShorthandPropertyConfiguration(propertyConfiguration);
    });
    // Return updated configuration
    return propertyConfiguration;
  };

}