/** * * Creates a new standalone helper object. * * @param string $name The helper name. * * @param array $config Configuration value overrides, if any. * * @return object A new standalone helper object. * * @see Solar_Class_Stack::load() * */ public function newHelper($name, $config = null) { $name[0] = strtolower($name[0]); $class = $this->_helper_class->load($name); settype($config, 'array'); $config['_view'] = $this; $helper = new $class($config); return $helper; }
/** * * Sets the model stack. * * @param array $classes An array of class prefixes to use for the model * stack. * * @return void * */ protected function _setStack($classes) { if (!$classes) { // add per the vendor on this catalog and its inheritance $parents = Solar_Class::parents(get_class($this), true); array_shift($parents); // Solar_Base $old_vendor = false; foreach ($parents as $class) { $new_vendor = Solar_Class::vendor($class); if ($new_vendor != $old_vendor) { $classes[] = "{$new_vendor}_Model"; } $old_vendor = $new_vendor; } } // build the class stack $this->_stack = Solar::factory('Solar_Class_Stack'); $this->_stack->add($classes); }
/** * * Finds the page-controller class name from a page name. * * @param string $page The page name. * * @return string The related page-controller class picked from * the routing, or from the list of available classes. If not found, * returns false. * */ protected function _getPageClass($page) { if (!empty($this->_routing[$page])) { // found an explicit route $this->_routing_key = $page; $class = $this->_routing[$page]; } else { // no explicit route $this->_routing_key = null; // try to find a matching class $page = str_replace('-', ' ', strtolower($page)); $page = str_replace(' ', '', ucwords(trim($page))); $class = $this->_stack->load($page, false); } return $class; }
/** * * Fixes the cache class name. * * @return void * */ protected function _fixCache() { // make sure we have a cache class if (empty($this->_cache_class)) { $class = $this->_stack->load('Cache', false); if (!$class) { $class = 'Solar_Sql_Model_Cache'; } $this->_cache_class = $class; } }
/** * * 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></head><body>"; $content[] = "<h1>404 Not Found</h1>"; $content[] = "<p>" . htmlspecialchars("Page controller class for '{$page}' not found.") . "</p>"; if ($this->_config['explain']) { $content[] = "<h2>Track</h2>"; $content[] = "<dl>"; foreach ($this->_explain as $code => $text) { $content[] = "<dt><code>{$code}:</code></dt>"; $content[] = "<dd><code>" . ($text ? htmlspecialchars($text) : "<em>empty</em>") . "</code></dd>"; } $content[] = "</dl>"; $content[] = "<h2>Page Class Prefixes</h2>"; $content[] = '<ol>'; foreach ($this->_stack->get() as $class) { $content[] = "<li>{$class}*</li>"; } $content[] = '</ol>'; } $content[] = "</body></html>"; $response = Solar_Registry::get('response'); $response->setStatusCode(404); $response->content = implode("\n", $content); return $response; }
/** * * Creates a new filter object by method name. * * @param string $method The method name, e.g. 'sanitizeTrim'. * * @return Solar_Filter_Abstract The new filter object. * */ public function newFilter($method) { $method[0] = strtolower($method[0]); $class = $this->_stack->load($method); $obj = Solar::factory($class, array('filter' => $this)); return $obj; }