Example #1
0
 public function testSavingToCache()
 {
     $dir = realpath(__DIR__) . '/fixtures';
     $cache = new \Message\Cog\Cache\Instance(new FauxCache());
     $env = new FauxEnvironment();
     $loader = new LoaderCache($dir, $env, $cache);
     $registry = new NonLoadingRegistry($loader);
     $expected = (include 'expected_groups.php');
     $env->set('live');
     $env->setInstallation('server6');
     $loader->load($registry);
     $this->assertEquals($cache->fetch($loader->getCacheKey()), $expected);
 }
Example #2
0
 /**
  * Instantiates the service container, runs the Cog bootstraps and sets the
  * context.
  *
  * @return Loader Returns $this for chainability
  */
 public function loadCog()
 {
     // Add the application loader as a service
     $appLoader = $this;
     $this->_services['app.loader'] = function () use($appLoader) {
         return $appLoader;
     };
     $this->_services['cache.adapter'] = function () use($appLoader) {
         if (extension_loaded('apc') && ini_get('apc.enabled')) {
             $adapter = new \Message\Cog\Cache\Adapter\APC();
         } else {
             // NOTE: Can't use cog:// stream here as the stream wrapper
             // has not yet been defined
             $adapter = new \Message\Cog\Cache\Adapter\Filesystem($appLoader->getBaseDir() . 'tmp');
         }
         return $adapter;
     };
     $this->_services['cache'] = function ($c) {
         $cache = new \Message\Cog\Cache\Instance($c['cache.adapter']);
         $cache->setPrefix(implode('.', array($c['app.loader']->getAppName(), $c['environment']->get(), $c['environment']->installation())));
         return $cache;
     };
     // Register the service for the bootstrap loader
     $this->_services['bootstrap.loader'] = $this->_services->factory(function ($c) {
         // Can not call $this->_services['filesystem.finder'] as it has not yet been created.
         $loader = new \Message\Cog\Bootstrap\Loader($c, new \Message\Cog\Filesystem\Finder());
         if ('local' !== $c['env']) {
             $loader->enableCaching();
         }
         return $loader;
     });
     // Register the service for the environment
     $env = new Environment();
     $this->_services['environment'] = function () use($env) {
         return $env;
     };
     $this->_services['env'] = $this->_services->factory(function ($c) {
         return $c['environment']->get();
     });
     // Load the Cog bootstraps
     $this->_services['bootstrap.loader']->addFromDirectory(__DIR__ . '/Bootstrap', 'Message\\Cog\\Application\\Bootstrap')->load();
     $this->_services['event.dispatcher']->dispatch('cog.load.success', $this->_services['event']);
     return $this;
 }