public function testGet_elemDefault() { Solar_Config::set('__TEST__', null, $this->_store); $expect = '*default*'; $actual = Solar_Config::get('__TEST__', 'no-such-elem', $expect); $this->assertSame($actual, $expect); }
/** * * Generates a link to the TypeKey login site. * * @param string $text The text to display for the link. * * @param array $attribs Attributes for the anchor. * * @return string * */ public function typekeyLink($text = null, $attribs = null) { // get a URI processor; defaults to the current URI. $uri = Solar::factory('Solar_Uri'); // do not retain the GET 'process' value on the current URI. // this prevents double-processing of actions submitted via GET. $key = $this->_config['process_key']; if (!empty($uri->query[$key])) { unset($uri->query[$key]); } // save the current URI as the return location after typekey. $return = $uri->get(true); // now reset the URI to point to the typekey service $uri->set($this->_config['href']); // add the typekey token if (empty($this->_config['token'])) { $uri->query['t'] = Solar_Config::get('Solar_Auth_Adapter_Typekey', 'token'); } else { $uri->query['t'] = $this->_config['token']; } // convert need_email from true/false to 1/0 and add $uri->query['need_email'] = (int) $this->_config['need_email']; // add the return location $uri->query['_return'] = $return; if (empty($text)) { // Preserve behavior of returning only the link if no text is passed. return $uri->get(true); } // done! return $this->_view->anchor($uri->get(true), $text, $attribs); }
/** * isValidUser * Given credentionals, is this a valid user. (Login) * * @param $values * @return bool */ public function isValidUser($values = array()) { if (!array_key_exists('username', $values) || !array_key_exists('password', $values)) { return false; } $salt = Solar_Config::get('Solar_Auth_Adapter_Sql', 'salt'); $username = $values['username']; $password = md5($salt . $values['password']); $where = array('username = ?' => $username, 'password = ?' => $password); $result = $this->fetchAllAsArray(array('cache' => false, 'where' => $where)); if (is_array($result) && count($result) > 0) { return true; } return false; }
/** * * Post-construction tasks to complete object construction. * * @return void * */ protected function _postConstruct() { if (!self::$_session) { self::$_session = Solar::factory('Solar_Session', array('class' => 'Solar_Csrf')); } if (!self::$_request) { self::$_request = Solar_Registry::get('request'); } // ignore construct-time configuration for the key, but honor // it from the config file. we want the key name to be the // same everywhere all the time. $key = Solar_Config::get('Solar_Csrf', 'key'); if ($key) { self::$_key = $key; } }
protected function _preRender() { parent::_preRender(); if (Solar_Config::get('Foresmo', 'dev')) { xdebug_stop_trace(); $trace_file = explode("\n", file_get_contents('/var/www/foresmo/tmp/trace.xt')); $trace_file_count = count($trace_file); $trace_dump = array(); $defined_funcs = get_defined_functions(); foreach ($trace_file as $line => $value) { if ($line == 0 || $line >= $trace_file_count - 4 || strstr($value, 'include(') || strstr($value, 'require(')) { continue; } $tl = explode('-> ', $value); $tl = explode(' ', $tl[1]); if (!in_array(str_replace('()', '', $tl[0]), $defined_funcs['internal']) && strstr($tl[0], 'Foresmo') && !in_array($tl[0], $trace_dump)) { $trace_dump[] = $tl[0]; } } $tests = array(); // Lets organize our trace dump calls to that we can easily check/run tests foreach ($trace_dump as $call) { if (strstr($call, '->')) { $class_method = explode('->', $call); } else { $class_method = explode('::', $call); } if (!isset($tests[$class_method[0]])) { $tests[$class_method[0]] = array($class_method[1]); } else { $tests[$class_method[0]][] = $class_method[1]; } } var_dump($trace_dump); var_dump($tests); die; } }
/** * * Stops Solar: runs stop scripts and cleans up the Solar environment. * * @return void * */ public static function stop() { // run any 'stop' hook methods $hooks = Solar_Config::get('Solar', 'stop', array()); Solar::callbacks($hooks); // unregister autoloader spl_autoload_unregister(array('Solar_Class', 'autoload')); // reset the status flag, and we're done. Solar::$_status = false; }
/** * _setup * * Set variables used throughout the app here. */ protected function _setup() { parent::_setup(); $this->web_root = isset($_SERVER['DOCUMENT_ROOT']) ? $_SERVER['DOCUMENT_ROOT'] : Solar::$system . '/docroot/'; $this->web_root = Solar_Dir::fix($this->web_root); if (!isset($this->session)) { $this->session = Solar::factory('Solar_Session', array('class' => 'Foresmo_App')); } // Set CSRF Token $this->_setToken(); $this->csrf_token = $this->_getToken(); $this->installed = (bool) Solar_Config::get('Foresmo', 'installed'); if (!$this->installed && $this->_controller != 'install' && $this->_controller != 'ajax') { $this->_redirect('/install'); } elseif (!$this->installed) { return; } $adapter_type = Solar_Config::get('Solar_Sql', 'adapter'); $adapter = Solar::factory($adapter_type); try { $adapter->connect(); } catch (Exception $e) { // Display No DB Connection view and exit. $this->connect = false; $view = Solar::factory('Solar_View', array('template_path' => dirname(__FILE__) . '/Base/View/')); $view->assign('adapter_config', Solar_Config::get($adapter_type)); echo $view->fetch('nodb'); exit; } $this->_adapter = $adapter; $this->_model = Solar_Registry::get('model_catalog'); // Set Cache $cache_settings = Solar_Config::get('Foresmo', 'cache'); if (isset($cache_settings['adapter'])) { $this->_model->_config['cache'] = $cache_settings; $this->_cache = Solar::factory('Solar_Cache', $cache_settings); } $this->_setBlogOptions(); $this->page_title = $this->blog_title; $time_info = Foresmo::getTimeInfo(); Foresmo::$date_format = $time_info['blog_date_format']; Foresmo::$timezone = $time_info['blog_timezone']; $this->_model->posts->published_posts_count = $this->_model->posts->fetchPublishedPostsCount(); $this->_setPagesCount($this->_model->posts->posts_per_page, $this->_model->posts->published_posts_count); //$this->_layout_default = $this->blog_theme; // Load Themes $this->_themes = Solar::factory('Foresmo_Themes', array('model' => $this->_model)); // Load Modules $this->_modules = Solar::factory('Foresmo_Modules', array('model' => $this->_model)); $this->_modules->registerModuleHooks(); $this->enabled_modules = $this->_modules->getEnabledModulesData(); }
/** * * Loads the config values from the specified location. * * @param mixed $spec A config specification. * * @see fetch() * * @return void * */ public static function load($spec) { Solar_Config::$_store = Solar_Config::fetch($spec); Solar_Config::$_build = array(); $callback = Solar_Config::get('Solar_Config', 'load_callback'); if ($callback) { $merge = (array) call_user_func($callback); Solar_Config::$_store = array_merge(Solar_Config::$_store, $merge); } }
/** * * Builds and returns the default config for a class, including all * configs inherited from its parents. * * @param string $class The class to get the config build for. * * @return array The config build for the class. * */ protected function _buildConfig($class) { if (!$class) { return array(); } $config = Solar_Config::getBuild($class); if ($config === null) { $var = "_{$class}"; $prop = empty($this->{$var}) ? array() : (array) $this->{$var}; $parent = get_parent_class($class); $config = array_merge($this->_buildConfig($parent), $prop, Solar_Config::get($class, null, array())); // cache for future reference Solar_Config::setBuild($class, $config); } return $config; }
/** * _setup * * Set variables used throughout the app here. */ protected function _setup() { if (Solar_Config::get('Foresmo', 'dev')) { xdebug_start_trace('/var/www/foresmo/tmp/trace'); } if (!isset($this->session)) { $this->session = Solar::factory('Solar_Session', array('class' => 'Foresmo_App')); } $adapter = Solar_Config::get('Solar_Sql', 'adapter'); $adapter = Solar::factory($adapter); try { $adapter->connect(); } catch (Exception $e) { $this->connect = false; // should display an error page and die. } if ($this->connect) { $this->_adapter = $adapter; $this->installed = (bool) Solar_Config::get('Foresmo', 'installed'); if (!$this->installed && $this->_controller != 'install') { $this->_redirect('/install'); } $this->web_root = Solar::$system . '/content/'; $this->_model = Solar_Registry::get('model_catalog'); $cache_settings = Solar_Config::get('Foresmo', 'cache'); if (isset($cache_settings['adapter'])) { $this->_model->_config['cache'] = $cache_settings; $this->_cache = Solar::factory('Solar_Cache', $cache_settings); } $results = $this->_model->options->fetchBlogOptions(); foreach ($results as $result) { switch ($result['name']) { case 'blog_theme': $this->blog_theme = $result['value']; break; case 'blog_admin_theme': $this->blog_admin_theme = $result['value']; break; case 'blog_theme_options': $this->blog_theme_options = unserialize($result['value']); break; case 'blog_admin_theme_options': $this->blog_admin_theme_options = unserialize($result['value']); break; case 'blog_title': $this->blog_title = $result['value']; break; case 'blog_posts_per_page': $this->_model->posts->posts_per_page = (int) $result['value']; break; case 'blog_comment_link_limit': $this->_model->comments->link_count_limit = (int) $result['value']; break; } } $this->page_title = $this->blog_title; $time_info = Foresmo::getTimeInfo(); Foresmo::$date_format = $time_info['blog_date_format']; Foresmo::$timezone = $time_info['blog_timezone']; $this->_model->posts->published_posts_count = $this->_model->posts->fetchPublishedPostsCount(); $this->_setPagesCount(); $this->_layout_default = $this->blog_theme; $this->_setToken(); $this->_modules = Solar::factory('Foresmo_Modules', array('model' => $this->_model)); $this->enabled_modules_data = $this->_modules->getEnabledModulesData(); $this->_registerModuleHooks(); } }