get() public static method

public static get ( $key )
 /**
  * Try to retrieve a default setting from a config fallback.
  *
  * @param string $key
  * @param mixed  $default
  *
  * @return mixed config setting or default when not found
  */
 protected function getDefault($key, $default)
 {
     if (!$this->fallback) {
         return $default;
     }
     return $this->fallback->get($key, $default);
 }
Example #2
1
/**
 *  2Moons
 *  Copyright (C) 2012 Jan Kröpke
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @package 2Moons
 * @author Jan Kröpke <*****@*****.**>
 * @copyright 2012 Jan Kröpke <*****@*****.**>
 * @license http://www.gnu.org/licenses/gpl.html GNU GPLv3 License
 * @version 1.7.3 (2013-05-19)
 * @info $Id: CreateOnePlanetRecord.php 2640 2013-03-23 19:23:26Z slaver7 $
 * @link http://2moons.cc/
 */
function CreateOnePlanetRecord($Galaxy, $System, $Position, $Universe, $PlanetOwnerID, $PlanetName, $HomeWorld = false, $AuthLevel = 0, $Iron, $Gold, $Crystal, $Elyrium, $iPlanetCount)
{
    global $LNG;
    $CONF = Config::getAll(NULL, $Universe);
    if (Config::get('max_galaxy') < $Galaxy || 1 > $Galaxy) {
        throw new Exception("Access denied for CreateOnePlanetRecord.php.<br>Try to create a planet at position:" . $Galaxy . ":" . $System . ":" . $Position);
    }
    if (Config::get('max_system') < $System || 1 > $System) {
        throw new Exception("Access denied for CreateOnePlanetRecord.php.<br>Try to create a planet at position:" . $Galaxy . ":" . $System . ":" . $Position);
    }
    if (Config::get('max_planets') < $Position || 1 > $Position) {
        throw new Exception("Access denied for CreateOnePlanetRecord.php.<br>Try to create a planet at position:" . $Galaxy . ":" . $System . ":" . $Position);
    }
    if (CheckPlanetIfExist($Galaxy, $System, $Position, $Universe)) {
        return false;
    }
    $tp = 0;
    if ($iPlanetCount >= 3) {
        $tp = 1;
    }
    $FieldFactor = Config::get('planet_factor');
    require 'includes/PlanetData.php';
    $Pos = ceil($Position / (Config::get('max_planets') / count($PlanetData)));
    $TMax = $PlanetData[$Pos]['temp'];
    $TMin = $TMax - 40;
    $Fields = $PlanetData[$Pos]['fields'] * Config::get('planet_factor');
    $Types = $PlanetData[$Pos]['image'];
    $Name = !empty($PlanetName) ? $GLOBALS['DATABASE']->sql_escape($PlanetName) : $LNG['type_planet'][1];
    $GLOBALS['DATABASE']->query("INSERT INTO " . PLANETS . " SET\n\t\t\t\tname = '" . $Name . "',\n\t\t\t\tuniverse = " . $Universe . ",\n\t\t\t\tid_owner = " . $PlanetOwnerID . ",\n\t\t\t\tgalaxy = " . $Galaxy . ",\n\t\t\t\tsystem = " . $System . ",\n\t\t\t\tplanet = " . $Position . ",\n\t\t\t\tlast_update = " . TIMESTAMP . ",\n\t\t\t\tplanet_type = '1',\n\t\t\t\tcolo_metal = " . $Iron . ",\n\t\t\t\tcolo_crystal = " . $Gold . ",\n\t\t\t\tcolo_deut = " . $Crystal . ",\n\t\t\t\tcolo_elyrium = " . $Elyrium . ",\n\t\t\t\tteleport_portal = " . $tp . ",\n\t\t\t\timage = '" . $Types . "',\n\t\t\t\tdiameter = " . floor(1000 * sqrt($Fields)) . ",\n\t\t\t\tfield_max = " . ($HomeWorld ? Config::get('initial_fields') : floor($Fields)) . ",\n\t\t\t\ttemp_min = " . $TMin . ",\n\t\t\t\ttemp_max = " . $TMax . ",\n\t\t\t\tmetal = " . Config::get('metal_start') . ",\n\t\t\t\tmetal_perhour = " . Config::get('metal_basic_income') . ",\n\t\t\t\tcrystal = " . Config::get('crystal_start') . ",\n\t\t\t\tcrystal_perhour = " . Config::get('crystal_basic_income') . ",\n\t\t\t\tdeuterium = " . Config::get('deuterium_start') . ",\n\t\t\t\tdeuterium_perhour = " . Config::get('deuterium_basic_income') . ",\n\t\t\t\telyrium = " . Config::get('deuterium_start') . ",\n\t\t\t\telyrium_perhour = " . Config::get('deuterium_basic_income') . ";");
    return $GLOBALS['DATABASE']->GetInsertID();
}
Example #3
0
 /**
  * @param array $params
  * @param Config $mainConfig
  * @return array
  */
 public static function applyDefaultParameters(array $params, Config $mainConfig)
 {
     $logger = LoggerFactory::getInstance('Mime');
     $params += ['typeFile' => $mainConfig->get('MimeTypeFile'), 'infoFile' => $mainConfig->get('MimeInfoFile'), 'xmlTypes' => $mainConfig->get('XMLMimeTypes'), 'guessCallback' => function ($mimeAnalyzer, &$head, &$tail, $file, &$mime) use($logger) {
         // Also test DjVu
         $deja = new DjVuImage($file);
         if ($deja->isValid()) {
             $logger->info(__METHOD__ . ": detected {$file} as image/vnd.djvu\n");
             $mime = 'image/vnd.djvu';
             return;
         }
         // Some strings by reference for performance - assuming well-behaved hooks
         Hooks::run('MimeMagicGuessFromContent', [$mimeAnalyzer, &$head, &$tail, $file, &$mime]);
     }, 'extCallback' => function ($mimeAnalyzer, $ext, &$mime) {
         // Media handling extensions can improve the MIME detected
         Hooks::run('MimeMagicImproveFromExtension', [$mimeAnalyzer, $ext, &$mime]);
     }, 'initCallback' => function ($mimeAnalyzer) {
         // Allow media handling extensions adding MIME-types and MIME-info
         Hooks::run('MimeMagicInit', [$mimeAnalyzer]);
     }, 'logger' => $logger];
     if ($params['infoFile'] === 'includes/mime.info') {
         $params['infoFile'] = __DIR__ . "/libs/mime/mime.info";
     }
     if ($params['typeFile'] === 'includes/mime.types') {
         $params['typeFile'] = __DIR__ . "/libs/mime/mime.types";
     }
     $detectorCmd = $mainConfig->get('MimeDetectorCommand');
     if ($detectorCmd) {
         $params['detectCallback'] = function ($file) use($detectorCmd) {
             return wfShellExec("{$detectorCmd} " . wfEscapeShellArg($file));
         };
     }
     return $params;
 }
 /**
  * Get the producer object from kafka-php.
  * @return Produce
  */
 protected function getKafkaProducer()
 {
     if (!$this->producer) {
         $this->producer = Produce::getInstance(null, null, $this->config->get('KafkaEventHost'));
     }
     return $this->producer;
 }
