Пример #1
0
 /**
  * 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();
     }
 }
Пример #2
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);
 }