예제 #1
0
 /**
  * Return instance of object given its name.
  *
  * Note that the scope of the object (singleton/per call) depends on
  * how the object is configured by injector modules.
  *
  * @returns mixed instance of whatever is asked for
  */
 public function getInstance($name)
 {
     Preconditions::checkIsString($name, '$name should be string.');
     if (FajrConfig::get('Debug.Exception.ShowStacktrace')) {
         return $this->container->getService($name);
     } else {
         return @$this->container->getService($name);
     }
 }
 /**
  * Configure CurlConnection.options
  *
  * @param sfServiceContainerBuilder $container Symfony container to configure
  */
 public function configure(sfServiceContainerBuilder $container)
 {
     $options = array(CURLOPT_FORBID_REUSE => false, CURLOPT_FOLLOWLOCATION => true, CURLOPT_VERBOSE => false, CURLOPT_SSL_VERIFYPEER => true, CURLOPT_SSL_VERIFYHOST => true, CURLOPT_USERAGENT => FajrConfig::get('Connection.UserAgent'), CURLOPT_ENCODING => 'gzip');
     // overridnutie adresara pre certifikaty
     if (FajrConfig::get('SSL.CertificatesDir')) {
         $options[CURLOPT_CAPATH] = FajrConfig::get('SSL.CertificatesDir');
     }
     $container->setParameter('CurlConnection.options', $options);
 }
예제 #3
0
 public function getPath()
 {
     $dir = $this->config['path'];
     if (FajrUtils::isAbsolutePath($dir)) {
         return $dir;
     }
     // default resolve relative to Template.Directory
     $relativeTo = FajrConfig::getDirectory('Template.Directory');
     return FajrUtils::joinPath($relativeTo, $dir);
 }
예제 #4
0
 /**
  * Constructs settings object. Omitting $settingsStorage will
  * result in "unmodifiable and default" settings.
  *
  * @param FajrConfig $config fajr configuration
  * @param sfStorage $settingsStorage user settings storage
  */
 public function __construct(FajrConfig $config, sfStorage $settingsStorage = null)
 {
     $this->settingsStorage = $settingsStorage;
     $allSkins = $config->get(FajrConfigOptions::TEMPLATE_SKINS);
     foreach ($allSkins as $skin) {
         Preconditions::check($skin instanceof SkinConfig);
     }
     $skins = array();
     foreach ($allSkins as $key => $skin) {
         if (!$skin->isInternal()) {
             $skins[$key] = $skin;
         }
     }
     $this->skins = $skins;
     $default = $config->get(FajrConfigOptions::TEMPLATE_DEFAULT_SKIN);
     if (!in_array($default, array_keys($this->skins))) {
         throw new RuntimeException("Default skin is not available!");
     }
     $this->defaultSkinName = $default;
 }
예제 #5
0
 /**
  *
  * @return ServerConfig
  */
 public function getActiveServer()
 {
     $request = $this->request;
     $session = $this->session;
     $serverList = $this->config->get('AIS2.ServerList');
     $serverName = $this->config->get('AIS2.DefaultServer');
     if (($server = $session->read('server')) !== null) {
         //if ($session->read('login/login.class') === null) {
         //  throw new Exception('Fajr is in invalid state. Delete cookies and try again.');
         //}
         return $server;
     }
     if ($request->getParameter("serverName")) {
         $serverName = $request->getParameter("serverName");
         if (!isset($serverList[$serverName])) {
             throw new SecurityException("Invalid serverName!");
         }
     }
     assert(isset($serverList[$serverName]));
     return $serverList[$serverName];
 }
