<?php
namespace Moto\Application\Menus; use Zend\Validator\AbstractValidator; class MenuItemsValidator extends AbstractValidator { const ERROR_BAD_STRUCTURE = 'badStructure'; protected $messageTemplates = array( self::ERROR_BAD_STRUCTURE => 'Items not valid', ); protected $_errors = array(); public function isValid($items, array $context = array()) { $this->_context = $context; if (!is_array($items)) { $this->error(self::ERROR_BAD_STRUCTURE); return false; } $isValid = true; $filter = new MenuItemFilter(); for ($i = 0, $itemsLen = count($items); $i < $itemsLen; $i++) { $item = $items[$i]; $filter->setData($item); $isValidItem = $filter->isValid(); if (!$isValidItem) { $this->_errors[$i] = $filter->getMessagesKeys(); } $isValid &= $isValidItem; } return $isValid; } public function getMessages() { return $this->_errors; } }