Browse files

(Note to self: first run tests THEN commit)

  • Loading branch information...
1 parent b163a64 commit be953af43ce2173ab7abb8733f35a43b8b82f1a0 @pornel pornel committed Jan 25, 2008
View
4 classes/PHPTAL/GetTextTranslator.php
@@ -37,7 +37,7 @@ class PHPTAL_GetTextTranslator implements PHPTAL_TranslationService
{
public function __construct()
{
- if (!function_exists('gettext')) throw new Exception("Gettext not installed");
+ if (!function_exists('gettext')) throw new PHPTAL_Exception("Gettext not installed");
}
public function setEncoding($enc)
@@ -108,4 +108,4 @@ public function translate($key, $htmlencode=true)
private $_currentDomain = null;
private $_encoding = 'UTF-8';
}
-?>
+
View
9 classes/PHPTAL/Php/Attribute/TAL/Repeat.php
@@ -98,14 +98,7 @@ private function initRepeat()
$this->tag->generator->doEnd();
// instantiate controller using expression
- $this->tag->generator->doSetVar('$tmp', $code);
- $this->tag->generator->doIf('($tmp) instanceof IteratorAggregate');
- $this->tag->generator->doSetVar($this->controller, 'new PHPTAL_RepeatController($tmp->getIterator())');
- $this->tag->generator->doElseIf('is_array($tmp)');
- $this->tag->generator->doSetVar($this->controller, 'new PHPTAL_RepeatController($tmp)');
- $this->tag->generator->doElse();
- $this->tag->generator->doSetVar($this->controller, 'new PHPTAL_RepeatController(array())');
- $this->tag->generator->doEnd();
+ $this->tag->generator->doSetVar($this->controller, 'new PHPTAL_RepeatController('.$code.')');
}
private function doForeach()
View
18 classes/PHPTAL/RepeatController.php
@@ -55,6 +55,9 @@ class PHPTAL_RepeatController
*/
public function __construct($source)
{
+ if ($source instanceof IteratorAggregate) $source = $source->getIterator();
+ else if (!is_array($source) && !($source instanceof Iterator)) $source = array();
+
$this->source = $source;
$this->index = -1;
$this->number = 0;
@@ -79,18 +82,19 @@ public function key()
/** Returns the size of an iterable. */
private function _size($iterable)
{
- if (is_array($iterable))
+ if (is_array($iterable) || $iterable instanceof Countable)
return count($iterable);
if (is_string($iterable))
return strlen($iterable);
- if (is_object($iterable) && method_exists($iterable, 'size'))
- return $iterable->size();
- if (is_object($iterable) && method_exists($iterable, 'length'))
- return $iterable->length();
+ if (is_object($iterable))
+ {
+ if (method_exists($iterable, 'size'))
+ return $iterable->size();
+ if (method_exists($iterable, 'length'))
+ return $iterable->length();
+ }
return 0;
}
private $_keys;
}
-
-?>
View
27 tests/GetTextTest.php
@@ -26,9 +26,22 @@
class GetTextTest extends PHPUnit_Framework_TestCase
{
+ private function getTextTranslator()
+ {
+ try
+ {
+ $gettext = new PHPTAL_GetTextTranslator();
+ }
+ catch(PHPTAL_Exception $e)
+ {
+ $this->markTestSkipped($e->getMessage());
+ }
+ }
+
+
function testSimple()
{
- $gettext = new PHPTAL_GetTextTranslator();
+ $gettext = $this->getTextTranslator();
$gettext->setLanguage('en_GB', 'en_GB.utf8');
$gettext->addDomain('test');
$gettext->useDomain('test');
@@ -42,7 +55,7 @@ function testSimple()
function testLang()
{
- $gettext = new PHPTAL_GetTextTranslator();
+ $gettext = $this->getTextTranslator();
$gettext->setLanguage('fr_FR', 'fr_FR@euro', 'fr_FR.utf8');
$gettext->addDomain('test');
$gettext->useDomain('test');
@@ -56,7 +69,7 @@ function testLang()
function testInterpol()
{
- $gettext = new PHPTAL_GetTextTranslator();
+ $gettext = $this->getTextTranslator();
$gettext->setLanguage('fr_FR', 'fr_FR@euro', 'fr_FR.utf8');
$gettext->setEncoding('UTF-8');
$gettext->addDomain('test');
@@ -73,7 +86,7 @@ function testInterpol()
function testDomainChange()
{
- $gettext = new PHPTAL_GetTextTranslator();
+ $gettext = $this->getTextTranslator();
$gettext->setEncoding('UTF-8');
$gettext->setLanguage('fr_FR', 'fr_FR@euro', 'fr_FR.utf8');
$gettext->addDomain('test');
@@ -92,7 +105,7 @@ function testDomainChange()
function testSpaces()
{
- $gettext = new PHPTAL_GetTextTranslator();
+ $gettext = $this->getTextTranslator();
$gettext->setLanguage('en_GB', 'en_GB.utf8');
$gettext->addDomain('test');
$gettext->useDomain('test');
@@ -107,7 +120,7 @@ function testSpaces()
function testAccentuateKey()
{
- $gettext = new PHPTAL_GetTextTranslator();
+ $gettext = $this->getTextTranslator();
$gettext->setLanguage('en_GB', 'en_GB.utf8');
$gettext->addDomain('test');
$gettext->useDomain('test');
@@ -122,7 +135,7 @@ function testAccentuateKey()
function testQuote()
{
- $gettext = new PHPTAL_GetTextTranslator();
+ $gettext = $this->getTextTranslator();
$gettext->setLanguage('en_GB', 'en_GB.utf8');
$gettext->addDomain('test');
$gettext->useDomain('test');

0 comments on commit be953af

Please sign in to comment.