__tostring() === $accepted_tag->__tostring()) { $found = True; break; } } return $found; } /** * Instanciate client from name, with tag as an argument * * @param string $client_name Name of the client * @param \core\log\Tag $tag Tag associated to the client * * @throws \core\log\StreamException * * @return \core\log\Client */ public static function create_client(string $client_name, \core\log\Tag $tag) : \core\log\Stream { $client = null; $client_name = \ucwords($client_name); $client_name = \str_replace(' ', '', $client_name); $vanilla = '\\core\\log\\clients\\' . $client_name; if (\in_array($client_name, self::AVAILABLE_CLIENTS)) { return new $vanilla($tag); } $plugin = \core\plugin\PluginManager::fetch_class($client_name); if (!\is_null($plugin) && \class_exists($plugin)) { return new $plugin($tag); } throw new \core\log\StreamException(\core\substitute( _('unknown client {client} in configuration', 1), array('client' => $client_name), ), 1); } /** * Build the wanted tag to use for future logging purpose * * @throws \core\config\ConfigException * @throws \core\log\StreamException * * @return \core\log\Stream | null If the tag should not be built, return null */ public static function build(\core\log\Tag $tag) : \core\log\Stream | null { $hardcoded_configuration = new \core\config\class\core\LogConfiguration(array( 'tags' => new \core\log\TagsType(array()), 'client' => array('name' => 'File'), )); $client_name = $hardcoded_configuration->get('client', 'name'); $tags = $hardcoded_configuration->get('tags'); if (\core\config\GlobalConfiguration::exists('class', 'core', 'log')) # set over hard-coded fallback { $configuration = \core\config\GlobalConfiguration::read('class', 'core', 'log'); if ($configuration->exists('client', 'name')) { $client_name = $configuration->get('client', 'name'); } if ($configuration->exists('tags')) { $tags = $configuration->get('tags'); } } if (!self::search_tag($tag, $tags)) { return null; # NOTE: the tag should not be created because the admin does not ask to log it } return self::create_client($client_name, $tag); } } ?>