/**
  * Reads the environment file either by parsing it directly or from a cached file
  */
 public function read()
 {
     if ($this->cache->isEnabled()) {
         if ($this->cache->hasCache()) {
             $this->cache->loadCache();
         } else {
             $superGlobalEnvBackup = $_ENV;
             $this->parseEnvironmentVariables();
             $writtenEnvVars = array_diff_assoc($_ENV, $superGlobalEnvBackup);
             $this->cache->storeCache($this->getCachedCode($writtenEnvVars));
         }
     } else {
         $this->parseEnvironmentVariables();
     }
 }
Beispiel #2
0
 /**
  * Constructs the include file content
  *
  * @param string $includeFile The path to the file that will be included by composer in autoload.php
  * @return array
  * @throws \RuntimeException
  * @throws \InvalidArgumentException
  */
 protected function getIncludeFileContent($includeFile)
 {
     $filesystem = new Filesystem();
     $includeFileTemplate = dirname(__DIR__) . self::INCLUDE_FILE_TEMPLATE;
     $envDir = $this->config->get('env-dir');
     $pathToEnvFileCode = $filesystem->findShortestPathCode(dirname($includeFile), $envDir, true);
     $cacheDir = $this->config->get('cache-dir');
     $allowOverridesCode = $this->config->get('allow-overrides') ? 'true' : 'false';
     if ($cacheDir === null) {
         $pathToCacheDirCode = 'null';
     } else {
         $cache = new Cache($cacheDir, $envDir);
         $cache->cleanCache();
         $pathToCacheDirCode = $filesystem->findShortestPathCode(dirname($includeFile), $cacheDir, true);
     }
     $includeFileContent = file_get_contents($includeFileTemplate);
     $includeFileContent = $this->replaceToken('env-dir', $pathToEnvFileCode, $includeFileContent);
     $includeFileContent = $this->replaceToken('allow-overrides', $allowOverridesCode, $includeFileContent);
     $includeFileContent = $this->replaceToken('cache-dir', $pathToCacheDirCode, $includeFileContent);
     return $includeFileContent;
 }
Beispiel #3
0
 /**
  * @test
  */
 public function touchChangesCacheFile()
 {
     $cacheDir = __DIR__ . '/Fixtures/cache';
     $envFilePath = __DIR__ . '/Fixtures/env';
     $cache = new Cache($cacheDir, $envFilePath);
     $cache->storeCache('<?php' . PHP_EOL . '$GLOBALS[\'BLA\'] = \'blupp\';');
     $origContent = file_get_contents($envFilePath . '/.env');
     file_put_contents($envFilePath . '/.env', $origContent . PHP_EOL);
     clearstatcache();
     $cache = new Cache($cacheDir, $envFilePath);
     $this->assertFalse($cache->hasCache());
     file_put_contents($envFilePath . '/.env', $origContent);
 }