set() static public method

Add object to catalog
static public set ( $key, $obj ) : object
$key string
$obj object
return object
Example #1
0
{
    /**
	 * Guarda a variáveis definidas pelo usuário a serem passadas para a view
	 * @var	array
	 */
    protected $_vars = array();
    /**
	 * Guarda uma instância da classe Registry
Example #2
0
 public function database($driver, $hostname, $username, $password, $database, $prefix = null, $charset = 'UTF8')
 {
     $file = DIR_ROOT . "'/system/database/{$driver}.php";
     $class = 'Database' . preg_replace('/[^a-zA-Z0-9]/', '', $driver);
     if (file_exists($file)) {
         include $file;
         $this->registry->set(str_replace('/', '_', $driver), new $class());
     } else {
         trigger_error('Error: Could not load database ' . $driver . '!');
         exit;
     }
 }
Example #3
0
 /**
  * Load all specific cms data.
  */
 public function loadCms()
 {
     $this->fileConfig->loadConfigFromFile(CONFIG_PATH . '/config.php');
     if ($this->fileConfig->get('dbUser') !== null) {
         /*
          * Cms is installed
          */
         if ($this->fileConfig->get('debugModus') === false) {
             @ini_set('display_errors', 'off');
             error_reporting(0);
         }
         $dbFactory = new Database\Factory();
         $db = $dbFactory->getInstanceByConfig($this->fileConfig);
         $databaseConfig = new Config\Database($db);
         $databaseConfig->loadConfigFromDatabase();
         Registry::set('db', $db);
         Registry::set('config', $databaseConfig);
         $this->plugin->addPluginData('db', $db);
         $this->plugin->addPluginData('config', $databaseConfig);
         $this->plugin->addPluginData('translator', $this->translator);
         $this->plugin->execute('AfterDatabaseLoad');
         $this->router->defineStartPage($databaseConfig->get('start_page'), $this->translator);
     } else {
         /*
          * Cms not installed yet.
          */
         $this->request->setModuleName('install');
         if (!empty($_SESSION['language'])) {
             $this->translator->setLocale($_SESSION['language']);
         }
     }
 }
Example #4
0
 /**
  * Получение настроек
  * @param  string $key Имя настройки
  * @return string Значение настройки
  */
 public static function get($key)
 {
     if (!Registry::has('setting')) {
         Registry::set('setting', App::arrayAssoc(self::all(), 'name', 'value'));
     }
     return Registry::get('setting')[$key];
 }
Example #5
0
 public function getController2()
 {
     $route = pathinfo(Request::getVar("route9sd3jdk3", "GET") . "/1.1");
     unset($_GET["route9sd3jdk3"]);
     $route = $route["dirname"];
     $route = preg_replace("/index\\.php\$/i", "", $route);
     $route = preg_replace("/\\/\$/", "", $route);
     if (($rm = RoadMap::get()) != NULL) {
         $found = false;
         $i = 0;
         $matches = array();
         for (; !$found && $i < count($rm); $i++) {
             $found = preg_match_all("/^" . addcslashes($rm[$i]["url"], "/") . "\$/", $route, $matches);
         }
         if ($found && $rm[$i - 1]["hasPage"] != 0) {
             $name = ucfirst($rm[$i - 1]["ctrl"]);
             $ctrl = Class_routines::loadClass(__ROOT_PATH . DS . "controller" . DS . "ctrl" . $name . ".class.php");
             Registry::set("controllerParams", array("route" => $route, "XHROnly" => $rm[$i - 1]["XHROnly"]));
             Registry::set("viewName", $name);
             Registry::set("controller", new $ctrl());
             Registry::set("route:params", $matches);
             return Registry::get("controller");
         } else {
             self::raiseException(!$found ? ERR_ROUTER_NO_ROUTE_FOUND : ERR_ROUTE_IS_NOT_LEAF, $route);
             return NULL;
         }
     }
 }
Example #6
0
 public function beforeroute()
 {
     $this->response = new \View\Backend();
     \Registry::set('VIEW', $this->response);
     $this->response->addTitle(\Base::instance()->get('LN__AdminCP'));
     $this->hasSub = $this->showMenu($this->moduleBase);
 }
 static function render()
 {
     $args = func_get_args();
     $action = $args[0];
     $controller = isset($args[1]) ? $args[1] : self::controller_name();
     $controllerClass = $controller . 'Controller';
     $ContrArgs = isset($args[2]) ? $args[2] : '';
     if (!is_callable(array($controllerClass, $action))) {
         if (is_file('controllers/' . $controller . '_controller.php')) {
             include 'controllers/' . $controller . '_controller.php';
         }
         Registry::set('controller', $controller, true);
         //loading model
         if (is_file('models/' . $controller . '.php')) {
             include 'models/' . $controller . '.php';
         } else {
             Registry::addDebug('<div class="notice">Notice: No model For: <i>"' . $controller . '"</i> controller</div>');
         }
         $controllerClass::$action($ContrArgs);
         ob_start();
         include 'views/' . $controller . '/' . $action . '.html.php';
         Registry::set('content', ob_get_contents());
         ob_end_clean();
     }
 }
 public function __construct()
 {
     $this->prefix = DB_PREFIX;
     $this->sdsdb = new DB(DB_DRIVER, DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, DB_DATABASE);
     $registry = new Registry();
     $registry->set('db', $this->sdsdb);
 }
Example #9
0
 public static function start()
 {
     $config = Registry::get('config');
     if (isset($config->session)) {
         // optional parameters sent to the constructor
         if (isset($config->session->params)) {
             $sessionParams = $config->session->params;
         }
         if (is_object($config->session->handler)) {
             $sessionHandler = self::factory($config->session->handler->namespace, $config->session->handler->class, $sessionParams, $config->session->lifetime);
         } else {
             $sessionHandler = self::factory('Nf\\Session', $config->session->handler, $sessionParams, $config->session->lifetime);
         }
         session_name($config->session->cookie->name);
         session_set_cookie_params(0, $config->session->cookie->path, $config->session->cookie->domain, false, true);
         session_set_save_handler(array(&$sessionHandler, 'open'), array(&$sessionHandler, 'close'), array(&$sessionHandler, 'read'), array(&$sessionHandler, 'write'), array(&$sessionHandler, 'destroy'), array(&$sessionHandler, 'gc'));
         register_shutdown_function('session_write_close');
         session_start();
         // session_regenerate_id(true);
         Registry::set('session', $sessionHandler);
         return $sessionHandler;
     } else {
         return false;
     }
 }
 /**
  * Register a plugin with the registry in the given category.
  * @param $category String the name of the category to extend
  * @param $plugin The instantiated plugin to add
  * @param $path The path the plugin was found in
  * @return boolean True IFF the plugin was registered successfully
  */
 function register($category, &$plugin, $path)
 {
     // Normalize plugin name to lower case for
     // PHP4 compatibility in case we use class names here.
     $pluginName = $plugin->getName();
     $plugins =& PluginRegistry::getPlugins();
     if (!$plugins) {
         $plugins = array();
     }
     // If the plugin was already loaded, do not load it again.
     if (isset($plugins[$category][$pluginName])) {
         return false;
     }
     // Allow the plugin to register.
     if (!$plugin->register($category, $path)) {
         return false;
     }
     if (isset($plugins[$category])) {
         $plugins[$category][$pluginName] =& $plugin;
     } else {
         $plugins[$category] = array($pluginName => &$plugin);
     }
     Registry::set('plugins', $plugins);
     return true;
 }
function post_list()
{
    // only run on the first call
    if (!Registry::has('rwar_post_archive')) {
        // capture original article if one is set
        if ($article = Registry::get('article')) {
            Registry::set('original_article', $article);
        }
    }
    if (!($posts = Registry::get('rwar_post_archive'))) {
        $posts = Post::where('status', '=', 'published')->sort('created', 'desc')->get();
        Registry::set('rwar_post_archive', $posts = new Items($posts));
    }
    if ($result = $posts->valid()) {
        // register single post
        Registry::set('article', $posts->current());
        // move to next
        $posts->next();
    } else {
        // back to the start
        $posts->rewind();
        // reset original article
        Registry::set('article', Registry::get('original_article'));
        // remove items
        Registry::set('rwar_post_archive', false);
    }
    return $result;
}
Example #12
0
 public static function rub_create()
 {
     $currencies = Registry::get('currencies');
     $symbol = SYMBOL_RUBL;
     if (empty($currencies[CURRENCY_RUB])) {
         $rub = array('currency_code' => CURRENCY_RUB, 'after' => 'Y', 'symbol' => $symbol, 'coefficient' => '1', 'is_primary' => 'Y', 'position' => '0', 'decimals_separator' => '', 'thousands_separator' => '', 'decimals' => '0', 'status' => 'A');
         db_query("UPDATE ?:currencies SET is_primary = 'N' WHERE is_primary = 'Y'");
         $rub_id = db_query('INSERT INTO ?:currencies ?e', $rub);
         if (!empty($rub_id)) {
             $rub_array = $rub;
             $rub_array['currency_id'] = $rub_id;
             Registry::set('currencies.RUB', $rub_array);
             foreach (fn_get_translation_languages() as $lang_code => $v) {
                 db_query("REPLACE INTO ?:currency_descriptions (`currency_code`, `description`, `lang_code`) VALUES (?s, 'Рубли', ?s)", CURRENCY_RUB, $lang_code);
             }
             fn_set_notification('N', __('notice'), __('rus_ruble.symbol_rub_created'));
         }
     } else {
         if ($currencies[CURRENCY_RUB]['is_primary'] == 'N') {
             db_query("UPDATE ?:currencies SET is_primary = 'N' WHERE is_primary = 'Y'");
             db_query("UPDATE ?:currencies SET is_primary = 'Y', coefficient = 1 WHERE currency_code = ?s", CURRENCY_RUB);
         }
         if ($currencies[CURRENCY_RUB]['symbol'] != $symbol) {
             self::symbol_update($symbol);
         }
     }
     return true;
 }
Example #13
0
 /**
  * Register a plugin with the registry in the given category.
  * @param $category String the name of the category to extend
  * @param $plugin The instantiated plugin to add
  * @param $path The path the plugin was found in
  * @return boolean True IFF the plugin was registered successfully
  */
 function register($category, &$plugin, $path)
 {
     $pluginName = $plugin->getName();
     $plugins =& PluginRegistry::getPlugins();
     if (!$plugins) {
         $plugins = array();
     }
     // If the plugin was already loaded, do not load it again.
     if (isset($plugins[$category][$pluginName])) {
         return false;
     }
     // Initialize the plug-in
     // FIXME: Move this to the hook registry once caching is implemented
     if (!$plugin->initialize($category, $path)) {
         return false;
     }
     // Allow the plugin to register.
     if (!$plugin->register($category, $path)) {
         return false;
     }
     if (isset($plugins[$category])) {
         $plugins[$category][$plugin->getName()] =& $plugin;
     } else {
         $plugins[$category] = array($plugin->getName() => &$plugin);
     }
     Registry::set('plugins', $plugins);
     return true;
 }
Example #14
0
 public static function addEntry($type, $action, $uid = FALSE)
 {
     if (\Registry::exists('LOGGER')) {
         $logger = \Registry::get('LOGGER');
     } else {
         $logger = new self();
         \Registry::set('LOGGER', $logger);
     }
     /*
     	eFiction 3 log types:
     	"RG" => _NEWREG
     	"ED" => _ADMINEDIT
     	"DL" => _ADMINDELETE
     	"VS" => _VALIDATESTORY
     	"LP"=> _LOSTPASSWORD
     	"BL" => _BADLOGIN
     	"RE" => "Reviews"
     	"AM" => "Admin Maintenance"
     	"EB" => _EDITBIO
     */
     // Force add entry
     $logger->reset();
     // Submitted data:
     $logger->type = $type;
     $logger->action = $action;
     // Use id of active user, unless specified
     $logger->uid = $uid ? $uid : $_SESSION['userID'];
     $logger->ip = $_SERVER['REMOTE_ADDR'];
     $logger->version = 2;
     // Add entry
     $test = $logger->save();
 }
 function register($category, $path)
 {
     if (parent::register($category, $path)) {
         error_log('OJS - UHBP: der Haken wird registriert.');
         Registry::set('UserHomeBlockPlugin', $this);
         HookRegistry::register('Templates::User::Index::MyAccount', array(&$this, 'callback'));
     }
 }
Example #16
0
File: registry.php Project: ning/ub
/** 
 * Set or retrieve an object
 *
 * @param $key string entry key to set or get
 * @param $instance optional object. If provided, set the entry
 *  for $key to this object. If not provided, return the entry
 *  for $key. If null, clear the entry for $key.
 *
 * @return object|null
 */
function Registry($key, $instance = -1)
{
    if ($instance === -1) {
        return Registry::get($key);
    } else {
        return Registry::set($key, $instance);
    }
}
Example #17
0
 /**
  * Construct DB\SQL
  * @return DB\SQL
  */
 public static function database($db = [])
 {
     if (!Registry::exists('database')) {
         $db = $db ?: Base::instance()->get('database');
         return Registry::set('database', new DB\SQL('mysql:host=' . $db['host'] . ';port=' . $db['port'] . ';dbname=' . $db['name'], $db['user'], $db['password']));
     }
     return Registry::get('database');
 }
Example #18
0
 public function testRemove()
 {
     Registry::set('a', 'a');
     Registry::set('b', 'b');
     Registry::remove('b');
     $this->assertEquals(true, Registry::isValidKey('a'));
     $this->assertEquals(false, Registry::isValidKey('b'));
 }
Example #19
0
 /**
  * Set the path to the configuration file.
  * @param $configFile string
  */
 function setConfigFileName($configFile)
 {
     // Reset the config data
     $configData = null;
     Registry::set('configData', $configData);
     // Set the config file
     Registry::set('configFile', $configFile);
 }
Example #20
0
 /**
  *	Return class instance
  *	@return static
  **/
 static function instance()
 {
     if (!Registry::exists($class = get_called_class())) {
         $ref = new Reflectionclass($class);
         $args = func_get_args();
         Registry::set($class, $args ? $ref->newinstanceargs($args) : new $class());
     }
     return Registry::get($class);
 }
Example #21
0
 public static function connect()
 {
     $config = self::_getConfig();
     $adapter = $config['adapter'];
     $dbConfig = array('dbname' => $config['dbname'], 'username' => $config['username'], 'password' => $config['password'], 'profiler' => $config['profiler']);
     $db = \libDb\Db::factory($adapter, $dbConfig);
     Registry::set('db', $db);
     return $db;
 }
Example #22
0
 public function get($key)
 {
     if (isset($this->services[$key])) {
         $cache = call_user_func($this->services[$key]);
         unset($this->services[$key]);
         parent::set($key, $cache);
     }
     return parent::get($key);
 }
Example #23
0
 /**
  * init the View
  */
 public function beforeroute()
 {
     if (\Base::instance()->get('AJAX') === TRUE) {
         $this->response = new \View\JSON();
     } else {
         $this->response = new \View\Frontend();
     }
     \Registry::set('VIEW', $this->response);
 }
Example #24
0
 public function __construct()
 {
     if (!$this->initialized) {
         // initialize mailer
         $transport = \Swift_SmtpTransport::newInstance(Config::get('mailer.host'), Config::get('mailer.port'))->setUsername(Config::get('mailer.username'))->setPassword(Config::get('mailer.password'));
         Registry::set('SwiftMailer', \Swift_Mailer::newInstance($transport));
         $this->initialized = true;
     }
 }
Example #25
0
 public function init()
 {
     Registry::set('config', new Config());
     // Initializing the language
     $translation = Translate::getInstance();
     // If requested with ?lang=<lang> we load the language.
     $lang = $translation->getLanguageToLoad();
     $translation->loadLanguage($lang);
 }
Example #26
0
 /**
  * 
  */
 public function testGet()
 {
     // Set test key/value
     Registry::set('getTest', 'getValue');
     // Test if it's possible to retrieve it
     $this->assertEquals('getValue', Registry::get('getTest'));
     // Should return null if key doesn't exist.
     $this->assertNull(Registry::get('not_existing_key'));
 }
Example #27
0
 /**
  * __construct
  * 
  * @param string $user
  * @param string $pass
  * @param string $host
  * @param int $port
  */
 public function __construct($user = '******', $pass = '', $host = 'localhost', $port = 21)
 {
     $this->_res = ftp_connect($host, $port, 10);
     ftp_login($this->_res, $user, $pass);
     ftp_pasv($this->_res, true);
     Registry::set('sysType', strtoupper(substr(ftp_systype($this->_res), 0, 3)) == 'WIN' ? 'WIN' : 'NIX');
     // URL
     //$this->_url = 'ftp://' . $user . ':' . $pass . '@' . $host . ':' . $port;
 }
function my_article_has_comments()
{
    if (!($itm = Registry::get('article'))) {
        return false;
    }
    $comments = Comment::where('status', '=', 'approved')->where('post', '=', $itm->id)->get();
    $comments = new Items($comments);
    Registry::set('my_article_comments', $comments);
    return $comments->length();
}
Example #29
0
 /**
  * Get an instance of the Help object.
  */
 function &getHelp()
 {
     $instance =& Registry::get('help');
     if ($instance == null) {
         unset($instance);
         $instance = new Help();
         Registry::set('help', $instance);
     }
     return $instance;
 }
Example #30
0
 public static function instance()
 {
     if (\Registry::exists('CONFIG')) {
         $cfg = \Registry::get('CONFIG');
     } else {
         $cfg = new self();
         \Registry::set('CONFIG', $cfg);
     }
     return $cfg;
 }