Example #1
0
 /**
  * Adds an external tag to the Hydrogen template engine.  Once added,
  * the tag can be used in any Hydrogen template file for the duration
  * of that request.
  *
  * @param string $tagName The name of the tag to add.  The name is
  * 		what will be typed in the template files themselves.
  * @param string $className The class name (with namespace) of this
  * 		tag.  The tag must extend the class
  * 		{@link \hydrogen\view\engines\hydrogen\Tag}.
  * @param string $path The path to the PHP to require_once before using
  * 		the given class, either absolute or relative to the base_url
  * 		defined in the hydrogen.autoconfig.php file.  This argument is
  * 		OPTIONAL: if omitted, Hydrogen will assume the class will be
  * 		automatically loaded when accessed.
  */
 public static function addTag($tagName, $className, $path = false)
 {
     $tagName = strtolower($tagName);
     static::$tagClass[$tagName] = static::formatNamespace($className, false);
     if ($path) {
         static::$tagPath[$tagName] = Config::getAbsolutePath($path);
     }
 }
Example #2
0
 public function __construct()
 {
     $logdir = Config::getVal('log', 'logdir');
     $prefix = Config::getVal('log', 'fileprefix', false) ?: 'log';
     $filename = $prefix . date('ymd') . '.log';
     // Get our path relative to the config file
     $logdir = Config::getAbsolutePath($logdir);
     // Add the trailing slash if necessary
     if ($logdir[strlen($logdir) - 1] != DIRECTORY_SEPARATOR) {
         $logdir .= DIRECTORY_SEPARATOR;
     }
     $this->logfile = $logdir . $filename;
 }
Example #3
0
 /**
  * Loads and displays the specified view, making available all of the
  * variables set with {@link #setVar} as well as any passed in the
  * $varArray argument.
  *
  * The view name to be loaded is the name of the .php file in the
  * views folder, without the .php on the end.  So if your views folder contains
  * a file named "homepage.php", it can be loaded by submitting "homepage" as
  * the $viewName argument.  If the views folder contains a folder named blog, and
  * inside of that a file named "summary.php", that view can be loaded using the
  * name "blog/summary".
  *
  * The views folder is specified in the configuration file like this:
  *
  * <pre>
  * [view]
  * folder = /path/to/views/folder
  * </pre>
  *
  * Although, this setting and the other view settings may be better placed in
  * Hydrogen's autoconfig file as direct calls to the Config library, since these
  * are not typically things that end users should set themselves.
  *
  * @param viewName string The name of the view to load, as described above.
  * @param varArray array|boolean An optional array of variables to pass into
  * 		the loaded view.
  */
 public static function load($viewName, $varArray = false)
 {
     if (is_array($varArray)) {
         static::setVar($varArray);
     }
     if (static::$view === false) {
         static::$view = new View();
     }
     $path = Config::getRequiredVal("view", "folder") . DIRECTORY_SEPARATOR . "{$viewName}.php";
     $path = Config::getAbsolutePath($path);
     static::$view->display($path);
 }
Example #4
0
 /**
  * Translates a view name into an absolute path at which the view can
  * be found.
  *
  * @param string viewName The name of the view to be found.
  * @return string The absolute path to the requested view.
  */
 public function getViewPath($viewName)
 {
     $path = Config::getRequiredVal("view", "folder") . '/' . $viewName . Config::getRequiredVal("view", "file_extension");
     return Config::getAbsolutePath($path);
 }
Example #5
0
 /**
  * Registers a new namespace with the autoloader.  As soon as this
  * function is called, classes within that namespace (or within
  * child namespaces within that namespace) will be autoloaded.
  *
  * Note that it's expected that the namespace being added will follow the
  * proper convention for file organization: the folder structure should
  * match the namespace exactly, so that a class named something like
  * myapp\models\exceptions\UserNotFoundException would be found in
  * models/exceptions/UserNotFoundException.php within the root folder
  * for the 'myapp' namespace.
  *
  * The Autoloader also supports replacing underscores in a filename with
  * directory separators, which is useful for compatibility with old code
  * written with a Zend-style autoloader.  This feature is optional on a
  * per-namespace basis.
  *
  * The root folder supplied to this function should point to the first
  * folder of the namespace itself.  For example, if the above PHP file were
  * located at this path:
  * [webroot]/lib/myapp/models/exceptions/UserNotFoundException.php
  * then the namespace would be 'myapp' and the root folder would be
  * 'lib/myapp'.
  *
  * @param string $namespace The root namespace for which classes should be
  * 		autoloaded.
  * @param string $rootFolder The folder that the namespace's files reside
  * 		in.  Relative paths will be evaluated relative to the base path set
  * 		in the autoconfig.
  * @param boolean $replaceUnderscores true to replace any underscores in
  * 		the class name with directory separators when loading; false to
  * 		treat them as part of the file name.
  */
 public static function registerNamespace($namespace, $rootFolder, $replaceUnderscores = true)
 {
     $rootFolder = Config::getAbsolutePath($rootFolder);
     $rootFolder = rtrim($rootFolder, DIRECTORY_SEPARATOR);
     static::$namespaces[$namespace] = array($rootFolder, $replaceUnderscores);
     static::register();
 }