Beispiel #1
0
 /**
  * Load config
  */
 public function loadConfig()
 {
     Config::load(CONFIG_DIR . DS . 'config.default.php');
     Config::load(CONFIG_DIR . DS . sprintf('config.%s.php', getenv('RAD_ENVIRONMENT')));
     Config::set('environment', getenv('RAD_ENVIRONMENT'));
     Config::set('debug', boolval(getenv('RAD_DEBUG')));
 }
Beispiel #2
0
 /**
  * {@inheritdoc}
  *
  * @return RedirectResponse|TwigResponse
  */
 public function __invoke()
 {
     if ($this->getAuth()->isAuthenticated()) {
         return new RedirectResponse(Config::get('users.authentication.loginRedirect', '/'));
     }
     $form = $this->getData('form');
     return new TwigResponse(Config::get('users.loginTwigTemplate', '@Users/login.twig'), ['form' => $form->createView()]);
 }
Beispiel #3
0
 /**
  * Test PhpConfig dump
  */
 public function testDump()
 {
     Config::load(self::$fixtures . '/Engine/PhpConfig/base_config.php');
     $filename = sprintf('/tmp/%s/config.php', uniqid());
     $this->assertTrue(Config::dump($filename));
     Config::load($filename, 'default', false);
     $this->assertEquals(Config::get('key2.sub-key1.sub-sub-key2'), 'val2');
     chmod($filename, 0400);
     $this->setExpectedExceptionRegExp('Rad\\Configure\\Exception', sprintf('/File "%s" is not writable/', preg_quote($filename, '/')));
     Config::dump($filename);
 }
 /**
  * Overrides the original method from phinx in order to return a tailored
  * Config object containing the connection details for the database.
  *
  * @return Phinx\Config\Config
  */
 public function getConfig()
 {
     if ($this->configuration) {
         return $this->configuration;
     }
     $dir = APP_DIR . DS . 'Resource' . DS . 'migrations';
     $migrationTable = 'phinxlog';
     if ($bundleName = $this->input->getOption('bundle')) {
         $dir = Bundles::getPath($bundleName) . DS . 'Resource' . DS . 'migrations';
     }
     return $this->configuration = new Config(['paths' => ['migrations' => $dir], 'environments' => ['default_migration_table' => $migrationTable, 'default_database' => getenv('RAD_ENVIRONMENT'), getenv('RAD_ENVIRONMENT') => \Rad\Configure\Config::get('migrations.environments.' . getenv('RAD_ENVIRONMENT'))]]);
 }
 /**
  * {@inheritdoc}
  */
 public function loadConfig()
 {
     Config::load(__DIR__ . DS . 'Resource' . DS . 'config' . DS . 'config.php');
 }
Beispiel #6
0
 /**
  * Test json serialize interface
  */
 public function testJsonSerializeInterface()
 {
     Config::load(self::$fixtures . '/Engine/PhpConfig/base_config.php');
     $configArray = json_decode(json_encode(Config::getInstance()), true);
     $this->assertEquals($configArray['foo'], 'bar');
 }