Example #5
0
 /**
  * Gets all user limited with page and limit
  *
  * @param  int  $page
  * @param  into $limit
  * @return object
  */
 public function getAll($page = 1, $limit = 40)
 {
     $users = $this->dc->qb()->select('*')->from($this->dc->p($this->config->get('foolz/foolframe', 'foolauth', 'table_name')), 't')->setMaxResults($limit)->setFirstResult($page * $limit - $limit)->execute()->fetchAll();
     $users = User::forge($this->getContext(), $users);
     $count = $this->dc->qb()->select('COUNT(*) as count')->from($this->dc->p($this->config->get('foolz/foolframe', 'foolauth', 'table_name')), 't')->execute()->fetch();
     return ['result' => $users, 'count' => $count['count']];
 }
 /**
  * @param array  $settings
  * @param string $environment
  */
 public function __construct(array $settings = [], $environment = self::ENV_DEVELOPMENT)
 {
     parent::__construct();
     if (!defined('INFUSE_BASE_DIR')) {
         die('INFUSE_BASE_DIR has not been defined!');
     }
     /* Load Configuration */
     $configWithDirs = ['dirs' => ['app' => INFUSE_BASE_DIR . '/app', 'assets' => INFUSE_BASE_DIR . '/assets', 'public' => INFUSE_BASE_DIR . '/public', 'temp' => INFUSE_BASE_DIR . '/temp', 'views' => INFUSE_BASE_DIR . '/views']];
     $settings = array_replace_recursive(static::$baseConfig, $configWithDirs, $settings);
     $config = new Config($settings);
     $this['config'] = $config;
     $this['environment'] = $environment;
     /* Base URL */
     $this['base_url'] = function () use($config) {
         $url = ($config->get('app.ssl') ? 'https' : 'http') . '://';
         $url .= $config->get('app.hostname');
         $port = $config->get('app.port');
         $url .= (!in_array($port, [0, 80, 443]) ? ':' . $port : '') . '/';
         return $url;
     };
     /* Services  */
     foreach ($config->get('services') as $name => $class) {
         $this[$name] = new $class($this);
     }
     // set the last created app instance
     self::$default = $this;
 }
