From 29de5e515f319d7bd07b890206e4674719e40a88 Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 27 Aug 2009 23:40:36 -0400 Subject: [PATCH 01/19] Allowing Controller::flash() layout to be set with a parameter. Fixes #5034 --- cake/libs/controller/controller.php | 5 +++-- cake/tests/cases/libs/controller/controller.test.php | 7 +++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/cake/libs/controller/controller.php b/cake/libs/controller/controller.php index d7ceb7cad..4c80d0056 100644 --- a/cake/libs/controller/controller.php +++ b/cake/libs/controller/controller.php @@ -917,17 +917,18 @@ class Controller extends Object { * @param string $message Message to display to the user * @param mixed $url Relative string or array-based URL to redirect to after the time expires * @param integer $pause Time to show the message + * @param string $layout Layout you want to use, defaults to 'flash' * @return void Renders flash layout * @access public * @link http://book.cakephp.org/view/426/flash */ - function flash($message, $url, $pause = 1) { + function flash($message, $url, $pause = 1, $layout = 'flash') { $this->autoRender = false; $this->set('url', Router::url($url)); $this->set('message', $message); $this->set('pause', $pause); $this->set('page_title', $message); - $this->render(false, 'flash'); + $this->render(false, $layout); } /** diff --git a/cake/tests/cases/libs/controller/controller.test.php b/cake/tests/cases/libs/controller/controller.test.php index 33dbe3e7f..71dd672c4 100644 --- a/cake/tests/cases/libs/controller/controller.test.php +++ b/cake/tests/cases/libs/controller/controller.test.php @@ -721,6 +721,13 @@ class ControllerTest extends CakeTestCase { $result = str_replace(array("\t", "\r\n", "\n"), "", $result); $expected = str_replace(array("\t", "\r\n", "\n"), "", $expected); $this->assertEqual($result, $expected); + + App::build(array('views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS))); + $Controller =& new Controller(); + $Controller->flash('this should work', '/flash', 1, 'ajax2'); + $result = $Controller->output; + $this->assertPattern('/Ajax!/', $result); + App::build(); } /** From 7c100f3b7532e3562815caed4a1dc7c31298dc09 Mon Sep 17 00:00:00 2001 From: "renan.saddam" Date: Thu, 10 Sep 2009 23:26:54 -0300 Subject: [PATCH 02/19] Fixing notice error message. Fixes #34 --- cake/console/libs/tasks/extract.php | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/cake/console/libs/tasks/extract.php b/cake/console/libs/tasks/extract.php index 73bf03125..83338c3b9 100644 --- a/cake/console/libs/tasks/extract.php +++ b/cake/console/libs/tasks/extract.php @@ -168,7 +168,7 @@ class ExtractTask extends Shell{ } else { $response = ''; while ($response == '') { - $response = $this->in("What is the full path you would like to output?\nExample: " . $this->path . DS . "locale\n[Q]uit", null, $this->path . DS . "locale"); + $response = $this->in("What is the full path you would like to output?\nExample: " . $this->path . DS . "locale\n[Q]uit", null, $this->path . DS . 'locale'); if (strtoupper($response) === 'Q') { $this->out('Extract Aborted'); $this->_stop(); @@ -199,14 +199,14 @@ class ExtractTask extends Shell{ $this->out(''); $this->out(__('Extracting...', true)); $this->hr(); - $this->out(__('Path: ', true). $this->path); - $this->out(__('Output Directory: ', true). $this->__output); + $this->out(__('Path: ', true) . $this->path); + $this->out(__('Output Directory: ', true) . $this->__output); $this->hr(); $response = ''; $filename = ''; while ($response == '') { - $response = $this->in(__('Would you like to merge all translations into one file?', true), array('y','n'), 'y'); + $response = $this->in(__('Would you like to merge all translations into one file?', true), array('y', 'n'), 'y'); if (strtolower($response) == 'n') { $this->__oneFile = false; } else { @@ -343,7 +343,7 @@ class ExtractTask extends Shell{ $this->__strings[$this->__formatString($singular)][$this->__file][] = $line; } } else { - if ($plural) { + if (isset($plural)) { $this->__strings[$this->__file][$this->__formatString($singular) . "\0" . $this->__formatString($plural)][] = $line; } else { $this->__strings[$this->__file][$this->__formatString($singular)][] = $line; @@ -458,9 +458,9 @@ class ExtractTask extends Shell{ $output = $this->__mergeFiles($output); foreach ($output as $file => $content) { - $tmp = str_replace(array($this->path, '.php','.ctp','.thtml', '.inc','.tpl' ), '', $file); + $tmp = str_replace(array($this->path, '.php', '.ctp', '.thtml', '.inc', '.tpl'), '', $file); $tmp = str_replace(DS, '.', $tmp); - $file = str_replace('.', '-', $tmp) .'.pot'; + $file = str_replace('.', '-', $tmp) . '.pot'; $fileList = $content[1]; unset($content[1]); @@ -478,14 +478,14 @@ class ExtractTask extends Shell{ if (is_file($this->__output . $file)) { $response = ''; while ($response == '') { - $response = $this->in("\n\nError: ".$file . ' already exists in this location. Overwrite?', array('y','n', 'q'), 'n'); + $response = $this->in("\n\nError: ".$file . ' already exists in this location. Overwrite?', array('y', 'n', 'q'), 'n'); if (strtoupper($response) === 'Q') { $this->out('Extract Aborted'); $this->_stop(); } elseif (strtoupper($response) === 'N') { $response = ''; while ($response == '') { - $response = $this->in("What would you like to name this file?\nExample: new_" . $file, null, "new_" . $file); + $response = $this->in("What would you like to name this file?\nExample: new_" . $file, null, 'new_' . $file); $file = $response; } } @@ -626,7 +626,7 @@ class ExtractTask extends Shell{ */ function __searchDirectory($path = null) { if ($path === null) { - $path = $this->path .DS; + $path = $this->path . DS; } $files = glob("$path*.{php,ctp,thtml,inc,tpl}", GLOB_BRACE); $dirs = glob("$path*", GLOB_ONLYDIR); @@ -636,7 +636,7 @@ class ExtractTask extends Shell{ foreach ($dirs as $dir) { if (!preg_match("!(^|.+/)(CVS|.svn)$!", $dir)) { - $files = array_merge($files, $this->__searchDirectory("$dir" . DS)); + $files = array_merge($files, $this->__searchDirectory($dir . DS)); if (($id = array_search($dir . DS . 'extract.php', $files)) !== FALSE) { unset($files[$id]); } From 78e01cdb472a2422d19b5b920d1a5d16200096bf Mon Sep 17 00:00:00 2001 From: "renan.saddam" Date: Tue, 15 Sep 2009 00:43:59 -0300 Subject: [PATCH 03/19] Refactoring ExtractTask to support extraction from multi-directories and splitting domain in different files. --- cake/console/libs/tasks/extract.php | 411 +++++------------- .../cases/console/libs/tasks/extract.test.php | 23 +- 2 files changed, 136 insertions(+), 298 deletions(-) diff --git a/cake/console/libs/tasks/extract.php b/cake/console/libs/tasks/extract.php index 83338c3b9..4f02f8133 100644 --- a/cake/console/libs/tasks/extract.php +++ b/cake/console/libs/tasks/extract.php @@ -1,6 +1,6 @@ params['files']) && !is_array($this->params['files'])) { - $this->files = explode(',', $this->params['files']); + $this->__files = explode(',', $this->params['files']); } - if (isset($this->params['path'])) { - $this->path = $this->params['path']; + if (isset($this->params['paths'])) { + $this->__paths = explode(',', $this->params['paths']); } else { - $response = ''; - while ($response == '') { - $response = $this->in("What is the full path you would like to extract?\nExample: " . $this->params['root'] . DS . "myapp\n[Q]uit", null, $this->params['working']); + $defaultPath = $this->params['working']; + $message = sprintf(__("What is the full path you would like to extract?\nExample: %s\n[Q]uit [D]one", true), $this->params['root'] . DS . 'myapp'); + while (true) { + $response = $this->in($message, null, $defaultPath); if (strtoupper($response) === 'Q') { - $this->out('Extract Aborted'); + $this->out(__('Extract Aborted', true)); $this->_stop(); + } elseif (strtoupper($response) === 'D') { + $this->out(''); + break; + } elseif (is_dir($response)) { + $this->__paths[] = $response; + $defaultPath = 'D'; + } else { + $this->err(__('The directory path you supplied was not found. Please try again.', true)); } + $this->out(''); } - - if (is_dir($response)) { - $this->path = $response; - } else { - $this->err('The directory path you supplied was not found. Please try again.'); - $this->execute(); - } - } - - if (isset($this->params['debug'])) { - $this->path = ROOT; - $this->files = array(__FILE__); } if (isset($this->params['output'])) { $this->__output = $this->params['output']; } else { - $response = ''; - while ($response == '') { - $response = $this->in("What is the full path you would like to output?\nExample: " . $this->path . DS . "locale\n[Q]uit", null, $this->path . DS . 'locale'); + $message = sprintf(__("What is the full path you would like to output?\nExample: %s\n[Q]uit", true), $this->__paths[0] . DS . 'locale'); + while (true) { + $response = $this->in($message, null, $this->__paths[0] . DS . 'locale'); if (strtoupper($response) === 'Q') { - $this->out('Extract Aborted'); + $this->out(__('Extract Aborted', true)); $this->_stop(); + } elseif (is_dir($response)) { + $this->__output = $response . DS; + break; + } else { + $this->err(__('The directory path you supplied was not found. Please try again.', true)); } - } - - if (is_dir($response)) { - $this->__output = $response . DS; - } else { - $this->err('The directory path you supplied was not found. Please try again.'); - $this->execute(); + $this->out(''); } } - if (empty($this->files)) { - $this->files = $this->__searchDirectory(); + if (empty($this->__files)) { + $this->__searchFiles(); } $this->__extract(); } @@ -192,6 +146,7 @@ class ExtractTask extends Shell{ /** * Extract text * + * @return void * @access private */ function __extract() { @@ -199,32 +154,19 @@ class ExtractTask extends Shell{ $this->out(''); $this->out(__('Extracting...', true)); $this->hr(); - $this->out(__('Path: ', true) . $this->path); + $this->out(__('Paths:', true)); + foreach ($this->__paths as $path) { + $this->out(' ' . $path); + } $this->out(__('Output Directory: ', true) . $this->__output); $this->hr(); - - $response = ''; - $filename = ''; - while ($response == '') { - $response = $this->in(__('Would you like to merge all translations into one file?', true), array('y', 'n'), 'y'); - if (strtolower($response) == 'n') { - $this->__oneFile = false; - } else { - while ($filename == '') { - $filename = $this->in(__('What should we name this file?', true), null, $this->__filename); - if ($filename == '') { - $this->out(__('The filesname you supplied was empty. Please try again.', true)); - } - } - $this->__filename = $filename; - } - } $this->__extractTokens(); } /** * Show help options * + * @return void * @access public */ function help() { @@ -234,33 +176,31 @@ class ExtractTask extends Shell{ $this->out(__('By default the .pot file(s) will be place in the locale directory of -app', true)); $this->out(__('By default -app is ROOT/app', true)); $this->hr(); - $this->out(__('usage: cake i18n extract [command] [path...]', true)); + $this->out(__('Usage: cake i18n extract [command] [path...]', true)); $this->out(''); - $this->out(__('commands:', true)); + $this->out(__('Commands:', true)); $this->out(__(' -app [path...]: directory where your application is located', true)); $this->out(__(' -root [path...]: path to install', true)); $this->out(__(' -core [path...]: path to cake directory', true)); - $this->out(__(' -path [path...]: Full path to directory to extract strings', true)); + $this->out(__(' -paths [comma separated list of paths, full path is needed]', true)); $this->out(__(' -output [path...]: Full path to output directory', true)); $this->out(__(' -files: [comma separated list of files, full path to file is needed]', true)); $this->out(__(' cake i18n extract help: Shows this help message.', true)); - $this->out(__(' -debug: Perform self test.', true)); $this->out(''); } /** * Extract tokens out of all files to be processed * + * @return void * @access private */ function __extractTokens() { - foreach ($this->files as $file) { + foreach ($this->__files as $file) { $this->__file = $file; $this->out(sprintf(__('Processing %s...', true), $file)); $code = file_get_contents($file); - - $this->__findVersion($code, $file); $allTokens = token_get_all($code); $this->__tokens = array(); $lineNumber = 1; @@ -290,7 +230,8 @@ class ExtractTask extends Shell{ } $this->__buildFiles(); $this->__writeFiles(); - $this->out('Done.'); + $this->out(''); + $this->out(__('Done.', true)); } /** @@ -298,7 +239,8 @@ 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) - * @access public + * @return void + * @access private */ function __parse($functionName, $map) { $count = 0; @@ -336,19 +278,14 @@ class ExtractTask extends Shell{ if ($mapCount == count($strings)) { extract(array_combine($map, $strings)); - if ($this->__oneFile === true) { - if (isset($plural)) { - $this->__strings[$this->__formatString($singular) . "\0" . $this->__formatString($plural)][$this->__file][] = $line; - } else { - $this->__strings[$this->__formatString($singular)][$this->__file][] = $line; - } - } else { - if (isset($plural)) { - $this->__strings[$this->__file][$this->__formatString($singular) . "\0" . $this->__formatString($plural)][] = $line; - } else { - $this->__strings[$this->__file][$this->__formatString($singular)][] = $line; - } + 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; } else { $this->__markerError($this->__file, $line, $functionName, $count); } @@ -360,170 +297,89 @@ class ExtractTask extends Shell{ /** * Build the translate template file contents out of obtained strings * + * @return void * @access private */ function __buildFiles() { - foreach ($this->__strings as $str => $fileInfo) { - $output = ''; - $occured = $fileList = array(); - - if ($this->__oneFile === true) { - foreach ($fileInfo as $file => $lines) { - $occured[] = "$file:" . join(';', $lines); - - if (isset($this->__fileVersions[$file])) { - $fileList[] = $this->__fileVersions[$file]; - } + foreach ($this->__strings as $domain => $strings) { + foreach ($strings as $string => $files) { + $occurances = array(); + foreach ($files as $file => $lines) { + $occurances[] = $file . ':' . implode(';', $lines); } - $occurances = join("\n#: ", $occured); - $occurances = str_replace($this->path, '', $occurances); - $output = "#: $occurances\n"; - $filename = $this->__filename; + $occurances = implode("\n#: ", $occurances); + $header = '#: ' . str_replace($this->__paths, '', $occurances) . "\n"; - if (strpos($str, "\0") === false) { - $output .= "msgid \"$str\"\n"; - $output .= "msgstr \"\"\n"; + if (strpos($string, "\0") === false) { + $sentence = "msgid \"{$string}\"\n"; + $sentence .= "msgstr \"\"\n\n"; } else { - list($singular, $plural) = explode("\0", $str); - $output .= "msgid \"$singular\"\n"; - $output .= "msgid_plural \"$plural\"\n"; - $output .= "msgstr[0] \"\"\n"; - $output .= "msgstr[1] \"\"\n"; + list($singular, $plural) = explode("\0", $string); + $sentence = "msgid \"{$singular}\"\n"; + $sentence .= "msgid_plural \"{$plural}\"\n"; + $sentence .= "msgstr[0] \"\"\n"; + $sentence .= "msgstr[1] \"\"\n\n"; } - $output .= "\n"; - } else { - foreach ($fileInfo as $file => $lines) { - $filename = $str; - $occured = array("$str:" . join(';', $lines)); - if (isset($this->__fileVersions[$str])) { - $fileList[] = $this->__fileVersions[$str]; - } - $occurances = join("\n#: ", $occured); - $occurances = str_replace($this->path, '', $occurances); - $output .= "#: $occurances\n"; - - if (strpos($file, "\0") === false) { - $output .= "msgid \"$file\"\n"; - $output .= "msgstr \"\"\n"; - } else { - list($singular, $plural) = explode("\0", $file); - $output .= "msgid \"$singular\"\n"; - $output .= "msgid_plural \"$plural\"\n"; - $output .= "msgstr[0] \"\"\n"; - $output .= "msgstr[1] \"\"\n"; - } - $output .= "\n"; + $this->__store($domain, $header, $sentence); + if ($domain != 'default') { + $this->__store('default', $header, $sentence); } } - $this->__store($filename, $output, $fileList); } } /** * Prepare a file to be stored * - * @param string $file Filename - * @param string $input What to store - * @param array $fileList File list - * @param integer $get Set to 1 to get files to store, false to set - * @return mixed If $get == 1, files to store, otherwise void + * @return void * @access private */ - function __store($file = 0, $input = 0, $fileList = array(), $get = 0) { - static $storage = array(); - - if (!$get) { - if (isset($storage[$file])) { - $storage[$file][1] = array_unique(array_merge($storage[$file][1], $fileList)); - $storage[$file][] = $input; - } else { - $storage[$file] = array(); - $storage[$file][0] = $this->__writeHeader(); - $storage[$file][1] = $fileList; - $storage[$file][2] = $input; - } + 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; } else { - return $storage; + $this->__storage[$domain][$sentence] .= $header; } } /** * Write the files that need to be stored * + * @return void * @access private */ function __writeFiles() { - $output = $this->__store(0, 0, array(), 1); - $output = $this->__mergeFiles($output); - - foreach ($output as $file => $content) { - $tmp = str_replace(array($this->path, '.php', '.ctp', '.thtml', '.inc', '.tpl'), '', $file); - $tmp = str_replace(DS, '.', $tmp); - $file = str_replace('.', '-', $tmp) . '.pot'; - $fileList = $content[1]; - - unset($content[1]); - - $fileList = str_replace(array($this->path), '', $fileList); - - if (count($fileList) > 1) { - $fileList = "Generated from files:\n# " . join("\n# ", $fileList); - } elseif (count($fileList) == 1) { - $fileList = 'Generated from file: ' . join('', $fileList); - } else { - $fileList = 'No version information was available in the source files.'; + foreach ($this->__storage as $domain => $sentences) { + $output = $this->__writeHeader(); + foreach ($sentences as $sentence => $header) { + $output .= $header . $sentence; } - if (is_file($this->__output . $file)) { + $filename = $domain . '.pot'; + $File = new File($this->__output . $filename); + if ($File->exists()) { $response = ''; while ($response == '') { - $response = $this->in("\n\nError: ".$file . ' already exists in this location. Overwrite?', array('y', 'n', 'q'), 'n'); - if (strtoupper($response) === 'Q') { - $this->out('Extract Aborted'); - $this->_stop(); - } elseif (strtoupper($response) === 'N') { + $this->out(''); + $response = $this->in(sprintf(__('Error: %s already exists in this location. Overwrite?', true), $filename), array('y', 'n'), 'y'); + if (strtoupper($response) === 'N') { $response = ''; while ($response == '') { - $response = $this->in("What would you like to name this file?\nExample: new_" . $file, null, 'new_' . $file); - $file = $response; + $response = $this->in(sprintf(__("What would you like to name this file?\nExample: %s", true), 'new_' . $filename), null, 'new_' . $filename); + $File = new File($this->__output . $response); } } } } - $fp = fopen($this->__output . $file, 'w'); - fwrite($fp, str_replace('--VERSIONS--', $fileList, join('', $content))); - fclose($fp); + $File->write($output); + $File->close(); } } -/** - * Merge output files - * - * @param array $output Output to merge - * @return array Merged output - * @access private - */ - function __mergeFiles($output) { - foreach ($output as $file => $content) { - if (count($content) <= 1 && $file != $this->__filename) { - @$output[$this->__filename][1] = array_unique(array_merge($output[$this->__filename][1], $content[1])); - - if (!isset($output[$this->__filename][0])) { - $output[$this->__filename][0] = $content[0]; - } - unset($content[0]); - unset($content[1]); - - foreach ($content as $msgid) { - $output[$this->__filename][] = $msgid; - } - unset($output[$file]); - } - } - return $output; - } - /** * Build the translation template header * @@ -533,7 +389,6 @@ class ExtractTask extends Shell{ function __writeHeader() { $output = "# LANGUAGE translation of CakePHP Application\n"; $output .= "# Copyright YEAR NAME \n"; - $output .= "# --VERSIONS--\n"; $output .= "#\n"; $output .= "#, fuzzy\n"; $output .= "msgid \"\"\n"; @@ -550,21 +405,6 @@ class ExtractTask extends Shell{ return $output; } -/** - * Find the version number of a file looking for SVN commands - * - * @param string $code Source code of file - * @param string $file File - * @access private - */ - function __findVersion($code, $file) { - $header = '$Id' . ':'; - if (preg_match('/\\' . $header . ' [\\w.]* ([\\d]*)/', $code, $versionInfo)) { - $version = str_replace(ROOT, '', 'Revision: ' . $versionInfo[1] . ' ' .$file); - $this->__fileVersions[$file] = $version; - } - } - /** * Format a string to be added as a translateable string * @@ -591,10 +431,11 @@ class ExtractTask extends Shell{ * @param integer $line Line number * @param string $marker Marker found * @param integer $count Count + * @return void * @access private */ function __markerError($file, $line, $marker, $count) { - $this->out("Invalid marker content in $file:$line\n* $marker(", true); + $this->out(sprintf(__("Invalid marker content in %s:%s\n* %s(", true), $file, $line, $marker), true); $count += 2; $tokenCount = count($this->__tokens); $parenthesis = 1; @@ -618,31 +459,17 @@ class ExtractTask extends Shell{ } /** - * Search the specified path for files that may contain translateable strings + * Search files that may contain translateable strings * - * @param string $path Path (or set to null to use current) - * @return array Files + * @return void * @access private */ - function __searchDirectory($path = null) { - if ($path === null) { - $path = $this->path . DS; + function __searchFiles() { + foreach ($this->__paths as $path) { + $Folder = new Folder($path); + $files = $Folder->findRecursive('.*\.(php|ctp|thtml|inc|tpl)', true); + $this->__files += $files; } - $files = glob("$path*.{php,ctp,thtml,inc,tpl}", GLOB_BRACE); - $dirs = glob("$path*", GLOB_ONLYDIR); - - $files = $files ? $files : array(); - $dirs = $dirs ? $dirs : array(); - - foreach ($dirs as $dir) { - if (!preg_match("!(^|.+/)(CVS|.svn)$!", $dir)) { - $files = array_merge($files, $this->__searchDirectory($dir . DS)); - if (($id = array_search($dir . DS . 'extract.php', $files)) !== FALSE) { - unset($files[$id]); - } - } - } - return $files; } } ?> \ No newline at end of file diff --git a/cake/tests/cases/console/libs/tasks/extract.test.php b/cake/tests/cases/console/libs/tasks/extract.test.php index 89394485e..a4973f716 100644 --- a/cake/tests/cases/console/libs/tasks/extract.test.php +++ b/cake/tests/cases/console/libs/tasks/extract.test.php @@ -84,15 +84,12 @@ class ExtractTaskTest extends CakeTestCase { * @access public */ function testExecute() { - $path = TMP . 'extract_task_test'; - $folder1 = $path . DS . 'locale'; - - new Folder($path, true); - new Folder($folder1, true); + $path = TMP . 'tests' . DS . 'extract_task_test'; + new Folder($path . DS . 'locale', true); $this->Task->interactive = false; - $this->Task->params['path'] = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS . 'pages'; + $this->Task->params['paths'] = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS . 'pages'; $this->Task->params['output'] = $path . DS; $this->Task->Dispatch->expectNever('stderr'); $this->Task->Dispatch->expectNever('_stop'); @@ -146,6 +143,20 @@ class ExtractTaskTest extends CakeTestCase { $pattern = '/msgid "You deleted %d message \(domain\)."\nmsgid_plural "You deleted %d messages \(domain\)."/'; $this->assertPattern($pattern, $result); + // extract.ctp - reading the domain.pot + $result = file_get_contents($path . DS . 'domain.pot'); + + $pattern = '/msgid "You have %d new message."\nmsgid_plural "You have %d new messages."/'; + $this->assertNoPattern($pattern, $result); + $pattern = '/msgid "You deleted %d message."\nmsgid_plural "You deleted %d messages."/'; + $this->assertNoPattern($pattern, $result); + + $pattern = '/msgid "You have %d new message \(domain\)."\nmsgid_plural "You have %d new messages \(domain\)."/'; + $this->assertPattern($pattern, $result); + $pattern = '/msgid "You deleted %d message \(domain\)."\nmsgid_plural "You deleted %d messages \(domain\)."/'; + $this->assertPattern($pattern, $result); + + $Folder = new Folder($path); $Folder->delete(); } From 5ac7361a766af6f61788de2f21408eeae39a2166 Mon Sep 17 00:00:00 2001 From: davidpersson Date: Mon, 21 Sep 2009 14:18:09 +0200 Subject: [PATCH 04/19] Removing support for string input in Shell::nl(). Updating Shell::out() and Shell::err() parameter usage. Updating method to always return strings, renaming parameter. Updating docblocks. Updating test. --- cake/console/libs/shell.php | 35 ++++++++------------ cake/tests/cases/console/libs/shell.test.php | 6 +++- 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/cake/console/libs/shell.php b/cake/console/libs/shell.php index 47ff50b63..3ac43aa6c 100644 --- a/cake/console/libs/shell.php +++ b/cake/console/libs/shell.php @@ -366,60 +366,53 @@ class Shell extends Object { * Outputs a single or multiple messages to stdout. * * @param mixed $message A string or a an array of strings to output - * @param mixed $after Appended to message, if true a newline is used + * @param integer $newlines Number of newlines to append * @access public */ - function out($message, $after = true) { + function out($message, $newlines = 1) { if (is_array($message)) { $message = implode($this->nl(), $message); } - $this->Dispatch->stdout($message . $this->nl($after), false); + $this->Dispatch->stdout($message . $this->nl($newlines), false); } /** * Outputs a single or multiple error messages to stderr. * * @param mixed $message A string or a an array of strings to output - * @param mixed $after Appended to message, if true a newline is used + * @param integer $newlines Number of newlines to append * @access public */ - function err($message, $after = true) { + function err($message, $newlines = 1) { if (is_array($message)) { $message = implode($this->nl(), $message); } - $this->Dispatch->stderr($message . $this->nl($after)); + $this->Dispatch->stderr($message . $this->nl($newlines)); } /** * Returns a single or multiple linefeeds sequences. * - * @param mixed $format If true returns a linefeed sequence, if false null, - * if a string is given that is returned, - * if an integer is given it is used as a multiplier to return multiple linefeed sequences + * @param integer $multiplier Number of times the linefeed sequence should be repeated * @access public * @return string */ - function nl($format = true) { - if (is_string($format)) { - return $format . "\n"; - } - if (is_int($format)) { - return str_repeat("\n", $format); - } - return $format ? "\n" : null; + function nl($multiplier = 1) { + return str_repeat("\n", $multiplier); } /** * Outputs a series of minus characters to the standard output, acts as a visual separator. * - * @param mixed $surround If true, the outputs gets surrounded by newlines. + * @param integer $newlines Number of newlines to pre- and append * @access public */ - function hr($surround = false) { - $this->out(null, $surround); + function hr($newlines = 0) { + $this->out(null, $newlines); $this->out('---------------------------------------------------------------'); - $this->out(null, $surround); + $this->out(null, $newlines); } + /** * Displays a formatted error message * and exits the application with status code 1 diff --git a/cake/tests/cases/console/libs/shell.test.php b/cake/tests/cases/console/libs/shell.test.php index ee51e0aef..a7a7f2d55 100644 --- a/cake/tests/cases/console/libs/shell.test.php +++ b/cake/tests/cases/console/libs/shell.test.php @@ -236,6 +236,7 @@ class ShellTest extends CakeTestCase { $this->Shell->Dispatch->expectAt(2, 'stdout', array("Just\na\ntest\n\n", false)); $this->Shell->out(array('Just', 'a', 'test'), 2); } + /** * testErr method * @@ -252,6 +253,7 @@ class ShellTest extends CakeTestCase { $this->Shell->Dispatch->expectAt(2, 'stderr', array("Just\na\ntest\n\n")); $this->Shell->err(array('Just', 'a', 'test'), 2); } + /** * testNl * @@ -264,8 +266,8 @@ class ShellTest extends CakeTestCase { $this->assertEqual($this->Shell->nl(false), ""); $this->assertEqual($this->Shell->nl(2), "\n\n"); $this->assertEqual($this->Shell->nl(1), "\n"); - $this->assertEqual($this->Shell->nl("custom"), "custom\n"); } + /** * testHr * @@ -290,6 +292,7 @@ class ShellTest extends CakeTestCase { $this->Shell->Dispatch->expectAt(5, 'stdout', array("\n\n", false)); $this->Shell->hr(2); } + /** * testError * @@ -308,6 +311,7 @@ class ShellTest extends CakeTestCase { $this->Shell->error('Foo Not Found', 'Searched all...'); $this->assertIdentical($this->Shell->stopped, 1); } + /** * testLoadTasks method * From 86274357b99579df175be83df9b31d3262b4b2f9 Mon Sep 17 00:00:00 2001 From: davidpersson Date: Mon, 21 Sep 2009 22:52:08 +0200 Subject: [PATCH 05/19] Updating Shell class to use nl() where possible. --- cake/console/libs/shell.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/cake/console/libs/shell.php b/cake/console/libs/shell.php index 3ac43aa6c..190852b42 100644 --- a/cake/console/libs/shell.php +++ b/cake/console/libs/shell.php @@ -206,7 +206,7 @@ class Shell extends Object { function _welcome() { $this->Dispatch->clear(); $this->out("\nWelcome to CakePHP v" . Configure::version() . " Console"); - $this->out("---------------------------------------------------------------"); + $this->hr(); $this->out('App : '. $this->params['app']); $this->out('Path: '. $this->params['working']); $this->hr(); @@ -456,14 +456,14 @@ class Shell extends Object { */ function createFile ($path, $contents) { $path = str_replace(DS . DS, DS, $path); - $this->out("\n" . sprintf(__("Creating file %s", true), $path)); + $this->out($this->nl() . sprintf(__("Creating file %s", true), $path)); if (is_file($path) && $this->interactive === true) { $key = $this->in(__("File exists, overwrite?", true). " {$path}", array('y', 'n', 'q'), 'n'); if (strtolower($key) == 'q') { - $this->out(__("Quitting.", true) ."\n"); + $this->out(__("Quitting.", true), 2); exit; } elseif (strtolower($key) != 'y') { - $this->out(__("Skip", true) ." {$path}\n"); + $this->out(__("Skip", true) ." {$path}", 2); return false; } } @@ -477,7 +477,7 @@ class Shell extends Object { $this->out(__("Wrote", true) ." {$path}"); return true; } else { - $this->err(__("Error! Could not write to", true)." {$path}.\n"); + $this->err(__("Error! Could not write to", true)." {$path}", 2); return false; } } @@ -489,7 +489,8 @@ class Shell extends Object { */ function help() { if ($this->command != null) { - $this->err("Unknown {$this->name} command '$this->command'.\nFor usage, try 'cake {$this->shell} help'.\n\n"); + $this->err("Unknown {$this->name} command '$this->command'."); + $this->err("For usage, try 'cake {$this->shell} help'.", 2); } else { $this->Dispatch->help(); } From 0f6bca7496dab8faa9e58f0dbaec14ffd7c0b961 Mon Sep 17 00:00:00 2001 From: davidpersson Date: Sat, 26 Sep 2009 23:02:54 +0200 Subject: [PATCH 06/19] Making first parameter of Shell::out() and err() optional. --- cake/console/libs/shell.php | 10 ++++++---- cake/tests/cases/console/libs/shell.test.php | 6 ++++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/cake/console/libs/shell.php b/cake/console/libs/shell.php index 190852b42..f100ebf33 100644 --- a/cake/console/libs/shell.php +++ b/cake/console/libs/shell.php @@ -363,13 +363,14 @@ class Shell extends Object { } /** - * Outputs a single or multiple messages to stdout. + * Outputs a single or multiple messages to stdout. If no parameters + * are passed outputs just a newline. * * @param mixed $message A string or a an array of strings to output * @param integer $newlines Number of newlines to append * @access public */ - function out($message, $newlines = 1) { + function out($message = null, $newlines = 1) { if (is_array($message)) { $message = implode($this->nl(), $message); } @@ -377,13 +378,14 @@ class Shell extends Object { } /** - * Outputs a single or multiple error messages to stderr. + * Outputs a single or multiple error messages to stderr. If no parameters + * are passed outputs just a newline. * * @param mixed $message A string or a an array of strings to output * @param integer $newlines Number of newlines to append * @access public */ - function err($message, $newlines = 1) { + function err($message = null, $newlines = 1) { if (is_array($message)) { $message = implode($this->nl(), $message); } diff --git a/cake/tests/cases/console/libs/shell.test.php b/cake/tests/cases/console/libs/shell.test.php index a7a7f2d55..3e0e77e4f 100644 --- a/cake/tests/cases/console/libs/shell.test.php +++ b/cake/tests/cases/console/libs/shell.test.php @@ -235,6 +235,9 @@ class ShellTest extends CakeTestCase { $this->Shell->Dispatch->expectAt(2, 'stdout', array("Just\na\ntest\n\n", false)); $this->Shell->out(array('Just', 'a', 'test'), 2); + + $this->Shell->Dispatch->expectAt(3, 'stdout', array("\n", false)); + $this->Shell->out(); } /** @@ -252,6 +255,9 @@ class ShellTest extends CakeTestCase { $this->Shell->Dispatch->expectAt(2, 'stderr', array("Just\na\ntest\n\n")); $this->Shell->err(array('Just', 'a', 'test'), 2); + + $this->Shell->Dispatch->expectAt(3, 'stderr', array("\n", false)); + $this->Shell->err(); } /** From ccbc6f35f0d6f00c3a598fcfbe3a2646c7edda81 Mon Sep 17 00:00:00 2001 From: davidpersson Date: Sat, 26 Sep 2009 23:08:37 +0200 Subject: [PATCH 07/19] Updating all calls to Shell::out(). --- cake/console/libs/bake.php | 2 +- cake/console/libs/console.php | 4 ++-- cake/console/libs/i18n.php | 2 +- cake/console/libs/schema.php | 4 ++-- cake/console/libs/tasks/controller.php | 14 +++++++------- cake/console/libs/tasks/db_config.php | 2 +- cake/console/libs/tasks/extract.php | 18 +++++++++--------- cake/console/libs/tasks/fixture.php | 4 ++-- cake/console/libs/tasks/model.php | 14 +++++++------- cake/console/libs/tasks/plugin.php | 10 +++++----- cake/console/libs/tasks/project.php | 4 ++-- cake/console/libs/tasks/view.php | 12 ++++++------ cake/console/libs/testsuite.php | 12 ++++++------ 13 files changed, 51 insertions(+), 51 deletions(-) diff --git a/cake/console/libs/bake.php b/cake/console/libs/bake.php index 469e952ef..ec7c8b9f4 100644 --- a/cake/console/libs/bake.php +++ b/cake/console/libs/bake.php @@ -225,7 +225,7 @@ class BakeShell extends Shell { $this->out("\n\tbake model\n\t\tbakes a model. run 'bake model help' for more info"); $this->out("\n\tbake view\n\t\tbakes views. run 'bake view help' for more info"); $this->out("\n\tbake controller\n\t\tbakes a controller. run 'bake controller help' for more info"); - $this->out(""); + $this->out(); } } diff --git a/cake/console/libs/console.php b/cake/console/libs/console.php index 82427d9b4..d8a833731 100644 --- a/cake/console/libs/console.php +++ b/cake/console/libs/console.php @@ -238,7 +238,7 @@ class ConsoleShell extends Shell { $this->out("\t$field2: $value2"); } - $this->out(""); + $this->out(); } else { $this->out("\t$field: $value"); } @@ -253,7 +253,7 @@ class ConsoleShell extends Shell { $this->out("\t$field2: $value2"); } - $this->out(""); + $this->out(); } else { $this->out("\t$field: $value"); } diff --git a/cake/console/libs/i18n.php b/cake/console/libs/i18n.php index 5e8d547ed..d0e428f28 100644 --- a/cake/console/libs/i18n.php +++ b/cake/console/libs/i18n.php @@ -128,7 +128,7 @@ class I18nShell extends Shell { $this->out(__('usage:', true)); $this->out(' cake i18n help'); $this->out(' cake i18n initdb [-datasource custom]'); - $this->out(''); + $this->out(); $this->hr(); $this->Extract->help(); diff --git a/cake/console/libs/schema.php b/cake/console/libs/schema.php index 42c06c9d6..59cb1487d 100644 --- a/cake/console/libs/schema.php +++ b/cake/console/libs/schema.php @@ -371,7 +371,7 @@ class SchemaShell extends Shell { $this->out("\n" . __('The following statements will run.', true)); $this->out(array_map('trim', $contents)); if ('y' == $this->in(__('Are you sure you want to alter the tables?', true), array('y', 'n'), 'n')) { - $this->out(''); + $this->out(); $this->out(__('Updating Database...', true)); $this->__run($contents, 'update', $Schema); } @@ -447,7 +447,7 @@ class SchemaShell extends Shell { $this->out("\n\tschema dump \n\t\tDump database sql based on schema file to . \n\t\tIf is write, schema dump will be written to a file\n\t\tthat has the same name as the app directory."); $this->out("\n\tschema run create \n\t\tDrop and create tables based on schema file\n\t\toptional arg for selecting schema name\n\t\toptional
arg for creating only one table\n\t\tpass the -s param with a number to use a snapshot\n\t\tTo see the changes, perform a dry run with the -dry param"); $this->out("\n\tschema run update
\n\t\talter tables based on schema file\n\t\toptional arg for selecting schema name.\n\t\toptional
arg for altering only one table.\n\t\tTo use a snapshot, pass the -s param with the snapshot number\n\t\tTo see the changes, perform a dry run with the -dry param"); - $this->out(""); + $this->out(); $this->_stop(); } } diff --git a/cake/console/libs/tasks/controller.php b/cake/console/libs/tasks/controller.php index 103a1d210..a9462e670 100644 --- a/cake/console/libs/tasks/controller.php +++ b/cake/console/libs/tasks/controller.php @@ -222,7 +222,7 @@ class ControllerTask extends Shell { * @return void **/ function confirmController($controllerName, $useDynamicScaffold, $helpers, $components) { - $this->out(''); + $this->out(); $this->hr(); $this->out(__('The following controller will be created:', true)); $this->hr(); @@ -457,27 +457,27 @@ class ControllerTask extends Shell { $this->out("Usage: cake bake controller ..."); $this->hr(); $this->out('Commands:'); - $this->out(''); + $this->out(); $this->out("controller "); $this->out("\tbakes controller with var \$scaffold"); - $this->out(''); + $this->out(); $this->out("controller public"); $this->out("\tbakes controller with basic crud actions"); $this->out("\t(index, view, add, edit, delete)"); - $this->out(''); + $this->out(); $this->out("controller admin"); $this->out("\tbakes a controller with basic crud actions for"); $this->out("\tConfigure::read('Routing.admin') methods."); - $this->out(''); + $this->out(); $this->out("controller public admin"); $this->out("\tbakes a controller with basic crud actions for"); $this->out("\tConfigure::read('Routing.admin') and non admin methods."); $this->out("\t(index, view, add, edit, delete,"); $this->out("\tadmin_index, admin_view, admin_edit, admin_add, admin_delete)"); - $this->out(''); + $this->out(); $this->out("controller all"); $this->out("\tbakes all controllers with CRUD methods."); - $this->out(""); + $this->out(); $this->_stop(); } } diff --git a/cake/console/libs/tasks/db_config.php b/cake/console/libs/tasks/db_config.php index befedb4c1..cc73caf1b 100644 --- a/cake/console/libs/tasks/db_config.php +++ b/cake/console/libs/tasks/db_config.php @@ -204,7 +204,7 @@ class DbConfigTask extends Shell { function __verify($config) { $config = array_merge($this->__defaultConfig, $config); extract($config); - $this->out(''); + $this->out(); $this->hr(); $this->out('The following database configuration will be created:'); $this->hr(); diff --git a/cake/console/libs/tasks/extract.php b/cake/console/libs/tasks/extract.php index 4f02f8133..e5c67d67c 100644 --- a/cake/console/libs/tasks/extract.php +++ b/cake/console/libs/tasks/extract.php @@ -106,7 +106,7 @@ class ExtractTask extends Shell { $this->out(__('Extract Aborted', true)); $this->_stop(); } elseif (strtoupper($response) === 'D') { - $this->out(''); + $this->out(); break; } elseif (is_dir($response)) { $this->__paths[] = $response; @@ -114,7 +114,7 @@ class ExtractTask extends Shell { } else { $this->err(__('The directory path you supplied was not found. Please try again.', true)); } - $this->out(''); + $this->out(); } } @@ -133,7 +133,7 @@ class ExtractTask extends Shell { } else { $this->err(__('The directory path you supplied was not found. Please try again.', true)); } - $this->out(''); + $this->out(); } } @@ -150,8 +150,8 @@ class ExtractTask extends Shell { * @access private */ function __extract() { - $this->out(''); - $this->out(''); + $this->out(); + $this->out(); $this->out(__('Extracting...', true)); $this->hr(); $this->out(__('Paths:', true)); @@ -177,7 +177,7 @@ class ExtractTask extends Shell { $this->out(__('By default -app is ROOT/app', true)); $this->hr(); $this->out(__('Usage: cake i18n extract [command] [path...]', true)); - $this->out(''); + $this->out(); $this->out(__('Commands:', true)); $this->out(__(' -app [path...]: directory where your application is located', true)); $this->out(__(' -root [path...]: path to install', true)); @@ -186,7 +186,7 @@ class ExtractTask extends Shell { $this->out(__(' -output [path...]: Full path to output directory', true)); $this->out(__(' -files: [comma separated list of files, full path to file is needed]', true)); $this->out(__(' cake i18n extract help: Shows this help message.', true)); - $this->out(''); + $this->out(); } /** @@ -230,7 +230,7 @@ class ExtractTask extends Shell { } $this->__buildFiles(); $this->__writeFiles(); - $this->out(''); + $this->out(); $this->out(__('Done.', true)); } @@ -364,7 +364,7 @@ class ExtractTask extends Shell { if ($File->exists()) { $response = ''; while ($response == '') { - $this->out(''); + $this->out(); $response = $this->in(sprintf(__('Error: %s already exists in this location. Overwrite?', true), $filename), array('y', 'n'), 'y'); if (strtoupper($response) === 'N') { $response = ''; diff --git a/cake/console/libs/tasks/fixture.php b/cake/console/libs/tasks/fixture.php index de374dedc..672c07356 100644 --- a/cake/console/libs/tasks/fixture.php +++ b/cake/console/libs/tasks/fixture.php @@ -415,12 +415,12 @@ class FixtureTask extends Shell { $this->out('Commands:'); $this->out("\nfixture \n\tbakes fixture with specified name."); $this->out("\nfixture all\n\tbakes all fixtures."); - $this->out(""); + $this->out(); $this->out('Parameters:'); $this->out("\t-count When using generated data, the number of records to include in the fixture(s)."); $this->out("\t-connection Which database configuration to use for baking."); $this->out("\t-plugin lowercased_underscored name of plugin to bake fixtures for."); - $this->out(""); + $this->out(); $this->_stop(); } } diff --git a/cake/console/libs/tasks/model.php b/cake/console/libs/tasks/model.php index 6dfb2c081..4efe1cf93 100644 --- a/cake/console/libs/tasks/model.php +++ b/cake/console/libs/tasks/model.php @@ -220,7 +220,7 @@ class ModelTask extends Shell { $associations = $this->doAssociations($tempModel); } - $this->out(''); + $this->out(); $this->hr(); $this->out(__('The following Model will be created:', true)); $this->hr(); @@ -379,7 +379,7 @@ class ModelTask extends Shell { $anotherValidator = 'y'; while ($anotherValidator == 'y') { if ($this->interactive) { - $this->out(''); + $this->out(); $this->out(sprintf(__('Field: %s', true), $fieldName)); $this->out(sprintf(__('Type: %s', true), $metaData['type'])); $this->hr(); @@ -801,7 +801,7 @@ class ModelTask extends Shell { $tableIsGood = false; if (array_search($useTable, $this->__tables) === false) { - $this->out(''); + $this->out(); $this->out(sprintf(__("Given your model named '%s',\nCake would expect a database table named '%s'", true), $modelName, $fullTableName)); $tableIsGood = $this->in(__('Do you want to use this table?', true), array('y','n'), 'y'); } @@ -883,16 +883,16 @@ class ModelTask extends Shell { $this->out("Usage: cake bake model "); $this->hr(); $this->out('Commands:'); - $this->out(''); + $this->out(); $this->out("model"); $this->out("\tbakes model in interactive mode."); - $this->out(''); + $this->out(); $this->out("model "); $this->out("\tbakes model file with no associations or validation"); - $this->out(''); + $this->out(); $this->out("model all"); $this->out("\tbakes all model files with associations and validation"); - $this->out(""); + $this->out(); $this->_stop(); } diff --git a/cake/console/libs/tasks/plugin.php b/cake/console/libs/tasks/plugin.php index 557b60b60..702cf0f21 100644 --- a/cake/console/libs/tasks/plugin.php +++ b/cake/console/libs/tasks/plugin.php @@ -232,19 +232,19 @@ class PluginTask extends Shell { $this->out("Usage: cake bake plugin ..."); $this->hr(); $this->out('Commands:'); - $this->out(''); + $this->out(); $this->out("plugin "); $this->out("\tbakes plugin directory structure"); - $this->out(''); + $this->out(); $this->out("plugin model"); $this->out("\tbakes model. Run 'cake bake model help' for more info."); - $this->out(''); + $this->out(); $this->out("plugin controller"); $this->out("\tbakes controller. Run 'cake bake controller help' for more info."); - $this->out(''); + $this->out(); $this->out("plugin view"); $this->out("\tbakes view. Run 'cake bake view help' for more info."); - $this->out(""); + $this->out(); $this->_stop(); } } diff --git a/cake/console/libs/tasks/project.php b/cake/console/libs/tasks/project.php index 6fdfde6ce..7c59849b8 100644 --- a/cake/console/libs/tasks/project.php +++ b/cake/console/libs/tasks/project.php @@ -308,11 +308,11 @@ class ProjectTask extends Shell { $this->out("Usage: cake bake project "); $this->hr(); $this->out('Commands:'); - $this->out(''); + $this->out(); $this->out("project "); $this->out("\tbakes app directory structure."); $this->out("\tif begins with '/' path is absolute."); - $this->out(""); + $this->out(); $this->_stop(); } diff --git a/cake/console/libs/tasks/view.php b/cake/console/libs/tasks/view.php index b79dc0b4b..54ec5b2ea 100644 --- a/cake/console/libs/tasks/view.php +++ b/cake/console/libs/tasks/view.php @@ -242,7 +242,7 @@ class ViewTask extends Shell { $this->bakeActions($adminActions, $vars); } $this->hr(); - $this->out(''); + $this->out(); $this->out(__("View Scaffolding Complete.\n", true)); } else { $this->customAction(); @@ -332,7 +332,7 @@ class ViewTask extends Shell { $this->out(__('The action name you supplied was empty. Please try again.', true)); } } - $this->out(''); + $this->out(); $this->hr(); $this->out(__('The following view will be created:', true)); $this->hr(); @@ -419,7 +419,7 @@ class ViewTask extends Shell { $this->out("Usage: cake bake view ..."); $this->hr(); $this->out('Commands:'); - $this->out(''); + $this->out(); $this->out("view "); $this->out("\tWill read the given controller for methods"); $this->out("\tand bake corresponding views."); @@ -427,14 +427,14 @@ class ViewTask extends Shell { $this->out("\tthat begin with Routing.admin."); $this->out("\tIf var scaffold is found it will bake the CRUD actions"); $this->out("\t(index,view,add,edit)"); - $this->out(''); + $this->out(); $this->out("view "); $this->out("\tWill bake a template. core templates: (index, add, edit, view)"); - $this->out(''); + $this->out(); $this->out("view