/** * * Setup; runs before each test method. * */ public function setup() { $this->_sql = Solar::factory('Solar_Sql', array('adapter' => 'Solar_Sql_Adapter_Sqlite', 'name' => ':memory:')); // forcibly add sql to registry Solar_Registry::set('sql', $this->_sql); $cmd = "CREATE TABLE acl (" . " flag VARCHAR(10)," . " type CHAR(100)," . " name VARCHAR(255)," . " class_name VARCHAR(255)," . " action_name VARCHAR(255)," . " position VARCHAR(255)" . ")"; $this->_sql->query($cmd); $dir = Solar_Class::dir('Test_Solar_Access_Adapter', '_support'); $lines = file_get_contents($dir . 'access.txt'); $rows = explode("\n", $lines); $pos = 0; foreach ($rows as $row) { $row = trim($row); // skip empty lines and comments if (empty($row) || substr($row, 0, 1) == '#') { continue; } $row = preg_replace('/[ \\t]{2,}/', ' ', $row); $row = explode(' ', $row); $data['flag'] = trim($row[0]); $data['type'] = trim($row[1]); $data['name'] = trim($row[2]); $data['class_name'] = trim($row[3]); $data['action_name'] = trim($row[4]); $data['position'] = $pos; $this->_sql->insert('acl', $data); $pos++; } parent::setup(); }
/** * * Write out a series of dirs and symlinks for a new Vendor source. * * @param string $vendor The Vendor name. * * @return void * */ protected function _exec($vendor = null) { // we need a vendor name, at least if (!$vendor) { throw $this->_exception('ERR_NO_VENDOR_NAME'); } $this->_outln("Removing links for vendor '{$vendor}' ..."); // build "foo-bar" and "FooBar" versions of the vendor name. $this->_inflect = Solar_Registry::get('inflect'); $this->_dashes = $this->_inflect->camelToDashes($vendor); $this->_studly = $this->_inflect->dashesToStudly($this->_dashes); // the base system dir $system = Solar::$system; // the links to remove (reverse order from make-vendor) $links = array("script/{$this->_dashes}", "include/Mock/{$this->_studly}", "include/Test/{$this->_studly}", "include/{$this->_studly}"); // remove the links foreach ($links as $link) { $this->_out(" Removing '{$link}' ... "); $path = "{$system}/{$link}"; if (Solar_File::exists($path)) { unlink($path); $this->_outln("done."); } else { $this->_outln("missing."); } } // done! $this->_outln("... done."); // reminders $this->_outln("Remember to remove '{$this->_studly}_App' from the " . "['Solar_Controller_Front']['classes'] element " . "in your config file."); $this->_outln("Remember to remove '{$this->_studly}_Model' from the " . "['Solar_Sql_Model_Catalog']['classes'] element " . "in your config file."); // need to write a recursive-remove method for Solar_Dir that will // delete only the symlinked files (not the real files) $this->_outln("You will need to remove the " . "'docroot/public/{$this->_studly}' directory yourself, as it " . "may contain copies of public assets (not links)."); }
/** * * Write out a series of dirs and symlinks for a new Vendor source. * * @param string $vendor The Vendor name. * * @return void * */ protected function _exec($vendor = null) { // we need a vendor name, at least if (!$vendor) { throw $this->_exception('ERR_NO_VENDOR'); } $this->_outln("Making links for vendor '{$vendor}' ..."); // build "foo-bar" and "FooBar" versions of the vendor name. $this->_inflect = Solar_Registry::get('inflect'); $this->_dashes = $this->_inflect->camelToDashes($vendor); $this->_studly = $this->_inflect->dashesToStudly($this->_dashes); $links = array(array('dir' => "include", 'tgt' => $this->_studly, 'src' => "../source/{$this->_dashes}/{$this->_studly}"), array('dir' => "include/Test", 'tgt' => $this->_studly, 'src' => "../../source/{$this->_dashes}/tests/Test/{$this->_studly}"), array('dir' => "include/Mock", 'tgt' => $this->_studly, 'src' => "../../source/{$this->_dashes}/tests/Mock/{$this->_studly}"), array('dir' => "include/Fixture", 'tgt' => $this->_studly, 'src' => "../../source/{$this->_dashes}/tests/Fixture/{$this->_studly}"), array('dir' => "script", 'tgt' => $this->_dashes, 'src' => "../source/solar/script/solar")); $system = Solar::$system; foreach ($links as $link) { // $dir, $src, $tgt extract($link); // make it $this->_out(" Making link '{$dir}/{$tgt}' ... "); try { Solar_Symlink::make($src, $tgt, "{$system}/{$dir}"); $this->_outln("done."); } catch (Exception $e) { $this->_out($e->getMessage()); $this->_outln(" ... failed."); } } // done with this part $this->_outln("... done."); // make public links $link_public = Solar::factory('Solar_Cli_LinkPublic'); $link_public->exec($vendor); // done for real $this->_outln("Remember to add '{$this->_studly}_App' to the " . "['Solar_Controller_Front']['classes'] element " . "in your config file so that it finds your apps."); $this->_outln("Remember to add '{$this->_studly}_Model' to the " . "['Solar_Sql_Model_Catalog']['classes'] element " . "in your config file so that it finds your models."); }
public function actionOverview($page = 1) { $model_news = new JForg_Model_News(); $locale = Solar_Registry::get('locale'); if ($this->_format != null) { //requesting an newsfeed (rss,rss2 or atom) //disable all pageing stuff $this->title = $this->locale('TEXT_NEWS'); $items_per_page = 15; $page = 1; } else { //requesting an usual (xhtml) webpage. //do this pageing stuff $page = (int) $page; $items_per_page = 5; $pagecount = $model_news->countPages(array('where' => 'language = \'' . $locale->getCode() . '\'', 'paging' => $items_per_page, 'page' => $page)); if ($page > $pagecount['pages']) { $page = $pagecount['pages']; } if ($page == 0) { $page = 1; } $this->title = $this->locale('TEXT_NEWS') . ' - ' . $this->locale('TEXT_PAGE') . ': ' . $page; $this->page = $page; $this->max_page = $pagecount['pages']; } $collection = $model_news->fetchAllByLanguage($locale->getCode(), array('page' => $page, 'paging' => $items_per_page)); $this->news = $collection; }
/** * * Returns a localized string WITH NO ESCAPING. * * @param string $key The locale key to look up from the class. * * @param int|float $num A number to help determine if the * translation should return singluar or plural. * * @param array $replace If an array, will call vsprintf() on the * localized string using the replacements in the array. * * @return string The translated locale string. * */ public function getTextRaw($key, $num = 1, $replace = null) { static $locale; if (!$locale) { $locale = Solar_Registry::get('locale'); } return $locale->fetch($this->_class, $key, $num, $replace); }
/** * * The login was a failure, complete the protocol * * @return void * */ public function postLoginFailure() { $response = Solar_Registry::get('response'); $response->setHeader('WWW-Authenticate', 'Basic realm="' . $this->_config['realm'] . '"'); $response->setStatusCode(401); $response->display(); exit(0); }
protected function _postConstruct() { parent::_postConstruct(); // "Test_Solar_View_Helper_" = 23 $this->_helper_name = substr(get_class($this), 23); $this->_helper_class = substr(get_class($this), 5); $this->_request = Solar_Registry::get('request'); $this->_view = Solar::factory('Solar_View'); }
/** * * Post-construction tasks to complete object construction. * * @return void * */ protected function _postConstruct() { parent::_postConstruct(); // only set up the handler if it doesn't exist yet. if (!self::$_handler) { self::$_handler = Solar::dependency('Solar_Session_Handler', $this->_config['handler']); } $this->_request = Solar_Registry::get('request'); }
public function setup() { parent::setup(); $this->_view = Solar::factory('Solar_View'); $this->_name = substr(get_class($this), 18, -4); $this->_name[0] = strtolower($this->_name[0]); // retain and reset the request environment $this->_request = Solar_Registry::get('request'); $this->_request->reset(); }
/** * * Setup; runs before each test method. * */ public function setup() { parent::setup(); // remove "Test_" prefix $this->_class = substr(get_class($this), 5); // get the request environment $this->_request = Solar_Registry::get('request'); // get a new adapter $this->_auth = Solar::factory($this->_class, $this->_config); }
/** * * Setup; runs before each test method. * */ public function setup() { parent::setup(); // set up an SQL connection $this->_sql = Solar::factory('Solar_Sql', $this->_sql_config); // set up a model catalog $this->_catalog = Solar::factory('Solar_Sql_Model_Catalog', $this->_catalog_config); // register the connection and catalog Solar_Registry::set('sql', $this->_sql); Solar_Registry::set('model_catalog', $this->_catalog); }
/** * * Setup; runs before each test method. * */ public function preTest() { parent::preTest(); // set up an SQL connection $this->_sql = Solar::factory('Solar_Sql', $this->_sql_config); $this->_sql->setProfiling(true); // set up a model catalog $this->_catalog = Solar::factory('Solar_Sql_Model_Catalog', $this->_catalog_config); // register the connection and catalog Solar_Registry::set('sql', $this->_sql); Solar_Registry::set('model_catalog', $this->_catalog); // fixture to populate tables $this->_fixture = Solar::factory('Fixture_Solar_Sql_Model'); }
/** * * Setup; runs before each test method. * */ public function setup() { parent::setup(); // set up an SQL connection $this->_sql = Solar::factory('Solar_Sql', $this->_sql_config); $this->_sql->setProfiling(true); // set up a model catalog $this->_catalog = Solar::factory('Solar_Sql_Model_Catalog', $this->_catalog_config); // register the connection and catalog Solar_Registry::set('sql', $this->_sql); Solar_Registry::set('model_catalog', $this->_catalog); // populate everything $this->_populateAll(); }
/** * * Post-construction tasks to complete object construction. * * @return void * */ protected function _postConstruct() { parent::_postConstruct(); // get the current request environment $this->_request = Solar_Registry::get('request'); // set convenience vars from config $this->_routing = $this->_config['routing']; $this->_default = $this->_config['default']; $this->_disable = (array) $this->_config['disable']; // set up a class stack for finding commands $this->_stack = Solar::factory('Solar_Class_Stack'); $this->_stack->add($this->_config['classes']); // extended setup $this->_setup(); }
/** * * Write out a series of dirs and symlinks for a new Vendor source. * * @param string $vendor The Vendor name. * * @return void * */ protected function _exec($vendor = null) { // we need a vendor name, at least if (!$vendor) { throw $this->_exception('ERR_NO_VENDOR_NAME'); } // build "foo-bar" and "FooBar" versions of the vendor name. $this->_inflect = Solar_Registry::get('inflect'); $this->_dashes = $this->_inflect->camelToDashes($vendor); $this->_studly = $this->_inflect->dashesToStudly($this->_dashes); // create dirs, files, and symlinks $this->_createDirs(); $this->_createFiles(); $this->_createLinks(); }
/** * * 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; } }
/** * * Setup; runs before each test method. * */ public function setup() { parent::setup(); // set up an SQL connection $this->_sql = Solar::factory('Solar_Sql', $this->_sql_config); $this->_sql->setProfiling(true); // set up a model catalog $this->_catalog = Solar::factory('Solar_Sql_Model_Catalog', $this->_catalog_config); // register the connection and catalog Solar_Registry::set('sql', $this->_sql); Solar_Registry::set('model_catalog', $this->_catalog); // set the class name for relateds $len = strlen('Test_'); $this->_class = substr(get_class($this), $len); // populate everything $this->_populateAll(); }
/** * * Registers an object under a unique name. * * @param string $name The name under which to register the object. * * @param object|string $spec The registry specification. * * @param mixed $config If lazy-loading, use this as the config. * * @return void * * @todo Localize these errors. * */ public static function set($name, $spec, $config = null) { if (Solar_Registry::exists($name)) { // name already exists in registry $class = get_class(Solar_Registry::$_obj[$name]); throw Solar::exception('Solar_Registry', 'ERR_REGISTRY_NAME_EXISTS', "Object with '{$name}' of class '{$class}' already in registry", array('name' => $name, 'class' => $class)); } // register as an object, or as a class and config? if (is_object($spec)) { // directly register the object Solar_Registry::$_obj[$name] = $spec; } elseif (is_string($spec)) { // register a class and config for lazy loading Solar_Registry::$_obj[$name] = array($spec, $config); } else { throw Solar::exception('Solar_Registry', 'ERR_REGISTRY_FAILURE', 'Please pass an object, or a class name and a config array', array()); } }
/** * * Write out a series of dirs and symlinks for a new Vendor source. * * @param string $vendor The Vendor name. * * @return void * */ protected function _exec($vendor = null) { // we need a vendor name, at least if (!$vendor) { throw $this->_exception('ERR_NO_VENDOR_NAME'); } // build "foo-bar" and "FooBar" versions of the vendor name. $this->_inflect = Solar_Registry::get('inflect'); $this->_dashes = $this->_inflect->camelToDashes($vendor); $this->_studly = $this->_inflect->dashesToStudly($this->_dashes); // create dirs, files, and symlinks $this->_createDirs(); $this->_createFiles(); $this->_createLinks(); // done! $this->_outln("Done!"); $this->_outln("Remember to add '{$this->_studly}_App' to the " . "['Solar_Controller_Front']['classes'] element " . "in your config file so that it finds your apps."); $this->_outln("Remember to add '{$this->_studly}_Model' to the " . "['Solar_Sql_Model_Catalog']['classes'] element " . "in your config file so that it finds your models."); }
/** * * Setup; runs before each test method. * */ public function preTest() { parent::preTest(); // set up an SQL connection $this->_sql = Solar::factory('Solar_Sql', $this->_sql_config); // set up a model catalog $this->_catalog = Solar::factory('Solar_Sql_Model_Catalog', $this->_catalog_config); // register the connection and catalog Solar_Registry::set('sql', $this->_sql); Solar_Registry::set('model_catalog', $this->_catalog); // fixture to populate tables $this->_fixture = Solar::factory('Fixture_Solar_Sql_Model'); $this->_fixture->setup(); // preload all models to get discovery out of the way $this->_catalog->users; $this->_catalog->prefs; $this->_catalog->areas; $this->_catalog->nodes; $this->_catalog->metas; $this->_catalog->tags; $this->_catalog->taggings; $this->_catalog->comments; $this->_sql->setProfiling(true); }
public function __construct($config = null) { parent::__construct($config); $locale = Solar_Registry::get('locale'); $locale->setCode('de_DE'); }
/** * * Post-construction tasks to complete object construction. * * @return void * */ protected function _postConstruct() { parent::_postConstruct(); // get the current request environment. may already have been set by // extended classes. if (!$this->_request) { $this->_request = Solar_Registry::get('request'); } // fix the base path by adding leading and trailing slashes if (trim($this->_config['path']) == '') { $this->_config['path'] = '/'; } if ($this->_config['path'][0] != '/') { $this->_config['path'] = '/' . $this->_config['path']; } $this->_config['path'] = rtrim($this->_config['path'], '/') . '/'; // set properties $this->set($this->_config['uri']); }
/** * * Issues an immediate "Location" redirect. Use instead of display() * to perform a redirect. You should die() or exit() after calling this. * * @param Solar_Uri_Action|string $spec The URI to redirect to. * * @param int|string $code The HTTP status code to redirect with; default * is '302 Found'. * * @return void * */ public function redirect($spec, $code = '302') { if ($spec instanceof Solar_Uri_Action) { $href = $spec->get(true); } elseif (strpos($spec, '://') !== false) { // external link, protect against header injections $href = str_replace(array("\r", "\n"), '', $spec); } else { $uri = Solar::factory('Solar_Uri_Action'); $href = $uri->quick($spec, true); } // kill off all output buffers while (@ob_end_clean()) { } // make sure there's actually an href $href = trim($href); if (!$href) { throw $this->_exception('ERR_REDIRECT_FAILED', array('href' => $href)); } // set the status code $this->setStatusCode($code); // set the redirect location $this->setHeader('Location', $href); // clear the response body $this->content = null; // is this a GET-after-(POST|PUT) redirect? $request = Solar_Registry::get('request'); if ($request->isPost() || $request->isPut()) { // tell the next request object that it's a get-after-post $session = Solar::factory('Solar_Session', array('class' => get_class($request))); $session->setFlash('is_gap', true); } // save the session session_write_close(); // send the response directly -- done. $this->display(); }
/** * * Post-construction tasks to complete object construction. * * @return void * */ protected function _postConstruct() { parent::_postConstruct(); // get the current request environment $this->_request = Solar_Registry::get('request'); }
/** * * Starts the session; automatically sends a P3P header if one is defined * (and it is, by default). * * @return void * */ public function start() { // don't start more than once. if ($this->isStarted()) { // be sure the segment is loaded, though $this->load(); return; } // set the privacy headers if ($this->_config['P3P']) { $response = Solar_Registry::get('response'); $response->setHeader('P3P', $this->_config['P3P']); } // start the session session_start(); // load the session segment $this->load(); }
/** * * Checks the server variables to see if we have a SOLAR_URI_ACTION_PATH * value set from Apache; also pre-sets $this->_request. * * In a standard solar system, when mod_rewrite is turned on, it * may "SetEnv SOLAR_URI_ACTION_PATH /" as a hint for the default * action path. This lets you go from no-rewriting to rewriting in * one easy step, rather than having to remember to change the action * path in the Solar.config.php file as well. * * @return void * */ protected function _preConfig() { parent::_preConfig(); $this->_request = Solar_Registry::get('request'); $this->_Solar_Uri_Action['path'] = $this->_request->server('SOLAR_URI_ACTION_PATH', '/index.php'); }
/** * * Redirects to another URI after valid authentication. * * Looks at the value of the 'redirect' source key, and sets a 'Location:' * header from it. Note that this will end any further processing on this * page-load. * * If the 'redirect' key is empty or not present, will not redirect, and * processing will continue. * * @return void * */ protected function _redirect() { $method = strtolower($this->_config['source']); $href = $this->_request->{$method}($this->_config['source_redirect']); if ($href) { $response = Solar_Registry::get('response'); $response->redirectNoCache($href); exit(0); } }
public function __construct() { $this->_model = Solar_Registry::get('model_catalog'); }
/** * * Combination dependency-injection and service-locator method; returns * a dependency object as passed, or an object from the registry, or a * new factory instance. * * @param string $class The dependency object should be an instance of * this class. Technically, this is more a hint than a requirement, * although it will be used as the class name if [[Solar::factory()]] * gets called. * * @param mixed $spec If an object, check to make sure it's an instance * of $class. If a string, treat as a [[Solar_Registry::get()]] key. * Otherwise, use this as a config param to [[Solar::factory()]] to * create a $class object. * * @return object The dependency object. * */ public static function dependency($class, $spec) { // is it an object already? if (is_object($spec)) { return $spec; } // check for registry objects if (is_string($spec)) { return Solar_Registry::get($spec); } // not an object, not in registry. // try to create an object with $spec as the config return Solar::factory($class, $spec); }
/** * * Checks to see if user is allowed access to the requested action * for this controller. * * On access failure, changes $this->_action to 'error' and adds * an error message stating the user is not allowed access. * * @return void * */ protected function _preAction() { $allow = Solar_Registry::get('user')->access->isAllowed(get_class($this), $this->_action); if (!$allow) { $this->_errors[] = $this->locale('ERR_NOT_ALLOWED_ACCESS'); $this->_action = 'error'; } }