Merge branch 'argument' into form

Conflicts:
	core/lib/Thelia/Core/Template/Smarty/Plugins/TheliaLoop.php
	core/lib/Thelia/Core/Template/Smarty/SmartyParser.php
This commit is contained in:
Manuel Raynaud
2013-06-24 16:28:47 +02:00
17 changed files with 597 additions and 71 deletions

View File

@@ -25,6 +25,7 @@ namespace Thelia\Core\Template\Element;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
/** /**
* *
@@ -96,7 +97,7 @@ abstract class BaseLoop
* ) * )
* ); * );
* *
* @return array * @return ArgumentCollection
*/ */
abstract public function defineArgs(); abstract public function defineArgs();

View File

@@ -29,12 +29,13 @@ namespace Thelia\Core\Template\Loop\Argument;
*/ */
class Argument class Argument
{ {
protected $name; public $name;
protected $type; public $type;
protected $mandatory; public $default;
protected $default; public $mandatory;
public $empty;
public function __construct($name, \Thelia\Type\TypeCollection $type, $mandatory = false, $default = null) public function __construct($name, \Thelia\Type\TypeCollection $type, $default = null, $mandatory = false, $empty = true)
{ {
$this->name = $name; $this->name = $name;
$this->type = $type; $this->type = $type;

View File

@@ -65,7 +65,7 @@ class ArgumentCollection implements \Iterator
* (PHP 5 &gt;= 5.0.0)<br/> * (PHP 5 &gt;= 5.0.0)<br/>
* Return the current element * Return the current element
* @link http://php.net/manual/en/iterator.current.php * @link http://php.net/manual/en/iterator.current.php
* @return \Thelia\Core\Template\Element\LoopResultRow * @return Argument
*/ */
public function current() public function current()
{ {
@@ -80,7 +80,7 @@ class ArgumentCollection implements \Iterator
*/ */
public function next() public function next()
{ {
++$this->arguments; $this->position++;
} }
/** /**
@@ -91,7 +91,7 @@ class ArgumentCollection implements \Iterator
*/ */
public function key() public function key()
{ {
return $this->arguments; return $this->position;
} }
/** /**

View File

@@ -85,35 +85,33 @@ class Category extends BaseLoop
new Argument( new Argument(
'id', 'id',
new TypeCollection( new TypeCollection(
new Type\AnyType() new Type\IntListType()
) )
), ),
new Argument( new Argument(
'parent', 'parent',
new TypeCollection( new TypeCollection(
new Type\AnyType() new Type\IntType()
) )
), ),
new Argument( new Argument(
'current', 'current',
new TypeCollection( new TypeCollection(
new Type\AnyType() new Type\IntType()
) )
), ),
new Argument( new Argument(
'not_empty', 'not_empty',
new TypeCollection( new TypeCollection(
new Type\AnyType() new Type\IntType()
), ),
false,
0 0
), ),
new Argument( new Argument(
'visible', 'visible',
new TypeCollection( new TypeCollection(
new Type\AnyType() new Type\IntType()
), ),
false,
1 1
), ),
new Argument( new Argument(
@@ -125,7 +123,7 @@ class Category extends BaseLoop
new Argument( new Argument(
'order', 'order',
new TypeCollection( new TypeCollection(
new Type\AnyType() new Type\EnumType('alpha', 'alpha_reverse', 'reverse')
) )
), ),
new Argument( new Argument(
@@ -133,29 +131,26 @@ class Category extends BaseLoop
new TypeCollection( new TypeCollection(
new Type\AnyType() new Type\AnyType()
), ),
false,
0 0
), ),
new Argument( new Argument(
'exclude', 'exclude',
new TypeCollection( new TypeCollection(
new Type\AnyType() new Type\IntListType()
) )
), ),
new Argument( new Argument(
'limit', 'limit',
new TypeCollection( new TypeCollection(
new Type\AnyType() new Type\IntType()
), ),
false,
10 10
), ),
new Argument( new Argument(
'offset', 'offset',
new TypeCollection( new TypeCollection(
new Type\AnyType() new Type\IntType()
), ),
false,
0 0
) )
); );

View File

@@ -23,6 +23,7 @@
namespace Thelia\Core\Template\Smarty\Plugins; namespace Thelia\Core\Template\Smarty\Plugins;
use Thelia\Core\Template\Element\BaseLoop;
use Thelia\Core\Template\Smarty\SmartyPluginInterface; use Thelia\Core\Template\Smarty\SmartyPluginInterface;
use Thelia\Core\Template\Smarty\SmartyPluginDescriptor; use Thelia\Core\Template\Smarty\SmartyPluginDescriptor;
@@ -34,6 +35,7 @@ use Symfony\Component\EventDispatcher\EventDispatcherInterface;
class TheliaLoop implements SmartyPluginInterface class TheliaLoop implements SmartyPluginInterface
{ {
protected $loopDefinition = array(); protected $loopDefinition = array();
protected $request; protected $request;
@@ -61,6 +63,7 @@ class TheliaLoop implements SmartyPluginInterface
if (empty($params['name'])) if (empty($params['name']))
throw new \InvalidArgumentException("Missing 'name' parameter in loop arguments"); throw new \InvalidArgumentException("Missing 'name' parameter in loop arguments");
if (empty($params['type'])) if (empty($params['type']))
throw new \InvalidArgumentException("Missing 'type' parameter in loop arguments"); throw new \InvalidArgumentException("Missing 'type' parameter in loop arguments");
@@ -84,18 +87,17 @@ class TheliaLoop implements SmartyPluginInterface
if ($loopResults->valid()) { if ($loopResults->valid()) {
$loopResultRow = $loopResults->current();
foreach ($loopResultRow->getVarVal() as $var => $val) { foreach($loopResultRow->getVarVal() as $var => $val) {
$template->assign(substr($var, 1), $val);
}
$template->assign(substr($var, 1), $val); $template->assign('__COUNT__', 1 + $loopResults->key());
$template->assign('__TOTAL__', $loopResults->getCount());
$template->assign('__COUNT__', 1 + $loopResults->key()); $repeat = $loopResults->valid();
$template->assign('__TOTAL__', $loopResults->getCount()); }
}
$repeat = $loopResults->valid();
}
if ($content !== null) { if ($content !== null) {
@@ -115,10 +117,11 @@ class TheliaLoop implements SmartyPluginInterface
*/ */
public function theliaElseloop($params, $content, $template, &$repeat) public function theliaElseloop($params, $content, $template, &$repeat)
{ {
// When encoutering close tag, check if loop has results.
if ($repeat === false) { // When encoutering close tag, check if loop has results.
return $this->checkEmptyLoop($params, $template) ? $content : ''; if ($repeat === false) {
} return $this->checkEmptyLoop($params, $template) ? $content : '';
}
} }
/** /**
@@ -132,10 +135,11 @@ class TheliaLoop implements SmartyPluginInterface
*/ */
public function theliaIfLoop($params, $content, $template, &$repeat) public function theliaIfLoop($params, $content, $template, &$repeat)
{ {
// When encountering close tag, check if loop has results.
if ($repeat === false) { // When encountering close tag, check if loop has results.
return $this->checkEmptyLoop($params, $template) ? '' : $content; if ($repeat === false) {
} return $this->checkEmptyLoop($params, $template) ? '' : $content;
}
} }
/** /**
@@ -148,8 +152,9 @@ class TheliaLoop implements SmartyPluginInterface
*/ */
protected function checkEmptyLoop($params, $template) protected function checkEmptyLoop($params, $template)
{ {
if (empty($params['rel']))
throw new \InvalidArgumentException("Missing 'rel' parameter in ifloop/elseloop arguments"); if (empty($params['rel']))
throw new \InvalidArgumentException("Missing 'rel' parameter in ifloop/elseloop arguments");
$loopName = $params['rel']; $loopName = $params['rel'];
@@ -199,7 +204,7 @@ class TheliaLoop implements SmartyPluginInterface
* @param unknown $smartyParam * @param unknown $smartyParam
* @throws \InvalidArgumentException * @throws \InvalidArgumentException
*/ */
protected function getLoopArgument($loop, $smartyParam) protected function getLoopArgument(BaseLoop $loop, $smartyParam)
{ {
$defaultItemsParams = array('required' => true); $defaultItemsParams = array('required' => true);
@@ -209,33 +214,45 @@ class TheliaLoop implements SmartyPluginInterface
$faultActor = array(); $faultActor = array();
$faultDetails = array(); $faultDetails = array();
foreach ($loop->defineArgs() as $name => $param) {
if (is_integer($name)) { $argumentsCollection = $loop->defineArgs();
$name = $param; $argumentsCollection->rewind();
$param = $defaultItemsParams;
while ($argumentsCollection->valid()) {
$argument = $argumentsCollection->current();
$argumentsCollection->next();
$value = isset($smartyParam[$argument->name]) ? $smartyParam[$argument->name] : null;
/* check if mandatory */
if($value === null && $argument->mandatory) {
$faultActor[] = $argument->name;
$faultDetails[] = sprintf('"%s" parameter is missing', $argument->name);
continue;
} }
if (is_string($param) && array_key_exists($param, $shortcutItemParams)) { /* check if empty */
$param = $shortcutItemParams[$param]; if($value === '' && !$argument->empty) {
$faultActor[] = $argument->name;
$faultDetails[] = sprintf('"%s" parameter cannot be empty', $argument->name);
continue;
} }
if (!is_array($param)) { /* check type */
$param = array('default' => $param); if($value !== null && !$argument->type->isValid($value)) {
$faultActor[] = $argument->name;
$faultDetails[] = sprintf('Invalid value for "%s" argument', $argument->name);
continue;
} }
$value = isset($smartyParam[$name]) ? $smartyParam[$name] : null; /* set default */
/* did it as last checking for we consider default value is acceptable no matter type or empty restriction */
if ($value == null) { if($value === null) {
if (isset($param['default'])) { $value = $argument->default;
$value = $param['default'];
} elseif ($param['required'] === true) {
$faultActor[] = $name;
$faultDetails[] = sprintf('"%s" parameter is missing', $name);
continue;
}
} }
$loop->{$name} = $value; $loop->{$argument->name} = $value;
} }
if (!empty($faultActor)) { if (!empty($faultActor)) {
@@ -282,9 +299,10 @@ class TheliaLoop implements SmartyPluginInterface
public function getPluginDescriptors() public function getPluginDescriptors()
{ {
return array( return array(
new SmartyPluginDescriptor('block', 'loop' , $this, 'theliaLoop'),
new SmartyPluginDescriptor('block', 'elseloop' , $this, 'theliaElseloop'), new SmartyPluginDescriptor('block', 'loop' , $this, 'theliaLoop'),
new SmartyPluginDescriptor('block', 'ifloop' , $this, 'theliaIfLoop') new SmartyPluginDescriptor('block', 'elseloop' , $this, 'theliaElseloop'),
new SmartyPluginDescriptor('block', 'ifloop' , $this, 'theliaIfLoop'),
); );
} }
} }

View File

@@ -15,9 +15,11 @@ use Thelia\Core\Template\Exception\ResourceNotFoundException;
/** /**
* *
* @author Franck Allimant <franck@cqfdev.fr> * @author Franck Allimant <franck@cqfdev.fr>
* @author Etienne Roudeix <eroudeix@openstudio.fr>
*/ */
class SmartyParser extends Smarty implements ParserInterface class SmartyParser extends Smarty implements ParserInterface
{ {
public $plugins = array(); public $plugins = array();
protected $request, $dispatcher; protected $request, $dispatcher;
@@ -57,13 +59,28 @@ class SmartyParser extends Smarty implements ParserInterface
// Prevent smarty ErrorException: Notice: Undefined index bla bla bla... // Prevent smarty ErrorException: Notice: Undefined index bla bla bla...
$this->error_reporting = E_ALL ^ E_NOTICE; $this->error_reporting = E_ALL ^ E_NOTICE;
// Activer le cache, avec une lifetime de 15mn, et en vérifiant que les templates sources n'ont pas été modifiés. // Si on n'est pas en mode debug, activer le cache, avec une lifetime de 15mn, et en vérifiant que les templates sources n'ont pas été modifiés.
$this->caching = 1; if($debug == false) {
$this->cache_lifetime = 300; $this->caching = Smarty::CACHING_LIFETIME_CURRENT;
$this->compile_check = true; $this->cache_lifetime = 300;
$this->compile_check = true;
} else {
$this->caching = Smarty::CACHING_OFF;
$this->force_compile = true;
}
// The default HTTP status // The default HTTP status
$this->status = 200; $this->status = 200;
$this->registerFilter('pre', array($this, "pretest"));
}
public function pretest($tpl_source, \Smarty_Internal_Template $template)
{
$new_source = preg_replace('`{#([a-zA-Z][a-zA-Z0-9\-_]*)(.*)}`', '{\$$1$2}', $tpl_source);
$new_source = preg_replace('`#([a-zA-Z][a-zA-Z0-9\-_]*)`', '{\$$1|default:\'#$1\'}', $new_source);
return $new_source;
} }
public function setTemplate($template_path_from_template_base) public function setTemplate($template_path_from_template_base)

View File

@@ -0,0 +1,129 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Tests\Core\Template\Loop\Argument;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Core\Template\Loop\Argument\Argument;
use Thelia\Type;
use Thelia\Type\TypeCollection;
/**
*
* @author Etienne Roudeix <eroudeix@openstudio.fr>
*
*/
class ArgumentTest extends \PHPUnit_Framework_TestCase
{
public function testArgumentCollectionConstruction()
{
$collection = new ArgumentCollection(
new Argument(
'arg0',
new TypeCollection(
new Type\AnyType()
)
),
new Argument(
'arg1',
new TypeCollection(
new Type\AnyType()
)
)
);
$collection->addArgument(
new Argument(
'arg2',
new TypeCollection(
new Type\AnyType()
)
)
);
$this->assertAttributeEquals(
array(
0 => new Argument(
'arg0',
new TypeCollection(
new Type\AnyType()
)
),
1 => new Argument(
'arg1',
new TypeCollection(
new Type\AnyType()
)
),
2 => new Argument(
'arg2',
new TypeCollection(
new Type\AnyType()
)
),
),
'arguments',
$collection
);
}
public function testArgumentCollectionFetch()
{
$collection = new ArgumentCollection(
new Argument(
'arg0',
new TypeCollection(
new Type\AnyType()
)
),
new Argument(
'arg1',
new TypeCollection(
new Type\AnyType()
)
),
new Argument(
'arg2',
new TypeCollection(
new Type\AnyType()
)
)
);
$arguments = \PHPUnit_Framework_Assert::readAttribute($collection, 'arguments');
$collection->rewind();
while ($collection->valid()) {
$argument = $collection->current();
$this->assertEquals(
$argument,
$arguments[$collection->key()]
);
$collection->next();
}
}
}

View File

@@ -0,0 +1,113 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Tests\Type;
use Thelia\Type;
use Thelia\Type\TypeCollection;
/**
*
* @author Etienne Roudeix <eroudeix@openstudio.fr>
*
*/
class TypeTest extends \PHPUnit_Framework_TestCase
{
public function testTypeCollectionConstruction()
{
$collection = new TypeCollection(
new Type\AnyType(),
new Type\AnyType()
);
$collection->addType(
new Type\AnyType()
);
$this->assertAttributeEquals(
array(
new Type\AnyType(),
new Type\AnyType(),
new Type\AnyType(),
),
'types',
$collection
);
}
public function testTypeCollectionFetch()
{
$collection = new TypeCollection(
new Type\AnyType(),
new Type\AnyType(),
new Type\AnyType()
);
$types = \PHPUnit_Framework_Assert::readAttribute($collection, 'types');
$collection->rewind();
while ($collection->valid()) {
$type = $collection->current();
$this->assertEquals(
$type,
$types[$collection->key()]
);
$collection->next();
}
}
public function testTypes()
{
$anyType = new Type\AnyType();
$this->assertTrue($anyType->isValid(md5(rand(1000, 10000))));
$intType = new Type\IntType();
$this->assertTrue($intType->isValid('1'));
$this->assertTrue($intType->isValid(2));
$this->assertFalse($intType->isValid('3.3'));
$floatType = new Type\FloatType();
$this->assertTrue($floatType->isValid('1.1'));
$this->assertTrue($floatType->isValid(2.2));
$this->assertFalse($floatType->isValid('foo'));
$enumType = new Type\EnumType(array("cat", "dog"));
$this->assertTrue($enumType->isValid('cat'));
$this->assertTrue($enumType->isValid('dog'));
$this->assertFalse($enumType->isValid('monkey'));
$this->assertFalse($enumType->isValid('catdog'));
$intListType = new Type\IntListType();
$this->assertTrue($intListType->isValid('1'));
$this->assertTrue($intListType->isValid('1,2,3'));
$this->assertFalse($intListType->isValid('1,2,3.3'));
$jsonType = new Type\JsonType();
$this->assertTrue($jsonType->isValid('{"k0":"v0","k1":"v1","k2":"v2"}'));
$this->assertFalse($jsonType->isValid('1,2,3'));
}
}

0
core/lib/Thelia/Type/AnyType.php Normal file → Executable file
View File

View File

@@ -0,0 +1,50 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Type;
/**
*
* @author Etienne Roudeix <eroudeix@openstudio.fr>
*
*/
class EnumType implements TypeInterface
{
protected $values = array();
public function __construct($values = array())
{
if(is_array($values))
$this->values = $values;
}
public function getType()
{
return 'Enum type';
}
public function isValid($value)
{
return in_array($value, $this->values);
}
}

View File

@@ -0,0 +1,42 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Type;
/**
*
* @author Etienne Roudeix <eroudeix@openstudio.fr>
*
*/
class FloatType implements TypeInterface
{
public function getType()
{
return 'Float type';
}
public function isValid($value)
{
return filter_var($value, FILTER_VALIDATE_FLOAT) === false ? false : true;
}
}

View File

@@ -0,0 +1,47 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Type;
/**
*
* @author Etienne Roudeix <eroudeix@openstudio.fr>
*
*/
class IntListType implements TypeInterface
{
public function getType()
{
return 'Int list type';
}
public function isValid($values)
{
foreach(explode(',', $values) as $value) {
if(filter_var($value, FILTER_VALIDATE_INT) === false)
return false;
}
return true;
}
}

View File

@@ -0,0 +1,42 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Type;
/**
*
* @author Etienne Roudeix <eroudeix@openstudio.fr>
*
*/
class IntType implements TypeInterface
{
public function getType()
{
return 'Int type';
}
public function isValid($value)
{
return filter_var($value, FILTER_VALIDATE_INT) === false ? false : true;
}
}

View File

@@ -0,0 +1,43 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Type;
/**
*
* @author Etienne Roudeix <eroudeix@openstudio.fr>
*
*/
class JsonType implements TypeInterface
{
public function getType()
{
return 'Json type';
}
public function isValid($value)
{
json_decode($value);
return (json_last_error() == JSON_ERROR_NONE);
}
}

27
core/lib/Thelia/Type/TypeCollection.php Normal file → Executable file
View File

@@ -65,7 +65,7 @@ class TypeCollection implements \Iterator
* (PHP 5 &gt;= 5.0.0)<br/> * (PHP 5 &gt;= 5.0.0)<br/>
* Return the current element * Return the current element
* @link http://php.net/manual/en/iterator.current.php * @link http://php.net/manual/en/iterator.current.php
* @return \Thelia\Core\Template\Element\LoopResultRow * @return \Thelia\Type\TypeInterface
*/ */
public function current() public function current()
{ {
@@ -80,7 +80,7 @@ class TypeCollection implements \Iterator
*/ */
public function next() public function next()
{ {
++$this->types; $this->position++;
} }
/** /**
@@ -91,7 +91,7 @@ class TypeCollection implements \Iterator
*/ */
public function key() public function key()
{ {
return $this->types; return $this->position;
} }
/** /**
@@ -116,4 +116,25 @@ class TypeCollection implements \Iterator
{ {
$this->position = 0; $this->position = 0;
} }
/**
* @param $value
*
* @return bool
*/
public function isValid($value)
{
$this->rewind();
while ($this->valid()) {
$type = $this->current();
if($type->isValid($value)) {
return true;
}
$this->next();
}
return false;
}
} }

0
core/lib/Thelia/Type/TypeInterface.php Normal file → Executable file
View File

View File

@@ -91,4 +91,11 @@ An image from asset directory :
{/for} {/for}
</div> </div>
<div>
<p>Loops also work with #</p>
{loop type="category" name="catloop1"}
#TITLE : {#DESCRIPTION|upper} #NOTATAG<br />
{/loop}
</div>
{include file="includes/footer.html"} {include file="includes/footer.html"}