Exemplo n.º 1
0
 public function init($filters = array(), $filterFile = '', $exclusive = array())
 {
     if (count($exclusive) > 0 && (count($filters) > 0 || $filterFile !== '')) {
         throw new \RuntimeException("It's not possible to define filter lists and an exclusive list at the same time [Extension: " . get_class($this) . '].');
     }
     if ($filterFile !== '') {
         if (!file_exists($filterFile)) {
             throw new \RuntimeException('Filter file not found: ' . $filterFile);
         }
         $filterElements = EnvAwareYaml::parse(file_get_contents($filterFile));
         foreach ($filterElements['filters'] as $rule => $uris) {
             foreach ($uris as $uri) {
                 $this->filters[] = array('rule' => $rule, 'uri' => $uri);
             }
         }
     } elseif (!is_null($filters)) {
         foreach ($filters as $rule => $filteredUrls) {
             if (!is_null($filteredUrls)) {
                 foreach ($filteredUrls as $uri) {
                     $this->filters[] = array('rule' => $rule, 'uri' => $uri);
                 }
             }
         }
     }
     if (count($exclusive) > 0) {
         $this->exclusives = $exclusive;
         $this->currentModus = self::MODUS_EXCLUSIVE;
     }
 }
Exemplo n.º 2
0
 /**
  * Returns an array representing the configuration.
  *
  * @param $configFile
  *
  * @return array
  */
 protected function getConfigArray($configFile, $mandatory = false)
 {
     $configArray = array();
     if ($configFile) {
         if (strpos($configFile, 'http://') === 0 || strpos($configFile, 'https://') === 0) {
             $fileContent = (string) $this->getHttpClient()->get($configFile)->getBody();
         } else {
             if (file_exists($configFile)) {
                 $fileContent = file_get_contents($configFile);
             } else {
                 throw new \RuntimeException("Config file was not found ('" . $configFile . "').");
             }
         }
         $configArray = EnvAwareYaml::parse($fileContent);
     } else {
         if ($mandatory) {
             throw new \RuntimeException('Config file was not defined.');
         }
     }
     return $configArray;
 }