Esempio n. 1
0
 public function testBadLoadSerializeFails()
 {
     $file = PHPUNIT_ROOT . '/resources/data.php';
     $data = "\n\n" . 'string';
     file_put_contents($file, $data);
     $data = Library::loadSerialize($file);
     $this->assertFalse($data);
     unlink($file);
 }
Esempio n. 2
0
 /**
  * Attempt to load cached configuration files.
  *
  * @return boolean
  */
 protected function loadCache()
 {
     $dir = $this->app['resources']->getPath('config');
     /* Get the timestamps for the config files. config_local defaults to '0', because if it isn't present,
           it shouldn't trigger an update for the cache, while the others should.
        */
     $timestamps = [file_exists($dir . '/config.yml') ? filemtime($dir . '/config.yml') : 10000000000, file_exists($dir . '/taxonomy.yml') ? filemtime($dir . '/taxonomy.yml') : 10000000000, file_exists($dir . '/contenttypes.yml') ? filemtime($dir . '/contenttypes.yml') : 10000000000, file_exists($dir . '/menu.yml') ? filemtime($dir . '/menu.yml') : 10000000000, file_exists($dir . '/routing.yml') ? filemtime($dir . '/routing.yml') : 10000000000, file_exists($dir . '/permissions.yml') ? filemtime($dir . '/permissions.yml') : 10000000000, file_exists($dir . '/config_local.yml') ? filemtime($dir . '/config_local.yml') : 0];
     if (file_exists($this->app['resources']->getPath('cache/config_cache.php'))) {
         $this->cachetimestamp = filemtime($this->app['resources']->getPath('cache/config_cache.php'));
     } else {
         $this->cachetimestamp = 0;
     }
     if ($this->cachetimestamp > max($timestamps)) {
         $this->data = Lib::loadSerialize($this->app['resources']->getPath('cache/config_cache.php'));
         // Check if we loaded actual data.
         if (count($this->data) < 4 || empty($this->data['general'])) {
             return false;
         }
         // Check to make sure the version is still the same. If not, effectively invalidate the
         // cached config to force a reload.
         if (!isset($this->data['version']) || $this->data['version'] != $this->app['bolt_long_version']) {
             // The logger and the flashbags aren't available yet, so we set a flag to notify the user later.
             $this->notify_update = true;
             return false;
         }
         // Trigger the config loaded event on the resource manager
         $this->app['resources']->initializeConfig($this->data);
         // Yup, all seems to be right.
         return true;
     }
     return false;
 }