. */ /* */ /**********************************************************************************/ namespace Thelia\Constraint; use Thelia\Coupon\CouponAdapterInterface; use Thelia\Coupon\CouponRuleCollection; /** * Created by JetBrains PhpStorm. * Date: 8/19/13 * Time: 3:24 PM * * Manage how Constraint could interact * * @package Constraint * @author Guillaume MOREL * */ class ConstraintManager { /** @var CouponAdapterInterface Provide necessary value from Thelia*/ protected $adapter; /** @var array CouponRuleCollection to process*/ protected $rules = null; /** * Constructor * * @param CouponAdapterInterface $adapter Provide necessary value from Thelia * @param CouponRuleCollection $rules Rules associated with the Constraint */ function __construct(CouponAdapterInterface $adapter, CouponRuleCollection $rules) { $this->adapter = $adapter; $this->rule = $rules; } /** * Check if the current Coupon is matching its conditions (Rules) * Thelia variables are given by the CouponAdapterInterface * * @return bool */ public function isMatching() { $isMatching = true; /** @var CouponRuleInterface $rule */ foreach ($this->rules->getRules() as $rule) { if (!$rule->isMatching($this->adapter)) { $isMatching = false; } } return $isMatching; } }