Class Sugar

Description

Sugar core class.

Instantiate this class to use Sugar.

Located in /Sugar.php (line 90)


	
			
Class Constant Summary
 CACHE_HTML = 'chtml'
 CACHE_TPL = 'ctpl'
 CHARSET = 1
 DEBUG = 3
 ERRORS = 4
 ERROR_DIE = 102
 ERROR_IGNORE = 103
 ERROR_PRINT = 100
 ERROR_THROW = 101
 OUTPUT = 2
 OUTPUT_HTML = 200
 OUTPUT_TEXT = 203
 OUTPUT_XHTML = 201
 OUTPUT_XML = 202
 VERSION = '0.84'
Variable Summary
string $cacheDir
Sugar_CacheHandler $cacheHandler
string $charset
bool $debug
string $delimEnd
string $delimStart
int $errors
callback $methodAcl
int $output
mixed $pluginDir
mixed $templateDir
Method Summary
bool addFunction (string $name, [callback $invoke = null], [bool $cache = true], [bool $escape = true])
bool addModifier (string $name, [callback $invoke = null])
bool addStorage (string $name, Sugar_StorageDriver $driver)
void clearCache ()
bool display (string $file, [array $vars = null], [string $inherit = null])
bool displayCache (string $file, string $cacheId, [array $vars = null], [string $inherit = null])
bool displayString (string $source, [array $vars = null])
Sugar __construct ()
string escape (string $string)
string fetch (string $file, [array $vars = null], [string $inherit = null])
string fetchCache (string $file, string $cacheId, [array $vars = null], [string $inherit = null])
string fetchString (string $source, [array $vars = null])
Sugar_Runtime getContext ()
array getFunction (string $name)
array getModifier (string $name)
mixed getOption ( $code, int $option)
Sugar_Runtime getRuntime ()
mixed getStorage (string $name)
Sugar_Template getTemplate (string $name, [string $cacheId = null])
mixed getVariable (string $name)
bool handleError ( $e)
bool isCached (string $file, string $cacheId, [array $vars = null])
bool set (string $name, mixed $value)
bool setDelimiter (string $start, string $end)
void setOption ( $code, mixed $value, int $option)
void uncache (string $file, string $cacheId)
Variables
Sugar_CacheDriver $cache = null (line 244)

This is the cache driver to use for storing bytecode and HTML caches.

This is initialized to the Sugar_Cache_File driver by default.

  • access: public
string $cacheDir = './templates/cache' (line 309)

Directory in which bytecode and HTML caches can be stored when using the file cache driver.

  • access: public
Sugar_CacheHandler $cacheHandler = null (line 229)

Cache management. Used internally.

  • access: public
int $cacheLimit = 3600 (line 293)

Maximum age of HTML caches in seconds.

  • access: public
string $charset = 'UTF-8' (line 323)

Character set that output should be in.

  • access: public
bool $debug = false (line 252)

Setting this to true will disable all caching, forcing every template to be recompiled and executed on every load.

  • access: public
string $defaultStorage = 'file' (line 286)

This is the default storage driver to use when no storage driver is specified as part of a template name.

  • access: public
string $delimEnd = '}}' (line 337)

Closing delimiter character.

  • access: public
string $delimStart = '{{' (line 330)

Opening delimiter character.

  • access: public
int $errors (line 265)

This is the error handling method Sugar should use. By default,

errors are echoed to the screen and no exceptions are thrown. Set this to one of the following:

  • access: public
callback $methodAcl (line 344)

Callback for checking method access.

  • access: public
int $output (line 278)

This is the output escaping method to be used. This is necessary for many formats, such as XML and HTML, to ensure that special are escaped properly.

  • access: public
mixed $pluginDir = './plugins' (line 316)

Directory to search for plugins. This can either be a single string or an array.

  • access: public
mixed $templateDir = './templates' (line 301)

Directory in which templates can be found when using the file storage driver. This can either be a single string or an array.

  • access: public
Methods
addFunction (line 439)

Registers a new function to be available within templates.

  • return: true on success
  • access: public
bool addFunction (string $name, [callback $invoke = null], [bool $cache = true], [bool $escape = true])
  • string $name: The name to register the function under.
  • callback $invoke: Optional PHP callback; if null, the $name parameter is used as the callback.
  • bool $cache: Whether the function is cacheable.
  • bool $escape: Whether the function output should be escaped.
addModifier (line 459)

Registers a new modifier to be available within templates.

  • return: true on success
  • access: public
