Ejemplo n.º 1
0
 /**
  * Will validate a potential configuration file. Returns false if file is no valid Doppelgaenger configuration.
  * Will return the validated configuration on success
  *
  * @param string $file Path of the potential configuration file
  *
  * @return array|boolean
  * @throws \AppserverIo\Doppelgaenger\Exceptions\ConfigException
  */
 protected function validate($file)
 {
     $configCandidate = json_decode(file_get_contents($file), true);
     // Did we even get an array?
     if (!is_array($configCandidate)) {
         throw new ConfigException(sprintf('Could not parse configuration file %s.', $file));
     } else {
         $configCandidate = $this->flattenArray($configCandidate);
     }
     // We need some formatting utilities
     $formattingUtil = new Formatting();
     // We will normalize the paths we got and check if they are valid
     if (isset($configCandidate['cache' . self::VALUE_NAME_DELIMITER . 'dir'])) {
         $tmp = $formattingUtil->normalizePath($configCandidate['cache' . self::VALUE_NAME_DELIMITER . 'dir']);
         if (is_writable($tmp)) {
             $configCandidate['cache' . self::VALUE_NAME_DELIMITER . 'dir'] = $tmp;
         } else {
             throw new ConfigException(sprintf('The configured cache directory %s is not writable.', $tmp));
         }
     }
     // Same for enforcement dirs
     $configCandidate = $this->normalizeConfigDirs('enforcement', $configCandidate);
     // Do we still have an array here?
     if (!is_array($configCandidate)) {
         return false;
     }
     // Do the same for the autoloader dirs
     $configCandidate = $this->normalizeConfigDirs('autoloader', $configCandidate);
     // Lets check if there is a valid processing in place
     if ($configCandidate === false || !$this->validateProcessing($configCandidate)) {
         return false;
     }
     // Return what we got
     return $configCandidate;
 }
Ejemplo n.º 2
0
 /**
  * Will test if we can sanitize different pathes
  *
  * @param string $testPath       The path to sanitize
  * @param string $separator      The separator
  * @param string $expectedResult The expected result
  *
  * @return void
  *
  * @dataProvider sanitizeSeparatorsProvider
  */
 public function testSanitizeSeparators($testPath, $separator, $expectedResult)
 {
     $formatter = new Formatting();
     $this->assertEquals($expectedResult, $formatter->sanitizeSeparators($testPath, $separator));
 }
Ejemplo n.º 3
0
 /**
  * Will reindex the structure map aka create it anew.
  * If $specificPath is supplied we will reindex the specified path only and add it to the map.
  * $specificPath MUST be within the root pathes of this StructureMap instance, otherwise it is no REindexing.
  *
  * @param string|null $specificPath A certain path which will be reindexed
  *
  * @return boolean
  */
 public function reIndex($specificPath = null)
 {
     // If we have no specific path we will delete the current map
     if ($specificPath === null) {
         // Make our map empty
         $this->map = array();
     } else {
         // We need some formatting utilities and normalize the path as it might contain regex
         $formattingUtil = new Formatting();
         $specificPath = $formattingUtil->normalizePath($specificPath);
         // If there was a specific path give, we have to check it for compatibility with $this.
         // First thing: is it contained in one of $this root pathes, if not it is no REindexing
         $isContained = false;
         foreach ($this->rootPaths as $rootPath) {
             if (strpos($specificPath, $rootPath) === 0) {
                 $isContained = true;
                 break;
             }
         }
         // Did we find it?
         if (!$isContained) {
             return false;
         }
         // Second thing: is the path readable?
         if (!is_readable($specificPath)) {
             return false;
         }
         // Everything fine, set the root path to our specific path
         $this->rootPaths = array($specificPath);
     }
     // Generate the map, all needed details have been altered above
     $this->generate();
     return true;
 }