Пример #1
0
 /**
  * @covers Config::getParam
  * @todo   Implement testGetParam().
  */
 public function testGetParam()
 {
     $config = array('app_key' => 'appkeyvalue', 'user_key' => 'userkeyvalue');
     $this->object->setConfig($config);
     $this->assertEquals('appkeyvalue', $this->object->getParam('app_key'));
     $this->assertEquals('userkeyvalue', $this->object->getParam('user_key'));
 }
Пример #2
0
 /**
  * Handle unknown method calls (get() or post() - request methods)
  * 
  * @param string $func Function name
  * @param mixed  $args Arguments list
  * 
  * @return null
  */
 public function __call($func, $args)
 {
     $func = strtolower($func);
     $path = strtolower($args[0]);
     if (isset($args[2])) {
         // we've been given a route-specific config, set it up!
         Config::setConfig($args[2], 'route::' . $path);
     }
     if (isset($args[1])) {
         // see if the path includes params
         if (strpos($path, ':') !== false) {
             preg_match_all('/\\[(.+?)\\]/', $path, $params);
             // and replace the values in the path
             foreach ($params[1] as $p) {
                 $path = str_replace('/[' . $p . ']', '/(.+?)', $path);
             }
             $this->params[$func][$path] = $params[1];
         }
         $this->routes[$func][$path] = $args[1];
         $this->log->log('SETTING PATH [' . strtoupper($func) . ']: ' . $path);
     } else {
         $this->throwError('No path to set for : ' . strtoupper($func));
         $this->log->log('NO PATH TO SET [' . strtoupper($func) . ']: ' . $path);
     }
 }
 public function indexAction($url)
 {
     $this->setNoRender();
     // let shindig do the rendering
     set_include_path(ENGINEBLOCK_FOLDER_SHINDIG . PATH_SEPARATOR . get_include_path());
     include_once 'src/common/Config.php';
     include_once 'src/common/File.php';
     // You can't inject a Config, so force it to try loading
     // and ignore errors from config file not being there :(
     global $shindigConfig;
     $shindigConfig = array();
     @Config::setConfig(array('allow_plaintext_token' => true, 'person_service' => 'EngineBlock_Shindig_DataService', 'activity_service' => 'EngineBlock_Shindig_DataService', 'group_service' => 'EngineBlock_Shindig_DataService'));
     spl_autoload_register(array(get_class($this), 'shindigAutoLoad'));
     // Shindig expects urls to be moiunted on /social/rest so we enforce that.
     $_SERVER['REQUEST_URI'] = '/social/rest/' . $url;
     // We only support JSON
     $_SERVER['CONTENT_TYPE'] = 'application/json';
     // Shindig wants a security token, but interface F in coin is auth-less so we fake one.
     $_REQUEST["st"] = $_GET["st"] = $_POST["st"] = "o:v:a:d:u:m:c";
     $requestMethod = EngineBlock_ApplicationSingleton::getInstance()->getHttpRequest()->getMethod();
     $methodName = 'do' . ucfirst(strtolower($requestMethod));
     $servletInstance = new DataServiceServlet();
     if (is_callable(array($servletInstance, $methodName))) {
         $servletInstance->{$methodName}();
     } else {
         echo "Invalid method";
         // @todo Error out
     }
 }
Пример #4
0
 /**
  * Test that the custom configuration can be set correctly
  * 
  * @return null
  */
 public function testSetCustomConfiguration()
 {
     $option = 'foo123';
     $config = array('test' => $option);
     Config::setConfig($config);
     $this->assertEquals(Config::get('test'), $option);
 }
Пример #5
0
 *
 * This software is distributed under the GNU GPL v3.0 license.
 *
 * @author    Gemorroj
 * @copyright 2008-2012 http://wapinet.ru
 * @license   http://www.gnu.org/licenses/gpl-3.0.txt
 * @link      http://wapinet.ru/gmanager/
 * @version   0.8.1 beta
 *
 * PHP version >= 5.2.3
 *
 */
define('GMANAGER_START', microtime(true));
define('GMANAGER_PATH', dirname(__FILE__));
define('GMANAGER_URL', (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] && $_SERVER['HTTPS'] != 'off' ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . str_replace(array('\\', '//'), '/', dirname($_SERVER['PHP_SELF']) . '/'));
Config::setConfig('.config.ini');
set_include_path(get_include_path() . PATH_SEPARATOR . GMANAGER_PATH . DIRECTORY_SEPARATOR . 'lib' . PATH_SEPARATOR . GMANAGER_PATH . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'PEAR');
/**
 * Autoloader
 *
 * @param string $class
 */