bool addModifier (string $name, [callback $invoke = null])
  • string $name: The name to register the modifier under.
  • callback $invoke: Optional PHP callback; if null, the $name parameter is used as the callback.
addStorage (line 568)

Register a new storage driver.

  • return: true on success
  • access: public
bool addStorage (string $name, Sugar_StorageDriver $driver)
  • string $name: Name to register driver under, used in template references.
  • Sugar_StorageDriver $driver: Driver object to register.
clearCache (line 717)

Clear all HTML cache files.

  • access: public
void clearCache ()
display (line 755)

Load, compile, and display the requested template.

  • return: true on success.
  • deprecated:
  • throws: Sugar_Exception_Usage when the template name is invalid or the template cannot be found.
  • access: public
bool display (string $file, [array $vars = null], [string $inherit = null])
  • string $file: Template to display.
  • array $vars: Additional vars to set during execution.
  • string $inherit: Template to inherit from; overrides source.
displayCache (line 735)

Load, compile, and display a template, caching the result.

  • return: true on success.
  • deprecated:
  • throws: Sugar_Exception_Usage when the template name is invalid.
  • access: public
bool displayCache (string $file, string $cacheId, [array $vars = null], [string $inherit = null])
  • string $file: Template to display.
  • string $cacheId: Cache identifier.
  • array $vars: Additional vars to set during execution.
  • string $inherit: Template to inherit from; overrides source.
displayString (line 810)

Compile and display the template source code given as a string.

It is recommended that this method be avoided in real applications, as it can have drastic performance consequences.

  • return: true on success.
  • deprecated:
bool displayString (string $source, [array $vars = null])
  • string $source: Template code to display.
  • array $vars: Additional vars to set during execution.
Constructor __construct (line 349)

Constructor

  • access: public
Sugar __construct ()
escape (line 609)

Escape the input string according to the current value of Sugar::$charset.

  • return: Escaped output.
  • access: public
string escape (string $string)
  • string $string: String to escape.
fetch (line 792)

Displays a template using Sugar::display, but returns the result as a string instead of displaying it to the user.

  • return: Template output.
  • deprecated:
  • access: public
string fetch (string $file, [array $vars = null], [string $inherit = null])
  • string $file: Template to process.
  • array $vars: Additional vars to set during execution.
  • string $inherit: Template to inherit from; overrides source.
fetchCache (line 773)

Displays a cached template using Sugar::displayCache, but returns the result as a string instead of displaying it to the user.

  • return: Template output.
  • deprecated:
  • access: public
string fetchCache (string $file, string $cacheId, [array $vars = null], [string $inherit = null])
  • string $file: Template to process.
  • string $cacheId: Cache identifier.
  • array $vars: Additional vars to set during execution.
  • string $inherit: Template to inherit from; overrides source.
fetchString (line 829)

Processes template source using Sugar::displayString, but returns the result as a string instead of displaying it to the user.

It is recommended that this method be avoided in real applications, as it can have drastic performance consequences.

  • return: Template output.
  • deprecated:
  • access: public
string fetchString (string $source, [array $vars = null])
  • string $source: Template code to process.
  • array $vars: Additional vars to set during execution.
getContext (line 673)

Get the global variable context.

  • access: public
Sugar_Runtime getContext ()
getFunction (line 491)

Returns an array containing the data for template function. This will first look for registered functions, then it will attempt to auto-register a function using the smarty_function_foo naming scheme. Finally, it will attempt to load a function plugin.

  • access: public
array getFunction (string $name)
  • string $name: Function name to lookup.
getModifier (line 532)

Returns the callback for a template modifier, if it exists. This will first look for registered modifiers, then it will attempt to auto-register a modifier using the smarty_modifier_foo naming scheme. Finally, it will attempt to load a modifier plugin.

  • access: public
array getModifier (string $name)
  • string $name: Modifier name to lookup.
getOption (line 369)

Get the value of an option

  • return: The value to assign to the option.
  • throws: Sugar_Exception_Usage when an invalid option code is given or an invalid value for the specific option is given.
  • access: public
mixed getOption ( $code, int $option)
  • int $option: The option code to lookup.
  • $code
getRuntime (line 663)

Get a runtime instance.

  • access: public
Sugar_Runtime getRuntime ()
getStorage (line 581)

Get a storage driver.

  • return: Sugar_StorageDriver if found, null otherwise.
  • access: public
mixed getStorage (string $name)
  • string $name: Name of driver to look up.
getTemplate (line 687)

Load a template object

  • throws: Sugar_Exception_Usage when the template cannot be found
  • access: public