Example #7
0
 /**
  * Initialize the internal static variables using the global variables
  *
  * @param Config $config Configuration object to load data from
  */
 public function init(Config $config)
 {
     foreach ($config->get('PasswordConfig') as $type => $options) {
         $this->register($type, $options);
     }
     $this->setDefaultType($config->get('PasswordDefault'));
 }
Example #8
0
 public static function init()
 {
     if (self::$hasinit) {
         return false;
     }
     // Load configuration.
     self::$config = new Config('realms.ini');
     if (!self::$config->get('general', 'service_requests')) {
         // Service unavaliable. :(
         http_response_code(503);
         // 503 Service Unavaliable.
         echo 'service unavaliable';
         exit;
         // terminate here.
     }
     // Load request registry
     self::$requestRegistry = new RequestRegistry();
     // create request registry instance
     // Dynamically load request handlers.
     $handler_files = scandir('inc/Requests');
     foreach ($handler_files as $handler_file) {
         if ($handler_file == '.' || $handler_file == '..') {
             continue;
         }
         // skip ghost files
         // Load PHP file
         require 'inc/Requests/' . $handler_file;
         // Register handler
         $classname = pathinfo($handler_file, PATHINFO_FILENAME);
         self::$requestRegistry->register(new $classname());
     }
     // Realms init finish.
     self::$hasinit = true;
     return true;
 }
Example #9
0
 /**
  * Test root/production/host1 level config
  *
  * @covers Phossa\Config\Reference\Config::get()
  */
 public function testGet3()
 {
     $this->object = new Config(__DIR__ . '/testData/', 'production/host1');
     $this->assertEquals('bingo', $this->object->get('db.auth.user'));
     $this->assertEquals('nopass', $this->object->get('db.auth.pass'));
     $this->assertEquals('dbhost', $this->object->get('db.auth.host'));
     $this->assertEquals(3506, $this->object->get('db.auth.port'));
 }
Example #10
0
 public function testFromArray()
 {
     $expected = array('nome' => 'andre', 'sobrenome' => 'nascimento');
     $config = new Config();
     $config->fromArray($expected);
     $this->AssertEquals($expected['nome'], $config->get('nome'));
     $this->AssertEquals($expected['sobrenome'], $config->get('sobrenome'));
 }
