From cd3529c986f5cbd9acf2da1b0e697e05b5b2c46c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Renan=20Gon=C3=A7alves?= Date: Mon, 25 Apr 2011 19:22:14 +0200 Subject: [PATCH 01/16] Implementing support to multiline string in __*() calls. --- lib/Cake/Console/Command/Task/ExtractTask.php | 47 +++++++++++++------ .../Console/Command/Task/ExtractTaskTest.php | 11 +++-- .../tests/test_app/View/pages/extract.ctp | 11 ++++- 3 files changed, 50 insertions(+), 19 deletions(-) diff --git a/lib/Cake/Console/Command/Task/ExtractTask.php b/lib/Cake/Console/Command/Task/ExtractTask.php index bcf38d386..649f0b869 100644 --- a/lib/Cake/Console/Command/Task/ExtractTask.php +++ b/lib/Cake/Console/Command/Task/ExtractTask.php @@ -316,24 +316,13 @@ class ExtractTask extends Shell { } $mapCount = count($map); - $strings = array(); - while (count($strings) < $mapCount && ($this->__tokens[$position] == ',' || $this->__tokens[$position][0] == T_CONSTANT_ENCAPSED_STRING)) { - if ($this->__tokens[$position][0] == T_CONSTANT_ENCAPSED_STRING) { - $strings[] = $this->__tokens[$position][1]; - } - $position++; - } + $strings = $this->__getStrings($position, $mapCount); if ($mapCount == count($strings)) { extract(array_combine($map, $strings)); - if (!isset($domain)) { - $domain = '\'default\''; - } - $string = $this->__formatString($singular); - if (isset($plural)) { - $string .= "\0" . $this->__formatString($plural); - } - $this->__strings[$this->__formatString($domain)][$string][$this->__file][] = $line; + $domain = isset($domain) ? $domain : 'default'; + $string = isset($plural) ? $singular . "\0" . $plural : $singular; + $this->__strings[$domain][$string][$this->__file][] = $line; } else { $this->__markerError($this->__file, $line, $functionName, $count); } @@ -454,6 +443,34 @@ class ExtractTask extends Shell { $output .= "\"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\\n\"\n\n"; return $output; } + +/** + * Get the strings from the position forward + * + * @param int $position Actual position on tokens array + * @param int $target Number of strings to extract + * @return array Strings extracted + * @access private + */ + function __getStrings(&$position, $target) { + $strings = array(); + while (count($strings) < $target && ($this->__tokens[$position] == ',' || $this->__tokens[$position][0] == T_CONSTANT_ENCAPSED_STRING)) { + if ($this->__tokens[$position][0] == T_CONSTANT_ENCAPSED_STRING && $this->__tokens[$position+1] == '.') { + $string = ''; + while ($this->__tokens[$position][0] == T_CONSTANT_ENCAPSED_STRING || $this->__tokens[$position] == '.') { + if ($this->__tokens[$position][0] == T_CONSTANT_ENCAPSED_STRING) { + $string .= $this->__formatString($this->__tokens[$position][1]); + } + $position++; + } + $strings[] = $string; + } else if ($this->__tokens[$position][0] == T_CONSTANT_ENCAPSED_STRING) { + $strings[] = $this->__formatString($this->__tokens[$position][1]); + } + $position++; + } + return $strings; + } /** * Format a string to be added as a translateable string diff --git a/lib/Cake/tests/Case/Console/Command/Task/ExtractTaskTest.php b/lib/Cake/tests/Case/Console/Command/Task/ExtractTaskTest.php index c401bbd09..346786da4 100644 --- a/lib/Cake/tests/Case/Console/Command/Task/ExtractTaskTest.php +++ b/lib/Cake/tests/Case/Console/Command/Task/ExtractTaskTest.php @@ -118,7 +118,6 @@ class ExtractTaskTest extends CakeTestCase { $pattern = '/To change its layout, create: APP\/views\/layouts\/default\.ctp\./s'; $this->assertPattern($pattern, $result); - // extract.ctp $pattern = '/\#: (\\\\|\/)extract\.ctp:6\n'; $pattern .= 'msgid "You have %d new message."\nmsgid_plural "You have %d new messages."/'; @@ -131,9 +130,15 @@ class ExtractTaskTest extends CakeTestCase { $pattern = '/\#: (\\\\|\/)extract\.ctp:14\n'; $pattern .= '\#: (\\\\|\/)home\.ctp:99\n'; $pattern .= 'msgid "Editing this Page"\nmsgstr ""/'; - $this->assertPattern($pattern, $result); - + + $pattern = '/\#: (\\\\|\/)extract\.ctp:17\nmsgid "'; + $pattern .= 'Hot features!'; + $pattern .= '\\\n - No Configuration: Set-up the database and let the magic begin'; + $pattern .= '\\\n - Extremely Simple: Just look at the name...It\'s Cake'; + $pattern .= '\\\n - Active, Friendly Community: Join us #cakephp on IRC. We\'d love to help you get started'; + $pattern .= '"\nmsgstr ""/'; + $this->assertPattern($pattern, $result); // extract.ctp - reading the domain.pot $result = file_get_contents($this->path . DS . 'domain.pot'); diff --git a/lib/Cake/tests/test_app/View/pages/extract.ctp b/lib/Cake/tests/test_app/View/pages/extract.ctp index bc4e7eb40..5e6abf54e 100644 --- a/lib/Cake/tests/test_app/View/pages/extract.ctp +++ b/lib/Cake/tests/test_app/View/pages/extract.ctp @@ -11,4 +11,13 @@ echo __dn('domain', 'You have %d new message (domain).', 'You have %d new messag echo __dn('domain', 'You deleted %d message (domain).', 'You deleted %d messages (domain).', $messages['count']); // Duplicated Message -echo __('Editing this Page'); \ No newline at end of file +echo __('Editing this Page'); + +// Multiline +__('Hot features!' + . "\n - No Configuration:" + . ' Set-up the database and let the magic begin' + . "\n - Extremely Simple:" + . ' Just look at the name...It\'s Cake' + . "\n - Active, Friendly Community:" + . ' Join us #cakephp on IRC. We\'d love to help you get started'); From 3251faf8e9c0ddd4d15bd75912e9e7080f26045c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Renan=20Gon=C3=A7alves?= Date: Mon, 25 Apr 2011 19:39:13 +0200 Subject: [PATCH 02/16] Expliciting methods visibility. No need to keep track of line anymore, token_get_all (PHP 5.2.2) returns it. ... and fixing some grammar typos on the way. --- lib/Cake/Console/Command/Task/ExtractTask.php | 44 +++++++------------ 1 file changed, 17 insertions(+), 27 deletions(-) diff --git a/lib/Cake/Console/Command/Task/ExtractTask.php b/lib/Cake/Console/Command/Task/ExtractTask.php index 649f0b869..53bfa81fc 100644 --- a/lib/Cake/Console/Command/Task/ExtractTask.php +++ b/lib/Cake/Console/Command/Task/ExtractTask.php @@ -103,7 +103,7 @@ class ExtractTask extends Shell { * @return void * @access private */ - function execute() { + public function execute() { if (!empty($this->params['exclude'])) { $this->_exclude = explode(',', $this->params['exclude']); } @@ -172,7 +172,7 @@ class ExtractTask extends Shell { * @return void * @access private */ - function __extract() { + private function __extract() { $this->out(); $this->out(); $this->out(__d('cake_console', 'Extracting...')); @@ -201,7 +201,7 @@ class ExtractTask extends Shell { $parser = parent::getOptionParser(); return $parser->description(__d('cake_console', 'CakePHP Language String Extraction:')) ->addOption('app', array('help' => __d('cake_console', 'Directory where your application is located.'))) - ->addOption('paths', array('help' => __d('cake_console', 'Comma separted list of paths.'))) + ->addOption('paths', array('help' => __d('cake_console', 'Comma separated list of paths.'))) ->addOption('merge', array( 'help' => __d('cake_console', 'Merge all domain strings into the default.po file.'), 'choices' => array('yes', 'no') @@ -247,29 +247,19 @@ class ExtractTask extends Shell { * @return void * @access private */ - function __extractTokens() { + private function __extractTokens() { foreach ($this->__files as $file) { $this->__file = $file; $this->out(__d('cake_console', 'Processing %s...', $file)); $code = file_get_contents($file); $allTokens = token_get_all($code); + $this->__tokens = array(); - $lineNumber = 1; - foreach ($allTokens as $token) { - if ((!is_array($token)) || (($token[0] != T_WHITESPACE) && ($token[0] != T_INLINE_HTML))) { - if (is_array($token)) { - $token[] = $lineNumber; - } + if (!is_array($token) || ($token[0] != T_WHITESPACE && $token[0] != T_INLINE_HTML)) { $this->__tokens[] = $token; } - - if (is_array($token)) { - $lineNumber += count(explode("\n", $token[1])) - 1; - } else { - $lineNumber += count(explode("\n", $token)) - 1; - } } unset($allTokens); $this->__parse('__', array('singular')); @@ -290,7 +280,7 @@ class ExtractTask extends Shell { * @return void * @access private */ - function __parse($functionName, $map) { + private function __parse($functionName, $map) { $count = 0; $tokenCount = count($this->__tokens); @@ -337,7 +327,7 @@ class ExtractTask extends Shell { * @return void * @access private */ - function __buildFiles() { + private function __buildFiles() { foreach ($this->__strings as $domain => $strings) { foreach ($strings as $string => $files) { $occurrences = array(); @@ -372,7 +362,7 @@ class ExtractTask extends Shell { * @return void * @access private */ - function __store($domain, $header, $sentence) { + private function __store($domain, $header, $sentence) { if (!isset($this->__storage[$domain])) { $this->__storage[$domain] = array(); } @@ -389,7 +379,7 @@ class ExtractTask extends Shell { * @return void * @access private */ - function __writeFiles() { + private function __writeFiles() { $overwriteAll = false; foreach ($this->__storage as $domain => $sentences) { $output = $this->__writeHeader(); @@ -425,7 +415,7 @@ class ExtractTask extends Shell { * @return string Translation template header * @access private */ - function __writeHeader() { + private function __writeHeader() { $output = "# LANGUAGE translation of CakePHP Application\n"; $output .= "# Copyright YEAR NAME \n"; $output .= "#\n"; @@ -452,7 +442,7 @@ class ExtractTask extends Shell { * @return array Strings extracted * @access private */ - function __getStrings(&$position, $target) { + private function __getStrings(&$position, $target) { $strings = array(); while (count($strings) < $target && ($this->__tokens[$position] == ',' || $this->__tokens[$position][0] == T_CONSTANT_ENCAPSED_STRING)) { if ($this->__tokens[$position][0] == T_CONSTANT_ENCAPSED_STRING && $this->__tokens[$position+1] == '.') { @@ -473,13 +463,13 @@ class ExtractTask extends Shell { } /** - * Format a string to be added as a translateable string + * Format a string to be added as a translatable string * * @param string $string String to format * @return string Formatted string * @access private */ - function __formatString($string) { + private function __formatString($string) { $quote = substr($string, 0, 1); $string = substr($string, 1, -1); if ($quote == '"') { @@ -501,7 +491,7 @@ class ExtractTask extends Shell { * @return void * @access private */ - function __markerError($file, $line, $marker, $count) { + private function __markerError($file, $line, $marker, $count) { $this->out(__d('cake_console', "Invalid marker content in %s:%s\n* %s(", $file, $line, $marker), true); $count += 2; $tokenCount = count($this->__tokens); @@ -526,12 +516,12 @@ class ExtractTask extends Shell { } /** - * Search files that may contain translateable strings + * Search files that may contain translatable strings * * @return void * @access private */ - function __searchFiles() { + private function __searchFiles() { $pattern = false; if (!empty($this->_exclude)) { $pattern = '/[\/\\\\]' . implode('|', $this->_exclude) . '[\/\\\\]/'; From abbe5aaea22c976ea541638791d321dbf21c1416 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Renan=20Gon=C3=A7alves?= Date: Mon, 25 Apr 2011 21:17:59 +0200 Subject: [PATCH 03/16] Updating console to use i18n'ed strings. --- lib/Cake/Console/Command/AclShell.php | 36 +++++------- lib/Cake/Console/Command/ApiShell.php | 8 +-- lib/Cake/Console/Command/BakeShell.php | 31 +++++----- lib/Cake/Console/Command/CommandListShell.php | 17 +++--- lib/Cake/Console/Command/ConsoleShell.php | 35 ++++++----- lib/Cake/Console/Command/SchemaShell.php | 10 ++-- .../Console/Command/Task/ControllerTask.php | 2 +- .../Console/Command/Task/DbConfigTask.php | 58 +++++++++---------- lib/Cake/Console/Command/Task/FixtureTask.php | 8 +-- lib/Cake/Console/Command/Task/ModelTask.php | 8 +-- lib/Cake/Console/Command/Task/PluginTask.php | 4 +- lib/Cake/Console/Command/Task/ProjectTask.php | 4 +- lib/Cake/Console/Command/Task/TestTask.php | 2 +- lib/Cake/Console/Command/Task/ViewTask.php | 2 +- lib/Cake/Console/Command/TestsuiteShell.php | 6 +- lib/Cake/Console/ConsoleErrorHandler.php | 5 +- lib/Cake/Console/ConsoleInputArgument.php | 6 +- lib/Cake/Console/ConsoleInputOption.php | 6 +- lib/Cake/Console/ConsoleInputSubcommand.php | 2 +- lib/Cake/Console/ConsoleOptionParser.php | 10 ++-- lib/Cake/Console/ConsoleOutput.php | 18 +++--- lib/Cake/Console/HelpFormatter.php | 19 +++--- lib/Cake/Console/Shell.php | 18 +++--- lib/Cake/Console/ShellDispatcher.php | 4 +- 24 files changed, 153 insertions(+), 166 deletions(-) diff --git a/lib/Cake/Console/Command/AclShell.php b/lib/Cake/Console/Command/AclShell.php index 29312eaef..2a4c72e45 100644 --- a/lib/Cake/Console/Command/AclShell.php +++ b/lib/Cake/Console/Command/AclShell.php @@ -71,10 +71,8 @@ class AclShell extends Shell { if (!in_array(Configure::read('Acl.classname'), array('DbAcl', 'DB_ACL'))) { $out = "--------------------------------------------------\n"; - $out .= __d('cake_console', 'Error: Your current Cake configuration is set to') . "\n"; - $out .= __d('cake_console', 'an ACL implementation other than DB. Please change') . "\n"; - $out .= __d('cake_console', 'your core config to reflect your decision to use') . "\n"; - $out .= __d('cake_console', 'DbAcl before attempting to use this script') . ".\n"; + $out .= __d('cake_console', 'Error: Your current Cake configuration is set to an ACL implementation other than DB.') . "\n"; + $out .= __d('cake_console', 'Please change your core config to reflect your decision to use DbAcl before attempting to use this script') . "\n"; $out .= "--------------------------------------------------\n"; $out .= __d('cake_console', 'Current ACL Classname: %s', Configure::read('Acl.classname')) . "\n"; $out .= "--------------------------------------------------\n"; @@ -150,7 +148,7 @@ class AclShell extends Shell { $nodeId = $this->_getNodeId($class, $identifier); if (!$this->Acl->{$class}->delete($nodeId)) { - $this->error(__d('cake_console', 'Node Not Deleted') . __d('cake_console', 'There was an error deleting the %s. Check that the node exists', $class) . ".\n"); + $this->error(__d('cake_console', 'Node Not Deleted') . __d('cake_console', 'There was an error deleting the %s. Check that the node exists.', $class) . "\n"); } $this->out(__d('cake_console', '%s deleted.', $class), 2); } @@ -263,7 +261,7 @@ class AclShell extends Shell { } /** - * Set an ARO to inhermit permission to an ACO. + * Set an ARO to inherit permission to an ACO. * */ public function inherit() { @@ -308,7 +306,7 @@ class AclShell extends Shell { $this->error(__d('cake_console', '%s not found', $this->args[0]), __d('cake_console', 'No tree returned.')); } } - $this->out($class . " tree:"); + $this->out($class . ' tree:'); $this->hr(); $stack = array(); @@ -357,7 +355,7 @@ class AclShell extends Shell { 'help' => __d('cake_console', 'Type of node to create.') ); - $parser->description('A console tool for managing the DbAcl') + $parser->description(__d('cake_console', 'A console tool for managing the DbAcl')) ->addSubcommand('create', array( 'help' => __d('cake_console', 'Create a new ACL node'), 'parser' => array( @@ -407,8 +405,7 @@ class AclShell extends Shell { 'parser' => array( 'description' => array( __d('cake_console', "Returns the path to the ACL object specified by ."), - __d('cake_console', "This command is useful in determining the inhertiance of permissions"), - __d('cake_console', "for a certain object in the tree.") + __d('cake_console', "This command is useful in determining the inheritance of permissions for a certain object in the tree.") ), 'arguments' => array( 'type' => $type, @@ -422,9 +419,7 @@ class AclShell extends Shell { 'help' => __d('cake_console', 'Check the permissions between an ACO and ARO.'), 'parser' => array( 'description' => array( - __d('cake_console', "Use this command to grant ACL permissions. Once executed, the ARO "), - __d('cake_console', "specified (and its children, if any) will have ALLOW access to the"), - __d('cake_console', "specified ACO action (and the ACO's children, if any).") + __d('cake_console', 'Use this command to grant ACL permissions. Once executed, the ARO specified (and its children, if any) will have ALLOW access to the specified ACO action (and the ACO\'s children, if any).') ), 'arguments' => array( 'aro' => array('help' => __d('cake_console', 'ARO to check.'), 'required' => true), @@ -436,9 +431,7 @@ class AclShell extends Shell { 'help' => __d('cake_console', 'Grant an ARO permissions to an ACO.'), 'parser' => array( 'description' => array( - __d('cake_console', "Use this command to grant ACL permissions. Once executed, the ARO"), - __d('cake_console', "specified (and its children, if any) will have ALLOW access to the"), - __d('cake_console', "specified ACO action (and the ACO's children, if any).") + __d('cake_console', 'Use this command to grant ACL permissions. Once executed, the ARO specified (and its children, if any) will have ALLOW access to the specified ACO action (and the ACO\'s children, if any).') ), 'arguments' => array( 'aro' => array('help' => __d('cake_console', 'ARO to grant permission to.'), 'required' => true), @@ -450,9 +443,7 @@ class AclShell extends Shell { 'help' => __d('cake_console', 'Deny an ARO permissions to an ACO.'), 'parser' => array( 'description' => array( - __d('cake_console', "Use this command to deny ACL permissions. Once executed, the ARO"), - __d('cake_console', "specified (and its children, if any) will have DENY access to the"), - __d('cake_console', "specified ACO action (and the ACO's children, if any).") + __d('cake_console', 'Use this command to deny ACL permissions. Once executed, the ARO specified (and its children, if any) will have DENY access to the specified ACO action (and the ACO\'s children, if any).') ), 'arguments' => array( 'aro' => array('help' => __d('cake_console', 'ARO to deny.'), 'required' => true), @@ -464,11 +455,10 @@ class AclShell extends Shell { 'help' => __d('cake_console', 'Inherit an ARO\'s parent permissions.'), 'parser' => array( 'description' => array( - __d('cake_console', "Use this command to force a child ARO object to inherit its"), - __d('cake_console', "permissions settings from its parent.") + __d('cake_console', "Use this command to force a child ARO object to inherit its permissions settings from its parent.") ), 'arguments' => array( - 'aro' => array('help' => __d('cake_console', 'ARO to have permisssions inherit.'), 'required' => true), + 'aro' => array('help' => __d('cake_console', 'ARO to have permissions inherit.'), 'required' => true), 'aco' => array('help' => __d('cake_console', 'ACO to inherit permissions on.'), 'required' => true), 'action' => array('help' => __d('cake_console', 'Action to inherit'), 'default' => 'all') ) @@ -526,7 +516,7 @@ class AclShell extends Shell { } /** - * Parse an identifier into Model.foriegnKey or an alias. + * Parse an identifier into Model.foreignKey or an alias. * Takes an identifier determines its type and returns the result as used by other methods. * * @param string $identifier Identifier to parse diff --git a/lib/Cake/Console/Command/ApiShell.php b/lib/Cake/Console/Command/ApiShell.php index d37b6acd0..3e6fab460 100644 --- a/lib/Cake/Console/Command/ApiShell.php +++ b/lib/Cake/Console/Command/ApiShell.php @@ -36,7 +36,7 @@ class ApiShell extends Shell { public $paths = array(); /** - * Override intialize of the Shell + * Override initialize of the Shell * */ public function initialize() { @@ -140,9 +140,9 @@ class ApiShell extends Shell { public function getOptionParser() { $parser = parent::getOptionParser(); $parser->addArgument('type', array( - 'help' => 'Either a full path or type of class (model, behavior, controller, component, view, helper)' + 'help' => __d('cake_console', 'Either a full path or type of class (model, behavior, controller, component, view, helper)') ))->addArgument('className', array( - 'help' => 'A CakePHP core class name (e.g: Component, HtmlHelper).' + 'help' => __d('cake_console', 'A CakePHP core class name (e.g: Component, HtmlHelper).') ))->addOption('method', array( 'short' => 'm', 'help' => __d('cake_console', 'The specific method you want help on.') @@ -181,7 +181,7 @@ class ApiShell extends Shell { } elseif (isset($commands[strtolower($this->args[1])])) { $this->out($commands[strtolower($this->args[1])] . "\n\n"); } else { - $this->out("Command '" . $this->args[1] . "' not found"); + $this->out(__d('cake_console', 'Command %s not found', $this->args[1])); } } diff --git a/lib/Cake/Console/Command/BakeShell.php b/lib/Cake/Console/Command/BakeShell.php index 94b06f379..8ef726db6 100644 --- a/lib/Cake/Console/Command/BakeShell.php +++ b/lib/Cake/Console/Command/BakeShell.php @@ -79,16 +79,16 @@ class BakeShell extends Shell { $this->args = null; return $this->DbConfig->execute(); } - $this->out('Interactive Bake Shell'); + $this->out(__d('cake_console', 'Interactive Bake Shell')); $this->hr(); - $this->out('[D]atabase Configuration'); - $this->out('[M]odel'); - $this->out('[V]iew'); - $this->out('[C]ontroller'); - $this->out('[P]roject'); - $this->out('[F]ixture'); - $this->out('[T]est case'); - $this->out('[Q]uit'); + $this->out(__d('cake_console', '[D]atabase Configuration')); + $this->out(__d('cake_console', '[M]odel')); + $this->out(__d('cake_console', '[V]iew')); + $this->out(__d('cake_console', '[C]ontroller')); + $this->out(__d('cake_console', '[P]roject')); + $this->out(__d('cake_console', '[F]ixture')); + $this->out(__d('cake_console', '[T]est case')); + $this->out(__d('cake_console', '[Q]uit')); $classToBake = strtoupper($this->in(__d('cake_console', 'What would you like to Bake?'), array('D', 'M', 'V', 'C', 'P', 'F', 'T', 'Q'))); switch ($classToBake) { @@ -199,12 +199,11 @@ class BakeShell extends Shell { */ public function getOptionParser() { $parser = parent::getOptionParser(); - return $parser->description( - 'The Bake script generates controllers, views and models for your application.' . - 'If run with no command line arguments, Bake guides the user through the class' . - 'creation process. You can customize the generation process by telling Bake' . - 'where different parts of your application are using command line arguments.' - )->addSubcommand('all', array( + return $parser->description(__d('cake_console', + 'The Bake script generates controllers, views and models for your application.' + . ' If run with no command line arguments, Bake guides the user through the class creation process.' . + . ' You can customize the generation process by telling Bake where different parts of your application are using command line arguments.' + ))->addSubcommand('all', array( 'help' => __d('cake_console', 'Bake a complete MVC. optional of a Model'), ))->addSubcommand('project', array( 'help' => __d('cake_console', 'Bake a new app folder in the path supplied or in current directory if no path is specified'), @@ -231,7 +230,7 @@ class BakeShell extends Shell { 'help' => __d('cake_console', 'Bake a unit test.'), 'parser' => $this->Test->getOptionParser() ))->addOption('connection', array( - 'help' => __d('cake_console', 'Database connection to use in conjunction with `bake all`.'), + 'help' => __d('cake_console', 'Database connection to use in conjunction with `bake all`.'), 'short' => 'c', 'default' => 'default' )); diff --git a/lib/Cake/Console/Command/CommandListShell.php b/lib/Cake/Console/Command/CommandListShell.php index aa3d0d4ed..56f487299 100644 --- a/lib/Cake/Console/Command/CommandListShell.php +++ b/lib/Cake/Console/Command/CommandListShell.php @@ -43,18 +43,17 @@ class CommandListShell extends Shell { */ public function main() { if (empty($this->params['xml'])) { - $this->out("Current Paths:", 2); + $this->out(__d('cake_console', "Current Paths:"), 2); $this->out(" -app: ". APP_DIR); $this->out(" -working: " . rtrim(APP_PATH, DS)); $this->out(" -root: " . rtrim(ROOT, DS)); $this->out(" -core: " . rtrim(CORE_PATH, DS)); $this->out(""); - $this->out("Changing Paths:", 2); - $this->out("Your working path should be the same as your application path"); - $this->out("to change your path use the '-app' param."); - $this->out("Example: -app relative/path/to/myapp or -app /absolute/path/to/myapp", 2); + $this->out(__d('cake_console', "Changing Paths:"), 2); + $this->out(__d('cake_console', "Your working path should be the same as your application path to change your path use the '-app' param.")); + $this->out(__d('cake_console', "Example: -app relative/path/to/myapp or -app /absolute/path/to/myapp"), 2); - $this->out("Available Shells:", 2); + $this->out(__d('cake_console', "Available Shells:"), 2); } $shellList = $this->_getShellList(); @@ -140,8 +139,8 @@ class CommandListShell extends Shell { $this->out(" " . $row); } $this->out(); - $this->out("To run a command, type cake shell_name [args]"); - $this->out("To get help on a specific command, type cake shell_name --help", 2); + $this->out(__d('cake_console', "To run a command, type cake shell_name [args]")); + $this->out(__d('cake_console', "To get help on a specific command, type cake shell_name --help"), 2); } /** @@ -212,7 +211,7 @@ class CommandListShell extends Shell { */ public function getOptionParser() { $parser = parent::getOptionParser(); - return $parser->description('Get the list of available shells for this CakePHP application.') + return $parser->description(__d('cake_console', 'Get the list of available shells for this CakePHP application.')) ->addOption('xml', array( 'help' => __d('cake_console', 'Get the listing as XML.'), 'boolean' => true diff --git a/lib/Cake/Console/Command/ConsoleShell.php b/lib/Cake/Console/Command/ConsoleShell.php index 1e00d7dd7..099c3921f 100644 --- a/lib/Cake/Console/Command/ConsoleShell.php +++ b/lib/Cake/Console/Command/ConsoleShell.php @@ -47,7 +47,7 @@ class ConsoleShell extends Shell { public $models = array(); /** - * Override intialize of the Shell + * Override initialize of the Shell * */ public function initialize() { @@ -61,8 +61,8 @@ class ConsoleShell extends Shell { App::uses($class, 'Model'); $this->{$class} = new $class(); } - $this->out('Model classes:'); - $this->out('--------------'); + $this->out(__d('cake_console', 'Model classes:')); + $this->hr(); foreach ($this->models as $model) { $this->out(" - {$model}"); @@ -151,7 +151,7 @@ class ConsoleShell extends Shell { return true; break; case 'models': - $this->out('Model classes:'); + $this->out(__d('cake_console', 'Model classes:')); $this->hr(); foreach ($this->models as $model) { $this->out(" - {$model}"); @@ -169,9 +169,10 @@ class ConsoleShell extends Shell { if ($this->_isValidModel($modelA) && $this->_isValidModel($modelB) && in_array($association, $this->associations)) { $this->{$modelA}->bindModel(array($association => array($modelB => array('className' => $modelB))), false); - $this->out("Created $association association between $modelA and $modelB"); + $this->out(__d('cake_console', "Created %s association between %s and %s", + $association, $modelA, $modelB)); } else { - $this->out("Please verify you are using valid models and association types"); + $this->out(__d('cake_console', "Please verify you are using valid models and association types")); } break; case (preg_match("/^(\w+) unbind (\w+) (\w+)/", $command, $tmp) == true): @@ -196,9 +197,10 @@ class ConsoleShell extends Shell { if ($this->_isValidModel($modelA) && $this->_isValidModel($modelB) && in_array($association, $this->associations) && $validCurrentAssociation) { $this->{$modelA}->unbindModel(array($association => array($modelB))); - $this->out("Removed $association association between $modelA and $modelB"); + $this->out(__d('cake_console', "Removed %s association between %s and %s", + $association, $modelA, $modelB)); } else { - $this->out("Please verify you are using valid models, valid current association, and valid association types"); + $this->out(__d('cake_console', "Please verify you are using valid models, valid current association, and valid association types")); } break; case (strpos($command, "->find") > 0): @@ -248,10 +250,11 @@ class ConsoleShell extends Shell { } } } else { - $this->out("\nNo result set found"); + $this->out(); + $this->out(__d('cake_console', "No result set found")); } } else { - $this->out("$modelToCheck is not a valid model"); + $this->out(__d('cake_console', "%s is not a valid model", $modelToCheck)); } break; @@ -267,7 +270,7 @@ class ConsoleShell extends Shell { $data = preg_replace('/^\(*(array)?\(*(.+?)\)*$/i', '\\2', $data); $saveCommand = "\$this->{$modelToSave}->save(array('{$modelToSave}' => array({$data})));"; @eval($saveCommand); - $this->out('Saved record for ' . $modelToSave); + $this->out(__d('cake_console', 'Saved record for %s', $modelToSave)); } break; case (preg_match("/^(\w+) columns/", $command, $tmp) == true): @@ -284,17 +287,16 @@ class ConsoleShell extends Shell { } } } else { - $this->out("Please verify that you selected a valid model"); + $this->out(__d('cake_console', "Please verify that you selected a valid model")); } break; case (preg_match("/^routes\s+reload/i", $command, $tmp) == true): $router = Router::getInstance(); if (!$this->_loadRoutes()) { - $this->out("There was an error loading the routes config. Please check that the file"); - $this->out("exists and is free of parse errors."); + $this->out(__d('cake_console', "There was an error loading the routes config. Please check that the file exists and is free of parse errors.")); break; } - $this->out("Routes configuration reloaded, " . count($router->routes) . " routes connected"); + $this->out(__d('cake_console', "Routes configuration reloaded, %d routes connected", count($router->routes))); break; case (preg_match("/^routes\s+show/i", $command, $tmp) == true): $router = Router::getInstance(); @@ -309,7 +311,8 @@ class ConsoleShell extends Shell { $this->out(var_export(Router::parse($tmp[1]), true)); break; default: - $this->out("Invalid command\n"); + $this->out(__d('cake_console', "Invalid command")); + $this->out(); break; } $command = ''; diff --git a/lib/Cake/Console/Command/SchemaShell.php b/lib/Cake/Console/Command/SchemaShell.php index e051355c9..20454e4d6 100644 --- a/lib/Cake/Console/Command/SchemaShell.php +++ b/lib/Cake/Console/Command/SchemaShell.php @@ -137,7 +137,8 @@ class SchemaShell extends Shell { if (!$snapshot && file_exists($this->Schema->path . DS . $this->params['file'])) { $snapshot = true; - $result = strtolower($this->in("Schema file exists.\n [O]verwrite\n [S]napshot\n [Q]uit\nWould you like to do?", array('o', 's', 'q'), 's')); + $prompt = __d('cake_console', "Schema file exists.\n [O]verwrite\n [S]napshot\n [Q]uit\nWould you like to do?"); + $result = strtolower($this->in($prompt, array('o', 's', 'q'), 's')); if ($result === 'q') { return $this->_stop(); } @@ -453,7 +454,7 @@ class SchemaShell extends Shell { 'help' => __d('cake_console', 'Snapshot number to use/make.') ); $dry = array( - 'help' => 'Perform a dry run on create and update commands. Queries will be output instead of run.', + 'help' => __d('cake_console', 'Perform a dry run on create and update commands. Queries will be output instead of run.'), 'boolean' => true ); $force = array( @@ -467,10 +468,9 @@ class SchemaShell extends Shell { $parser = parent::getOptionParser(); $parser->description( - 'The Schema Shell generates a schema object from' . - 'the database and updates the database from the schema.' + __d('cake_console', 'The Schema Shell generates a schema object from the database and updates the database from the schema.') )->addSubcommand('view', array( - 'help' => 'read and output the contents of a schema file', + 'help' => __d('cake_console', 'Read and output the contents of a schema file'), 'parser' => array( 'options' => compact('plugin', 'path', 'file', 'name', 'connection'), 'arguments' => compact('name') diff --git a/lib/Cake/Console/Command/Task/ControllerTask.php b/lib/Cake/Console/Command/Task/ControllerTask.php index 6f4723c64..417f9e38a 100644 --- a/lib/Cake/Console/Command/Task/ControllerTask.php +++ b/lib/Cake/Console/Command/Task/ControllerTask.php @@ -305,7 +305,7 @@ class ControllerTask extends BakeTask { * @return string Baked controller */ public function bake($controllerName, $actions = '', $helpers = null, $components = null) { - $this->out("\nBaking controller class for $controllerName...", 1, Shell::QUIET); + $this->out("\n" . __d('cake_console', 'Baking controller class for %s...', $controllerName), 1, Shell::QUIET); $isScaffold = ($actions === 'scaffold') ? true : false; diff --git a/lib/Cake/Console/Command/Task/DbConfigTask.php b/lib/Cake/Console/Command/Task/DbConfigTask.php index 2ffdd4ada..c76bb2b40 100644 --- a/lib/Cake/Console/Command/Task/DbConfigTask.php +++ b/lib/Cake/Console/Command/Task/DbConfigTask.php @@ -94,19 +94,19 @@ class DbConfigTask extends Shell { $name = ''; while ($name == '') { - $name = $this->in("Name:", null, 'default'); + $name = $this->in(__d('cake_console', "Name:"), null, 'default'); if (preg_match('/[^a-z0-9_]/i', $name)) { $name = ''; - $this->out('The name may only contain unaccented latin characters, numbers or underscores'); + $this->out(__d('cake_console', 'The name may only contain unaccented latin characters, numbers or underscores')); } else if (preg_match('/^[^a-z_]/i', $name)) { $name = ''; - $this->out('The name must start with an unaccented latin character or an underscore'); + $this->out(__d('cake_console', 'The name must start with an unaccented latin character or an underscore')); } } - $driver = $this->in('Driver:', array('mssql', 'mysql', 'oracle', 'postgres', 'sqlite'), 'mysql'); + $driver = $this->in(__d('cake_console', 'Driver:'), array('mssql', 'mysql', 'oracle', 'postgres', 'sqlite'), 'mysql'); - $persistent = $this->in('Persistent Connection?', array('y', 'n'), 'n'); + $persistent = $this->in(__d('cake_console', 'Persistent Connection?'), array('y', 'n'), 'n'); if (strtolower($persistent) == 'n') { $persistent = 'false'; } else { @@ -115,12 +115,12 @@ class DbConfigTask extends Shell { $host = ''; while ($host == '') { - $host = $this->in('Database Host:', null, 'localhost'); + $host = $this->in(__d('cake_console', 'Database Host:'), null, 'localhost'); } $port = ''; while ($port == '') { - $port = $this->in('Port?', null, 'n'); + $port = $this->in(__d('cake_console', 'Port?'), null, 'n'); } if (strtolower($port) == 'n') { @@ -129,16 +129,16 @@ class DbConfigTask extends Shell { $login = ''; while ($login == '') { - $login = $this->in('User:', null, 'root'); + $login = $this->in(__d('cake_console', 'User:'), null, 'root'); } $password = ''; $blankPassword = false; while ($password == '' && $blankPassword == false) { - $password = $this->in('Password:'); + $password = $this->in(__d('cake_console', 'Password:')); if ($password == '') { - $blank = $this->in('The password you supplied was empty. Use an empty password?', array('y', 'n'), 'n'); + $blank = $this->in(__d('cake_console', 'The password you supplied was empty. Use an empty password?'), array('y', 'n'), 'n'); if ($blank == 'y') { $blankPassword = true; } @@ -147,12 +147,12 @@ class DbConfigTask extends Shell { $database = ''; while ($database == '') { - $database = $this->in('Database Name:', null, 'cake'); + $database = $this->in(__d('cake_console', 'Database Name:'), null, 'cake'); } $prefix = ''; while ($prefix == '') { - $prefix = $this->in('Table Prefix?', null, 'n'); + $prefix = $this->in(__d('cake_console', 'Table Prefix?'), null, 'n'); } if (strtolower($prefix) == 'n') { $prefix = null; @@ -160,7 +160,7 @@ class DbConfigTask extends Shell { $encoding = ''; while ($encoding == '') { - $encoding = $this->in('Table encoding?', null, 'n'); + $encoding = $this->in(__d('cake_console', 'Table encoding?'), null, 'n'); } if (strtolower($encoding) == 'n') { $encoding = null; @@ -169,7 +169,7 @@ class DbConfigTask extends Shell { $schema = ''; if ($driver == 'postgres') { while ($schema == '') { - $schema = $this->in('Table schema?', null, 'n'); + $schema = $this->in(__d('cake_console', 'Table schema?'), null, 'n'); } } if (strtolower($schema) == 'n') { @@ -183,7 +183,7 @@ class DbConfigTask extends Shell { } $dbConfigs[] = $config; - $doneYet = $this->in('Do you wish to add another database configuration?', null, 'n'); + $doneYet = $this->in(__d('cake_console', 'Do you wish to add another database configuration?'), null, 'n'); if (strtolower($doneYet == 'n')) { $done = true; @@ -205,35 +205,35 @@ class DbConfigTask extends Shell { extract($config); $this->out(); $this->hr(); - $this->out('The following database configuration will be created:'); + $this->out(__d('cake_console', 'The following database configuration will be created:')); $this->hr(); - $this->out("Name: $name"); - $this->out("Driver: $driver"); - $this->out("Persistent: $persistent"); - $this->out("Host: $host"); + $this->out(__d('cake_console', "Name: %s", $name)); + $this->out(__d('cake_console', "Driver: %s", $driver)); + $this->out(__d('cake_console', "Persistent: %s", $persistent)); + $this->out(__d('cake_console', "Host: %s", $host)); if ($port) { - $this->out("Port: $port"); + $this->out(__d('cake_console', "Port: %s", $port)); } - $this->out("User: $login"); - $this->out("Pass: " . str_repeat('*', strlen($password))); - $this->out("Database: $database"); + $this->out(__d('cake_console', "User: %s", $login)); + $this->out("Pass: %s", str_repeat('*', strlen($password)))); + $this->out("Database: %s", $database)); if ($prefix) { - $this->out("Table prefix: $prefix"); + $this->out(__d('cake_console', "Table prefix: %s", $prefix)); } if ($schema) { - $this->out("Schema: $schema"); + $this->out(__d('cake_console', "Schema: %s", $schema)); } if ($encoding) { - $this->out("Encoding: $encoding"); + $this->out(__d('cake_console', "Encoding: %s", $encoding)); } $this->hr(); - $looksGood = $this->in('Look okay?', array('y', 'n'), 'y'); + $looksGood = $this->in(__d('cake_console', 'Look okay?'), array('y', 'n'), 'y'); if (strtolower($looksGood) == 'y') { return $config; @@ -249,7 +249,7 @@ class DbConfigTask extends Shell { */ public function bake($configs) { if (!is_dir($this->path)) { - $this->err($this->path . ' not found'); + $this->err(__d('cake_console', '%s not found', $this->path)); return false; } diff --git a/lib/Cake/Console/Command/Task/FixtureTask.php b/lib/Cake/Console/Command/Task/FixtureTask.php index 3af4120e4..d7359bbcc 100644 --- a/lib/Cake/Console/Command/Task/FixtureTask.php +++ b/lib/Cake/Console/Command/Task/FixtureTask.php @@ -83,7 +83,7 @@ class FixtureTask extends BakeTask { 'help' => __d('cake_console', 'CamelCased name of the plugin to bake fixtures for.'), 'short' => 'p', ))->addOption('records', array( - 'help' => 'Used with --count and /all commands to pull [n] records from the live tables, where [n] is either --count or the default of 10', + 'help' => __d('cake_console', 'Used with --count and /all commands to pull [n] records from the live tables, where [n] is either --count or the default of 10'), 'short' => 'r', 'boolean' => true ))->epilog(__d('cake_console', 'Omitting all arguments and options will enter into an interactive mode.'));; @@ -91,7 +91,7 @@ class FixtureTask extends BakeTask { /** * Execution method always used for tasks - * Handles dispatching to interactive, named, or all processess. + * Handles dispatching to interactive, named, or all processeses. * * @return void */ @@ -137,7 +137,7 @@ class FixtureTask extends BakeTask { protected function _interactive() { $this->DbConfig->interactive = $this->Model->interactive = $this->interactive = true; $this->hr(); - $this->out(sprintf("Bake Fixture\nPath: %s", $this->path)); + $this->out(__d('cake_console', "Bake Fixture\nPath: %s", $this->path)); $this->hr(); if (!isset($this->connection)) { @@ -254,7 +254,7 @@ class FixtureTask extends BakeTask { $this->Template->set($vars); $content = $this->Template->generate('classes', 'fixture'); - $this->out("\nBaking test fixture for $model...", 1, Shell::QUIET); + $this->out("\n" . __d('cake_console', 'Baking test fixture for %s...', $model), 1, Shell::QUIET); $this->createFile($path . $filename, $content); return $content; } diff --git a/lib/Cake/Console/Command/Task/ModelTask.php b/lib/Cake/Console/Command/Task/ModelTask.php index a8aa79e68..70f6dff99 100644 --- a/lib/Cake/Console/Command/Task/ModelTask.php +++ b/lib/Cake/Console/Command/Task/ModelTask.php @@ -168,7 +168,7 @@ class ModelTask extends BakeTask { */ protected function _interactive() { $this->hr(); - $this->out(sprintf("Bake Model\nPath: %s", $this->path)); + $this->out(__d('cake_console', "Bake Model\nPath: %s", $this->path)); $this->hr(); $this->interactive = true; @@ -215,7 +215,7 @@ class ModelTask extends BakeTask { $this->hr(); $this->out(__d('cake_console', 'The following Model will be created:')); $this->hr(); - $this->out("Name: " . $currentModelName); + $this->out(__d('cake_console', "Name: %s", $currentModelName)); if ($this->connection !== 'default') { $this->out(__d('cake_console', "DB Config: %s", $this->connection)); @@ -561,7 +561,7 @@ class ModelTask extends BakeTask { * Find the hasAndBelongsToMany relations and add them to associations list * * @param object $model Model instance being generated - * @param array $associations Array of inprogress associations + * @param array $associations Array of in-progress associations * @return array $associations with hasAndBelongsToMany added in. */ public function findHasAndBelongsToMany($model, $associations) { @@ -738,7 +738,7 @@ class ModelTask extends BakeTask { $path = $this->getPath(); $filename = $path . $name . '.php'; - $this->out("\nBaking model class for $name...", 1, Shell::QUIET); + $this->out("\n" . __d('cake_console', 'Baking model class for %s...', $name), 1, Shell::QUIET); $this->createFile($filename, $out); ClassRegistry::flush(); return $out; diff --git a/lib/Cake/Console/Command/Task/PluginTask.php b/lib/Cake/Console/Command/Task/PluginTask.php index 8c7f2ed50..e7d754048 100644 --- a/lib/Cake/Console/Command/Task/PluginTask.php +++ b/lib/Cake/Console/Command/Task/PluginTask.php @@ -185,10 +185,10 @@ class PluginTask extends Shell { */ public function getOptionParser() { $parser = parent::getOptionParser(); - return $parser->description( + return $parser->description(__d('cake_console', 'Create the directory structure, AppModel and AppController classes for a new plugin. ' . 'Can create plugins in any of your bootstrapped plugin paths.' - )->addArgument('name', array( + ))->addArgument('name', array( 'help' => __d('cake_console', 'CamelCased name of the plugin to create.') )); diff --git a/lib/Cake/Console/Command/Task/ProjectTask.php b/lib/Cake/Console/Command/Task/ProjectTask.php index 28e06b853..190f99819 100644 --- a/lib/Cake/Console/Command/Task/ProjectTask.php +++ b/lib/Cake/Console/Command/Task/ProjectTask.php @@ -357,7 +357,7 @@ class ProjectTask extends Shell { } if ($this->interactive) { $this->hr(); - $this->out('You need to enable Configure::write(\'Routing.prefixes\',array(\'admin\')) in /app/config/core.php to use prefix routing.'); + $this->out(__d('cake_console', 'You need to enable Configure::write(\'Routing.prefixes\',array(\'admin\')) in /app/config/core.php to use prefix routing.')); $this->out(__d('cake_console', 'What would you like the prefix route to be?')); $this->out(__d('cake_console', 'Example: www.example.com/admin/controller')); while ($admin == '') { @@ -365,7 +365,7 @@ class ProjectTask extends Shell { } if ($this->cakeAdmin($admin) !== true) { $this->out(__d('cake_console', 'Unable to write to /app/config/core.php.')); - $this->out('You need to enable Configure::write(\'Routing.prefixes\',array(\'admin\')) in /app/config/core.php to use prefix routing.'); + $this->out(__d('cake_console', 'You need to enable Configure::write(\'Routing.prefixes\',array(\'admin\')) in /app/config/core.php to use prefix routing.')); $this->_stop(); } return $admin . '_'; diff --git a/lib/Cake/Console/Command/Task/TestTask.php b/lib/Cake/Console/Command/Task/TestTask.php index 014988c56..991c9d754 100644 --- a/lib/Cake/Console/Command/Task/TestTask.php +++ b/lib/Cake/Console/Command/Task/TestTask.php @@ -142,7 +142,7 @@ class TestTask extends BakeTask { if ($this->plugin) { $plugin = $this->plugin . '.'; } - $this->out("\nBaking test case for $className $type...", 1, Shell::QUIET); + $this->out("\n" . __d('cake_console', 'Baking test case for %s %s ...', $className, $type), 1, Shell::QUIET); $this->Template->set('fixtures', $this->_fixtures); $this->Template->set('plugin', $plugin); diff --git a/lib/Cake/Console/Command/Task/ViewTask.php b/lib/Cake/Console/Command/Task/ViewTask.php index 03f6c4f3f..ab3bf784e 100644 --- a/lib/Cake/Console/Command/Task/ViewTask.php +++ b/lib/Cake/Console/Command/Task/ViewTask.php @@ -367,7 +367,7 @@ class ViewTask extends BakeTask { if (empty($content)) { return false; } - $this->out("\nBaking `$action` view file...", 1, Shell::QUIET); + $this->out("\n" . __d('cake_console', 'Baking `%s` view file...', $action), 1, Shell::QUIET); $path = $this->getPath(); $filename = $path . $this->controllerPath . DS . Inflector::underscore($action) . '.ctp'; return $this->createFile($filename, $content); diff --git a/lib/Cake/Console/Command/TestsuiteShell.php b/lib/Cake/Console/Command/TestsuiteShell.php index 07d9cf4c9..0d4de9de8 100644 --- a/lib/Cake/Console/Command/TestsuiteShell.php +++ b/lib/Cake/Console/Command/TestsuiteShell.php @@ -41,8 +41,8 @@ class TestsuiteShell extends Shell { public function getOptionParser() { $parser = new ConsoleOptionParser($this->name); $parser->description(array( - 'The CakePHP Testsuite allows you to run test cases from the command line', - 'If run with no command line arguments, a list of available core test cases will be shown' + __d('cake_console', 'The CakePHP Testsuite allows you to run test cases from the command line'), + __d('cake_console', 'If run with no command line arguments, a list of available core test cases will be shown') ))->addArgument('category', array( 'help' => __d('cake_console', 'app, core or name of a plugin.'), 'required' => true @@ -157,7 +157,7 @@ class TestsuiteShell extends Shell { } /** - * Initialization method installs Simpletest and loads all plugins + * Initialization method installs PHPUnit and loads all plugins * * @return void */ diff --git a/lib/Cake/Console/ConsoleErrorHandler.php b/lib/Cake/Console/ConsoleErrorHandler.php index 9020bd1be..e381b225f 100644 --- a/lib/Cake/Console/ConsoleErrorHandler.php +++ b/lib/Cake/Console/ConsoleErrorHandler.php @@ -57,8 +57,7 @@ class ConsoleErrorHandler extends ErrorHandler { */ public static function handleException(Exception $exception) { $stderr = self::getStderr(); - $stderr->write(sprintf( - __d('cake_console', "Error: %s\n%s"), + $stderr->write(__d('cake_console', "Error: %s\n%s", $exception->getMessage(), $exception->getTraceAsString() )); @@ -70,7 +69,7 @@ class ConsoleErrorHandler extends ErrorHandler { * @param int $code Error code * @param string $description Description of the error. * @param string $file The file the error occurred in. - * @param int $line The line the error ocurrred on. + * @param int $line The line the error occurred on. * @param array $context The backtrace of the error. * @return void */ diff --git a/lib/Cake/Console/ConsoleInputArgument.php b/lib/Cake/Console/ConsoleInputArgument.php index 885ce2180..649c50866 100644 --- a/lib/Cake/Console/ConsoleInputArgument.php +++ b/lib/Cake/Console/ConsoleInputArgument.php @@ -55,7 +55,7 @@ class ConsoleInputArgument { /** * Make a new Input Argument * - * @param mixed $name The long name of the option, or an array with all the properites. + * @param mixed $name The long name of the option, or an array with all the properties. * @param string $help The help text for this option * @param boolean $required Whether this argument is required. Missing required args will trigger exceptions * @param array $choices Valid choices for this option. @@ -139,8 +139,8 @@ class ConsoleInputArgument { return true; } if (!in_array($value, $this->_choices)) { - throw new ConsoleException(sprintf( - __d('cake_console', '"%s" is not a valid value for %s. Please use one of "%s"'), + throw new ConsoleException( + __d('cake_console', '"%s" is not a valid value for %s. Please use one of "%s"', $value, $this->_name, implode(', ', $this->_choices) )); } diff --git a/lib/Cake/Console/ConsoleInputOption.php b/lib/Cake/Console/ConsoleInputOption.php index 61497e5e4..25989be20 100644 --- a/lib/Cake/Console/ConsoleInputOption.php +++ b/lib/Cake/Console/ConsoleInputOption.php @@ -70,7 +70,7 @@ class ConsoleInputOption { /** * Make a new Input Option * - * @param mixed $name The long name of the option, or an array with all the properites. + * @param mixed $name The long name of the option, or an array with all the properties. * @param string $short The short alias for this option * @param string $help The help text for this option * @param boolean $boolean Whether this option is a boolean option. Boolean options don't consume extra tokens @@ -179,8 +179,8 @@ class ConsoleInputOption { return true; } if (!in_array($value, $this->_choices)) { - throw new ConsoleException(sprintf( - __d('cake_console', '"%s" is not a valid value for --%s. Please use one of "%s"'), + throw new ConsoleException( + __d('cake_console', '"%s" is not a valid value for --%s. Please use one of "%s"', $value, $this->_name, implode(', ', $this->_choices) )); } diff --git a/lib/Cake/Console/ConsoleInputSubcommand.php b/lib/Cake/Console/ConsoleInputSubcommand.php index b2903aec2..fef324334 100644 --- a/lib/Cake/Console/ConsoleInputSubcommand.php +++ b/lib/Cake/Console/ConsoleInputSubcommand.php @@ -50,7 +50,7 @@ class ConsoleInputSubcommand { /** * Make a new Subcommand * - * @param mixed $name The long name of the subcommand, or an array with all the properites. + * @param mixed $name The long name of the subcommand, or an array with all the properties. * @param string $help The help text for this option * @param mixed $parser A parser for this subcommand. Either a ConsoleOptionParser, or an array that can be * used with ConsoleOptionParser::buildFromArray() diff --git a/lib/Cake/Console/ConsoleOptionParser.php b/lib/Cake/Console/ConsoleOptionParser.php index 6c221502b..c73bec9c0 100644 --- a/lib/Cake/Console/ConsoleOptionParser.php +++ b/lib/Cake/Console/ConsoleOptionParser.php @@ -86,9 +86,9 @@ class ConsoleOptionParser { * * ### Options * - * Named arguments come in two forms, long and short. Long arguments are preceeded + * Named arguments come in two forms, long and short. Long arguments are preceded * by two - and give a more verbose option name. i.e. `--version`. Short arguments are - * preceeded by one - and are only one character long. They usually match with a long option, + * preceded by one - and are only one character long. They usually match with a long option, * and provide a more terse alternative. * * ### Using Options @@ -102,7 +102,7 @@ class ConsoleOptionParser { * * `cake myshell command --connection default --name=something` * - * Short options can be defined singally or in groups. + * Short options can be defined signally or in groups. * * `cake myshell command -cn` * @@ -127,7 +127,7 @@ class ConsoleOptionParser { $this->addOption('help', array( 'short' => 'h', - 'help' => 'Display this help.', + 'help' => __d('cake_console', 'Display this help.'), 'boolean' => true )); @@ -330,7 +330,7 @@ class ConsoleOptionParser { } /** - * Add multiple arugments at once. Take an array of arugment defintions. + * Add multiple arguments at once. Take an array of argument definitions. * The keys are used as the argument names, and the values as params for the argument. * * @param array $args Array of arguments to add. diff --git a/lib/Cake/Console/ConsoleOutput.php b/lib/Cake/Console/ConsoleOutput.php index 7d41da4d7..3a9f205cd 100644 --- a/lib/Cake/Console/ConsoleOutput.php +++ b/lib/Cake/Console/ConsoleOutput.php @@ -17,10 +17,10 @@ * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ /** - * Object wrapper for outputing information from a shell application. + * Object wrapper for outputting information from a shell application. * Can be connected to any stream resource that can be used with fopen() * - * Can generate colourized output on consoles that support it. There are a few + * Can generate colorized output on consoles that support it. There are a few * built in styles * * - `error` Error messages. @@ -37,7 +37,7 @@ * * `$this->out('Overwrite: foo.php was overwritten.');` * - * This would create orange 'Overwrite:' text, while the rest of the text would remain the normal colour. + * This would create orange 'Overwrite:' text, while the rest of the text would remain the normal color. * See ConsoleOutput::styles() to learn more about defining your own styles. Nested styles are not supported * at this time. * @@ -55,7 +55,7 @@ class ConsoleOutput { const PLAIN = 1; /** - * Colour output - Convert known tags in to ANSI color escape codes. + * Color output - Convert known tags in to ANSI color escape codes. */ const COLOR = 2; @@ -79,7 +79,7 @@ class ConsoleOutput { protected $_outputAs = self::COLOR; /** - * text colors used in coloured output. + * text colors used in colored output. * * @var array */ @@ -95,7 +95,7 @@ class ConsoleOutput { ); /** - * background colours used in coloured output. + * background colors used in colored output. * * @var array */ @@ -111,7 +111,7 @@ class ConsoleOutput { ); /** - * formatting options for coloured output + * formatting options for colored output * * @var string */ @@ -140,7 +140,7 @@ class ConsoleOutput { /** * Construct the output object. * - * Checks for a pretty console enviornment. Ansicon allows pretty consoles + * Checks for a pretty console environment. Ansicon allows pretty consoles * on windows, and is supported. * * @param string $stream The identifier of the stream to write output to. @@ -267,7 +267,7 @@ class ConsoleOutput { /** * Get/Set the output type to use. The output type how formatting tags are treated. * - * @param int $type The output type to use. Should be one of the class contstants. + * @param int $type The output type to use. Should be one of the class constants. * @return mixed Either null or the value if getting. */ public function outputAs($type = null) { diff --git a/lib/Cake/Console/HelpFormatter.php b/lib/Cake/Console/HelpFormatter.php index 94a32af88..283d1ee30 100644 --- a/lib/Cake/Console/HelpFormatter.php +++ b/lib/Cake/Console/HelpFormatter.php @@ -23,7 +23,7 @@ App::uses('String', 'Utility'); * Generally not directly used. Using $parser->help($command, 'xml'); is usually * how you would access help. Or via the `--help=xml` option on the command line. * - * Xml output is useful for intergration with other tools like IDE's or other build tools. + * Xml output is useful for integration with other tools like IDE's or other build tools. * * @package cake.console.libs * @since CakePHP(tm) v 2.0 @@ -52,12 +52,12 @@ class HelpFormatter { $out[] = String::wrap($description, $width); $out[] = ''; } - $out[] = 'Usage:'; + $out[] = __d('cake_console', 'Usage:'); $out[] = $this->_generateUsage(); $out[] = ''; $subcommands = $parser->subcommands(); if (!empty($subcommands)) { - $out[] = 'Subcommands:'; + $out[] = __d('cake_console', 'Subcommands:'); $out[] = ''; $max = $this->_getMaxLength($subcommands) + 2; foreach ($subcommands as $command) { @@ -68,17 +68,14 @@ class HelpFormatter { )); } $out[] = ''; - $out[] = sprintf( - __d('cake_console', 'To see help on a subcommand use `cake %s [subcommand] --help`'), - $parser->command() - ); + $out[] = __d('cake_console', 'To see help on a subcommand use `cake %s [subcommand] --help`', $parser->command()); $out[] = ''; } $options = $parser->options(); if (!empty($options)) { $max = $this->_getMaxLength($options) + 8; - $out[] = 'Options:'; + $out[] = __d('cake_console', 'Options:'); $out[] = ''; foreach ($options as $option) { $out[] = String::wrap($option->help($max), array( @@ -93,7 +90,7 @@ class HelpFormatter { $arguments = $parser->arguments(); if (!empty($arguments)) { $max = $this->_getMaxLength($arguments) + 2; - $out[] = 'Arguments:'; + $out[] = __d('cake_console', 'Arguments:'); $out[] = ''; foreach ($arguments as $argument) { $out[] = String::wrap($argument->help($max), array( @@ -114,7 +111,7 @@ class HelpFormatter { /** * Generate the usage for a shell based on its arguments and options. - * Usage strings favour short options over the long ones. and optional args will + * Usage strings favor short options over the long ones. and optional args will * be indicated with [] * * @return string @@ -156,7 +153,7 @@ class HelpFormatter { public function xml($string = true) { $parser = $this->_parser; $xml = new SimpleXmlElement(''); - $xml->addChild('commmand', $parser->command()); + $xml->addChild('command', $parser->command()); $xml->addChild('description', $parser->description()); $xml->addChild('epilog', $parser->epilog()); diff --git a/lib/Cake/Console/Shell.php b/lib/Cake/Console/Shell.php index 9ea899bb4..00aea53d6 100644 --- a/lib/Cake/Console/Shell.php +++ b/lib/Cake/Console/Shell.php @@ -188,7 +188,7 @@ class Shell extends Object { /** * Starts up the Shell * allows for checking and configuring prior to command or main execution - * can be overriden in subclasses + * can be overridden in subclasses * */ public function startup() { @@ -201,10 +201,10 @@ class Shell extends Object { */ protected function _welcome() { $this->out(); - $this->out('Welcome to CakePHP v' . Configure::version() . ' Console'); + $this->out(__d('cake_console', 'Welcome to CakePHP %s Console', 'v' . Configure::version())); $this->hr(); - $this->out('App : '. APP_DIR); - $this->out('Path: '. APP_PATH); + $this->out(__d('cake_console', 'App : %s', APP_DIR)); + $this->out(__d('cake_console', 'Path: %s', APP_PATH)); $this->hr(); } @@ -296,7 +296,7 @@ class Shell extends Object { * * ### Usage: * - * With a string commmand: + * With a string command: * * `return $this->dispatchShell('schema create DbAcl');` * @@ -578,7 +578,7 @@ class Shell extends Object { */ public function clear() { if (empty($this->params['noclear'])) { - if ( DS === '/') { + if (DS === '/') { passthru('clear'); } else { passthru('cls'); @@ -600,7 +600,7 @@ class Shell extends Object { if (is_file($path) && $this->interactive === true) { $this->out(__d('cake_console', 'File `%s` exists', $path)); - $key = $this->in(__d('cake_console', 'Do you want to overwrite?'), array('y', 'n', 'q'), 'n'); + $key = $this->in(__d('cake_console', 'Do you want to overwrite?'), array('y', 'n', 'q'), 'n'); if (strtolower($key) == 'q') { $this->out(__d('cake_console', 'Quitting.'), 2); @@ -636,13 +636,13 @@ class Shell extends Object { if (@include 'PHPUnit' . DS . 'Autoload.php') { return true; } - $prompt = 'PHPUnit is not installed. Do you want to bake unit test files anyway?'; + $prompt = __d('cake_console', 'PHPUnit is not installed. Do you want to bake unit test files anyway?'); $unitTest = $this->in($prompt, array('y','n'), 'y'); $result = strtolower($unitTest) == 'y' || strtolower($unitTest) == 'yes'; if ($result) { $this->out(); - $this->out('You can download PHPUnit from http://phpunit.de'); + $this->out(__d('cake_console', 'You can download PHPUnit from %s', 'http://phpunit.de')); } return $result; } diff --git a/lib/Cake/Console/ShellDispatcher.php b/lib/Cake/Console/ShellDispatcher.php index 465b6d303..f12550249 100644 --- a/lib/Cake/Console/ShellDispatcher.php +++ b/lib/Cake/Console/ShellDispatcher.php @@ -99,13 +99,13 @@ class ShellDispatcher { */ protected function _initEnvironment() { if (!$this->__bootstrap()) { - $message = "Unable to load CakePHP core.\nMake sure " . DS . 'cake' . DS . 'libs exists in ' . CAKE_CORE_INCLUDE_PATH; + $message = "Unable to load CakePHP core.\nMake sure " . DS . 'lib' . DS . 'Cake exists in ' . CAKE_CORE_INCLUDE_PATH; throw new CakeException($message); } if (!isset($this->args[0]) || !isset($this->params['working'])) { $message = "This file has been loaded incorrectly and cannot continue.\n" . - "Please make sure that " . DIRECTORY_SEPARATOR . "cake" . DIRECTORY_SEPARATOR . "console is in your system path,\n" . + "Please make sure that " . DS . 'lib' . DS . 'Cake' . DS . "Console is in your system path,\n" . "and check the cookbook for the correct usage of this command.\n" . "(http://book.cakephp.org/)"; throw new CakeException($message); From 9da76a865574773294706e21c32c4ca4193bbfee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Renan=20Gon=C3=A7alves?= Date: Mon, 25 Apr 2011 21:35:27 +0200 Subject: [PATCH 04/16] Fixing a couple of typos from last commit. --- lib/Cake/Console/Command/BakeShell.php | 2 +- lib/Cake/Console/Command/Task/DbConfigTask.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/Cake/Console/Command/BakeShell.php b/lib/Cake/Console/Command/BakeShell.php index 8ef726db6..650b52314 100644 --- a/lib/Cake/Console/Command/BakeShell.php +++ b/lib/Cake/Console/Command/BakeShell.php @@ -201,7 +201,7 @@ class BakeShell extends Shell { $parser = parent::getOptionParser(); return $parser->description(__d('cake_console', 'The Bake script generates controllers, views and models for your application.' - . ' If run with no command line arguments, Bake guides the user through the class creation process.' . + . ' If run with no command line arguments, Bake guides the user through the class creation process.' . ' You can customize the generation process by telling Bake where different parts of your application are using command line arguments.' ))->addSubcommand('all', array( 'help' => __d('cake_console', 'Bake a complete MVC. optional of a Model'), diff --git a/lib/Cake/Console/Command/Task/DbConfigTask.php b/lib/Cake/Console/Command/Task/DbConfigTask.php index c76bb2b40..9067a247f 100644 --- a/lib/Cake/Console/Command/Task/DbConfigTask.php +++ b/lib/Cake/Console/Command/Task/DbConfigTask.php @@ -217,8 +217,8 @@ class DbConfigTask extends Shell { } $this->out(__d('cake_console', "User: %s", $login)); - $this->out("Pass: %s", str_repeat('*', strlen($password)))); - $this->out("Database: %s", $database)); + $this->out(__d('cake_console', "Pass: %s", str_repeat('*', strlen($password)))); + $this->out(__d('cake_console', "Database: %s", $database)); if ($prefix) { $this->out(__d('cake_console', "Table prefix: %s", $prefix)); From 170ba71850d7b850145547850eeca7d9aa8b3fbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Renan=20Gon=C3=A7alves?= Date: Mon, 25 Apr 2011 22:08:12 +0200 Subject: [PATCH 05/16] Changing the visiblity from private to protected, for extensibility sake. --- lib/Cake/Console/Command/Task/ExtractTask.php | 210 +++++++++--------- 1 file changed, 105 insertions(+), 105 deletions(-) diff --git a/lib/Cake/Console/Command/Task/ExtractTask.php b/lib/Cake/Console/Command/Task/ExtractTask.php index 53bfa81fc..e1ed19b19 100644 --- a/lib/Cake/Console/Command/Task/ExtractTask.php +++ b/lib/Cake/Console/Command/Task/ExtractTask.php @@ -30,65 +30,65 @@ class ExtractTask extends Shell { * Paths to use when looking for strings * * @var string - * @access private + * @access protected */ - private $__paths = array(); + protected $_paths = array(); /** * Files from where to extract * * @var array - * @access private + * @access protected */ - private $__files = array(); + protected $_files = array(); /** * Merge all domains string into the default.pot file * * @var boolean - * @access private + * @access protected */ - private $__merge = false; + protected $_merge = false; /** * Current file being processed * * @var string - * @access private + * @access protected */ - private $__file = null; + protected $_file = null; /** * Contains all content waiting to be write * * @var string - * @access private + * @access protected */ - private $__storage = array(); + protected $_storage = array(); /** * Extracted tokens * * @var array - * @access private + * @access protected */ - private $__tokens = array(); + protected $_tokens = array(); /** * Extracted strings * * @var array - * @access private + * @access protected */ - private $__strings = array(); + protected $_strings = array(); /** * Destination path * * @var string - * @access private + * @access protected */ - private $__output = null; + protected $_output = null; /** * An array of directories to exclude. @@ -101,17 +101,17 @@ class ExtractTask extends Shell { * Execution method always used for tasks * * @return void - * @access private + * @access public */ public function execute() { if (!empty($this->params['exclude'])) { $this->_exclude = explode(',', $this->params['exclude']); } if (isset($this->params['files']) && !is_array($this->params['files'])) { - $this->__files = explode(',', $this->params['files']); + $this->_files = explode(',', $this->params['files']); } if (isset($this->params['paths'])) { - $this->__paths = explode(',', $this->params['paths']); + $this->_paths = explode(',', $this->params['paths']); } else { $defaultPath = APP_PATH; $message = __d('cake_console', "What is the path you would like to extract?\n[Q]uit [D]one"); @@ -124,7 +124,7 @@ class ExtractTask extends Shell { $this->out(); break; } elseif (is_dir($response)) { - $this->__paths[] = $response; + $this->_paths[] = $response; $defaultPath = 'D'; } else { $this->err(__d('cake_console', 'The directory path you supplied was not found. Please try again.')); @@ -134,16 +134,16 @@ class ExtractTask extends Shell { } if (isset($this->params['output'])) { - $this->__output = $this->params['output']; + $this->_output = $this->params['output']; } else { - $message = __d('cake_console', "What is the path you would like to output?\n[Q]uit", $this->__paths[0] . DS . 'locale'); + $message = __d('cake_console', "What is the path you would like to output?\n[Q]uit", $this->_paths[0] . DS . 'locale'); while (true) { - $response = $this->in($message, null, $this->__paths[0] . DS . 'locale'); + $response = $this->in($message, null, $this->_paths[0] . DS . 'locale'); if (strtoupper($response) === 'Q') { $this->out(__d('cake_console', 'Extract Aborted')); $this->_stop(); } elseif (is_dir($response)) { - $this->__output = $response . DS; + $this->_output = $response . DS; break; } else { $this->err(__d('cake_console', 'The directory path you supplied was not found. Please try again.')); @@ -153,41 +153,41 @@ class ExtractTask extends Shell { } if (isset($this->params['merge'])) { - $this->__merge = !(strtolower($this->params['merge']) === 'no'); + $this->_merge = !(strtolower($this->params['merge']) === 'no'); } else { $this->out(); $response = $this->in(__d('cake_console', 'Would you like to merge all domains strings into the default.pot file?'), array('y', 'n'), 'n'); - $this->__merge = strtolower($response) === 'y'; + $this->_merge = strtolower($response) === 'y'; } - if (empty($this->__files)) { - $this->__searchFiles(); + if (empty($this->_files)) { + $this->_searchFiles(); } - $this->__extract(); + $this->_extract(); } /** * Extract text * * @return void - * @access private + * @access protected */ - private function __extract() { + protected function _extract() { $this->out(); $this->out(); $this->out(__d('cake_console', 'Extracting...')); $this->hr(); $this->out(__d('cake_console', 'Paths:')); - foreach ($this->__paths as $path) { + foreach ($this->_paths as $path) { $this->out(' ' . $path); } - $this->out(__d('cake_console', 'Output Directory: ') . $this->__output); + $this->out(__d('cake_console', 'Output Directory: ') . $this->_output); $this->hr(); - $this->__extractTokens(); - $this->__buildFiles(); - $this->__writeFiles(); - $this->__paths = $this->__files = $this->__storage = array(); - $this->__strings = $this->__tokens = array(); + $this->_extractTokens(); + $this->_buildFiles(); + $this->_writeFiles(); + $this->_paths = $this->_files = $this->_storage = array(); + $this->_strings = $this->_tokens = array(); $this->out(); $this->out(__d('cake_console', 'Done.')); } @@ -245,30 +245,30 @@ class ExtractTask extends Shell { * Extract tokens out of all files to be processed * * @return void - * @access private + * @access protected */ - private function __extractTokens() { - foreach ($this->__files as $file) { - $this->__file = $file; + protected function _extractTokens() { + foreach ($this->_files as $file) { + $this->_file = $file; $this->out(__d('cake_console', 'Processing %s...', $file)); $code = file_get_contents($file); $allTokens = token_get_all($code); - $this->__tokens = array(); + $this->_tokens = array(); foreach ($allTokens as $token) { if (!is_array($token) || ($token[0] != T_WHITESPACE && $token[0] != T_INLINE_HTML)) { - $this->__tokens[] = $token; + $this->_tokens[] = $token; } } unset($allTokens); - $this->__parse('__', array('singular')); - $this->__parse('__n', array('singular', 'plural')); - $this->__parse('__d', array('domain', 'singular')); - $this->__parse('__c', array('singular')); - $this->__parse('__dc', array('domain', 'singular')); - $this->__parse('__dn', array('domain', 'singular', 'plural')); - $this->__parse('__dcn', array('domain', 'singular', 'plural')); + $this->_parse('__', array('singular')); + $this->_parse('__n', array('singular', 'plural')); + $this->_parse('__d', array('domain', 'singular')); + $this->_parse('__c', array('singular')); + $this->_parse('__dc', array('domain', 'singular')); + $this->_parse('__dn', array('domain', 'singular', 'plural')); + $this->_parse('__dcn', array('domain', 'singular', 'plural')); } } @@ -278,14 +278,14 @@ class ExtractTask extends Shell { * @param string $functionName Function name that indicates translatable string (e.g: '__') * @param array $map Array containing what variables it will find (e.g: domain, singular, plural) * @return void - * @access private + * @access protected */ - private function __parse($functionName, $map) { + protected function _parse($functionName, $map) { $count = 0; - $tokenCount = count($this->__tokens); + $tokenCount = count($this->_tokens); while (($tokenCount - $count) > 1) { - list($countToken, $firstParenthesis) = array($this->__tokens[$count], $this->__tokens[$count + 1]); + list($countToken, $firstParenthesis) = array($this->_tokens[$count], $this->_tokens[$count + 1]); if (!is_array($countToken)) { $count++; continue; @@ -297,24 +297,24 @@ class ExtractTask extends Shell { $depth = 0; while ($depth == 0) { - if ($this->__tokens[$position] == '(') { + if ($this->_tokens[$position] == '(') { $depth++; - } elseif ($this->__tokens[$position] == ')') { + } elseif ($this->_tokens[$position] == ')') { $depth--; } $position++; } $mapCount = count($map); - $strings = $this->__getStrings($position, $mapCount); + $strings = $this->_getStrings($position, $mapCount); if ($mapCount == count($strings)) { extract(array_combine($map, $strings)); $domain = isset($domain) ? $domain : 'default'; $string = isset($plural) ? $singular . "\0" . $plural : $singular; - $this->__strings[$domain][$string][$this->__file][] = $line; + $this->_strings[$domain][$string][$this->_file][] = $line; } else { - $this->__markerError($this->__file, $line, $functionName, $count); + $this->_markerError($this->_file, $line, $functionName, $count); } } $count++; @@ -325,17 +325,17 @@ class ExtractTask extends Shell { * Build the translate template file contents out of obtained strings * * @return void - * @access private + * @access protected */ - private function __buildFiles() { - foreach ($this->__strings as $domain => $strings) { + protected function _buildFiles() { + foreach ($this->_strings as $domain => $strings) { foreach ($strings as $string => $files) { $occurrences = array(); foreach ($files as $file => $lines) { $occurrences[] = $file . ':' . implode(';', $lines); } $occurrences = implode("\n#: ", $occurrences); - $header = '#: ' . str_replace($this->__paths, '', $occurrences) . "\n"; + $header = '#: ' . str_replace($this->_paths, '', $occurrences) . "\n"; if (strpos($string, "\0") === false) { $sentence = "msgid \"{$string}\"\n"; @@ -348,9 +348,9 @@ class ExtractTask extends Shell { $sentence .= "msgstr[1] \"\"\n\n"; } - $this->__store($domain, $header, $sentence); - if ($domain != 'default' && $this->__merge) { - $this->__store('default', $header, $sentence); + $this->_store($domain, $header, $sentence); + if ($domain != 'default' && $this->_merge) { + $this->_store('default', $header, $sentence); } } } @@ -360,16 +360,16 @@ class ExtractTask extends Shell { * Prepare a file to be stored * * @return void - * @access private + * @access protected */ - private function __store($domain, $header, $sentence) { - if (!isset($this->__storage[$domain])) { - $this->__storage[$domain] = array(); + protected function _store($domain, $header, $sentence) { + if (!isset($this->_storage[$domain])) { + $this->_storage[$domain] = array(); } - if (!isset($this->__storage[$domain][$sentence])) { - $this->__storage[$domain][$sentence] = $header; + if (!isset($this->_storage[$domain][$sentence])) { + $this->_storage[$domain][$sentence] = $header; } else { - $this->__storage[$domain][$sentence] .= $header; + $this->_storage[$domain][$sentence] .= $header; } } @@ -377,18 +377,18 @@ class ExtractTask extends Shell { * Write the files that need to be stored * * @return void - * @access private + * @access protected */ - private function __writeFiles() { + protected function _writeFiles() { $overwriteAll = false; - foreach ($this->__storage as $domain => $sentences) { - $output = $this->__writeHeader(); + foreach ($this->_storage as $domain => $sentences) { + $output = $this->_writeHeader(); foreach ($sentences as $sentence => $header) { $output .= $header . $sentence; } $filename = $domain . '.pot'; - $File = new File($this->__output . $filename); + $File = new File($this->_output . $filename); $response = ''; while ($overwriteAll === false && $File->exists() && strtoupper($response) !== 'Y') { $this->out(); @@ -397,7 +397,7 @@ class ExtractTask extends Shell { $response = ''; while ($response == '') { $response = $this->in(__d('cake_console', "What would you like to name this file?"), null, 'new_' . $filename); - $File = new File($this->__output . $response); + $File = new File($this->_output . $response); $filename = $response; } } elseif (strtoupper($response) === 'A') { @@ -413,9 +413,9 @@ class ExtractTask extends Shell { * Build the translation template header * * @return string Translation template header - * @access private + * @access protected */ - private function __writeHeader() { + protected function _writeHeader() { $output = "# LANGUAGE translation of CakePHP Application\n"; $output .= "# Copyright YEAR NAME \n"; $output .= "#\n"; @@ -440,22 +440,22 @@ class ExtractTask extends Shell { * @param int $position Actual position on tokens array * @param int $target Number of strings to extract * @return array Strings extracted - * @access private + * @access protected */ - private function __getStrings(&$position, $target) { + protected function _getStrings(&$position, $target) { $strings = array(); - while (count($strings) < $target && ($this->__tokens[$position] == ',' || $this->__tokens[$position][0] == T_CONSTANT_ENCAPSED_STRING)) { - if ($this->__tokens[$position][0] == T_CONSTANT_ENCAPSED_STRING && $this->__tokens[$position+1] == '.') { + while (count($strings) < $target && ($this->_tokens[$position] == ',' || $this->_tokens[$position][0] == T_CONSTANT_ENCAPSED_STRING)) { + if ($this->_tokens[$position][0] == T_CONSTANT_ENCAPSED_STRING && $this->_tokens[$position+1] == '.') { $string = ''; - while ($this->__tokens[$position][0] == T_CONSTANT_ENCAPSED_STRING || $this->__tokens[$position] == '.') { - if ($this->__tokens[$position][0] == T_CONSTANT_ENCAPSED_STRING) { - $string .= $this->__formatString($this->__tokens[$position][1]); + while ($this->_tokens[$position][0] == T_CONSTANT_ENCAPSED_STRING || $this->_tokens[$position] == '.') { + if ($this->_tokens[$position][0] == T_CONSTANT_ENCAPSED_STRING) { + $string .= $this->_formatString($this->_tokens[$position][1]); } $position++; } $strings[] = $string; - } else if ($this->__tokens[$position][0] == T_CONSTANT_ENCAPSED_STRING) { - $strings[] = $this->__formatString($this->__tokens[$position][1]); + } else if ($this->_tokens[$position][0] == T_CONSTANT_ENCAPSED_STRING) { + $strings[] = $this->_formatString($this->_tokens[$position][1]); } $position++; } @@ -467,9 +467,9 @@ class ExtractTask extends Shell { * * @param string $string String to format * @return string Formatted string - * @access private + * @access protected */ - private function __formatString($string) { + protected function _formatString($string) { $quote = substr($string, 0, 1); $string = substr($string, 1, -1); if ($quote == '"') { @@ -489,24 +489,24 @@ class ExtractTask extends Shell { * @param string $marker Marker found * @param integer $count Count * @return void - * @access private + * @access protected */ - private function __markerError($file, $line, $marker, $count) { + protected function _markerError($file, $line, $marker, $count) { $this->out(__d('cake_console', "Invalid marker content in %s:%s\n* %s(", $file, $line, $marker), true); $count += 2; - $tokenCount = count($this->__tokens); + $tokenCount = count($this->_tokens); $parenthesis = 1; while ((($tokenCount - $count) > 0) && $parenthesis) { - if (is_array($this->__tokens[$count])) { - $this->out($this->__tokens[$count][1], false); + if (is_array($this->_tokens[$count])) { + $this->out($this->_tokens[$count][1], false); } else { - $this->out($this->__tokens[$count], false); - if ($this->__tokens[$count] == '(') { + $this->out($this->_tokens[$count], false); + if ($this->_tokens[$count] == '(') { $parenthesis++; } - if ($this->__tokens[$count] == ')') { + if ($this->_tokens[$count] == ')') { $parenthesis--; } } @@ -519,14 +519,14 @@ class ExtractTask extends Shell { * Search files that may contain translatable strings * * @return void - * @access private + * @access protected */ - private function __searchFiles() { + protected function _searchFiles() { $pattern = false; if (!empty($this->_exclude)) { $pattern = '/[\/\\\\]' . implode('|', $this->_exclude) . '[\/\\\\]/'; } - foreach ($this->__paths as $path) { + foreach ($this->_paths as $path) { $Folder = new Folder($path); $files = $Folder->findRecursive('.*\.(php|ctp|thtml|inc|tpl)', true); if (!empty($pattern)) { @@ -537,7 +537,7 @@ class ExtractTask extends Shell { } $files = array_values($files); } - $this->__files = array_merge($this->__files, $files); + $this->_files = array_merge($this->_files, $files); } } } From b31f25fb8b205ddff5336e1ab300202b4493dd36 Mon Sep 17 00:00:00 2001 From: mark_story Date: Mon, 25 Apr 2011 21:04:50 -0400 Subject: [PATCH 06/16] Fixing issues rendering repeat errors coming from the rendering of an error page (like a missing helper). Test added. Fixes #1671 --- lib/Cake/Error/ExceptionRenderer.php | 14 +++++++++- .../Case/Error/ExceptionRendererTest.php | 28 +++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Error/ExceptionRenderer.php b/lib/Cake/Error/ExceptionRenderer.php index eb3fbfe95..fbd249925 100644 --- a/lib/Cake/Error/ExceptionRenderer.php +++ b/lib/Cake/Error/ExceptionRenderer.php @@ -184,7 +184,7 @@ class ExceptionRenderer { $this->controller->set($error->getAttributes()); $this->_outputMessage($this->template); } catch (Exception $e) { - $this->_outputMessage('error500'); + $this->_outputMessageSafe('error500'); } } @@ -235,4 +235,16 @@ class ExceptionRenderer { $this->controller->afterFilter(); $this->controller->response->send(); } + +/** + * A safer way to render error messages, replaces all helpers, with basics + * and doesn't call component methods. + * + * @param string $template The template to render + */ + protected function _outputMessageSafe($template) { + $this->controller->helpers = array('Form', 'Html', 'Session'); + $this->controller->render($template); + $this->controller->response->send(); + } } diff --git a/lib/Cake/tests/Case/Error/ExceptionRendererTest.php b/lib/Cake/tests/Case/Error/ExceptionRendererTest.php index 3017f125b..7e56f7c9c 100644 --- a/lib/Cake/tests/Case/Error/ExceptionRendererTest.php +++ b/lib/Cake/tests/Case/Error/ExceptionRendererTest.php @@ -609,4 +609,32 @@ class ExceptionRendererTest extends CakeTestCase { $this->assertPattern($pattern, $result); } } + +/** + * Test exceptions being raised when helpers are missing. + * + * @return void + */ + function testMissingRenderSafe() { + $exception = new MissingHelperFileException(array('class' => 'Fail')); + $ExceptionRenderer = new ExceptionRenderer($exception); + + $ExceptionRenderer->controller = $this->getMock('Controller'); + $ExceptionRenderer->controller->helpers = array('Fail', 'Boom'); + $ExceptionRenderer->controller->request = $this->getMock('CakeRequest'); + $ExceptionRenderer->controller->expects($this->at(2)) + ->method('render') + ->with('missingHelperFile') + ->will($this->throwException($exception)); + + $ExceptionRenderer->controller->expects($this->at(3)) + ->method('render') + ->with('error500') + ->will($this->returnValue(true)); + + $ExceptionRenderer->controller->response = $this->getMock('CakeResponse'); + $ExceptionRenderer->render(); + sort($ExceptionRenderer->controller->helpers); + $this->assertEquals(array('Form', 'Html', 'Session'), $ExceptionRenderer->controller->helpers); + } } From 1d7d20768f63f6d9ae9396d555dabfeb982f6cf2 Mon Sep 17 00:00:00 2001 From: evilbloodydemon Date: Sun, 24 Apr 2011 11:24:56 +0400 Subject: [PATCH 07/16] Fixed typo in variable name --- app/config/core.php | 2 +- lib/Cake/View/Helper/FormHelper.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/config/core.php b/app/config/core.php index ea285689b..b41657f4c 100644 --- a/app/config/core.php +++ b/app/config/core.php @@ -286,7 +286,7 @@ /** * Pick the caching engine to use. If APC is enabled use it. - * If running via cli - apc is disabled by default. ensure it's avaiable and enabled in this case + * If running via cli - apc is disabled by default. ensure it's available and enabled in this case * */ $engine = 'File'; diff --git a/lib/Cake/View/Helper/FormHelper.php b/lib/Cake/View/Helper/FormHelper.php index b46f39c11..8d806e2a1 100644 --- a/lib/Cake/View/Helper/FormHelper.php +++ b/lib/Cake/View/Helper/FormHelper.php @@ -1809,7 +1809,7 @@ class FormHelper extends AppHelper { $attributes['value'] = $meridian; } else { if (empty($value)) { - if (!$attribues['empty']) { + if (!$attributes['empty']) { $attributes['value'] = date('a'); } } else { From 9db411d9e427ff6d7ca10a3f47c4b81a77acbc84 Mon Sep 17 00:00:00 2001 From: Thomas Ploch Date: Mon, 25 Apr 2011 14:34:40 +0200 Subject: [PATCH 08/16] Added HttpSocket::config['request']['uri'] as parameter in HttpSocket::_parseUri() called by HttpSocket::get(). Now creates correct request array for GET if query params are given and the default request should be used. Fixes #1674. No tests modified since behaviour didn't change. --- lib/Cake/Network/Http/HttpSocket.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Cake/Network/Http/HttpSocket.php b/lib/Cake/Network/Http/HttpSocket.php index 9cee50af5..f810ef4ed 100644 --- a/lib/Cake/Network/Http/HttpSocket.php +++ b/lib/Cake/Network/Http/HttpSocket.php @@ -405,7 +405,7 @@ class HttpSocket extends CakeSocket { */ public function get($uri = null, $query = array(), $request = array()) { if (!empty($query)) { - $uri = $this->_parseUri($uri); + $uri = $this->_parseUri($uri, $this->config['request']['uri']); if (isset($uri['query'])) { $uri['query'] = array_merge($uri['query'], $query); } else { From 3433d123d477e0d2793d630e4cca8076a928844e Mon Sep 17 00:00:00 2001 From: Jose Lorenzo Rodriguez Date: Tue, 26 Apr 2011 21:30:12 -0430 Subject: [PATCH 09/16] Removing model id assignment form passedArgs, as it causes unexpected results. Closes #536 --- lib/Cake/Controller/Controller.php | 8 +------- lib/Cake/tests/Case/Controller/ControllerTest.php | 8 -------- 2 files changed, 1 insertion(+), 15 deletions(-) diff --git a/lib/Cake/Controller/Controller.php b/lib/Cake/Controller/Controller.php index abc734905..4d17d824f 100644 --- a/lib/Cake/Controller/Controller.php +++ b/lib/Cake/Controller/Controller.php @@ -495,15 +495,9 @@ class Controller extends Object { $this->Components->init($this); if ($this->uses !== null || ($this->uses !== array())) { - if (empty($this->passedArgs) || !isset($this->passedArgs['0'])) { - $id = false; - } else { - $id = $this->passedArgs['0']; - } $plugin = $this->plugin ? $this->plugin . '.' : null; - if ($this->uses === false) { - $this->loadModel($plugin . $this->modelClass, $id); + $this->loadModel($plugin . $this->modelClass); } elseif ($this->uses) { $uses = is_array($this->uses) ? $this->uses : array($this->uses); list($plugin, $modelClassName) = pluginSplit($uses[0]); diff --git a/lib/Cake/tests/Case/Controller/ControllerTest.php b/lib/Cake/tests/Case/Controller/ControllerTest.php index 2a25a281b..dd5f73700 100644 --- a/lib/Cake/tests/Case/Controller/ControllerTest.php +++ b/lib/Cake/tests/Case/Controller/ControllerTest.php @@ -470,16 +470,8 @@ class ControllerTest extends CakeTestCase { $request = new CakeRequest('controller_posts/index'); $Controller = new Controller($request); - $Controller->modelClass = 'ControllerPost'; - $Controller->passedArgs[] = '1'; - $Controller->constructClasses(); - $this->assertEqual($Controller->ControllerPost->id, 1); - - unset($Controller); - $Controller = new Controller($request); $Controller->uses = array('ControllerPost', 'ControllerComment'); - $Controller->passedArgs[] = '1'; $Controller->constructClasses(); $this->assertTrue(is_a($Controller->ControllerPost, 'ControllerPost')); $this->assertTrue(is_a($Controller->ControllerComment, 'ControllerComment')); From 1962e40c9a0a7735c6bfe7bbe120128c55ddfdca Mon Sep 17 00:00:00 2001 From: Juan Basso Date: Tue, 26 Apr 2011 22:10:24 -0400 Subject: [PATCH 10/16] Added tests to get with queryparams and custom configs. Refs #1674. --- .../Case/Network/Http/HttpSocketTest.php | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/lib/Cake/tests/Case/Network/Http/HttpSocketTest.php b/lib/Cake/tests/Case/Network/Http/HttpSocketTest.php index d0f46de52..259630c71 100644 --- a/lib/Cake/tests/Case/Network/Http/HttpSocketTest.php +++ b/lib/Cake/tests/Case/Network/Http/HttpSocketTest.php @@ -595,6 +595,34 @@ class HttpSocketTest extends CakeTestCase { $this->assertFalse($this->Socket->connected); } +/** + * testRequestWithConstructor method + * + * @return void + */ + public function testRequestWithConstructor() { + $request = array( + 'request' => array( + 'uri' => array( + 'scheme' => 'http', + 'host' => 'localhost', + 'port' => '5984', + 'user' => null, + 'pass' => null + ) + ) + ); + $http = new MockHttpSocketRequests($request); + + $expected = array('method' => 'GET', 'uri' => '/_test'); + $http->expects($this->at(0))->method('request')->with($expected); + $http->get('/_test'); + + $expected = array('method' => 'GET', 'uri' => 'http://localhost:5984/_test?count=4'); + $http->expects($this->at(0))->method('request')->with($expected); + $http->get('/_test', array('count' => 4)); + } + /** * testRequestWithResource * From df57b15f8943df7c5ed3efb875235725a4f58dd3 Mon Sep 17 00:00:00 2001 From: evilbloodydemon Date: Sun, 17 Apr 2011 12:30:31 +0400 Subject: [PATCH 11/16] Removed undefined variable in App::core, made test pass on Windows. Signed-off-by: mark_story --- lib/Cake/Core/App.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/Cake/Core/App.php b/lib/Cake/Core/App.php index 1ca082b4d..64449f97e 100644 --- a/lib/Cake/Core/App.php +++ b/lib/Cake/Core/App.php @@ -389,9 +389,7 @@ class App { * @return string full path to package */ public static function core($type) { - if ($type) { - return isset($paths[$type]) ? $paths[$type] : array(LIBS . $type . DS); - } + return array(LIBS . str_replace('/', DS, $type) . DS); } /** From 1523ff6874a1fc318c82f0011e161547cb3efd24 Mon Sep 17 00:00:00 2001 From: Juan Basso Date: Tue, 26 Apr 2011 22:19:17 -0400 Subject: [PATCH 12/16] Moved the CakeEmail to Network/Email. Now this class have similar structure of HttpSocket. --- lib/Cake/Controller/Component/EmailComponent.php | 2 +- lib/Cake/Network/{ => Email}/CakeEmail.php | 0 lib/Cake/tests/Case/Network/{ => Email}/CakeEmailTest.php | 2 +- lib/Cake/tests/Case/Network/Email/SmtpTransportTest.php | 2 +- 4 files changed, 3 insertions(+), 3 deletions(-) rename lib/Cake/Network/{ => Email}/CakeEmail.php (100%) rename lib/Cake/tests/Case/Network/{ => Email}/CakeEmailTest.php (99%) diff --git a/lib/Cake/Controller/Component/EmailComponent.php b/lib/Cake/Controller/Component/EmailComponent.php index 2311f0d55..de3e1e095 100644 --- a/lib/Cake/Controller/Component/EmailComponent.php +++ b/lib/Cake/Controller/Component/EmailComponent.php @@ -19,7 +19,7 @@ App::uses('Component', 'Controller'); App::uses('Multibyte', 'I18n'); -App::uses('CakeEmail', 'Network'); +App::uses('CakeEmail', 'Network/Email'); /** * EmailComponent diff --git a/lib/Cake/Network/CakeEmail.php b/lib/Cake/Network/Email/CakeEmail.php similarity index 100% rename from lib/Cake/Network/CakeEmail.php rename to lib/Cake/Network/Email/CakeEmail.php diff --git a/lib/Cake/tests/Case/Network/CakeEmailTest.php b/lib/Cake/tests/Case/Network/Email/CakeEmailTest.php similarity index 99% rename from lib/Cake/tests/Case/Network/CakeEmailTest.php rename to lib/Cake/tests/Case/Network/Email/CakeEmailTest.php index d44a602b9..45c7b1443 100644 --- a/lib/Cake/tests/Case/Network/CakeEmailTest.php +++ b/lib/Cake/tests/Case/Network/Email/CakeEmailTest.php @@ -16,7 +16,7 @@ * @since CakePHP(tm) v 2.0.0 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ -App::uses('CakeEmail', 'Network'); +App::uses('CakeEmail', 'Network/Email'); /** * Help to test CakeEmail diff --git a/lib/Cake/tests/Case/Network/Email/SmtpTransportTest.php b/lib/Cake/tests/Case/Network/Email/SmtpTransportTest.php index 2a7c10469..5b75da480 100644 --- a/lib/Cake/tests/Case/Network/Email/SmtpTransportTest.php +++ b/lib/Cake/tests/Case/Network/Email/SmtpTransportTest.php @@ -16,7 +16,7 @@ * @since CakePHP(tm) v 2.0.0 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ -App::uses('CakeEmail', 'Network'); +App::uses('CakeEmail', 'Network/Email'); App::uses('AbstractTransport', 'Network/Email'); App::uses('SmtpTransport', 'Network/Email'); From bea666bb128ebfca37e79366082e24407b3a4334 Mon Sep 17 00:00:00 2001 From: Thomas Ploch Date: Tue, 26 Apr 2011 14:36:20 +0200 Subject: [PATCH 13/16] Removed JsBaseEngineHelper::$useNative. Removed json_encode() emulation from JsBaseEngineHelper::object(). Removed unnessecary call to get_object_vars() in JsBaseEngineHelper::object(). Removed unnessecary tests for equalness of emulation and native json_encode(). Added test for correct encoding of objects to JsHelper test case. Fixes #704 --- lib/Cake/View/Helper/JsBaseEngineHelper.php | 53 +------------ .../tests/Case/View/Helper/JsHelperTest.php | 77 +++---------------- 2 files changed, 13 insertions(+), 117 deletions(-) diff --git a/lib/Cake/View/Helper/JsBaseEngineHelper.php b/lib/Cake/View/Helper/JsBaseEngineHelper.php index ade4ca558..b3f14680f 100644 --- a/lib/Cake/View/Helper/JsBaseEngineHelper.php +++ b/lib/Cake/View/Helper/JsBaseEngineHelper.php @@ -27,13 +27,6 @@ App::uses('AppHelper', 'View/Helper'); * @package cake.view.helpers */ abstract class JsBaseEngineHelper extends AppHelper { -/** - * Determines whether native JSON extension is used for encoding. Set by object constructor. - * - * @var boolean - * @access public - */ - public $useNative = false; /** * The js snippet for the current selection. @@ -76,7 +69,6 @@ abstract class JsBaseEngineHelper extends AppHelper { */ function __construct($View, $settings = array()) { parent::__construct($View, $settings); - $this->useNative = function_exists('json_encode'); } /** @@ -154,50 +146,7 @@ abstract class JsBaseEngineHelper extends AppHelper { ); $options = array_merge($defaultOptions, $options); - if (is_object($data)) { - $data = get_object_vars($data); - } - - $out = $keys = array(); - $numeric = true; - - if ($this->useNative && function_exists('json_encode')) { - $rt = json_encode($data); - } else { - if (is_null($data)) { - return 'null'; - } - if (is_bool($data)) { - return $data ? 'true' : 'false'; - } - if (is_array($data)) { - $keys = array_keys($data); - } - - if (!empty($keys)) { - $numeric = (array_values($keys) === array_keys(array_values($keys))); - } - - foreach ($data as $key => $val) { - if (is_array($val) || is_object($val)) { - $val = $this->object($val); - } else { - $val = $this->value($val); - } - if (!$numeric) { - $val = '"' . $this->value($key, false) . '":' . $val; - } - $out[] = $val; - } - - if (!$numeric) { - $rt = '{' . join(',', $out) . '}'; - } else { - $rt = '[' . join(',', $out) . ']'; - } - } - $rt = $options['prefix'] . $rt . $options['postfix']; - return $rt; + return $options['prefix'] . json_encode($data) . $options['postfix']; } /** diff --git a/lib/Cake/tests/Case/View/Helper/JsHelperTest.php b/lib/Cake/tests/Case/View/Helper/JsHelperTest.php index 69d946054..7aa1bbaff 100644 --- a/lib/Cake/tests/Case/View/Helper/JsHelperTest.php +++ b/lib/Cake/tests/Case/View/Helper/JsHelperTest.php @@ -25,6 +25,12 @@ App::uses('FormHelper', 'View/Helper'); App::uses('View', 'View'); App::uses('ClassRegistry', 'Utility'); +class JsEncodingObject { + protected $_title = 'Old thing'; + + private $__noshow = 'Never ever'; +} + class OptionEngineHelper extends JsBaseEngineHelper { protected $_optionMap = array( 'request' => array( @@ -797,13 +803,18 @@ class JsBaseEngineTest extends CakeTestCase { * @return void */ function testObject() { - $this->JsEngine->useNative = false; $object = array('title' => 'New thing', 'indexes' => array(5, 6, 7, 8)); $result = $this->JsEngine->object($object); $expected = '{"title":"New thing","indexes":[5,6,7,8]}'; $this->assertEqual($result, $expected); + $object = new JsEncodingObject(); + $object->title = 'New thing'; + $object->indexes = array(5,6,7,8); + $result = $this->JsEngine->object($object); + $this->assertEqual($result, $expected); + $result = $this->JsEngine->object(array('default' => 0)); $expected = '{"default":0}'; $this->assertEqual($result, $expected); @@ -842,70 +853,6 @@ class JsBaseEngineTest extends CakeTestCase { $this->assertNoPattern('/.POSTFIX./', $result); } -/** - * test compatibility of JsBaseEngineHelper::object() vs. json_encode() - * - * @return void - */ - function testObjectAgainstJsonEncode() { - $skip = $this->skipIf(!function_exists('json_encode'), 'json_encode() not found, comparison tests skipped. %s'); - if ($skip) { - return; - } - $this->JsEngine->useNative = false; - $data = array(); - $data['mystring'] = "simple string"; - $this->assertEqual(json_encode($data), $this->JsEngine->object($data)); - - $data['mystring'] = "strïng with spécial chârs"; - $this->assertEqual(json_encode($data), $this->JsEngine->object($data)); - - $data['mystring'] = "a two lines\nstring"; - $this->assertEqual(json_encode($data), $this->JsEngine->object($data)); - - $data['mystring'] = "a \t tabbed \t string"; - $this->assertEqual(json_encode($data), $this->JsEngine->object($data)); - - $data['mystring'] = "a \"double-quoted\" string"; - $this->assertEqual(json_encode($data), $this->JsEngine->object($data)); - - $data['mystring'] = 'a \\"double-quoted\\" string'; - $this->assertEqual(json_encode($data), $this->JsEngine->object($data)); - - unset($data['mystring']); - $data[3] = array(1, 2, 3); - $this->assertEqual(json_encode($data), $this->JsEngine->object($data)); - - unset($data[3]); - $data = array('mystring' => null, 'bool' => false, 'array' => array(1, 44, 66)); - $this->assertEqual(json_encode($data), $this->JsEngine->object($data)); - } - -/** - * test that JSON made with JsBaseEngineHelper::object() against json_decode() - * - * @return void - */ - function testObjectAgainstJsonDecode() { - $skip = $this->skipIf(!function_exists('json_encode'), 'json_encode() not found, comparison tests skipped. %s'); - if ($skip) { - return; - } - $this->JsEngine->useNative = false; - - $data = array("simple string"); - $result = $this->JsEngine->object($data); - $this->assertEqual(json_decode($result), $data); - - $data = array('my "string"'); - $result = $this->JsEngine->object($data); - $this->assertEqual(json_decode($result), $data); - - $data = array('my \\"string\\"'); - $result = $this->JsEngine->object($data); - $this->assertEqual(json_decode($result), $data); - } - /** * test Mapping of options. * From 8da7e5fa82ec6e065f49721cddd0c59aec88db07 Mon Sep 17 00:00:00 2001 From: Jose Lorenzo Rodriguez Date: Tue, 26 Apr 2011 23:44:32 -0430 Subject: [PATCH 14/16] Lazy loading models in controllers, now declaring multiple models in $uses is not a performance hit anymore --- lib/Cake/Controller/Controller.php | 43 +++++++++++++------ .../tests/Case/Controller/ControllerTest.php | 3 +- ...est_plugin_post.php => TestPluginPost.php} | 0 3 files changed, 31 insertions(+), 15 deletions(-) rename lib/Cake/tests/test_app/plugins/test_plugin/Model/{test_plugin_post.php => TestPluginPost.php} (100%) diff --git a/lib/Cake/Controller/Controller.php b/lib/Cake/Controller/Controller.php index 4d17d824f..e9853aa4a 100644 --- a/lib/Cake/Controller/Controller.php +++ b/lib/Cake/Controller/Controller.php @@ -336,6 +336,7 @@ class Controller extends Object { /** * Provides backwards compatibility to avoid problems with empty and isset to alias properties. + * Lazy loads models using the loadModel() method if declared in $uses * * @return void */ @@ -349,6 +350,27 @@ class Controller extends Object { case 'params': return true; } + + if (is_array($this->uses)) { + foreach ($this->uses as $modelClass) { + list($plugin, $class) = pluginSplit($modelClass, true); + if ($name === $class) { + if (!$plugin) { + $plugin = $this->plugin ? $this->plugin . '.' : null; + } + return $this->loadModel($modelClass); + } + } + } + + if ($name === $this->modelClass) { + list($plugin, $class) = pluginSplit($name, true); + if (!$plugin) { + $plugin = $this->plugin ? $this->plugin . '.' : null; + } + return $this->loadModel($plugin . $this->modelClass); + } + return false; } @@ -372,6 +394,11 @@ class Controller extends Object { case 'paginate': return $this->Components->load('Paginator')->settings; } + + if (isset($this->{$name})) { + return $this->{$name}; + } + return null; } @@ -493,19 +520,9 @@ class Controller extends Object { public function constructClasses() { $this->__mergeVars(); $this->Components->init($this); - - if ($this->uses !== null || ($this->uses !== array())) { - $plugin = $this->plugin ? $this->plugin . '.' : null; - if ($this->uses === false) { - $this->loadModel($plugin . $this->modelClass); - } elseif ($this->uses) { - $uses = is_array($this->uses) ? $this->uses : array($this->uses); - list($plugin, $modelClassName) = pluginSplit($uses[0]); - $this->modelClass = $modelClassName; - foreach ($uses as $modelClass) { - $this->loadModel($modelClass); - } - } + if ($this->uses) { + $this->uses = $uses = is_array($this->uses) ? $this->uses : array($this->uses); + list(, $this->modelClass) = pluginSplit($uses[0]); } return true; } diff --git a/lib/Cake/tests/Case/Controller/ControllerTest.php b/lib/Cake/tests/Case/Controller/ControllerTest.php index dd5f73700..9af38e2cb 100644 --- a/lib/Cake/tests/Case/Controller/ControllerTest.php +++ b/lib/Cake/tests/Case/Controller/ControllerTest.php @@ -486,7 +486,6 @@ class ControllerTest extends CakeTestCase { $Controller->uses = array('TestPlugin.TestPluginPost'); $Controller->constructClasses(); - $this->assertEqual($Controller->modelClass, 'TestPluginPost'); $this->assertTrue(isset($Controller->TestPluginPost)); $this->assertTrue(is_a($Controller->TestPluginPost, 'TestPluginPost')); @@ -909,7 +908,7 @@ class ControllerTest extends CakeTestCase { $this->assertTrue(in_array('ControllerPost', $appVars['uses'])); $this->assertNull($testVars['uses']); - $this->assertFalse(isset($TestController->ControllerPost)); + $this->assertFalse(property_exists($TestController, 'ControllerPost')); $TestController = new ControllerCommentsController($request); diff --git a/lib/Cake/tests/test_app/plugins/test_plugin/Model/test_plugin_post.php b/lib/Cake/tests/test_app/plugins/test_plugin/Model/TestPluginPost.php similarity index 100% rename from lib/Cake/tests/test_app/plugins/test_plugin/Model/test_plugin_post.php rename to lib/Cake/tests/test_app/plugins/test_plugin/Model/TestPluginPost.php From 84538ac10a06a2c2883fab9179d6f86b722911fa Mon Sep 17 00:00:00 2001 From: Juan Basso Date: Wed, 27 Apr 2011 00:26:42 -0400 Subject: [PATCH 15/16] Fixed the tests of MediaView in console/web. --- lib/Cake/tests/Case/View/MediaViewTest.php | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/Cake/tests/Case/View/MediaViewTest.php b/lib/Cake/tests/Case/View/MediaViewTest.php index 47f6b9b9b..d0f4be960 100644 --- a/lib/Cake/tests/Case/View/MediaViewTest.php +++ b/lib/Cake/tests/Case/View/MediaViewTest.php @@ -117,7 +117,7 @@ class MediaViewTest extends CakeTestCase { * @return void */ function testRenderWithUnknownFileTypeGeneric() { - $currentUserAgent = $_SERVER['HTTP_USER_AGENT']; + $currentUserAgent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : null; $_SERVER['HTTP_USER_AGENT'] = 'Some generic browser'; $this->MediaView->viewVars = array( 'path' => LIBS . 'tests' . DS . 'test_app' . DS . 'config' . DS, @@ -165,7 +165,9 @@ class MediaViewTest extends CakeTestCase { $output = ob_get_clean(); $this->assertEqual("some_key = some_value\nbool_key = 1\n", $output); $this->assertTrue($result !== false); - $_SERVER['HTTP_USER_AGENT'] = $currentUserAgent; + if ($currentUserAgent !== null) { + $_SERVER['HTTP_USER_AGENT'] = $currentUserAgent; + } } /** @@ -175,7 +177,7 @@ class MediaViewTest extends CakeTestCase { * @return void */ function testRenderWithUnknownFileTypeOpera() { - $currentUserAgent = $_SERVER['HTTP_USER_AGENT']; + $currentUserAgent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : null; $_SERVER['HTTP_USER_AGENT'] = 'Opera/9.80 (Windows NT 6.0; U; en) Presto/2.8.99 Version/11.10'; $this->MediaView->viewVars = array( 'path' => LIBS . 'tests' . DS . 'test_app' . DS . 'config' . DS, @@ -228,7 +230,9 @@ class MediaViewTest extends CakeTestCase { $output = ob_get_clean(); $this->assertEqual("some_key = some_value\nbool_key = 1\n", $output); $this->assertTrue($result !== false); - $_SERVER['HTTP_USER_AGENT'] = $currentUserAgent; + if ($currentUserAgent !== null) { + $_SERVER['HTTP_USER_AGENT'] = $currentUserAgent; + } } /** @@ -238,7 +242,7 @@ class MediaViewTest extends CakeTestCase { * @return void */ function testRenderWithUnknownFileTypeIE() { - $currentUserAgent = $_SERVER['HTTP_USER_AGENT']; + $currentUserAgent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : null; $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 5.2; Trident/4.0; Media Center PC 4.0; SLCC1; .NET CLR 3.0.04320)'; $this->MediaView->viewVars = array( 'path' => LIBS . 'tests' . DS . 'test_app' . DS . 'config' . DS, @@ -291,7 +295,9 @@ class MediaViewTest extends CakeTestCase { $output = ob_get_clean(); $this->assertEqual("some_key = some_value\nbool_key = 1\n", $output); $this->assertTrue($result !== false); - $_SERVER['HTTP_USER_AGENT'] = $currentUserAgent; + if ($currentUserAgent !== null) { + $_SERVER['HTTP_USER_AGENT'] = $currentUserAgent; + } } /** From 228230e67b8df98d0c4cb69f25f14f7c4f9dcead Mon Sep 17 00:00:00 2001 From: Jose Lorenzo Rodriguez Date: Wed, 27 Apr 2011 00:15:42 -0430 Subject: [PATCH 16/16] Simplifying code --- lib/Cake/Controller/Controller.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Cake/Controller/Controller.php b/lib/Cake/Controller/Controller.php index e9853aa4a..615696803 100644 --- a/lib/Cake/Controller/Controller.php +++ b/lib/Cake/Controller/Controller.php @@ -521,8 +521,8 @@ class Controller extends Object { $this->__mergeVars(); $this->Components->init($this); if ($this->uses) { - $this->uses = $uses = is_array($this->uses) ? $this->uses : array($this->uses); - list(, $this->modelClass) = pluginSplit($uses[0]); + $this->uses = (array) $this->uses; + list(, $this->modelClass) = pluginSplit(current($this->uses)); } return true; }