Sugar_Template getTemplate (string $name, [string $cacheId = null])
  • string $name: Name of template to load
  • string $cacheId: Optional cache ID for template
getVariable (line 476)

Looks up the current value of a variable.

  • access: public
mixed getVariable (string $name)
  • string $name: Name of the variable to lookup.
handleError (line 634)

Process an exception according to the current value of Sugar::$errors.

  • return: true on success
  • access: public
bool handleError ( $e)
  • Exception $e: Exception to process.
isCached (line 848)

Check if a given template has a valid HTML cache. If an HTML cache already exists, applications can avoid expensive database queries and other operations necessary to fill in template data.

  • return: True if a valid HTML cache exists for the file.
  • deprecated:
  • throws: Sugar_Exception_Usage when the template name is invalid.
bool isCached (string $file, string $cacheId, [array $vars = null])
  • string $file: File to check.
  • string $cacheId: Cache identifier.
  • array $vars: Additional vars to set during execution.
set (line 422)

Set a new variable to be available within templates.

  • return: true on success
  • access: public
bool set (string $name, mixed $value)
  • string $name: The variable's name.
  • mixed $value: The variable's value.
setDelimiter (line 594)

Change the current delimiters.

  • return: true on success
  • access: public
bool setDelimiter (string $start, string $end)
  • string $start: Starting delimiter (default '{%')
  • string $end: Ending delimiter (default '%}')
setOption (line 396)

Set the value of an option

  • throws: Sugar_Exception_Usage when an invalid option code is given or an invalid value for the specific option is given.
  • access: public
void setOption ( $code, mixed $value, int $option)
  • int $option: The option code to lookup.
  • mixed $value: The value to assign to the option.
  • $code
uncache (line 870)

Erases the HTML cache for a template if it exists.

  • deprecated:
  • throws: Sugar_Exception_Usage when the template name is invalid.
void uncache (string $file, string $cacheId)
  • string $file: File to check.
  • string $cacheId: Cache identifier.
Class Constants
CACHE_HTML = 'chtml' (line 105)

Passed to cache drivers to indicate that an HTML cache is requested.

CACHE_LIMIT = 5 (line 196)

Cache expiration time in seconds.

The default cache expiration time is 3600 seconds, or one hour.

CACHE_TPL = 'ctpl' (line 100)

Passed to cache drivers to indicate that a compile cache is requested.

CHARSET = 1 (line 161)

Option code for setting or retrieving the charset used during encoding.

The character set default is UTF-8. Another popular value that some applications may need is ISO-8859-1.

DEBUG = 3 (line 179)

Option code to for toggling debug mode.

Debug mode is either true (enabled) or false (disabled). It is disabled by default.

ERRORS = 4 (line 189)

Option code to set or get the error handling mode used during script execution.

The default error handling mode is Sugar::ERROR_PRINT. Other possible values are Sugar::ERROR_THROW, Sugar::ERROR_DIE, and Sugar::ERROR_IGNORE.

ERROR_DIE = 102 (line 123)

The error will be printed to the user, and then die() will be called to terminate the script.

ERROR_IGNORE = 103 (line 128)

The error will be silently ignored.

ERROR_PRINT = 100 (line 112)

Causes all errors generated by Sugar templates to be printed to the user.

No indication of the error is returned to the calling script. This is the default behavior.

ERROR_THROW = 101 (line 117)

Errors will be thrown as Sugar_Exception objects.

OUTPUT = 2 (line 171)

Option code for setting or retrieving the output mode used during escaping.

The default output mode is Sugar::OUTPUT_HTML. Other possible values are Sugar::OUTPUT_XHTML, Sugar::OUTPUT_XML, and Sugar::OUTPUT_TEXT.

OUTPUT_HTML = 200 (line 135)

All output will be escaped using htmlentities() with the ENT_QUOTES flag set, using the Sugar::$charset setting. This is the default behavior.

OUTPUT_TEXT = 203 (line 153)

Disables all output escaping.

OUTPUT_XHTML = 201 (line 140)

Identical to Sugar::OUTPUT_HTML.

OUTPUT_XML = 202 (line 148)

All output will be escaped using htmlspecialchars() with the ENT_QUOTES flag set, using the Sugar::$charset setting. This differs from Sugar::OUTPUT_HTML as only <, >, ", ', and & will escaped.

VERSION = '0.84' (line 95)

Version of Sugar.

Documentation generated on Sat, 18 Sep 2010 05:27:02 +0000 by phpDocumentor 1.4.3