예제 #6
0
 /**
  * Configure injection of SessionInitializer.class
  *
  * @param sfServiceContainerBuilder $container Symfony container to configure
  */
 public function configure(sfServiceContainerBuilder $container)
 {
     $lifeTimeSec = 36000;
     $options = array('session_cookie_lifetime' => $lifeTimeSec, 'session_cookie_path' => '/', 'session_cookie_domain' => '.' . $_SERVER['HTTP_HOST'], 'session_cookie_secure' => FajrConfig::get('SSL.Require'), 'session_cookie_httponly' => true, 'session_name' => 'fajr_session_id');
     // cache expire, server
     ini_set("session.gc_maxlifetime", $lifeTimeSec);
     ini_set("session.cookie_lifetime", $lifeTimeSec);
     // custom cache expire is possible only for custom session directory
     session_save_path(FajrConfig::getDirectory('Path.Temporary.Sessions'));
     // Note, we can't use setParameters as it will destroy previous values!
     $container->setParameter('session.options', $options);
     $container->register('Session.Storage.class', 'sfSessionStorage')->addArgument('%session.options%')->setShared(true);
 }
예제 #7
0
 /**
  * Configures Trace.class for injection.
  *
  * @param sfServiceContainer $container Container to configure
  */
 public function configure(sfServiceContainerBuilder $container)
 {
     if (FajrConfig::get('Debug.Trace') === true) {
         $debugFile = FajrConfig::getDirectory('Debug.Trace.File');
         if ($debugFile !== null) {
             $container->setParameter('Debug.Trace.File', $debugFile);
             $container->setParameter('Debug.Trace.File.Mode', 'a');
             $container->register('Debug.Trace.File.class', 'fajr\\util\\PHPFile')->addArgument('%Debug.Trace.File%')->addArgument('%Debug.Trace.File.Mode%');
             $container->register('Trace.class', 'fajr\\FileTrace')->addArgument(new sfServiceReference('Timer.class'))->addArgument(new sfServiceReference('Debug.Trace.File.class'))->addArgument(0)->addArgument('--Trace--');
         } else {
             $container->register('Trace.class', 'fajr\\ArrayTrace')->addArgument(new sfServiceReference('Timer.class'))->addArgument('--Trace--');
         }
     } else {
         $container->register('Trace.class', 'fajr\\libfajr\\pub\\base\\NullTrace');
     }
 }
 /**
  * Configure injection of DisplayManager.class
  *
  * @param sfServiceContainerBuilder $container Symfony container to configure
  */
 public function configure(sfServiceContainerBuilder $container)
 {
     $container->register('DisplayManager.class', '\\fajr\\rendering\\DisplayManager')->addArgument(new sfServiceReference('TwigFactory.class'))->addArgument('%Template.Skin.Default%');
     $skins = FajrConfig::get('Template.Skin.Skins');
     $skinName = FajrConfig::get('Template.Skin.Default');
     if (!isset($skins, $skinName)) {
         throw new RuntimeException("Default skin is not present!");
     }
     $container->setParameter('Template.Skin.Default', $skins[$skinName]);
     $container->register('TwigFactory.class', '\\fajr\\rendering\\TwigFactory')->addArgument('%Twig.Environment.options%')->addArgument('%Twig.Environment.extensions%');
     $container->setParameter('Twig.Environment.extensions', array(new Twig_Extension_Escaper(), new Extension()));
     $container->setParameter('Twig.Template.Directory', FajrConfig::getDirectory('Template.Directory'));
     if (FajrConfig::get('Template.Cache')) {
         $cache = FajrConfig::getDirectory('Template.Cache.Path');
     } else {
         $cache = false;
     }
     $container->setParameter('Twig.Environment.options', array('base_template_class' => '\\fajr\\rendering\\Template', 'cache' => $cache, 'strict_variables' => true));
 }
예제 #9
0
 private function setResponseFields(Response $response)
 {
     $response = $this->context->getResponse();
     $response->set('version', new Version());
     $response->set('banner_debug', FajrConfig::get('Debug.Banner'));
     $response->set('google_analytics', FajrConfig::get('GoogleAnalytics.Account'));
     $response->set('base', FajrUtils::basePath());
     $response->set('language', 'sk');
     $response->set('availableServers', array());
     $response->set('currentServer', array('isBeta' => false, 'instanceName' => 'Chyba'));
     $server = $this->getServer();
     $serverList = FajrConfig::get('AIS2.ServerList');
     $response->set('availableServers', $serverList);
     $response->set('currentServer', $server);
     $response->set('aisVersion', null);
     $response->set('aisVersionIncompatible', false);
 }
예제 #10
0
 /**
  * Returns a cookie file path for current session.
  *
  * Cookie file name is not the same as session_id() so that if one
  * configures the same path for cookie and session directories,
  * the filenames do not clash.
  *
  * @returns string file path to use to store cookies into.
  */
 public static function getCookieFile()
 {
     return self::joinPath(FajrConfig::getDirectory('Path.Temporary.Cookies'), 'cookie_' . session_id());
 }
예제 #11
0
#!/usr/bin/php
<?php 
use fajr\config\FajrConfig;
// register our autoloader
require_once __DIR__ . '/../src/libfajr/libfajr.php';
Loader::register();
Loader::searchForClasses(__DIR__ . '/../src', true);
if (!FajrConfig::isConfigured()) {
    echo 'Chyba: Fajr nie je nakonfigurovany' . "\n";
    return;
}
if (!FajrConfig::get('Template.Cache')) {
    echo 'Info: Template cache je vypnuta, nema zmysel ju mazat' . "\n";
    return;
}
$path = FajrConfig::getDirectory('Template.Cache.Path');
echo 'Info: Template cache je ' . $path . "\n";
foreach (new DirectoryIterator($path) as $fileInfo) {
    if (!$fileInfo->isDot() && $fileInfo->isFile()) {
        unlink($fileInfo->getPathname());
    }
}
예제 #12
0
      konfiguračných volieb by mali byť vhodné pre väčšinu inštalácií, no
      napriek tomu ponúkame možnosť ich pohodlne zmeniť na jednom mieste - v
      tomto súbore.
    </p>

    <p>
      <strong>Dôležité:</strong> Pred používaním aplikácie je ešte nutné správne
      nastaviť skupinu na <code>www-data</code> (alebo pod čím beží webserver) a
      práva na adresáre <code>./temp</code>, <code>./temp/cookies</code> a
      <code>./temp/sessions</code> (alebo na tie, čo ste nastavili v 
      konfigurácii), tak, aby boli nastavené práva len na zapisovanie a použitie
      , t.j. <code>d----wx---</code>.
    </p>
  ');
}
if (FajrConfig::get('SSL.Require') && !FajrUtils::isHTTPS()) {
    fajr_bootstrap_error('
     <p>
       Pre túto inštanciu fajr-u je vyžadované HTTPS spojenie.
       Prosím skontrolujte prepisovacie pravidlá v <code>.htaccess</code>
       (alebo konfigurácii web servera), ktoré presmerovávajú HTTP spojenia na HTTPS.
       Ak nechcete vyžadovať SSL spojenie, je možné túto kontrolu
       vypnúť v konfiguračnom súbore, <strong>avšak na produkčných inštaláciách,
       alebo inštaláciách s funkčným SSL sa neodporúča túto kontrolu vypínať.
       </strong>
     </p>
   ');
}
// bootstrapping whole application
$modules = array(new TimerModule($startTime), new StatisticsModule(), new ContextModule(), new ControllerModule(), new DisplayManagerModule(), new CurlConnectionOptionsModule(), new SessionModule(), new TraceModule(), new LoginFactoryModule(), new InputModule());
$injector = new Injector($modules);
예제 #13
0
     * @param string $key
     * @returns string absolute path for the directory specified in configuration
     *                 or null if this option was not specified and does not have
     *                 a default value
     * @see FajrConfig::$defaultOptions
     * @see FajrConfig::$directoriesRelativeTo
     * @see configuration.example.php
     */
    public static function getDirectory($key)
    {
        self::assertInitialized();
        $dir = self::get($key);
        if ($dir === null) {
            return null;
        }
        if (FajrUtils::isAbsolutePath($dir)) {
            return $dir;
        }
        // default resolve relative
        $relativeTo = FajrUtils::getProjectRootDirectory();
        $parameters = self::getParameterDescription();
        assert(array_key_exists($key, $parameters));
        $param = $parameters[$key];
        if (array_key_exists('relativeTo', $param)) {
            $relativeTo = self::getDirectory($param['relativeTo']);
        }
        return FajrUtils::joinPath($relativeTo, $dir);
    }
}
FajrConfig::load();