function __autoload($class)
{
    require GMANAGER_PATH . '/lib/' . str_replace('_', '/', $class) . '.php';
}
switch (isset($_GET['gmanager_action']) ? $_GET['gmanager_action'] : 'index') {
    case 'edit':
        include GMANAGER_PATH . '/controllers/edit.php';
        break;
    case 'change':
Пример #6
0
<?php

spl_autoload_register(function ($class) {
    require_once "{$class}.php";
});
Config::setConfig(array("database" => array("dbhost" => "localhost", "dbname" => "publications", "dbuser" => "root", "dbpassword" => "Mgdln%35!0")));
Пример #7
0
 /**
  * Load a full configuration (walk the whole heirarchy)
  *
  * @param string $name Name of config to load
  * @return array
  */
 function &GetConfig($name, $setcurrent = true, $role = "", $skipcache = false)
 {
     Profiler::StartTimer("ConfigManager::GetConfig()", 2);
     $ret = array();
     if ($name != "base" && strpos($name, ".") === false && strpos($name, "abtest") === false) {
         $name = "cobrand.{$name}";
     }
     $cachewrapper = null;
     $cachekey = "config.{$role}.{$name}";
     $data = DataManager::singleton();
     $cachewrapper =& $data->caches["apc"]["default"];
     $allversions = $this->GetAllRevisions($role);
     if (!$skipcache && !empty($cachewrapper) && $cachewrapper->enabled) {
         if (($cachedresult = $cachewrapper->get($cachekey)) !== false) {
             /*
             Logger::Info("Found '$cachekey' in apc cache (revision=" . $ret["revision"] . ")");
             $ret = unserialize($cachedresult);
             
             $versions = array();
             if (($cachedversions = $cachewrapper->get($cachekey . ".versions")) !== false ) {
               $versions = unserialize($cachedversions);
               $versionlog = "Found '$cachekey.versions' in apc cache (" . implode(", ", array_map(create_function('$a, $b', 'return "$a=$b";'), array_keys($versions), array_values($versions))) . ")";
               Logger::Info($versionlog);
             }
             $includes = $this->GetConfigHeirarchy($name, $role);
             */
             // New code transitioning to Config object
             // FIXME - this whole function should just be boiled down to a couple class functions
             $cachedcfg = unserialize($cachedresult);
             $ret = $cachedcfg->getConfig();
             $versions = $cachedcfg->getVersions();
             $includes = $cachedcfg->getHeirarchy();
             Logger::Info("Found '{$cachekey}' in apc cache (revision=" . $versions[$name] . " - " . implode(", ", array_map(create_function('$a, $b', 'return "$a=$b";'), array_keys($versions), array_values($versions))) . ")");
             // Check version numbers of all parents - if any have changed, invalidate the config and force a reload
             $allgood = true;
             foreach ($includes as $i => $inc) {
                 //$retinc = unserialize($cachewrapper->get("config.$role.$inc"));
                 //$vinc = $this->GetCobrandidAndRevision($inc, $role);
                 //if ($versions[$inc] < $vinc["revision"]){
                 if ($versions[$inc] < $allversions[$inc]) {
                     Logger::Warn("Revision number for '{$name}' parent '{$inc}' is out of date (old revision=" . $versions[$inc] . " new revision=" . $allversions[$inc] . ")");
                     $ret = array();
                     $skipcache = true;
                     $allgood = false;
                     /*
                     for ($j = $i; $j >= 0; $j--) { // Clear cache entries for anything above this one
                       Logger::Info("Delete cache: {$includes[$j]}");
                       $cachewrapper->delete("config.$role.{$includes[$j]}");
                       $cachewrapper->delete("config.$role.{$includes[$j]}.heirarchy");
                       $cachewrapper->delete("config.$role.{$includes[$j]}.versions");
                     }
                     */
                 }
             }
             if ($allgood) {
                 Logger::Info("Cached config for '{$name}' is up-to-date");
             }
         }
     }
     if (empty($ret)) {
         // Check to see if config exists in memory - if it doesn't, fetch it
         $config = null;
         $configversions = array();
         if (!empty($this->configs[$name])) {
             $config = $this->configs[$name];
         } else {
             $config = $this->Load($name, $role);
         }
         if (!empty($config)) {
             // Process includes first
             if (!empty($config["include"])) {
                 $includes = explode(",", $config["include"]);
                 foreach ($includes as $inc) {
                     $included_config =& $this->GetConfig($inc, false, $role, $skipcache);
                     if (!empty($included_config)) {
                         $this->ConfigMerge($ret, $included_config);
                     }
                 }
             }
             // Merge in my own config...
             $this->ConfigMerge($ret, $config);
             // and then merge in any overrides
             if (!empty($config["override"])) {
                 $includes = explode(",", $config["override"]);
                 foreach ($includes as $inc) {
                     $included_config =& $this->GetConfig($inc, false, $role, $skipcache);
                     if (!empty($included_config)) {
                         $this->ConfigMerge($ret, $included_config);
                     }
                 }
             }
         }
         if (!empty($ret) && !empty($cachewrapper) && $cachewrapper->enabled) {
             // Store merged config result in APC
             $configheirarchy = $this->GetConfigHeirarchy($name, $role, true);
             foreach ($configheirarchy as $inc) {
                 $included_version = $this->GetCobrandidAndRevision($inc, $role);
                 $configversions[$inc] = $allversions[$inc];
                 //$this->configs[$inc]["revision"];
             }
             /*
             Logger::Debug($configheirarchy);
             Logger::Debug($configversions);
             */
             $cachecfg = new Config();
             $cachecfg->setName($name);
             $cachecfg->setConfig($ret);
             $cachecfg->setHeirarchy($configheirarchy);
             $cachecfg->setVersions($configversions);
             $cachewrapper->set($cachekey, serialize($cachecfg));
             //$cachewrapper->set($cachekey . ".versions", serialize($configversions));
             Logger::Info("Set '{$cachekey}' in apc cache");
         }
     }
     if ($setcurrent) {
         $this->current = is_array($this->current) ? array_merge_recursive($this->current, $ret) : $ret;
         // Update locations to reflect any new settings we got from the cobrand config
         $this->locations = $this->getLocations();
     }
     Profiler::StopTimer("ConfigManager::GetConfig()");
     return $ret;
 }
Пример #8
0
<?php

// An example of using php-webdminer.
require_once '../vendor/autoload.php';
$config = new Config();
$config->setConfig("example1.xml");
$mine = new Miner("true");
// True for verbose logging to log.log
echo $mine->run();
Пример #9
0
 b) E_ALL -> show all errors
 c) 0 -> don't show any errors
