protected function loadTemplate($rawdata) { if (is_object($this->template)) { return; } if (preg_match('/^\\s*--- \\#YAML/im', $rawdata)) { // YAML based output - eg. .cc $this->template = AbstractTemplate::factory('gandiyaml'); } else { $this->template = AbstractTemplate::factory('standard'); } }
/** * Parses rawdata from whois server and call postProcess if exists afterwards * * @throws NoTemplateException * @throws RateLimitException * @return void */ private function parse() { $Config = $this->Config->getCurrent(); $Template = AbstractTemplate::factory($Config['template'], $this->customTemplateNamespace); // If Template is null then we do not have a template for that, but we // can still proceed to the end with just the rawdata if ($Template instanceof AbstractTemplate) { $this->Result->template[$Config['server']] = $Config['template']; $this->rawdata = $Template->translateRawData($this->rawdata, $Config); try { $Template->parse($this->Result, $this->rawdata, $this->Query); } catch (RateLimitException $e) { $server = $Config['server']; if (!in_array($server, $this->rateLimitedServers)) { $this->rateLimitedServers[] = $server; } throw new RateLimitException("Rate limit exceeded for server: " . $server); } // set rawdata to Result - this happens here because sometimes we // have to fix the rawdata as well in postProcess $this->Result->addItem('rawdata', $this->rawdata); // set registered to Result $this->Result->addItem('registered', isset($this->Result->registered) ? $this->Result->registered : false); if (!isset($this->Result->whoisserver)) { $this->Result->addItem('whoisserver', $Config['server']); } // start post processing $Template->postProcess($this); // set name to Result if (isset($this->Query->tld) && !isset($this->Query->fqdn)) { $this->Result->addItem('name', $this->Query->tld); } elseif (isset($this->Query->ip)) { $this->Result->addItem('name', $this->Query->ip); } elseif (isset($this->Query->asn)) { $this->Result->addItem('name', $this->Query->asn); } else { $this->Result->addItem('name', $this->Query->fqdn); $this->Result->addItem('idnName', $this->Query->idnFqdn); } } else { throw new NoTemplateException('Template ' . $Config['template'] . ' could not be found'); } }