ENHANCEMENT replacing static references with "self::"

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@43655 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Ingo Schommer 2007-10-21 00:39:14 +00:00
parent af68f3f298
commit ac8950e696
2 changed files with 70 additions and 68 deletions

View File

@ -760,7 +760,7 @@ class i18n extends Controller {
*/
static function get_common_languages($native = false) {
$languages = array();
foreach (i18n::$common_languages as $code => $name) {
foreach (self::$common_languages as $code => $name) {
$languages[$code] = ($native ? $name[1] : $name[0]);
}
return $languages;
@ -772,7 +772,7 @@ class i18n extends Controller {
* @return list of languages in the form 'code' => 'name'
*/
static function get_locale_list() {
return i18n::$all_locales;
return self::$all_locales;
}
/**
@ -788,7 +788,7 @@ class i18n extends Controller {
$dbLangs = $query->execute()->column();
$langlist = array_merge((array)Translatable::default_lang(), (array)$dbLangs);
$returnMap = array();
$allCodes = array_merge(i18n::$all_locales, i18n::$common_languages);
$allCodes = array_merge(self::$all_locales, self::$common_languages);
foreach ($langlist as $langCode) {
$returnMap[$langCode] = (is_array($allCodes[$langCode]) ? $allCodes[$langCode][0] : $allCodes[$langCode]);
}
@ -831,7 +831,7 @@ class i18n extends Controller {
* @return Name of the language
*/
static function get_language_name($code, $native = false) {
$langs = i18n::$common_languages;
$langs = self::$common_languages;
return ($native ? $langs[$code][1] : $langs[$code][0]);
}
@ -842,7 +842,7 @@ class i18n extends Controller {
* @return Name of the locale
*/
static function get_locale_name($code) {
$langs = i18n::get_locale_list();
$langs = self::get_locale_list();
return isset($langs[$code]) ? $langs[$code] : false;
}
@ -853,7 +853,7 @@ class i18n extends Controller {
* @return Language code (if the name is not found, it'll return the passed name)
*/
static function get_language_code($name) {
$code = array_search($name,i18n::get_common_languages());
$code = array_search($name,self::get_common_languages());
return ($code ? $code : $name);
}
@ -863,8 +863,8 @@ class i18n extends Controller {
* @return Language
*/
static function get_tinymce_lang() {
if(isset(i18n::$tinymce_lang[i18n::get_locale()])) {
return i18n::$tinymce_lang[i18n::get_locale()];
if(isset(self::$tinymce_lang[self::get_locale()])) {
return self::$tinymce_lang[self::get_locale()];
}
return 'en';
@ -887,7 +887,7 @@ class i18n extends Controller {
if(
is_dir($moduleDir)
&& is_file($moduleDir . DIRECTORY_SEPARATOR . "_config.php")
&& is_file($moduleDir . DIRECTORY_SEPARATOR . "lang" . DIRECTORY_SEPARATOR . i18n::$default_locale . ".php")
&& is_file($moduleDir . DIRECTORY_SEPARATOR . "lang" . DIRECTORY_SEPARATOR . self::$default_locale . ".php")
) {
$translatableModules[] = $module;
}
@ -909,18 +909,18 @@ class i18n extends Controller {
&& !in_array($module, array('sapphire','jsparty')) && substr($module,0,1) != '.') {
$fileList = array();
i18n::get_files_rec("$baseDir/$module/code", $fileList);
self::get_files_rec("$baseDir/$module/code", $fileList);
$mst = '';
foreach($fileList as $file) {
$mst .= i18n::report_calls_code($file);
$mst .= self::report_calls_code($file);
}
$fileList = NULL;
// Make sure the templates directory exists before trying to open it
if (is_dir("$baseDir/$module/templates")) {
i18n::get_files_rec("$baseDir/$module/templates", $fileList);
self::get_files_rec("$baseDir/$module/templates", $fileList);
foreach($fileList as $index => $file) {
$mst .= i18n::report_calls_tpl($index, $file);
$mst .= self::report_calls_tpl($index, $file);
}
}
@ -957,7 +957,7 @@ class i18n extends Controller {
if(substr($item,0,1) == '.') continue;
if(substr($item,-4) == '.php') $fileList[substr($item,0,-4)] = "$folder/$item";
else if(substr($item,-3) == '.ss') $fileList[$item] = "$folder/$item";
else if(is_dir("$folder/$item")) i18n::get_files_rec("$folder/$item", $fileList);
else if(is_dir("$folder/$item")) self::get_files_rec("$folder/$item", $fileList);
}
}
@ -1043,7 +1043,7 @@ class i18n extends Controller {
* @param string $locale Locale to be set
*/
static function set_locale($locale) {
if ($locale) i18n::$current_locale = $locale;
if ($locale) self::$current_locale = $locale;
}
/**
@ -1052,9 +1052,11 @@ class i18n extends Controller {
* @return string Current locale in the system
*/
static function get_locale() {
return i18n::$current_locale;
return self::$current_locale;
}
/**
* Include a locale file determined by module name and locale
*
@ -1098,11 +1100,11 @@ class i18n extends Controller {
$path = $_CLASS_MANIFEST[$class];
ereg('.*/([^/]+)/code/',$path,$module);
}
if (file_exists($file = Director::getAbsFile("{$module[1]}/lang/". i18n::get_locale() . '.php'))) {
if (file_exists($file = Director::getAbsFile("{$module[1]}/lang/". self::get_locale() . '.php'))) {
include_once($file);
} else if (i18n::get_locale() != 'en_US') {
i18n::set_locale('en_US');
i18n::include_by_class($class);
} else if (self::get_locale() != 'en_US') {
self::set_locale('en_US');
self::include_by_class($class);
} else {
user_error("Locale file $file should exist", E_USER_WARNING);
}
@ -1140,10 +1142,10 @@ class i18n extends Controller {
if (!isset($_GET['module'])) {
$topLevel = scandir($baseDir);
foreach($topLevel as $module) {
i18n::process_module($baseDir, $module);
self::process_module($baseDir, $module);
}
} else {
i18n::process_module($baseDir, $_GET['module']);
self::process_module($baseDir, $_GET['module']);
}
echo "Done!";

View File

@ -73,8 +73,8 @@ class Translatable extends DataObjectDecorator {
* @return boolean Returns true if $table exists.
*/
static function table_exists($table) {
if (!Translatable::$tableList) Translatable::$tableList = DB::tableList();
return isset(Translatable::$tableList[strtolower($table)]);
if (!self::$tableList) self::$tableList = DB::tableList();
return isset(self::$tableList[strtolower($table)]);
}
/**
@ -85,15 +85,15 @@ class Translatable extends DataObjectDecorator {
static function choose_site_lang() {
if(isset($_GET['lang'])) {
$_GET['lang'] = strtolower($_GET['lang']);
Translatable::set_reading_lang($_GET['lang']);
self::set_reading_lang($_GET['lang']);
}
else if($lang = Session::get('currentLang')) {
Translatable::set_reading_lang($lang);
self::set_reading_lang($lang);
}
else if (($member = Member::currentUser()) && ($lang = $member->Lang)) {
Translatable::set_reading_lang($lang);
self::set_reading_lang($lang);
}
Translatable::$language_decided = true;
self::$language_decided = true;
}
/**
@ -101,7 +101,7 @@ class Translatable extends DataObjectDecorator {
* @return string
*/
static function default_lang() {
return Translatable::$default_lang;
return self::$default_lang;
}
/**
@ -109,7 +109,7 @@ class Translatable extends DataObjectDecorator {
* @return boolean Return true if both default and reading language are the same.
*/
static function is_default_lang() {
return (!Translatable::current_lang() || Translatable::$default_lang == Translatable::current_lang());
return (!self::current_lang() || self::$default_lang == self::current_lang());
}
/**
@ -117,8 +117,8 @@ class Translatable extends DataObjectDecorator {
* @return string
*/
static function current_lang() {
if (!Translatable::$language_decided) Translatable::choose_site_lang();
return Translatable::$reading_lang;
if (!self::$language_decided) self::choose_site_lang();
return self::$reading_lang;
}
/**
@ -127,7 +127,7 @@ class Translatable extends DataObjectDecorator {
*/
static function set_reading_lang($lang) {
Session::set('currentLang',$lang);
Translatable::$reading_lang = $lang;
self::$reading_lang = $lang;
}
/**
@ -138,10 +138,10 @@ class Translatable extends DataObjectDecorator {
* @return DataObject
*/
static function get_one_by_lang($class, $lang, $filter = '') {
$oldLang = Translatable::current_lang();
Translatable::set_reading_lang($lang);
$oldLang = self::current_lang();
self::set_reading_lang($lang);
$result = DataObject::get_one($class, $filter, false);
Translatable::set_reading_lang($oldLang);
self::set_reading_lang($oldLang);
return $result;
}
@ -153,16 +153,16 @@ class Translatable extends DataObjectDecorator {
* @return DataObject
*/
static function get_one($callerClass, $filter = "") {
Translatable::$language_decided = true;Translatable::$reading_lang = Translatable::default_lang();
self::$language_decided = true;self::$reading_lang = self::default_lang();
$record = DataObject::get_one($callerClass, $filter);
if (!$record) {
Translatable::$bypass = true;
self::$bypass = true;
$record = DataObject::get_one($callerClass, $filter, false);
Translatable::$bypass = false;
if ($record) Translatable::set_reading_lang($record->Lang);
self::$bypass = false;
if ($record) self::set_reading_lang($record->Lang);
} else {
$langsAvailable = (array)Translatable::get_langs_by_id($callerClass, $record->ID);
$langsAvailable[] = Translatable::default_lang();
$langsAvailable = (array)self::get_langs_by_id($callerClass, $record->ID);
$langsAvailable[] = self::default_lang();
if(isset($_GET['lang']) && array_search(strtolower($_GET['lang']),$langsAvailable) !== false) {
$lang = strtolower($_GET['lang']);
} else if(($possible = Session::get('currentLang')) && array_search($possible,$langsAvailable)) {
@ -171,9 +171,9 @@ class Translatable extends DataObjectDecorator {
$lang = $possible;
}
if (isset($lang)) {
$transrecord = Translatable::get_one_by_lang($callerClass, $lang, "`$callerClass`.ID = $record->ID");
$transrecord = self::get_one_by_lang($callerClass, $lang, "`$callerClass`.ID = $record->ID");
if ($transrecord) {
Translatable::set_reading_lang($lang);
self::set_reading_lang($lang);
$record = $transrecord;
}
}
@ -191,10 +191,10 @@ class Translatable extends DataObjectDecorator {
* @return mixed The objects matching the conditions.
*/
static function get_by_lang($class, $lang, $filter = '', $sort = '') {
$oldLang = Translatable::current_lang();
Translatable::set_reading_lang($lang);
$oldLang = self::current_lang();
self::set_reading_lang($lang);
$result = DataObject::get($class, $filter, $sort);
Translatable::set_reading_lang($oldLang);
self::set_reading_lang($oldLang);
return $result;
}
@ -207,7 +207,7 @@ class Translatable extends DataObjectDecorator {
static function get_original($class, $originalLangID) {
$baseClass = $class;
while( ($p = get_parent_class($baseClass)) != "DataObject") $baseClass = $p;
return Translatable::get_one_by_lang($class,Translatable::default_lang(),"`$baseClass`.ID = $originalLangID");
return self::get_one_by_lang($class,self::default_lang(),"`$baseClass`.ID = $originalLangID");
}
/**
@ -230,10 +230,10 @@ class Translatable extends DataObjectDecorator {
* @param string $lang The name of the language
*/
static function write(DataObject $object, $lang) {
$oldLang = Translatable::current_lang();
Translatable::set_reading_lang($lang);
$oldLang = self::current_lang();
self::set_reading_lang($lang);
$result = $object->write();
Translatable::set_reading_lang($oldLang);
self::set_reading_lang($oldLang);
}
/**
@ -241,7 +241,7 @@ class Translatable extends DataObjectDecorator {
*
*/
static function enable() {
Translatable::$enabled = true;
self::$enabled = true;
}
/**
@ -249,7 +249,7 @@ class Translatable extends DataObjectDecorator {
*
*/
static function disable() {
Translatable::$enabled = false;
self::$enabled = false;
}
/**
@ -258,7 +258,7 @@ class Translatable extends DataObjectDecorator {
* @return boolean True if enabled
*/
static function is_enabled() {
return Translatable::$enabled;
return self::$enabled;
}
/**
@ -267,7 +267,7 @@ class Translatable extends DataObjectDecorator {
* @param int $id
*/
static function creating_from($id) {
Translatable::$creatingFromID = $id;
self::$creatingFromID = $id;
}
@ -290,13 +290,13 @@ class Translatable extends DataObjectDecorator {
function augmentSQL(SQLQuery &$query) {
if (! $this->stat('enabled')) return false;
if((($lang = Translatable::current_lang()) && !Translatable::is_default_lang()) || Translatable::$bypass) {
if((($lang = self::current_lang()) && !self::is_default_lang()) || self::$bypass) {
foreach($query->from as $table => $dummy) {
if(!isset($baseTable)) {
$baseTable = $table;
}
if (Translatable::table_exists("{$table}_lang")) {
if (self::table_exists("{$table}_lang")) {
$query->renameTable($table, $table . '_lang');
if (stripos($query->sql(),'.ID')) {
// Every reference to ID is now OriginalLangID
@ -339,7 +339,7 @@ class Translatable extends DataObjectDecorator {
}
// unless we are bypassing this query, add the language filter
if (!Translatable::$bypass) $query->where[] = "`{$table}_lang`.Lang = '$lang'";
if (!self::$bypass) $query->where[] = "`{$table}_lang`.Lang = '$lang'";
// unless this is a deletion, the query is applied to the joined table
if (!$query->delete) {
@ -402,7 +402,7 @@ class Translatable extends DataObjectDecorator {
function augmentDatabase() {
if (! $this->stat('enabled')) return false;
Translatable::set_reading_lang(Translatable::default_lang());
self::set_reading_lang(self::default_lang());
$table = $this->owner->class;
if(($fields = $this->owner->databaseFields()) && $this->hasOwnTranslatableFields()) {
@ -441,17 +441,17 @@ class Translatable extends DataObjectDecorator {
*/
function augmentWrite(&$manipulation) {
if (! $this->stat('enabled')) return false;
if(($lang = Translatable::current_lang()) && !Translatable::is_default_lang()) {
if(($lang = self::current_lang()) && !self::is_default_lang()) {
$tables = array_keys($manipulation);
foreach($tables as $table) {
if (Translatable::table_exists("{$table}_lang")) {
if (self::table_exists("{$table}_lang")) {
$manipulation["{$table}_lang"] = $manipulation[$table];
if ($manipulation[$table]['command'] == 'insert') {
$fakeID = $this->owner->ID;
// In an insert we've to populate our fields and generate a new id (since the passed one it's relative to $table)
$SessionOrigID = Session::get($this->owner->ID.'_originalLangID');
$manipulation["{$table}_lang"]['fields']['OriginalLangID'] = $this->owner->ID =
( $SessionOrigID ? $SessionOrigID : Translatable::$creatingFromID);
( $SessionOrigID ? $SessionOrigID : self::$creatingFromID);
$manipulation["{$table}_lang"]['RecordID'] = $manipulation["{$table}_lang"]['fields']['OriginalLangID'];
// populate lang field
$manipulation["{$table}_lang"]['fields']['Lang'] = "'$lang'" ;
@ -508,7 +508,7 @@ class Translatable extends DataObjectDecorator {
$baseClass = $this->owner->class;
while( ($p = get_parent_class($baseClass)) != "DataObject") $baseClass = $p;
$allFields = $this->owner->getAllFields();
if(!Translatable::is_default_lang()) {
if(!self::is_default_lang()) {
// Get the original version record, to show the original values
if (!is_numeric($allFields['ID'])) {
$originalLangID = Session::get($this->owner->ID . '_originalLangID');
@ -516,9 +516,9 @@ class Translatable extends DataObjectDecorator {
} else {
$originalLangID = $allFields['ID'];
}
$originalRecord = Translatable::get_one_by_lang(
$originalRecord = self::get_one_by_lang(
$this->owner->class,
Translatable::$default_lang,
self::$default_lang,
"`$baseClass`.ID = ".$originalLangID
);
$this->original_values = $originalRecord->getAllFields();
@ -538,7 +538,7 @@ class Translatable extends DataObjectDecorator {
} else {
$alreadyTranslatedLangs = null;
if (is_numeric($allFields['ID'])) {
$alreadyTranslatedLangs = Translatable::get_langs_by_id($baseClass,$allFields['ID']);
$alreadyTranslatedLangs = self::get_langs_by_id($baseClass,$allFields['ID']);
}
if (!$alreadyTranslatedLangs) $alreadyTranslatedLangs = array();
foreach ($alreadyTranslatedLangs as $i => $langCode) {
@ -681,8 +681,8 @@ class Translatable extends DataObjectDecorator {
* @return string Extended table name
*/
function extendWithSuffix($table) {
if((($lang = Translatable::current_lang()) && !Translatable::is_default_lang())) {
if (Translatable::table_exists("{$table}_lang")) return $table.'_lang';
if((($lang = self::current_lang()) && !self::is_default_lang())) {
if (self::table_exists("{$table}_lang")) return $table.'_lang';
}
return $table;
}