mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2025-07-30 19:00:10 +02:00
PSR-2 reformatting PHPDoc corrections
With minor corrections. Signed-off-by: Marcus Bointon <marcus@synchromedia.co.uk> Signed-off-by: Edward Z. Yang <ezyang@mit.edu>
This commit is contained in:
committed by
Edward Z. Yang
parent
19eee14899
commit
fac747bdbd
@@ -8,22 +8,26 @@ class HTMLPurifier_Language
|
||||
{
|
||||
|
||||
/**
|
||||
* ISO 639 language code of language. Prefers shortest possible version
|
||||
* ISO 639 language code of language. Prefers shortest possible version.
|
||||
* @type string
|
||||
*/
|
||||
public $code = 'en';
|
||||
|
||||
/**
|
||||
* Fallback language code
|
||||
* Fallback language code.
|
||||
* @type bool|string
|
||||
*/
|
||||
public $fallback = false;
|
||||
|
||||
/**
|
||||
* Array of localizable messages
|
||||
* Array of localizable messages.
|
||||
* @type array
|
||||
*/
|
||||
public $messages = array();
|
||||
|
||||
/**
|
||||
* Array of localizable error codes
|
||||
* Array of localizable error codes.
|
||||
* @type array
|
||||
*/
|
||||
public $errorNames = array();
|
||||
|
||||
@@ -31,21 +35,33 @@ class HTMLPurifier_Language
|
||||
* True if no message file was found for this language, so English
|
||||
* is being used instead. Check this if you'd like to notify the
|
||||
* user that they've used a non-supported language.
|
||||
* @type bool
|
||||
*/
|
||||
public $error = false;
|
||||
|
||||
/**
|
||||
* Has the language object been loaded yet?
|
||||
* @type bool
|
||||
* @todo Make it private, fix usage in HTMLPurifier_LanguageTest
|
||||
*/
|
||||
public $_loaded = false;
|
||||
|
||||
/**
|
||||
* Instances of HTMLPurifier_Config and HTMLPurifier_Context
|
||||
* @type HTMLPurifier_Config
|
||||
*/
|
||||
protected $config, $context;
|
||||
protected $config;
|
||||
|
||||
public function __construct($config, $context) {
|
||||
/**
|
||||
* @type HTMLPurifier_Context
|
||||
*/
|
||||
protected $context;
|
||||
|
||||
/**
|
||||
* @param HTMLPurifier_Config $config
|
||||
* @param HTMLPurifier_Context $context
|
||||
*/
|
||||
public function __construct($config, $context)
|
||||
{
|
||||
$this->config = $config;
|
||||
$this->context = $context;
|
||||
}
|
||||
@@ -54,8 +70,11 @@ class HTMLPurifier_Language
|
||||
* Loads language object with necessary info from factory cache
|
||||
* @note This is a lazy loader
|
||||
*/
|
||||
public function load() {
|
||||
if ($this->_loaded) return;
|
||||
public function load()
|
||||
{
|
||||
if ($this->_loaded) {
|
||||
return;
|
||||
}
|
||||
$factory = HTMLPurifier_LanguageFactory::instance();
|
||||
$factory->loadLanguage($this->code);
|
||||
foreach ($factory->keys as $key) {
|
||||
@@ -66,31 +85,43 @@ class HTMLPurifier_Language
|
||||
|
||||
/**
|
||||
* Retrieves a localised message.
|
||||
* @param $key string identifier of message
|
||||
* @param string $key string identifier of message
|
||||
* @return string localised message
|
||||
*/
|
||||
public function getMessage($key) {
|
||||
if (!$this->_loaded) $this->load();
|
||||
if (!isset($this->messages[$key])) return "[$key]";
|
||||
public function getMessage($key)
|
||||
{
|
||||
if (!$this->_loaded) {
|
||||
$this->load();
|
||||
}
|
||||
if (!isset($this->messages[$key])) {
|
||||
return "[$key]";
|
||||
}
|
||||
return $this->messages[$key];
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a localised error name.
|
||||
* @param $int integer error number, corresponding to PHP's error
|
||||
* reporting
|
||||
* @param int $int error number, corresponding to PHP's error reporting
|
||||
* @return string localised message
|
||||
*/
|
||||
public function getErrorName($int) {
|
||||
if (!$this->_loaded) $this->load();
|
||||
if (!isset($this->errorNames[$int])) return "[Error: $int]";
|
||||
public function getErrorName($int)
|
||||
{
|
||||
if (!$this->_loaded) {
|
||||
$this->load();
|
||||
}
|
||||
if (!isset($this->errorNames[$int])) {
|
||||
return "[Error: $int]";
|
||||
}
|
||||
return $this->errorNames[$int];
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts an array list into a string readable representation
|
||||
* @param array $array
|
||||
* @return string
|
||||
*/
|
||||
public function listify($array) {
|
||||
public function listify($array)
|
||||
{
|
||||
$sep = $this->getMessage('Item separator');
|
||||
$sep_last = $this->getMessage('Item separator last');
|
||||
$ret = '';
|
||||
@@ -108,15 +139,20 @@ class HTMLPurifier_Language
|
||||
|
||||
/**
|
||||
* Formats a localised message with passed parameters
|
||||
* @param $key string identifier of message
|
||||
* @param $args Parameters to substitute in
|
||||
* @param string $key string identifier of message
|
||||
* @param array $args Parameters to substitute in
|
||||
* @return string localised message
|
||||
* @todo Implement conditionals? Right now, some messages make
|
||||
* reference to line numbers, but those aren't always available
|
||||
*/
|
||||
public function formatMessage($key, $args = array()) {
|
||||
if (!$this->_loaded) $this->load();
|
||||
if (!isset($this->messages[$key])) return "[$key]";
|
||||
public function formatMessage($key, $args = array())
|
||||
{
|
||||
if (!$this->_loaded) {
|
||||
$this->load();
|
||||
}
|
||||
if (!isset($this->messages[$key])) {
|
||||
return "[$key]";
|
||||
}
|
||||
$raw = $this->messages[$key];
|
||||
$subst = array();
|
||||
$generator = false;
|
||||
@@ -124,9 +160,15 @@ class HTMLPurifier_Language
|
||||
if (is_object($value)) {
|
||||
if ($value instanceof HTMLPurifier_Token) {
|
||||
// factor this out some time
|
||||
if (!$generator) $generator = $this->context->get('Generator');
|
||||
if (isset($value->name)) $subst['$'.$i.'.Name'] = $value->name;
|
||||
if (isset($value->data)) $subst['$'.$i.'.Data'] = $value->data;
|
||||
if (!$generator) {
|
||||
$generator = $this->context->get('Generator');
|
||||
}
|
||||
if (isset($value->name)) {
|
||||
$subst['$'.$i.'.Name'] = $value->name;
|
||||
}
|
||||
if (isset($value->data)) {
|
||||
$subst['$'.$i.'.Data'] = $value->data;
|
||||
}
|
||||
$subst['$'.$i.'.Compact'] =
|
||||
$subst['$'.$i.'.Serialized'] = $generator->generateFromToken($value);
|
||||
// a more complex algorithm for compact representation
|
||||
@@ -157,7 +199,6 @@ class HTMLPurifier_Language
|
||||
}
|
||||
return strtr($raw, $subst);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// vim: et sw=4 sts=4
|
||||
|
Reference in New Issue
Block a user