Example #11
0
 public function testSetterMultidimensionOverwritesNestedValues()
 {
     $c = new Config(array('config' => array('deploy' => array('release_dir' => '/var/www'))));
     $this->assertEquals('/var/www', $c->get('config.deploy.release_dir'));
     $c->set('config.deploy.release_dir', '/var/www');
     $c->set('config.deploy.release_dir', '/var/www');
     $this->assertEquals('/var/www', $c->get('config.deploy.release_dir'));
 }
 /**
  * HTTPS Bool
  *
  * Gets HTTPS status in bool form
  *
  * @param Config $config
  * @return bool
  * @throws Exception
  */
 public static function httpsBool(Config $config)
 {
     if ($config->get('server', 'protocol') === 'https://') {
         return true;
     } elseif ($config->get('server', 'protocol') === 'http://') {
         return false;
     }
     throw new Exception("Protocol is not known. " . $config->get('server', 'protocol') === 'https://');
 }
Example #13
0
 /**
  * @param $userID
  * @param $serverID
  * @return int|string
  */
 public function get($userID, $serverID)
 {
     foreach ($this->config->get("admins", "permissions") as $adminID) {
         if ($adminID == $userID) {
             return 2;
         }
     }
     return $this->db->queryField("SELECT permission FROM permissions WHERE userID = :userID AND serverID = :serverID", "permission", [":userID" => $userID, ":serverID" => $serverID]);
 }
Example #14
0
 public function testLoadConfig()
 {
     $config = new Config(__DIR__, "/config.conf");
     $teste = $config->get('teste');
     $this->assertTrue(is_array($teste));
     $this->assertCount(2, $teste);
     $this->assertEquals('Ecomz\\Common', $teste['nome']);
     $this->assertEquals('Ivo Nascimento', $teste['author']);
     $this->assertEquals('qualquer data', $config->get('nosectiondata'));
 }
Example #15
0
 public function __construct()
 {
     $conf = new Config();
     $this->base_url = $conf->get('app.base_url');
     $this->_module = $conf->get('app.default_module');
     $this->_page = $conf->get('app.default_page');
     $this->_page = $conf->get('app.default_act');
     $this->_params = $conf->get('app.default_params');
     $conf->close();
 }
Example #16
0
File: MainTest.php Project: jasny/Q
 /**
  * Test adding settings
  *
  * @param Config $config
  */
 function setgetTest($config)
 {
     $this->assertEquals(array('grp1' => array('q' => 'abc', 'b' => 27), 'grp2' => array('a' => 'original')), $config->get());
     $config->set('grp2', array('b' => 'changed'));
     $config->set('grp3', array('rew' => 'MY VALUE', 'qq' => 2));
     $this->assertEquals(array('grp1' => array('q' => 'abc', 'b' => 27), 'grp2' => array('b' => 'changed'), 'grp3' => array('rew' => 'MY VALUE', 'qq' => 2)), $config->get());
     $this->assertEquals(array('rew' => 'MY VALUE', 'qq' => 2), $config->get('grp3'));
     $config->set(array('grp3', 'qq'), 19);
     $this->assertEquals(array('rew' => 'MY VALUE', 'qq' => 19), $config->get('grp3'));
 }
 /**
  * @covers       \Plugin\Config::__get
  * @depends      testCreateConfig
  * @dataProvider configProvider
  */
 public function testGetMagickValue($configData)
 {
     $config = new Config($configData);
     foreach ($configData as $key => $value) {
         if (is_array($value)) {
             $this->assertInstanceOf(Config::class, $config->get($key));
         } else {
             $this->assertEquals($value, $config->get($key));
         }
     }
 }
