/**
  * 
  * 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.");
 }
 /**
  * 
  * 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).");
 }
 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;
 }
Exemple #4
0
 /**
  * 
  * 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);
 }
Exemple #5
0
 /**
  * 
  * 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);
 }
Exemple #6
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');
 }
Exemple #7
0
 /**
  * 
  * 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');
 }
Exemple #8
0
 /**
  * 
  * 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);
 }
Exemple #9
0
 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();
 }
 /**
  * 
  * 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();
 }
Exemple #11
0
 /**
  * 
  * 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();
 }
Exemple #12
0
 /**
  * 
  * 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;
     }
 }
Exemple #13
0
 /**
  * 
  * 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.");
 }
 /**
  * 
  * 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();
 }
Exemple #15
0
 /**
  * 
  * 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');
 }
Exemple #16
0
 /**
  * 
  * 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();
 }
Exemple #17
0
 /**
  * 
  * 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';
     }
 }
Exemple #18
0
 /**
  * 
  * 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');
 }
Exemple #19
0
 /**
  * 
  * 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);
     }
 }
Exemple #20
0
 /**
  * 
  * Post-construction tasks to complete object construction.
  * 
  * @return void
  * 
  */
 protected function _postConstruct()
 {
     parent::_postConstruct();
     $this->_inflect = Solar_Registry::get('inflect');
 }
Exemple #21
0
 /**
  * 
  * Executes when fetch() cannot find a related page-controller class.
  * 
  * Generates an "HTTP 1.1/404 Not Found" status header and returns a
  * short HTML page describing the error.
  * 
  * @param string $page The name of the page not found.
  * 
  * @return string
  * 
  */
 protected function _notFound($page)
 {
     $content = "<html><head><title>Not Found</title>" . "<body><h1>404 Not Found</h1><p>" . htmlspecialchars("Page controller for '{$page}' not found.") . "</p></body></html>";
     $response = Solar_Registry::get('response');
     $response->setStatusCode(404);
     $response->content = $content;
     return $response;
 }
 /**
  * 
  * Setup logic to register and retain a model catalog.
  * 
  * @return void
  * 
  */
 protected function _setup()
 {
     // parent logic
     parent::_setup();
     // set properties from registry
     $this->_model = Solar_Registry::get('model_catalog');
     $this->user = Solar_Registry::get('user');
     // if model name not preset, use the last part of the class name.
     // e.g., `Vendor_Something_FooBar => foo_bar`.
     if (!$this->model_name) {
         $inflect = Solar_Registry::get('inflect');
         $name = strrchr(get_class($this), '_');
         $this->model_name = strtolower($inflect->camelToUnder($name));
     }
 }
Exemple #23
0
 public function __construct()
 {
     $this->_model = Solar_Registry::get('model_catalog');
 }
Exemple #24
0
 /**
  * 
  * 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']);
 }
Exemple #25
0
 /**
  * 
  * Makes one model/record/collection class for each table in the database 
  * using a class-name prefix.
  * 
  * @param string $prefix The prefix for each model class name.
  * 
  * @return void
  * 
  */
 protected function _execMulti($prefix)
 {
     $this->_outln("Making one '{$prefix}' class for each table in the database.");
     // get the list of tables
     $this->_out('Connecting to database for table list ... ');
     $sql = Solar::factory('Solar_Sql', $this->_getSqlConfig());
     $this->_outln('connected.');
     $list = $sql->fetchTableList();
     $this->_outln('Found ' . count($list) . ' tables.');
     // process each table in turn
     $inflect = Solar_Registry::get('inflect');
     foreach ($list as $table) {
         $name = $inflect->underToStudly($table);
         $class = "{$prefix}_{$name}";
         $this->_outln("Using table '{$table}' to make class '{$class}'.");
         $this->_exec($class);
     }
 }
Exemple #26
0
 * 
 * When you're ready to really get going, point your web server document root 
 * to `system/docroot/` and turn on mod_rewrite.
 * 
 */
// Solar system directory
$system = dirname(__FILE__);
// set the include-path
set_include_path("{$system}/include");
// load Solar
require_once 'Solar.php';
// get the system config array
$config = (require "{$system}/config.php");
// force the Action and Public URI path configs, overwriting anything from
// the original config
$path = $_SERVER['REQUEST_URI'];
$pos = strpos($path, "/index.php");
if ($pos !== false) {
    // strip "/index.php" and everything after it
    $path = substr($path, 0, $pos);
}
$path = rtrim($path, '/');
$config['Solar_Uri_Action']['path'] = "{$path}/index.php";
$config['Solar_Uri_Public']['path'] = "{$path}/docroot/public";
// start Solar with the modified config values
Solar::start($config);
// instantiate and run the front controller
$front = Solar_Registry::get('controller_front');
$front->display();
// Done!
Solar::stop();
 public function __construct($config = null)
 {
     parent::__construct($config);
     $locale = Solar_Registry::get('locale');
     $locale->setCode('de_DE');
 }
Exemple #28
0
 /**
  * 
  * Returns a localized exception object.
  * 
  * @param string $code The error code.
  * 
  * @param array $info Additional error information.
  * 
  * @return Solar_Exception
  * 
  */
 protected static function _exception($code, $info = null)
 {
     $class = 'Solar_Dir';
     $locale = Solar_Registry::get('locale');
     return Solar::exception($class, $code, $locale->fetch($class, $code, 1, $info), (array) $info);
 }
Exemple #29
0
 /**
  * 
  * 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);
 }
 /**
  * 
  * Establish state of this object prior to _setup().
  * 
  * @return void
  * 
  */
 protected function _preSetup()
 {
     // inflection reference
     $this->_inflect = Solar_Registry::get('inflect');
     // our class name so that we don't call get_class() all the time
     $this->_class = get_class($this);
     // get the catalog injection
     $this->_catalog = Solar::dependency('Solar_Sql_Model_Catalog', $this->_config['catalog']);
     // connect to the database
     $this->_sql = Solar::dependency('Solar_Sql', $this->_config['sql']);
 }