. */ /* */ /**********************************************************************************/ namespace Thelia\Coupon; use Symfony\Component\DependencyInjection\ContainerInterface; use Thelia\Constraint\Rule\CouponRuleInterface; use Thelia\Constraint\Rule\SerializableRule; /** * Created by JetBrains PhpStorm. * Date: 8/19/13 * Time: 3:24 PM * * Manage a set of CouponRuleInterface * * @package Coupon * @author Guillaume MOREL * */ class CouponRuleCollection { /** @var array Array of CouponRuleInterface */ protected $rules = array(); /** * Constructor */ function __construct() { } /** * Get Rules * * @return array Array of CouponRuleInterface */ public function getRules() { return $this->rules; } /** * Add a CouponRuleInterface to the Collection * * @param CouponRuleInterface $rule Rule * * @return $this */ public function add(CouponRuleInterface $rule) { $this->rules[] = $rule; return $this; } /** * Check if there is at least one rule in the collection * * @return bool */ public function isEmpty() { return isEmpty($this->rules); } /** * Allow to compare 2 set of rules * * @return string Jsoned data */ public function __toString() { $arrayToSerialize = array(); /** @var CouponRuleInterface $rule */ foreach ($this->getRules() as $rule) { $arrayToSerialize[] = $rule->getSerializableRule(); } return json_encode($arrayToSerialize); } }