*/
error_reporting(E_ALL ^ E_NOTICE);
// 1 -> turn on showing errors, 0 -> turn off showing errors
ini_set('display_error', '1');
$file = 'config.class.php';
if (file_exists($file)) {
    include $file;
}
// Block try..catch
try {
    // Create new object of class config
    $cfg = new Config('config.ini');
    // Initiating basic settings
    $cfg->init();
    // Set example settings
    // Attention: You can set just ONE config data with key port
    $cfg->setConfig('name1', 'val1');
    // Attention: You have to comment line above to see example below!!
    // First way to get Config data
    #echo '<p>First way to show settings data: </p>';
    #echo '<p>Host: '.$cfg -> getConfig(array('host'))[0].' Password: '******'password'))[0].'</p>';
    echo '<br>';
    // Just to example looks nicely :)
    // Second way to get Config data
    // $data = $cfg -> getConfig(array('host', 'password'));
    // echo '<p>Host: '.$data[0]. ' Password: '******'</p>';
} catch (Exception $e) {
    echo $e->getMessage();
}
Пример #10
0
        <link rel="stylesheet" type="text/css" href="http://code.jquery.com/ui/1.9.2/themes/sunny/jquery-ui.css"></link>


        <?php 
require_once 'classes/Config.php';
require_once 'classes/EventbriteICS.php';
$config = new Config();
$params = $config->read();
if (isset($_POST['app_key'])) {
    $params['app_key'] = $_POST['app_key'];
    $params['user_key'] = $_POST['user_key'];
    $params['output_file_name'] = $_POST['output_file_name'];
    $params['timezone'] = $_POST['timezone'];
    $params['before_period'] = $_POST['before_period'];
    $params['after_period'] = $_POST['after_period'];
    $config->setConfig($params);
    $config->write();
}
// $config->read();
$app_key = $config->getParam('app_key');
$user_key = $config->getParam('user_key');
$output_file_name = $config->getParam('output_file_name');
$before_period = $config->getParam('before_period');
$after_period = $config->getParam('after_period');
// Get the user data ...
$eb_client = new Eventbrite(array('app_key' => $app_key, 'user_key' => $user_key));
try {
    $user = $eb_client->user_get();
} catch (Exception $ex) {
    // No events means the key is no good
    // This is a validation that should be reported, but for now
Пример #11
0
    $db = DB::getInstance();
    $sqls = array("\n\t\t\tCREATE TABLE IF NOT EXISTS `user` (\n\t\t\t\t`id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,\n\t\t\t\t`email` VARCHAR(200) NOT NULL,\n\t\t\t\t`passwd` VARCHAR(200) NOT NULL,\n\t\t\t\t`name` VARCHAR(200) NOT NULL,\n\t\t\t\t`joined` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,\n\t\t\t\tPRIMARY KEY (`id`),\n\t\t\t\tUNIQUE INDEX `email` (`email`)\n\t\t\t) COLLATE='utf8_general_ci' ENGINE=InnoDB\n\t\t", "\n\t\t\tCREATE TABLE IF NOT EXISTS `file` (\n\t\t\t\t`id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,\n\t\t\t\t`file_name` VARCHAR(250) NOT NULL,\n\t\t\t\t`user_id` BIGINT(20) UNSIGNED NOT NULL,\n\t\t\t\t`original_name` VARCHAR(250) NOT NULL,\n\t\t\t\t`type` VARCHAR(50) NOT NULL,\n\t\t\t\t`size` BIGINT(20) UNSIGNED NOT NULL,\n\t\t\t\t`description` TEXT NULL,\n\t\t\t\t`public` TINYINT(1) UNSIGNED NOT NULL DEFAULT '1',\n\t\t\t\t`comments` TINYINT(1) UNSIGNED NOT NULL DEFAULT '1',\n\t\t\t\t`upload` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,\n\t\t\t\tPRIMARY KEY (`id`),\n\t\t\t\tUNIQUE INDEX `file_name` (`file_name`)\n\t\t\t) COLLATE='utf8_general_ci' ENGINE=InnoDB\n\t\t", "\n\t\t\tCREATE TABLE IF NOT EXISTS `upload` (\n\t\t\t\t`file_id` BIGINT(20) UNSIGNED NOT NULL,\n\t\t\t\t`ip` INT(11) UNSIGNED NOT NULL,\n\t\t\t\t`user_agent` TEXT NOT NULL,\n\t\t\t\tUNIQUE INDEX `file_id` (`file_id`)\n\t\t\t) COLLATE='utf8_general_ci' ENGINE=InnoDB\n\t\t", "\n\t\t\tCREATE TABLE IF NOT EXISTS `comment` (\n\t\t\t\t`id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,\n\t\t\t\t`file_id` BIGINT(20) UNSIGNED NOT NULL,\n\t\t\t\t`reply_to` BIGINT(20) UNSIGNED NULL DEFAULT NULL,\n\t\t\t\t`user_id` BIGINT(20) UNSIGNED NULL DEFAULT NULL,\n\t\t\t\t`comment` TEXT NOT NULL,\n\t\t\t\t`added` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,\n\t\t\t\tPRIMARY KEY (`id`)\n\t\t\t) COLLATE='utf8_general_ci' ENGINE=InnoDB\n\t\t");
    foreach ($sqls as $sql) {
        $db->exec($sql);
    }
}
/* PROCESS */
if (file_exists(CONFIG_FILE) && !confirm(sprintf("Config file '%s' exists. Continue and overwrite it?", CONFIG_FILE))) {
    exit;
}
$questions = array(array('name' => 'database', 'text' => _('Database connection string'), 'default' => 'mysql://*****:*****@localhost:3306/files', 'callback' => 'verify_connection_sting'), array('name' => 'repository', 'text' => _('Files location'), 'default' => dirname(__FILE__) . DIRECTORY_SEPARATOR . 'files', 'callback' => 'verify_directory'));
$config = array();
foreach ($questions as $question) {
    do {
        $answer = prompt($question['text'], $question['default']);
    } while (function_exists($question['callback']) && !call_user_func($question['callback'], $answer));
    $config[$question['name']] = $answer;
}
Config::setConfig($config);
try {
    create_structure();
} catch (Exception $e) {
    echo $e->getMessage() . "\n\n";
    die;
}
$config_file = fopen(ROOT_DIR . CONFIG_FILE, 'w');
foreach ($config as $option => $value) {
    fputs($config_file, "{$option} = {$value}\n");
}
fclose($config_file);
echo _("Configuration successful finished\n");
Пример #12
0
 /**
  * Обертки для зависимостей
  */
 protected static function config($task = null, $config = null)
 {
     if (!class_exists('Config')) {
         throw new Exception('Работа с конфигурацией невозможна.');
     }
     switch ($task) {
         case "set":
             $return = Config::setConfig($config);
             break;
         default:
             $return = Config::getConfig();
             break;
     }
     return $return;
 }
Пример #13
0
    }
    public static function autoload($class)
    {
        $file = ROOT_DIR . "classes/{$class}.php";
        if (file_exists($file)) {
            require_once $file;
            return true;
        } else {
            return false;
        }
    }
}
Autoloader::register();
class Config
{
    protected static $config;
    public static function setConfig($config)
    {
        self::$config = $config;
    }
    public static function getConfig($param)
    {
        return array_key_exists($param, self::$config) ? self::$config[$param] : '';
    }
    public static function getAll()
    {
        return self::$config;
    }
}
file_exists(ROOT_DIR . CONFIG_FILE) and Config::setConfig(parse_ini_file(ROOT_DIR . CONFIG_FILE));