mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
"Closes #1854, Core.po not loaded when using /app/locale/..../default.po
Closes #3539 Fixes #3611, Cannot redeclare loadmodels Fixes #3622, loadControllers() and loadModels() look in wrong folders for AppController resp. AppModel Added trigger_error to all deprecated functions in basics.php Refactored I18n class to remove debug_backtrace() usage in basics.php, all translations should be placed in a default.po or .mo file from this point forward. _ _d() function should be used if domain specific translations are used. Core translations can be placed in app/locales/{lang}/LC_MESSAGES/core.po or .mo these will now be merged with the specified language strings from default.po will replace the core message strings All translations are now cached to improve performance. " git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6065 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
2eef50c90b
commit
de8e7d8b01
9 changed files with 265 additions and 281 deletions
281
cake/basics.php
281
cake/basics.php
|
@ -48,58 +48,6 @@ if (!function_exists('clone')) {
|
|||
}');
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Loads all models, or set of specified models.
|
||||
* E.g:
|
||||
*
|
||||
* loadModels() - Loads all models
|
||||
* loadModels('User', 'Group') loads models User & Group
|
||||
*/
|
||||
function loadModels() {
|
||||
if (!class_exists('Model')) {
|
||||
require LIBS . 'model' . DS . 'model.php';
|
||||
}
|
||||
if (!class_exists('AppModel')) {
|
||||
if (file_exists(APP . 'app_model.php')) {
|
||||
require(APP . 'app_model.php');
|
||||
} else {
|
||||
require(CAKE . 'app_model.php');
|
||||
}
|
||||
Overloadable::overload('AppModel');
|
||||
}
|
||||
|
||||
$loadModels = array();
|
||||
if (func_num_args() > 0) {
|
||||
$args = func_get_args();
|
||||
foreach($args as $arg) {
|
||||
if (is_array($arg)) {
|
||||
$loadModels = am($loadModels, $arg);
|
||||
} else {
|
||||
$loadModels[] = $arg;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$loadedModels = array();
|
||||
$path = Configure::getInstance();
|
||||
foreach ($path->modelPaths as $path) {
|
||||
foreach (listClasses($path) as $modelFilename) {
|
||||
list($name) = explode('.', $modelFilename);
|
||||
$className = Inflector::camelize($name);
|
||||
|
||||
if (empty($loadModels) || in_array($className, $loadModels)) {
|
||||
$loadedModels[$modelFilename] = $modelFilename;
|
||||
}
|
||||
|
||||
if (isset($loadedModels[$modelFilename]) && !class_exists($className)) {
|
||||
require($path . $modelFilename);
|
||||
list($name) = explode('.', $modelFilename);
|
||||
Overloadable::overload(Inflector::camelize($name));
|
||||
}
|
||||
}
|
||||
}
|
||||
return $loadedModels;
|
||||
}
|
||||
/**
|
||||
* Get CakePHP basic paths as an indexed array.
|
||||
* Resulting array will contain array of paths
|
||||
|
@ -150,51 +98,6 @@ if (!function_exists('clone')) {
|
|||
}
|
||||
return $paths;
|
||||
}
|
||||
/**
|
||||
* Loads all controllers.
|
||||
*
|
||||
* @return array Set of loaded controllers
|
||||
*/
|
||||
function loadControllers() {
|
||||
$paths = Configure::getInstance();
|
||||
if (!class_exists('AppController')) {
|
||||
if (file_exists(APP . 'app_controller.php')) {
|
||||
require(APP . 'app_controller.php');
|
||||
} else {
|
||||
require(CAKE . 'app_controller.php');
|
||||
}
|
||||
}
|
||||
$loadedControllers = array();
|
||||
|
||||
foreach ($paths->controllerPaths as $path) {
|
||||
foreach (listClasses($path) as $controller) {
|
||||
list($name) = explode('.', $controller);
|
||||
$className = Inflector::camelize(str_replace('_controller', '', $name));
|
||||
|
||||
if (loadController($className)) {
|
||||
$loadedControllers[$controller] = $className;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $loadedControllers;
|
||||
}
|
||||
/**
|
||||
* Returns an array of filenames of PHP files in given directory.
|
||||
*
|
||||
* @param string $path Path to scan for files
|
||||
* @return array List of files in directory
|
||||
*/
|
||||
function listClasses($path) {
|
||||
$dir = opendir($path);
|
||||
$classes = array();
|
||||
while (false !== ($file = readdir($dir))) {
|
||||
if ((substr($file, -3, 3) == 'php') && substr($file, 0, 1) != '.') {
|
||||
$classes[] = $file;
|
||||
}
|
||||
}
|
||||
closedir($dir);
|
||||
return $classes;
|
||||
}
|
||||
/**
|
||||
* Loads configuration files. Receives a set of configuration files
|
||||
* to load.
|
||||
|
@ -777,14 +680,11 @@ if (!function_exists('clone')) {
|
|||
if (!class_exists('I18n')) {
|
||||
App::import('Core', 'i18n');
|
||||
}
|
||||
$calledFrom = debug_backtrace();
|
||||
$dir = dirname($calledFrom[0]['file']);
|
||||
unset($calledFrom);
|
||||
|
||||
if ($return === false) {
|
||||
echo I18n::translate($singular, null, null, 5, null, $dir);
|
||||
echo I18n::translate($singular);
|
||||
} else {
|
||||
return I18n::translate($singular, null, null, 5, null, $dir);
|
||||
return I18n::translate($singular);
|
||||
}
|
||||
}
|
||||
/**
|
||||
|
@ -804,14 +704,11 @@ if (!function_exists('clone')) {
|
|||
if (!class_exists('I18n')) {
|
||||
App::import('Core', 'i18n');
|
||||
}
|
||||
$calledFrom = debug_backtrace();
|
||||
$dir = dirname($calledFrom[0]['file']);
|
||||
unset($calledFrom);
|
||||
|
||||
if ($return === false) {
|
||||
echo I18n::translate($singular, $plural, null, 5, $count, $dir);
|
||||
echo I18n::translate($singular, $plural, null, 5, $count);
|
||||
} else {
|
||||
return I18n::translate($singular, $plural, null, 5, $count, $dir);
|
||||
return I18n::translate($singular, $plural, null, 5, $count);
|
||||
}
|
||||
}
|
||||
/**
|
||||
|
@ -963,14 +860,11 @@ if (!function_exists('clone')) {
|
|||
if (!class_exists('I18n')) {
|
||||
App::import('Core', 'i18n');
|
||||
}
|
||||
$calledFrom = debug_backtrace();
|
||||
$dir = dirname($calledFrom[0]['file']);
|
||||
unset($calledFrom);
|
||||
|
||||
if ($return === false) {
|
||||
echo I18n::translate($msg, null, null, $category, null, $dir);
|
||||
echo I18n::translate($msg, null, null, $category);
|
||||
} else {
|
||||
return I18n::translate($msg, null, null, $category, null, $dir);
|
||||
return I18n::translate($msg, null, null, $category);
|
||||
}
|
||||
}
|
||||
/**
|
||||
|
@ -1126,6 +1020,95 @@ if (!function_exists('clone')) {
|
|||
}
|
||||
return $val2;
|
||||
}
|
||||
/**
|
||||
* @deprecated
|
||||
* @see App::import('View', 'ViewName');
|
||||
*/
|
||||
function loadView($name) {
|
||||
trigger_error('loadView is deprecated see App::import(\'View\', \'ViewName\');', E_USER_WARNING);
|
||||
return App::import('View', $name);
|
||||
}
|
||||
/**
|
||||
* @deprecated
|
||||
* @see App::import('Model', 'ModelName');
|
||||
*/
|
||||
function loadModel($name = null) {
|
||||
trigger_error('loadModel is deprecated see App::import(\'Model\', \'ModelName\');', E_USER_WARNING);
|
||||
return App::import('Model', $name);
|
||||
}
|
||||
/**
|
||||
* @deprecated
|
||||
* @see App::import('Controller', 'ControllerName');
|
||||
*/
|
||||
function loadController($name) {
|
||||
trigger_error('loadController is deprecated see App::import(\'Controller\', \'ControllerName\');', E_USER_WARNING);
|
||||
return App::import('Controller', $name);
|
||||
}
|
||||
/**
|
||||
* @deprecated
|
||||
* @see App::import('Helper', 'HelperName');
|
||||
*/
|
||||
function loadHelper($name) {
|
||||
trigger_error('loadHelper is deprecated see App::import(\'Helper\', \'PluginName.HelperName\');', E_USER_WARNING);
|
||||
return App::import('Helper', $name);
|
||||
}
|
||||
/**
|
||||
* @deprecated
|
||||
* @see App::import('Helper', 'PluginName.HelperName');
|
||||
*/
|
||||
function loadPluginHelper($plugin, $helper) {
|
||||
trigger_error('loadPluginHelper is deprecated see App::import(\'Helper\', \'PluginName.HelperName\');', E_USER_WARNING);
|
||||
return App::import('Helper', $plugin . '.' . $helper);
|
||||
}
|
||||
/**
|
||||
* @deprecated
|
||||
* @see App::import('Component', 'ComponentName');
|
||||
*/
|
||||
function loadComponent($name) {
|
||||
trigger_error('loadComponent is deprecated see App::import(\'Component\', \'ComponentName\');', E_USER_WARNING);
|
||||
return App::import('Component', $name);
|
||||
}
|
||||
/**
|
||||
* @deprecated
|
||||
* @see App::import('Component', 'PluginName.ComponentName');
|
||||
*/
|
||||
function loadPluginComponent($plugin, $component) {
|
||||
trigger_error('loadPluginComponent is deprecated see App::import(\'Component\', \'PluginName.ComponentName\');', E_USER_WARNING);
|
||||
return App::import('Component', $plugin . '.' . $component);
|
||||
}
|
||||
/**
|
||||
* @deprecated
|
||||
* @see App::import('Behavior', 'BehaviorrName');
|
||||
*/
|
||||
function loadBehavior($name) {
|
||||
trigger_error('loadBehavior is deprecated see App::import(\'Behavior\', $name);', E_USER_WARNING);
|
||||
return App::import('Behavior', $name);
|
||||
}
|
||||
/**
|
||||
* @deprecated
|
||||
* @see $model = Configure::listObjects('model'); and App::import('Model', $models);
|
||||
* or App::import('Model', array(List of Models));
|
||||
*/
|
||||
function loadModels() {
|
||||
$loadModels = array();
|
||||
if (func_num_args() > 0) {
|
||||
$args = func_get_args();
|
||||
foreach($args as $arg) {
|
||||
if (is_array($arg)) {
|
||||
$loadModels = am($loadModels, $arg);
|
||||
} else {
|
||||
$loadModels[] = $arg;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($loadModels)) {
|
||||
$loadModels = Configure::listObjects('model');
|
||||
}
|
||||
App::import('Model', $loadModels);
|
||||
trigger_error('loadModels is deprecated see $model = Configure::listObjects(\'model\'); and App::import(\'Model\', $models);', E_USER_WARNING);
|
||||
return $loadModels;
|
||||
}
|
||||
/**
|
||||
* @deprecated
|
||||
* @see App::import('Model', 'PluginName.PluginModel');
|
||||
|
@ -1157,61 +1140,39 @@ if (!function_exists('clone')) {
|
|||
}
|
||||
}
|
||||
}
|
||||
trigger_error('loadPluginModels is deprecated see App::import(\'Model\', \'PluginName.PluginModel\');', E_USER_WARNING);
|
||||
}
|
||||
/**
|
||||
* @deprecated
|
||||
* @see App::import('View', 'ModelName');
|
||||
* @see $controllers = Configure::listObjects('controller'); and App::import('Controller', $controllers);
|
||||
* or App::import('Controller', array(List of Controllers);
|
||||
*/
|
||||
function loadView($name) {
|
||||
return App::import('View', $name);
|
||||
function loadControllers() {
|
||||
$loadControllers = array();
|
||||
if (func_num_args() > 0) {
|
||||
$args = func_get_args();
|
||||
foreach($args as $arg) {
|
||||
if (is_array($arg)) {
|
||||
$loadControllers = am($loadControllers, $arg);
|
||||
} else {
|
||||
$loadControllers[] = $arg;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($loadControllers)) {
|
||||
$loadControllers = Configure::listObjects('controller');
|
||||
}
|
||||
App::import('Controller', $loadControllers);
|
||||
trigger_error('loadControllers is deprecated see $controllers = Configure::listObjects(\'controller\'); and App::import(\'Controller\', $controllers);', E_USER_WARNING);
|
||||
return $loadControllers;
|
||||
}
|
||||
/**
|
||||
* @deprecated
|
||||
* @see App::import('Model', 'ModelName');
|
||||
* @see Configure::listObjects('file', $path);
|
||||
*/
|
||||
function loadModel($name = null) {
|
||||
return App::import('Model', $name);
|
||||
}
|
||||
/**
|
||||
* @deprecated
|
||||
* @see App::import('Controller', 'ControllerName');
|
||||
*/
|
||||
function loadController($name) {
|
||||
return App::import('Controller', $name);
|
||||
}
|
||||
/**
|
||||
* @deprecated
|
||||
* @see App::import('Helper', 'HelperName');
|
||||
*/
|
||||
function loadHelper($name) {
|
||||
return App::import('Helper', $name);
|
||||
}
|
||||
/**
|
||||
* @deprecated
|
||||
* @see App::import('Helper', 'PluginName.HelperName');
|
||||
*/
|
||||
function loadPluginHelper($plugin, $helper) {
|
||||
return App::import('Helper', $plugin . '.' . $helper);
|
||||
}
|
||||
/**
|
||||
* @deprecated
|
||||
* @see App::import('Component', 'PluginName.ComponentName');
|
||||
*/
|
||||
function loadComponent($name) {
|
||||
return App::import('Component', $name);
|
||||
}
|
||||
/**
|
||||
* @deprecated
|
||||
* @see App::import('Component', 'PluginName.ComponentName');
|
||||
*/
|
||||
function loadPluginComponent($plugin, $component) {
|
||||
return App::import('Component', $plugin . '.' . $component);
|
||||
}
|
||||
/**
|
||||
* @deprecated
|
||||
* @see App::import('Behavior', 'BehaviorrName');
|
||||
*/
|
||||
function loadBehavior($name) {
|
||||
return App::import('Behavior', $name);
|
||||
function listClasses($path ) {
|
||||
trigger_error('listClasses is deprecated see Configure::listObjects(\'file\', $path);', E_USER_WARNING);
|
||||
return Configure::listObjects('file', $path);
|
||||
}
|
||||
?>
|
|
@ -123,6 +123,16 @@ class Configure extends Object {
|
|||
function listObjects($type, $path = null) {
|
||||
$_this =& Configure::getInstance();
|
||||
$objects = array();
|
||||
$extension = false;
|
||||
$name = $type;
|
||||
|
||||
if($type === 'file' && !$path) {
|
||||
return false;
|
||||
} elseif ($type === 'file') {
|
||||
$extension = true;
|
||||
$name = $type . str_replace(DS, '', $path);
|
||||
}
|
||||
|
||||
if (empty($_this->__objects)) {
|
||||
$_this->__objects = Cache::read('object_map', '_cake_core_');
|
||||
}
|
||||
|
@ -131,11 +141,12 @@ class Configure extends Object {
|
|||
$Inflector =& Inflector::getInstance();
|
||||
|
||||
$types = array(
|
||||
'model' => array('suffix' => '.php', 'base' => 'AppModel'),
|
||||
'controller' => array('suffix' => '_controller.php', 'base' => 'AppController'),
|
||||
'helper' => array('suffix' => '.php', 'base' => 'AppHelper'),
|
||||
'plugin' => array('suffix' => '', 'base' => null),
|
||||
'class' => array('suffix' => '.php', 'base' => null)
|
||||
'model' => array('suffix' => '.php', 'base' => 'AppModel'),
|
||||
'controller' => array('suffix' => '_controller.php', 'base' => 'AppController'),
|
||||
'helper' => array('suffix' => '.php', 'base' => 'AppHelper'),
|
||||
'plugin' => array('suffix' => '', 'base' => null),
|
||||
'class' => array('suffix' => '.php', 'base' => null),
|
||||
'file' => array('suffix' => '.php', 'base' => null)
|
||||
);
|
||||
|
||||
if (!isset($types[$type])) {
|
||||
|
@ -159,19 +170,17 @@ class Configure extends Object {
|
|||
}
|
||||
|
||||
foreach ((array)$path as $dir) {
|
||||
$items = $_this->__list($dir, $types[$type]['suffix']);
|
||||
$items = $_this->__list($dir, $types[$type]['suffix'], $extension);
|
||||
$objects = am($items, $objects);
|
||||
|
||||
/*if (file_exists($path . $name . '.php')) {
|
||||
Configure::store('Models', 'class.paths', array($className => array('path' => $path . $name . '.php')));
|
||||
require($path . $name . '.php');
|
||||
return true;
|
||||
}*/
|
||||
}
|
||||
$_this->__objects[$type] = array_map(array(&$Inflector, 'camelize'), $objects);
|
||||
|
||||
if($type !== 'file') {
|
||||
$objects = array_map(array(&$Inflector, 'camelize'), $objects);
|
||||
}
|
||||
$_this->__objects[$name] = $objects;
|
||||
$_this->__cache = true;
|
||||
}
|
||||
return $_this->__objects[$type];
|
||||
return $_this->__objects[$name];
|
||||
}
|
||||
/**
|
||||
* Returns an array of filenames of PHP files in given directory.
|
||||
|
@ -180,7 +189,7 @@ class Configure extends Object {
|
|||
* @param string $suffix if false, return only directories. if string, match and return files
|
||||
* @return array List of directories or files in directory
|
||||
*/
|
||||
function __list($path, $suffix = false) {
|
||||
function __list($path, $suffix = false, $extension = false) {
|
||||
if(!class_exists('folder')) {
|
||||
uses('folder');
|
||||
}
|
||||
|
@ -193,7 +202,11 @@ class Configure extends Object {
|
|||
} else {
|
||||
foreach($contents[1] as $item) {
|
||||
if (substr($item, -strlen($suffix)) == $suffix) {
|
||||
$items[] = substr($item, 0, strlen($item) - strlen($suffix));
|
||||
if ($extension) {
|
||||
$items[] = $item;
|
||||
} else {
|
||||
$items[] = substr($item, 0, strlen($item) - strlen($suffix));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -881,7 +881,7 @@ class Controller extends Object {
|
|||
}
|
||||
|
||||
if (!is_object($object)) {
|
||||
trigger_error(sprintf(__("Controller::paginate() - can't find model %1$s in controller %2$sController", true), $object, $this->name), E_USER_WARNING);
|
||||
trigger_error(sprintf(__('Controller::paginate() - can\'t find model %1$s in controller %2$sController', true), $object, $this->name), E_USER_WARNING);
|
||||
return array();
|
||||
}
|
||||
$options = am($this->params, $this->params['url'], $this->passedArgs);
|
||||
|
|
|
@ -46,6 +46,13 @@ class I18n extends Object {
|
|||
* @access public
|
||||
*/
|
||||
var $l10n = null;
|
||||
/**
|
||||
* Current domain of translation
|
||||
*
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $domain = null;
|
||||
/**
|
||||
* Translation strings for a specific domain read from the .mo or .po files
|
||||
*
|
||||
|
@ -61,6 +68,13 @@ class I18n extends Object {
|
|||
* @access private
|
||||
*/
|
||||
var $__noLocale = false;
|
||||
/**
|
||||
* Determine if $__domains cache should be wrote
|
||||
*
|
||||
* @var boolean
|
||||
* @access private
|
||||
*/
|
||||
var $__cache = false;
|
||||
/**
|
||||
* Set to true when I18N::__bindTextDomain() is called for the first time.
|
||||
* If a translation file is found it is set to false again
|
||||
|
@ -98,11 +112,10 @@ class I18n extends Object {
|
|||
* @param string $domain Domain
|
||||
* @param string $category Category
|
||||
* @param integer $count Count
|
||||
* @param string $directory Directory that contains the file that is requesting translation
|
||||
* @return string translated strings.
|
||||
* @access public
|
||||
*/
|
||||
function translate($singular, $plural = null, $domain = null, $category = 5, $count = null, $directory = null) {
|
||||
function translate($singular, $plural = null, $domain = null, $category = 5, $count = null) {
|
||||
if (!$category) {
|
||||
$category = 5;
|
||||
}
|
||||
|
@ -110,22 +123,17 @@ class I18n extends Object {
|
|||
$_this->category = $_this->__categories[$category];
|
||||
|
||||
if (is_null($domain)) {
|
||||
if (preg_match('/views{0,1}\\'.DS.'([^\/]*)/', $directory, $regs)) {
|
||||
$domain = $regs[1];
|
||||
} elseif (preg_match('/controllers{0,1}\\'.DS.'([^\/]*)/', $directory, $regs)) {
|
||||
$domain = $regs[1];
|
||||
}
|
||||
$domain = 'default';
|
||||
}
|
||||
$_this->domain = $domain . '_' . $_this->l10n->locale;
|
||||
|
||||
if (isset($domain) && $domain == 'templates') {
|
||||
if (preg_match('/templates{0,1}\\'.DS.'([^\/]*)/', $directory, $regs)) {
|
||||
$domain = $regs[1];
|
||||
}
|
||||
}
|
||||
$directory = null;
|
||||
if (empty($_this->__domains)) {
|
||||
$_this->__domains = Cache::read($_this->domain, '_cake_core_');
|
||||
}
|
||||
|
||||
if (!isset($_this->__domains[$_this->category][$domain])) {
|
||||
$_this->__bindTextDomain($domain, $directory);
|
||||
$_this->__bindTextDomain($domain);
|
||||
$_this->__cache = true;
|
||||
}
|
||||
|
||||
if (!isset($count)) {
|
||||
|
@ -290,58 +298,57 @@ class I18n extends Object {
|
|||
}
|
||||
/**
|
||||
* Binds the given domain to a file in the specified directory.
|
||||
* If directory is null, will attempt to search default locations.
|
||||
*
|
||||
* @param string $domain Domain to bind
|
||||
* @param string $directory Directory
|
||||
* @return string Domain binded
|
||||
* @access private
|
||||
*/
|
||||
function __bindTextDomain($domain, $directory = null) {
|
||||
function __bindTextDomain($domain) {
|
||||
$_this =& I18n::getInstance();
|
||||
$_this->__noLocale = true;
|
||||
if (is_null($directory)) {
|
||||
$searchPath[] = APP . 'locale';
|
||||
$searchPath[] = CAKE_CORE_INCLUDE_PATH . DS . 'cake' . DS . 'locale';
|
||||
} else {
|
||||
$searchPath[] = $directory;
|
||||
$core = true;
|
||||
$merge = array();
|
||||
|
||||
$searchPath[] = APP . 'locale';
|
||||
$plugins = Configure::listObjects('plugin');
|
||||
|
||||
if (!empty($plugins)) {
|
||||
|
||||
}
|
||||
|
||||
foreach ($searchPath as $directory) {
|
||||
foreach ($_this->l10n->languagePath as $lang) {
|
||||
$file = $directory . DS . $lang . DS . $_this->category . DS . $domain;
|
||||
$default = APP . 'locale'. DS . $lang . DS . $_this->category . DS . 'default';
|
||||
$core = CAKE_CORE_INCLUDE_PATH . DS . 'cake' . DS . 'locale'. DS . $lang . DS . $_this->category . DS . 'core';
|
||||
|
||||
if ($core) {
|
||||
$app = $directory . DS . $lang . DS . $_this->category . DS . 'core';
|
||||
if (file_exists($fn = "$app.mo")) {
|
||||
$_this->__loadMo($fn, $domain);
|
||||
$_this->__noLocale = false;
|
||||
$merge = $_this->__domains;
|
||||
$core = null;
|
||||
} elseif (file_exists($fn = "$app.po") && ($f = fopen($fn, "r"))) {
|
||||
$_this->__loadPo($f, $domain);
|
||||
$_this->__noLocale = false;
|
||||
$merge = $_this->__domains;
|
||||
$core = null;
|
||||
}
|
||||
}
|
||||
|
||||
if (file_exists($fn = "$file.mo")) {
|
||||
$_this->__loadMo($fn, $domain);
|
||||
$_this->__noLocale = false;
|
||||
break 2;
|
||||
} elseif (file_exists($fn = "$default.mo")) {
|
||||
$_this->__loadMo($fn, $domain);
|
||||
$_this->__noLocale = false;
|
||||
break 2;
|
||||
} elseif (file_exists($fn = "$file.po") && ($f = fopen($fn, "r"))) {
|
||||
$_this->__loadPo($f, $domain);
|
||||
$_this->__noLocale = false;
|
||||
break 2;
|
||||
} elseif (file_exists($fn = "$default.po") && ($f = fopen($fn, "r"))) {
|
||||
$_this->__loadPo($f, $domain);
|
||||
$_this->__noLocale = false;
|
||||
break 2;
|
||||
} elseif (file_exists($fn = "$core.mo")) {
|
||||
$_this->__loadMo($fn, $domain);
|
||||
$_this->__noLocale = false;
|
||||
break 2;
|
||||
} elseif (file_exists($fn = "$core.po") && ($f = fopen($fn, "r"))) {
|
||||
$_this->__loadPo($f, $domain);
|
||||
$_this->__noLocale = false;
|
||||
break 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($_this->__domains[$_this->category][$domain])) {
|
||||
$_this->__domains[$_this->category][$domain] = array();
|
||||
return($domain);
|
||||
}
|
||||
|
||||
|
@ -356,6 +363,11 @@ class I18n extends Object {
|
|||
$switch = preg_replace("/[() {}\\[\\]^\\s*\\]]+/", "", $_this->__domains[$_this->category][$domain]["%po-header"]["plural-forms"]);
|
||||
$_this->__domains[$_this->category][$domain]["%plural-c"] = $switch;
|
||||
}
|
||||
$_this->__domains = Set::pushDiff($_this->__domains, $merge);
|
||||
|
||||
if (isset($_this->__domains[$_this->category][$domain][null])) {
|
||||
unset($_this->__domains[$_this->category][$domain][null]);
|
||||
}
|
||||
}
|
||||
return($domain);
|
||||
}
|
||||
|
@ -483,5 +495,17 @@ class I18n extends Object {
|
|||
function __bindTextDomainCodeset($domain, $codeset = null) {
|
||||
return($domain);
|
||||
}
|
||||
/**
|
||||
* Object destructor
|
||||
*
|
||||
* Write cache file if changes have been made to the $__map or $__paths
|
||||
* @access private
|
||||
*/
|
||||
function __destruct() {
|
||||
$_this =& I18n::getInstance();
|
||||
if ($_this->__cache) {
|
||||
Cache::write($_this->domain, array_filter($_this->__domains), '_cake_core_');
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -840,8 +840,8 @@ class View extends Object {
|
|||
|
||||
if (in_array($helper, array_keys($loaded)) !== true) {
|
||||
if (!class_exists($helperCn)) {
|
||||
if (is_null($plugin) || !loadPluginHelper($plugin, $helper)) {
|
||||
if (!loadHelper($helper)) {
|
||||
if (is_null($plugin) || !App::import('Helper', $plugin . '.' . $helper)) {
|
||||
if (!App::import('Helper', $helper)) {
|
||||
$this->cakeError('missingHelperFile', array(array(
|
||||
'helper' => $helper,
|
||||
'file' => Inflector::underscore($helper) . '.php',
|
||||
|
|
|
@ -37,16 +37,10 @@ class ConfigureTest extends UnitTestCase {
|
|||
|
||||
function setUp() {
|
||||
$this->Configure =& Configure::getInstance();
|
||||
$corePath = Configure::corePaths('cake');
|
||||
if (isset($corePath[0])) {
|
||||
$this->corePath = rtrim($corePath[0], DS) . DS;
|
||||
} else {
|
||||
$this->corePath = CAKE_CORE_INCLUDE_PATH;
|
||||
}
|
||||
}
|
||||
|
||||
function testListCoreObjects() {
|
||||
$result = $this->Configure->listObjects('class', $this->corePath . 'libs');
|
||||
$result = $this->Configure->listObjects('class', TEST_CAKE_CORE_INCLUDE_PATH . 'libs');
|
||||
$this->assertTrue(in_array('Xml', $result));
|
||||
$this->assertTrue(in_array('Cache', $result));
|
||||
$this->assertTrue(in_array('HttpSocket', $result));
|
||||
|
|
|
@ -76,7 +76,7 @@ class FolderTest extends UnitTestCase {
|
|||
}
|
||||
|
||||
function testOperations() {
|
||||
$path = CAKE_CORE_INCLUDE_PATH.DS.'cake'.DS.'console'.DS.'libs'.DS.'templates'.DS.'skel';
|
||||
$path = TEST_CAKE_CORE_INCLUDE_PATH.'console'.DS.'libs'.DS.'templates'.DS.'skel';
|
||||
$Folder =& new Folder($path);
|
||||
|
||||
$result = is_dir($Folder->pwd());
|
||||
|
@ -140,34 +140,34 @@ class FolderTest extends UnitTestCase {
|
|||
|
||||
function testFolderTree() {
|
||||
$Folder =& new Folder();
|
||||
$expected = array(array(CAKE_CORE_INCLUDE_PATH . DS . 'cake' . DS . 'config',
|
||||
CAKE_CORE_INCLUDE_PATH . DS . 'cake' . DS . 'config' . DS . 'unicode',
|
||||
CAKE_CORE_INCLUDE_PATH . DS . 'cake' . DS . 'config' . DS . 'unicode' . DS . 'casefolding'),
|
||||
array(CAKE_CORE_INCLUDE_PATH . DS . 'cake' . DS . 'config' . DS . 'config.php',
|
||||
CAKE_CORE_INCLUDE_PATH . DS . 'cake' . DS . 'config' . DS . 'paths.php',
|
||||
CAKE_CORE_INCLUDE_PATH . DS . 'cake' . DS . 'config' . DS . 'unicode' . DS . 'casefolding' . DS . '0000_007f.php',
|
||||
CAKE_CORE_INCLUDE_PATH . DS . 'cake' . DS . 'config' . DS . 'unicode' . DS . 'casefolding' . DS . '0080_00ff.php',
|
||||
CAKE_CORE_INCLUDE_PATH . DS . 'cake' . DS . 'config' . DS . 'unicode' . DS . 'casefolding' . DS . '0100_017f.php',
|
||||
CAKE_CORE_INCLUDE_PATH . DS . 'cake' . DS . 'config' . DS . 'unicode' . DS . 'casefolding' . DS . '0180_024F.php',
|
||||
CAKE_CORE_INCLUDE_PATH . DS . 'cake' . DS . 'config' . DS . 'unicode' . DS . 'casefolding' . DS . '0300_036f.php',
|
||||
CAKE_CORE_INCLUDE_PATH . DS . 'cake' . DS . 'config' . DS . 'unicode' . DS . 'casefolding' . DS . '0370_03ff.php',
|
||||
CAKE_CORE_INCLUDE_PATH . DS . 'cake' . DS . 'config' . DS . 'unicode' . DS . 'casefolding' . DS . '0400_04ff.php',
|
||||
CAKE_CORE_INCLUDE_PATH . DS . 'cake' . DS . 'config' . DS . 'unicode' . DS . 'casefolding' . DS . '0500_052f.php',
|
||||
CAKE_CORE_INCLUDE_PATH . DS . 'cake' . DS . 'config' . DS . 'unicode' . DS . 'casefolding' . DS . '0530_058f.php',
|
||||
CAKE_CORE_INCLUDE_PATH . DS . 'cake' . DS . 'config' . DS . 'unicode' . DS . 'casefolding' . DS . '10400_1044f.php',
|
||||
CAKE_CORE_INCLUDE_PATH . DS . 'cake' . DS . 'config' . DS . 'unicode' . DS . 'casefolding' . DS . '10a0_10ff.php',
|
||||
CAKE_CORE_INCLUDE_PATH . DS . 'cake' . DS . 'config' . DS . 'unicode' . DS . 'casefolding' . DS . '1e00_1eff.php',
|
||||
CAKE_CORE_INCLUDE_PATH . DS . 'cake' . DS . 'config' . DS . 'unicode' . DS . 'casefolding' . DS . '1f00_1fff.php',
|
||||
CAKE_CORE_INCLUDE_PATH . DS . 'cake' . DS . 'config' . DS . 'unicode' . DS . 'casefolding' . DS . '2100_214f.php',
|
||||
CAKE_CORE_INCLUDE_PATH . DS . 'cake' . DS . 'config' . DS . 'unicode' . DS . 'casefolding' . DS . '2150_218f.php',
|
||||
CAKE_CORE_INCLUDE_PATH . DS . 'cake' . DS . 'config' . DS . 'unicode' . DS . 'casefolding' . DS . '2460_24ff.php',
|
||||
CAKE_CORE_INCLUDE_PATH . DS . 'cake' . DS . 'config' . DS . 'unicode' . DS . 'casefolding' . DS . '2c00_2c5f.php',
|
||||
CAKE_CORE_INCLUDE_PATH . DS . 'cake' . DS . 'config' . DS . 'unicode' . DS . 'casefolding' . DS . '2c60_2c7f.php',
|
||||
CAKE_CORE_INCLUDE_PATH . DS . 'cake' . DS . 'config' . DS . 'unicode' . DS . 'casefolding' . DS . '2c80_2cff.php',
|
||||
CAKE_CORE_INCLUDE_PATH . DS . 'cake' . DS . 'config' . DS . 'unicode' . DS . 'casefolding' . DS . 'fb00_fb4f.php',
|
||||
CAKE_CORE_INCLUDE_PATH . DS . 'cake' . DS . 'config' . DS . 'unicode' . DS . 'casefolding' . DS . 'ff00_ffef.php'));
|
||||
$expected = array(array(TEST_CAKE_CORE_INCLUDE_PATH . 'config',
|
||||
TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'unicode',
|
||||
TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'unicode' . DS . 'casefolding'),
|
||||
array(TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'config.php',
|
||||
TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'paths.php',
|
||||
TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'unicode' . DS . 'casefolding' . DS . '0000_007f.php',
|
||||
TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'unicode' . DS . 'casefolding' . DS . '0080_00ff.php',
|
||||
TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'unicode' . DS . 'casefolding' . DS . '0100_017f.php',
|
||||
TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'unicode' . DS . 'casefolding' . DS . '0180_024F.php',
|
||||
TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'unicode' . DS . 'casefolding' . DS . '0300_036f.php',
|
||||
TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'unicode' . DS . 'casefolding' . DS . '0370_03ff.php',
|
||||
TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'unicode' . DS . 'casefolding' . DS . '0400_04ff.php',
|
||||
TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'unicode' . DS . 'casefolding' . DS . '0500_052f.php',
|
||||
TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'unicode' . DS . 'casefolding' . DS . '0530_058f.php',
|
||||
TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'unicode' . DS . 'casefolding' . DS . '10400_1044f.php',
|
||||
TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'unicode' . DS . 'casefolding' . DS . '10a0_10ff.php',
|
||||
TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'unicode' . DS . 'casefolding' . DS . '1e00_1eff.php',
|
||||
TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'unicode' . DS . 'casefolding' . DS . '1f00_1fff.php',
|
||||
TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'unicode' . DS . 'casefolding' . DS . '2100_214f.php',
|
||||
TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'unicode' . DS . 'casefolding' . DS . '2150_218f.php',
|
||||
TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'unicode' . DS . 'casefolding' . DS . '2460_24ff.php',
|
||||
TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'unicode' . DS . 'casefolding' . DS . '2c00_2c5f.php',
|
||||
TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'unicode' . DS . 'casefolding' . DS . '2c60_2c7f.php',
|
||||
TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'unicode' . DS . 'casefolding' . DS . '2c80_2cff.php',
|
||||
TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'unicode' . DS . 'casefolding' . DS . 'fb00_fb4f.php',
|
||||
TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'unicode' . DS . 'casefolding' . DS . 'ff00_ffef.php'));
|
||||
|
||||
$results = $Folder->tree(CAKE_CORE_INCLUDE_PATH . DS . 'cake' . DS . 'config', false);
|
||||
$results = $Folder->tree(TEST_CAKE_CORE_INCLUDE_PATH . 'config', false);
|
||||
$this->assertEqual($results, $expected);
|
||||
}
|
||||
|
||||
|
|
|
@ -28,17 +28,7 @@
|
|||
*/
|
||||
uses('configure');
|
||||
class AppImportTest extends UnitTestCase {
|
||||
var $corePath = null;
|
||||
|
||||
|
||||
function setUp(){
|
||||
$corePath = Configure::corePaths('cake');
|
||||
if (isset($corePath[0])) {
|
||||
$this->corePath = rtrim($corePath[0], DS) . DS;
|
||||
} else {
|
||||
$this->corePath = CAKE_CORE_INCLUDE_PATH;
|
||||
}
|
||||
}
|
||||
function testClassLoading() {
|
||||
$file = App::import();
|
||||
$this->assertTrue($file);
|
||||
|
@ -52,46 +42,48 @@ class AppImportTest extends UnitTestCase {
|
|||
$file = App::import('Model', 'AppModel', false);
|
||||
$this->assertTrue($file);
|
||||
|
||||
$classes = array_flip(get_declared_classes());
|
||||
$this->assertFalse(isset($classes['PagesController']));
|
||||
$this->assertFalse(isset($classes['AppController']));
|
||||
if (!class_exists('AppController')) {
|
||||
$classes = array_flip(get_declared_classes());
|
||||
$this->assertFalse(isset($classes['PagesController']));
|
||||
$this->assertFalse(isset($classes['AppController']));
|
||||
|
||||
$file = App::import('Controller', 'Pages');
|
||||
$this->assertTrue($file);
|
||||
$file = App::import('Controller', 'Pages');
|
||||
$this->assertTrue($file);
|
||||
|
||||
$classes = array_flip(get_declared_classes());
|
||||
$this->assertTrue(isset($classes['PagesController']));
|
||||
$this->assertTrue(isset($classes['AppController']));
|
||||
$classes = array_flip(get_declared_classes());
|
||||
$this->assertTrue(isset($classes['PagesController']));
|
||||
$this->assertTrue(isset($classes['AppController']));
|
||||
}
|
||||
}
|
||||
|
||||
function testFileLoading () {
|
||||
$file = App::import('File', 'RealFile', false, array(), $this->corePath . 'config' . DS . 'config.php');
|
||||
$file = App::import('File', 'RealFile', false, array(), TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'config.php');
|
||||
$this->assertTrue($file);
|
||||
|
||||
$file = App::import('File', 'NoFile', false, array(), $this->corePath . 'config' . DS . 'cake' . DS . 'config.php');
|
||||
$file = App::import('File', 'NoFile', false, array(), TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'cake' . DS . 'config.php');
|
||||
$this->assertFalse($file);
|
||||
}
|
||||
// import($type = null, $name = null, $parent = true, $file = null, $search = array(), $return = false) {
|
||||
function testFileLoadingWithArray() {
|
||||
$type = array('type' => 'File', 'name' => 'SomeName', 'parent' => false,
|
||||
'file' => $this->corePath . DS . 'config' . DS . 'config.php');
|
||||
'file' => TEST_CAKE_CORE_INCLUDE_PATH . DS . 'config' . DS . 'config.php');
|
||||
$file = App::import($type);
|
||||
$this->assertTrue($file);
|
||||
|
||||
$type = array('type' => 'File', 'name' => 'NoFile', 'parent' => false,
|
||||
'file' => $this->corePath . 'config' . DS . 'cake' . DS . 'config.php');
|
||||
'file' => TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'cake' . DS . 'config.php');
|
||||
$file = App::import($type);
|
||||
$this->assertFalse($file);
|
||||
}
|
||||
|
||||
function testFileLoadingReturnValue () {
|
||||
$file = App::import('File', 'Name', false, array(), $this->corePath . 'config' . DS . 'config.php', true);
|
||||
$file = App::import('File', 'Name', false, array(), TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'config.php', true);
|
||||
$this->assertTrue($file);
|
||||
|
||||
$this->assertTrue(isset($file['Cake.version']));
|
||||
|
||||
$type = array('type' => 'File', 'name' => 'OtherName', 'parent' => false,
|
||||
'file' => $this->corePath . 'config' . DS . 'config.php', 'return' => true);
|
||||
'file' => TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'config.php', 'return' => true);
|
||||
$file = App::import($type);
|
||||
$this->assertTrue($file);
|
||||
|
||||
|
@ -99,7 +91,7 @@ class AppImportTest extends UnitTestCase {
|
|||
}
|
||||
|
||||
function testLoadingWithSearch () {
|
||||
$file = App::import('File', 'NewName', false, array($this->corePath), 'config.php');
|
||||
$file = App::import('File', 'NewName', false, array(TEST_CAKE_CORE_INCLUDE_PATH ), 'config.php');
|
||||
$this->assertTrue($file);
|
||||
|
||||
$file = App::import('File', 'AnotherNewName', false, array(LIBS), 'config.php');
|
||||
|
@ -107,7 +99,7 @@ class AppImportTest extends UnitTestCase {
|
|||
}
|
||||
|
||||
function testLoadingWithSearchArray () {
|
||||
$type = array('type' => 'File', 'name' => 'RandomName', 'parent' => false, 'file' => 'config.php', 'search' => array($this->corePath));
|
||||
$type = array('type' => 'File', 'name' => 'RandomName', 'parent' => false, 'file' => 'config.php', 'search' => array(TEST_CAKE_CORE_INCLUDE_PATH ));
|
||||
$file = App::import($type);
|
||||
$this->assertTrue($file);
|
||||
|
||||
|
|
|
@ -461,7 +461,7 @@ class CakeTestCase extends UnitTestCase {
|
|||
$fixturePaths = array(
|
||||
TESTS . 'fixtures',
|
||||
VENDORS . 'tests' . DS . 'fixtures',
|
||||
CAKE_CORE_INCLUDE_PATH . DS . 'cake' . DS . 'tests' . DS . 'fixtures'
|
||||
TEST_CAKE_CORE_INCLUDE_PATH . DS . 'cake' . DS . 'tests' . DS . 'fixtures'
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue