Ejemplo n.º 1
0
 /**
  * Will normalize directories mentioned within a configuration aspect.
  * If there is an error false will be returned. If not we will return the given configuration array containing only
  * normalized paths.
  *
  * @param string $configAspect The aspect to check for non-normal dirs
  * @param array  $configArray  The array to check within
  *
  * @return array|bool
  */
 protected function normalizeConfigDirs($configAspect, array $configArray)
 {
     // Are there dirs within this config aspect?
     if (isset($configArray[$configAspect . self::VALUE_NAME_DELIMITER . 'dirs'])) {
         // Get ourselves a format utility
         $formattingUtil = new Formatting();
         // Iterate over all dir entries and normalize the paths
         foreach ($configArray[$configAspect . self::VALUE_NAME_DELIMITER . 'dirs'] as $key => $projectDir) {
             // Do the normalization
             $tmp = $formattingUtil->sanitizeSeparators($formattingUtil->normalizePath($projectDir));
             if (is_readable($tmp)) {
                 $configArray[$configAspect . self::VALUE_NAME_DELIMITER . 'dirs'][$key] = $tmp;
             } elseif (preg_match('/\\[|\\]|\\*|\\+|\\.|\\(|\\)|\\?|\\^/', $tmp)) {
                 // Kill the original path entry so the iterators wont give us a bad time
                 unset($configArray[$configAspect . self::VALUE_NAME_DELIMITER . 'dirs'][$key]);
                 // We will open up the paths with glob
                 foreach (glob($tmp, GLOB_ERR) as $regexlessPath) {
                     // collect the cleaned path
                     $configArray[$configAspect . self::VALUE_NAME_DELIMITER . 'dirs'][] = $regexlessPath;
                 }
             } else {
                 // Somethings wrong with the path, that should not be
                 return false;
             }
         }
     }
     // Everything seems fine, lets return the changes config array
     return $configArray;
 }
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
 /**
  * Default constructor
  *
  * @param array                             $autoloaderPaths  Which paths do we like to include in our map?
  * @param array                             $enforcementPaths Which paths do we have to enforce
  * @param \AppserverIo\Doppelgaenger\Config $config           Configuration
  */
 public function __construct($autoloaderPaths, $enforcementPaths, Config $config)
 {
     // Init as empty map
     $this->map = array();
     // As we do accept arrays we have to be sure that we got one. If not we convert it.
     if (!is_array($enforcementPaths)) {
         $enforcementPaths = array($enforcementPaths);
     }
     if (!is_array($autoloaderPaths)) {
         $autoloaderPaths = array($autoloaderPaths);
     }
     // Save the config for later use.
     $this->config = $config;
     // Set the enforcementPaths and autoloaderPaths and calculate the path to the map file
     $this->enforcementPaths = $enforcementPaths;
     $this->autoloaderPaths = $autoloaderPaths;
     // The rootPaths member holds the other path members combined to build up the root paths we have to create
     // an index for
     $this->rootPaths = array_merge($autoloaderPaths, $enforcementPaths);
     // Build up the path of the serialized map.
     // Get ourselves a format utility
     $formattingUtil = new Formatting();
     $this->mapPath = $formattingUtil->sanitizeSeparators($this->config->getValue('cache/dir') . DIRECTORY_SEPARATOR . md5(implode('', $autoloaderPaths) . implode('', $enforcementPaths)));
 }