Example #18
0
 public static function getInstance($database)
 {
     if (!isset(self::$m_instances[$database])) {
         $config = new Config();
         if ($config->have($database)) {
             $pdoOptions = [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION];
             self::$m_instances[$database] = new PDO('mysql:host=' . $config->get($database . '.hostname') . ';dbname=' . $config->get($database . '.database'), $config->get($database . '.username'), $config->get($database . '.password'), $pdoOptions);
         }
     }
     return self::$m_instances[$database];
 }
 /**
  * Loads skin and user CSS files.
  * @param OutputPage $out
  */
 public function setupSkinUserCss(OutputPage $out)
 {
     parent::setupSkinUserCss($out);
     if ($this->metrolookConfig->get('MetrolookMobile')) {
         $styles = array('mediawiki.skinning.interface', 'skins.metrolook.styles.responsive');
     } else {
         $styles = array('mediawiki.skinning.interface', 'skins.metrolook.styles');
     }
     Hooks::run('SkinMetrolookStyleModules', array($this, &$styles));
     $out->addModuleStyles($styles);
 }
Example #20
0
 /**
  * Set title of page
  * 
  * @param string $value
  * @param boolean $projectTitle Add prefix with project name
  */
 public function setTitle($value = '', $projectTitle = true)
 {
     $title = $this->config->get('project_title');
     if (empty($value)) {
         $value = $title;
     } else {
         if ($projectTitle) {
             $value = $value . ' | ' . $title;
         }
     }
     $this->set('title', $value);
 }
 public function __construct($botName)
 {
     $this->config = Config::getConfig();
     $this->env = $this->config->get($botName . '_bot_env');
     $this->baseUrl = $this->config->get('gm_base_url');
     $this->botId = $this->config->get($botName . '_bot_id_' . $this->env);
     try {
         $this->curlWrapper = new CurlWrapper();
     } catch (CurlWrapperException $e) {
         die($e->getMessage());
     }
 }
 private function __construct(iConfig $config = null)
 {
     if (!$config) {
         $config = new Config();
     }
     $conn = $config->get('database')["mysql"];
     // Load entity configuration from PHP file annotations
     // This is the most versatile mode, I advise using it!
     // If you don't like it, Doctrine also supports YAML or XML
     $isDevMode = $config->get('isDevMode');
     $config = Setup::createAnnotationMetadataConfiguration(array(__DIR__ . "/src"), $isDevMode);
     $this->entityManager = EntityManager::create($conn, $config);
 }
 public function testEmpty()
 {
     file_put_contents($this->file, '');
     $this->assertEquals($this->object->get('test.trees.oak.fairies', 'default'), 'default');
     $this->object->set('test.trees.oak.second_fairy', 'Trixie');
     $this->assertEquals($this->object->get('test.trees.oak.second_fairy'), 'Trixie');
     $this->object->write('test');
     $group = $this->object->get('test');
     $this->assertArrayHasKey('trees', $group);
     $this->assertArrayHasKey('oak', $group['trees']);
     $this->assertArrayHasKey('second_fairy', $group['trees']['oak']);
     $this->assertEquals($group['trees']['oak']['second_fairy'], 'Trixie');
 }
 /**
  * @param  \Controller|void $controller
  * @throws \Exception
  */
 public function __construct(Controller $controller = null)
 {
     if (!$controller && !Controller::has_curr()) {
         throw new \Exception("Controller based key creators must have a current controller");
     }
     $this->controller = $controller ?: Controller::curr();
     $this->config = Config::inst();
     $this->environmentType = Director::get_environment_type();
     $this->currentStage = Versioned::current_stage();
     $this->theme = $this->config->get('SSViewer', 'theme');
     $this->ssl = !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off';
     $this->memberID = Member::currentUserID();
 }
Example #25
0
 /**
  * @param string $feature
  * @param array  $context
  *
  * @return bool
  */
 public function isActive($feature, array $context = [])
 {
     $value = $this->config->get($feature);
     if (is_callable($value)) {
         $key = $this->generateKey($feature, $context);
         if (array_key_exists($key, $this->callback)) {
             $value = $this->callback[$key];
         } else {
             $value = call_user_func_array($value, $context);
             $this->callback[$key] = $value;
         }
     }
     return $this->isTruthy($value);
 }