Beispiel #7
0
 /**
  * {@inheritdoc}
  */
 public function loadService()
 {
     $this->getContainer()->setShared('twig', function () {
         $loader = new \Twig_Loader_Filesystem([]);
         $loader->addPath(SRC_DIR . "/App/Resource/template");
         foreach (Bundles::getLoaded() as $bundleName) {
             if (is_dir(SRC_DIR . "/{$bundleName}/Resource/template/")) {
                 $loader->addPath(SRC_DIR . "/{$bundleName}/Resource/template", $bundleName);
             }
         }
         $loader->addPath(ROOT_DIR . '/vendor/symfony/twig-bridge/Resources', 'TwigBridgeTemplates');
         if (Config::get('debug', false)) {
             $options = ['debug' => true, 'cache' => false];
         } else {
             $options = ['debug' => false, 'cache' => CACHE_DIR . '/twig/'];
         }
         $twig = new \Twig_Environment($loader, $options);
         if (Config::get('debug', false)) {
             $twig->addExtension(new Twig_Extension_Debug());
         }
         // add route generator function
         $twig->addFunction(new \Twig_SimpleFunction('generateUrl', function ($url = null, $withParams = true, $withLanguage = true, $incDomain = true) {
             $router = $this->getRouter();
             return $router->generateUrl($url, [Router::GEN_OPT_LANGUAGE => $withLanguage, Router::GEN_OPT_WITH_PARAMS => $withParams, Router::GEN_OPT_INC_DOMAIN => $incDomain]);
         }));
         $twig->addFunction(new \Twig_SimpleFunction('getService', function ($name, array $args = []) {
             return $this->getContainer()->get($name, $args);
         }));
         /** @var Registry $registry */
         $registry = $this->getContainer()->get('registry');
         // return css tags
         $twig->addFunction(new \Twig_SimpleFunction('getCss', function ($css = null, $priority = 0) use($registry) {
             $result = $registry->get(TwigHelper::GLOBAL_CSS, TwigHelper::TWIG_REGISTRY_SCOPE);
             if (null !== $css) {
                 $result = [['css' => $css, 'priority' => $priority]];
             }
             if (is_array($result)) {
                 foreach ($result as $row) {
                     $order[] = $row['priority'];
                 }
                 array_multisort($order, $result);
                 array_walk($result, function (&$item) {
                     $item = $item['css'];
                     // if it is direct link to file
                     if (strpos($item, 'file://') === 0) {
                         $item = substr($item, 7);
                         $item = "<link rel=\"stylesheet\" href=\"{$item}\">";
                     } else {
                         $item = "<style>\n{$item}\n</style>";
                     }
                 });
                 $result = implode("\n", $result);
             }
             return strval($result);
         }, ['is_safe' => ['html']]));
         // return js tags
         $twig->addFunction(new \Twig_SimpleFunction('getJs', function ($js = null, $priority = 0) use($registry) {
             $result = $registry->get(TwigHelper::GLOBAL_JS, TwigHelper::TWIG_REGISTRY_SCOPE);
             if (null !== $js) {
                 $result = [['js' => $js, 'priority' => $priority]];
             }
             if (is_array($result)) {
                 foreach ($result as $row) {
                     $order[] = $row['priority'];
                 }
                 array_multisort($order, $result);
                 array_walk($result, function (&$item) {
                     $item = $item['js'];
                     // if it is direct link to file
                     if (strpos($item, 'file://') === 0) {
                         $item = substr($item, 7);
                         $item = "<script src=\"{$item}\"></script>";
                     } else {
                         $item = "<script>\n{$item}\n</script>";
                     }
                 });
                 $result = implode("\n", $result);
             }
             return strval($result);
         }, ['is_safe' => ['html']]));
         $twig->addFunction(new \Twig_SimpleFunction('addCss', function ($css, $priority = 0) {
             TwigHelper::addCss($css, $priority);
         }));
         $twig->addFunction(new \Twig_SimpleFunction('addJs', function ($js, $priority = 0) {
             TwigHelper::addJs($js, $priority);
         }));
         // return master twig
         $twig->addFunction(new \Twig_SimpleFunction('getMasterTwig', function () use($registry) {
             $result = $registry->get(TwigHelper::MASTER_TWIG, TwigHelper::TWIG_REGISTRY_SCOPE);
             $item = array_pop($result);
             $registry->set(TwigHelper::MASTER_TWIG, $result, TwigHelper::TWIG_REGISTRY_SCOPE);
             return strval($item);
         }, ['is_safe' => ['html']]));
         Library\Helper::addMasterTwig('@App/master.twig');
         $renderer = new TwigRendererEngine(['@TwigBridgeTemplates/views/Form/form_div_layout.html.twig']);
         $renderer->setEnvironment($twig);
         $twig->addExtension(new FormExtension(new TwigRenderer($renderer)));
         $twig->addExtension(new TranslationExtension(new IdentityTranslator()));
         return $twig;
     });
     $this->getContainer()->setShared('form_factory', function () {
         if (class_exists('Symfony\\Component\\Validator\\Mapping\\Factory\\LazyLoadingMetadataFactory')) {
             $metadataFactory = new LazyLoadingMetadataFactory(new StaticMethodLoader());
         } else {
             $metadataFactory = new ClassMetadataFactory(new StaticMethodLoader());
         }
         $builder = Validation::createValidatorBuilder()->setConstraintValidatorFactory(new ConstraintValidatorFactory())->setTranslationDomain('validators')->setMetadataFactory($metadataFactory);
         $extensions = [new HttpFoundationExtension(), new ValidatorExtension($builder->getValidator())];
         return Forms::createFormFactoryBuilder()->addExtensions($extensions)->setResolvedTypeFactory(new ResolvedFormTypeFactory())->getFormFactory();
     });
 }
Beispiel #8
0
 /**
  * Load services from config
  *
  * @throws DependencyInjection\Exception\ServiceLockedException
  */
 protected function loadServicesFromConfig()
 {
     foreach (Config::get('services', []) as $name => $service) {
         $service += ['shared' => false, 'locked' => false, 'definition' => []];
         $this->container->set($name, $service['definition'], $service['shared'], $service['locked']);
     }
 }
Beispiel #9
0
 /**
  * If route is prefixed with language, extract it
  *
  * @param array $parts router parts
  */
 protected function extractLanguage(array &$parts)
 {
     if (!empty($parts) && in_array($parts[0], Config::get('languages.possible', ['en']))) {
         // We found the language, so set it as current language
         $this->language = array_shift($parts);
     } else {
         $this->language = Config::get('languages.default', 'en');
     }
 }
Beispiel #10
0
 /**
  * {@inheritdoc}
  *
  * @return RedirectResponse
  */
 public function __invoke()
 {
     return new RedirectResponse(Config::get('users.authentication.logoutRedirect', '/users/login'));
 }