/**
  * @param $url
  * @return null|WebResource
  */
 private function getLinkedResource($url)
 {
     try {
         if (!$this->hasLinkedResource($url)) {
             $request = $this->getConfiguration()->getHttpClient()->createRequest('GET', $url);
             $resource = $this->getConfiguration()->getWebResourceService()->get($request);
             $this->linkedResources[$this->getUrlHash($url)] = $resource;
             $this->responses[] = $resource;
         }
     } catch (WebResourceException $webResourceException) {
         $this->webResourceExceptions[$this->getUrlHash($url)] = $webResourceException;
         $this->responses[] = $webResourceException;
         return null;
     } catch (ConnectException $connectException) {
         $curlExceptionFactory = new CurlExceptionFactory();
         if ($curlExceptionFactory->isCurlException($connectException)) {
             $curlException = $curlExceptionFactory->fromConnectException($connectException);
             $this->curlExceptions[$this->getUrlHash($url)] = array('url' => $url, 'exception' => $curlException);
             $this->responses[] = $curlException;
             return null;
         }
     }
     return $this->linkedResources[$this->getUrlHash($url)];
 }
Ejemplo n.º 2
0
 /**
  * 
  * @return \webignition\CssValidatorOutput\CssValidatorOutput
  * @throws \InvalidArgumentException
  */
 public function validate()
 {
     if (!$this->hasConfiguration()) {
         throw new \InvalidArgumentException('Unable to validate; configuration not set', self::INVALID_ARGUMENT_EXCEPTION_CONFIGURATION_NOT_SET);
     }
     try {
         $this->getLocalProxyResource()->prepare();
     } catch (\webignition\WebResource\Exception\InvalidContentTypeException $invalidContentTypeException) {
         $cssValidatorOutput = new CssValidatorOutput();
         $cssValidatorOutputException = new ExceptionOutput();
         $cssValidatorOutputException->setType(new ExceptionOutputType('invalid-content-type:' . $invalidContentTypeException->getResponseContentType()->getTypeSubtypeString()));
         $cssValidatorOutput->setException($cssValidatorOutputException);
         return $cssValidatorOutput;
     } catch (\webignition\WebResource\Exception\Exception $webResourceException) {
         $cssValidatorOutput = new CssValidatorOutput();
         $cssValidatorOutputException = new ExceptionOutput();
         $cssValidatorOutputException->setType(new ExceptionOutputType('http' . $webResourceException->getResponse()->getStatusCode()));
         $cssValidatorOutput->setException($cssValidatorOutputException);
         return $cssValidatorOutput;
     } catch (ConnectException $connectException) {
         $curlExceptionFactory = new CurlExceptionFactory();
         if ($curlExceptionFactory->isCurlException($connectException)) {
             $curlException = $curlExceptionFactory->fromConnectException($connectException);
             $cssValidatorOutput = new CssValidatorOutput();
             $cssValidatorOutputException = new ExceptionOutput();
             $cssValidatorOutputException->setType(new ExceptionOutputType('curl' . $curlException->getCurlCode()));
             $cssValidatorOutput->setException($cssValidatorOutputException);
             return $cssValidatorOutput;
         }
     }
     $cssValidatorOutputParserConfiguration = new CssValidatorOutputParserConfiguration();
     $validatorOutput = $this->replaceLocalFilePathsWithOriginalFilePaths(implode("\n", $this->getRawValidatorOutputLines()));
     $cssValidatorOutputParserConfiguration->setRawOutput($validatorOutput);
     $this->localProxyResource->clear();
     if ($this->getConfiguration()->hasFlag(Flags::FLAG_IGNORE_FALSE_IMAGE_DATA_URL_MESSAGES)) {
         $cssValidatorOutputParserConfiguration->setIgnoreFalseImageDataUrlMessages(true);
     }
     if ($this->getConfiguration()->hasFlag(Flags::FLAG_IGNORE_WARNINGS)) {
         $cssValidatorOutputParserConfiguration->setIgnoreWarnings(true);
     }
     if ($this->getConfiguration()->getVendorExtensionSeverityLevel() === VendorExtensionSeverityLevel::LEVEL_IGNORE) {
         $cssValidatorOutputParserConfiguration->setIgnoreVendorExtensionIssues(true);
     }
     if ($this->getConfiguration()->getVendorExtensionSeverityLevel() === VendorExtensionSeverityLevel::LEVEL_WARN) {
         $cssValidatorOutputParserConfiguration->setReportVendorExtensionIssuesAsWarnings(true);
     }
     if ($this->getConfiguration()->hasDomainsToIgnore()) {
         $cssValidatorOutputParserConfiguration->setRefDomainsToIgnore($this->getConfiguration()->getDomainsToIgnore());
     }
     $cssValidatorOutputParser = new CssValidatorOutputParser();
     $cssValidatorOutputParser->setConfiguration($cssValidatorOutputParserConfiguration);
     $output = $cssValidatorOutputParser->getOutput();
     if ($this->getLocalProxyResource()->hasWebResourceExceptions()) {
         foreach ($this->getLocalProxyResource()->getWebResourceExceptions() as $webResourceException) {
             $error = new \webignition\CssValidatorOutput\Message\Error();
             $error->setContext('');
             $error->setLineNumber(0);
             if ($webResourceException instanceof \webignition\WebResource\Exception\InvalidContentTypeException) {
                 $error->setMessage('invalid-content-type:' . (string) $webResourceException->getResponseContentType());
             } else {
                 $error->setMessage('http-error:' . $webResourceException->getResponse()->getStatusCode());
             }
             $error->setRef($webResourceException->getRequest()->getUrl());
             $output->addMessage($error);
         }
     }
     if ($this->getLocalProxyResource()->hasCurlExceptions()) {
         foreach ($this->getLocalProxyResource()->getCurlExceptions() as $curlExceptionDetails) {
             $error = new \webignition\CssValidatorOutput\Message\Error();
             $error->setContext('');
             $error->setLineNumber(0);
             $error->setMessage('curl-error:' . $curlExceptionDetails['exception']->getCurlCode());
             $error->setRef($curlExceptionDetails['url']);
             $output->addMessage($error);
         }
     }
     return $cssValidatorOutputParser->getOutput();
 }