Example #26
0
 /**
  * Initializes output page and sets up skin-specific parameters
  * @param OutputPage $out Object to initialize
  */
 public function initPage(OutputPage $out)
 {
     parent::initPage($out);
     if ($this->vectorConfig->get('VectorResponsive')) {
         $out->addMeta('viewport', 'width=device-width, initial-scale=1');
         $out->addModuleStyles('skins.vector.styles.responsive');
     }
     // Append CSS which includes IE only behavior fixes for hover support -
     // this is better than including this in a CSS file since it doesn't
     // wait for the CSS file to load before fetching the HTC file.
     $min = $this->getRequest()->getFuzzyBool('debug') ? '' : '.min';
     $out->addHeadItem('csshover', '<!--[if lt IE 7]><style type="text/css">body{behavior:url("' . htmlspecialchars($this->getConfig()->get('LocalStylePath')) . "/{$this->stylename}/csshover{$min}.htc\")}</style><![endif]-->");
     $out->addModules(array('skins.vector.js'));
 }
Example #27
0
 /**
  * Run the application
  */
 public function run()
 {
     ini_set('session.cookie_httponly', 1);
     $config = new Config();
     mb_internal_encoding($config->get('app.charset'));
     $router = new Router($config->get('routes'));
     $uri = explode('?', $_SERVER['REQUEST_URI']);
     $uri = reset($uri);
     $action = $router->parse($uri);
     if ($action) {
         $this->runController($action['controller'], $action['method'], $action['params']);
     }
     return true;
 }
Example #28
0
 public function __construct($registry)
 {
     parent::__construct();
     $this->config = $registry->get('config');
     $this->language = $registry->get('language');
     $this->request = $registry->get('request');
     $this->currencies = $this->hash_sql("SELECT * FROM " . DB_PREFIX . "currency", 'code');
     if (isset($this->request->get['currency']) && isset($this->currencies[$this->request->get['currency']])) {
         $this->set($this->request->get['currency']);
     } elseif (isset($this->request->cookie['currency']) && isset($this->currencies[$this->request->cookie['currency']])) {
         $this->set($this->request->cookie['currency']);
     } else {
         $this->set($this->config->get('config_currency'));
     }
 }
 /**
  * Run the migrations.
  *
  * @return void
  */
 public function up()
 {
     Schema::create('activity_logs', function (Blueprint $table) {
         $table->increments('id');
         $table->integer(Config::get('activity-log-saas::key'));
         $table->integer('user_id');
         $table->integer('content_id');
         $table->string('content_type', 72);
         $table->string('action', 32);
         $table->string('description');
         $table->text('details');
         $table->boolean('developer');
         $table->string('ip_address', 64);
         $table->string('user_agent');
         $table->timestamps();
     });
     Schema::table('activity_logs', function ($table) {
         // We'll need to ensure that MySQL uses the InnoDB engine to
         // support the indexes, other engines aren't affected.
         $table->engine = 'InnoDB';
         // Useful for filters
         $table->index('user_id');
         $table->index('content_id');
         $table->index('content_type');
         $table->index('action');
     });
 }
 public function login($username = null, $password = null, $remember = false)
 {
     if (!$username && !$password && $this->exists()) {
         Session::put($this->_sessionName, $this->data()->id);
     } else {
         $user = $this->find($username);
         if ($user) {
             if ($this->data()->password === Hash::make($password, $this->data()->salt)) {
                 Session::put($this->_sessionName, $this->data()->id);
                 if ($remember) {
                     $hash = Hash::unique();
                     $hashCheck = $this->_db->get('users_session', array('user_id', '=', $this->data()->id));
                     if (!$hashCheck->count()) {
                         $this->_db->insert('users_session', array('user_id' => $this->data()->id, 'hash' => $hash));
                     } else {
                         $hash = $hashCheck->first()->hash;
                     }
                     Cookie::put($this->_cookieName, $hash, Config::get('remember.cookie_expiry'));
                 }
                 return true;
             }
         }
     }
     return false;
 }