Esempio n. 1
0
 private function getCurrentLocale()
 {
     if ($this->container->isDefined(RouteAttribute::LOCALE)) {
         return $this->container->get(RouteAttribute::LOCALE);
     } else {
         return $this->config->get('translation.defaultLocale', null);
     }
 }
Esempio n. 2
0
 private function assertLocaleConfig()
 {
     $this->defaultLocale = $this->config->get('translation.defaultLocale', null);
     $this->availableLocales = $this->config->get('translation.availableLocales', []);
     if (empty($this->availableLocales)) {
         throw new InvalidConfigException("Invalid or missing translation.availableLocales configuration!");
     }
     if (empty($this->defaultLocale)) {
         throw new InvalidConfigException("Invalid or missing translation.defaultLocale configuration!");
     }
 }
Esempio n. 3
0
 /**
  * Factory method for creating a configution for a PHP file and
  * optionally an .env.json file
  * @param type $filename
  * @return \Blend\Component\Configuration\Configuration
  * @throws FileNotFoundException
  */
 public static function createFromFile($filename)
 {
     if (file_exists($filename)) {
         $params = json_decode(file_get_contents($filename), true);
         $config = new Configuration($params);
         $envfile = dirname($filename) . '/.env.json';
         if (file_exists($envfile)) {
             $envparams = json_decode(file_get_contents($envfile), true);
             $config->mergeWith($envparams);
         }
         return $config;
     } else {
         throw new FileNotFoundException($filename, 500);
     }
 }
 /**
  * Creates a Logger component
  */
 private function createLogger()
 {
     $logFolder = $this->filesystem->assertFolderWritable($this->rootFolder . '/var/log');
     $logLevel = $this->debug === true ? LogLevel::DEBUG : $this->config->get('logger.level', LogLevel::WARNING);
     $args = [$logFolder, $this->config->get('logger.name', 'application'), $this->config->get('logger.filelogger.maxfiles', 10), $logLevel];
     $this->logger = (new \ReflectionClass($this->loggerFactory))->newInstanceArgs($args)->create();
     $this->logger->debug('Logger started');
 }
 public function create()
 {
     $configFile = $this->rootFolder . '/config/config.json';
     $cacheFile = $this->rootFolder . '/var/cache/config.cache';
     if ($this->filesystem->exists($cacheFile) && !$this->debug) {
         $config = new Configuration();
         $config->load($cacheFile);
     } else {
         $config = Configuration::createFromFile($configFile);
         $config->dump($cacheFile);
     }
     if (!$config->has('debug')) {
         $config->mergeWith(['debug' => $this->debug]);
     }
     return $config;
 }
Esempio n. 6
0
 protected function initialize(Configuration $config)
 {
     date_default_timezone_set($config->get('timezone', 'UTC'));
     $this->container = new ServiceContainer();
     $this->dispatcher = new EventDispatcher();
     $this->filesystem = new Filesystem();
     $this->container->setScalars([LoggerInterface::class => $this->logger, Configuration::class => $config, LocalCache::class => $this->localCache, EventDispatcherInterface::class => $this->dispatcher, Container::class => $this->container, Filesystem::class => $this->filesystem, RuntimeAttribute::APPLICATION_ROOT_FOLDER => $this->rootFolder, RuntimeAttribute::APPLICATION_CACHE_FOLDER => $this->localCache->getCacheFolder(), RuntimeAttribute::DEBUG => $config->get('debug', false)]);
     /**
      * Adds the SecurityHandler class by default. This will
      * add a small overdead to the request/response cycle
      * but we gain functionality by having a _authenticated_user
      * when possible
      */
     $this->container->defineSingleton(SecurityHandler::class);
     if (!$this->container->loadServicesFromFile($this->rootFolder . '/config/services.json')) {
         $this->logger->notice("No service description file found!");
     }
     $this->installEventSubscribers();
 }
Esempio n. 7
0
 public function create()
 {
     $appname = strtolower($this->config->get('name'));
     return new Database(['host' => $this->config->get('database.host', '127.0.0.1'), 'port' => $this->config->get('database.port', 5432), 'database' => $this->config->get('database.database', $appname), 'username' => $this->config->get('database.username', $appname), 'password' => $this->config->get('database.password')], $this->logger);
 }
Esempio n. 8
0
 /**
  * @expectedException \Symfony\Component\Filesystem\Exception\FileNotFoundException
  */
 public function testTestFileMissing()
 {
     $conf = Configuration::createFromFile($this->fixturesFolder . '/aaaa.json');
 }