Пример #1
0
 /**
  * @TODO better error handling
  *
  * @param array $data
  * @param UserInterface $user
  * @param string $errorExtension
  *
  * @return bool
  */
 protected function isPwdChangeAllowed(array $data, UserInterface $user, $errorExtension)
 {
     $form = $this->changePasswordForm;
     $form->setData($data);
     if (!$form->isValid()) {
         $this->flashMessenger->setNamespace(AccountController::ERROR_NAME_SPACE . $errorExtension)->addMessage('Form not valid.');
         return false;
     }
     $data = $form->getData();
     if (!$user->hashPassword($user, $data['currentPassword'])) {
         $this->flashMessenger->setNamespace(AccountController::ERROR_NAME_SPACE . $errorExtension)->addMessage('Wrong Password.');
         return false;
     }
     return true;
 }
 /**
  * Outputs message depending on flag
  *
  * @return string
  */
 public function render()
 {
     $allMessages = ['danger' => array_unique(array_merge($this->flashMessenger->getErrorMessages(), $this->flashMessenger->getCurrentErrorMessages())), 'success' => array_unique(array_merge($this->flashMessenger->getSuccessMessages(), $this->flashMessenger->getCurrentSuccessMessages())), 'warning' => array_unique(array_merge($this->flashMessenger->getWarningMessages(), $this->flashMessenger->getCurrentWarningMessages())), 'info' => array_unique(array_merge($this->flashMessenger->getInfoMessages(), $this->flashMessenger->getCurrentInfoMessages())), 'default' => array_unique(array_merge($this->flashMessenger->getMessages(), $this->flashMessenger->getCurrentMessages()))];
     $this->flashMessenger->clearMessagesFromContainer();
     $this->flashMessenger->clearCurrentMessagesFromContainer();
     $output = '';
     foreach ($allMessages as $groupKey => $groupMessages) {
         foreach ($groupMessages as $message) {
             $addClass = $groupKey == 'default' ? 'alert-info' : 'alert-' . $groupKey;
             $viewModel = new ViewModel();
             $viewModel->setVariable('alertClass', $addClass);
             $viewModel->setVariable('alertMessage', $message);
             $viewModel->setTemplate('travello-view-helper/widget/bootstrap-alert');
             $output .= $this->getView()->render($viewModel);
         }
     }
     return $output;
 }
 public function testAddMessageWithLoops()
 {
     $helper = new FlashMessenger();
     $helper->addMessage('foo');
     $helper->addMessage('bar', null, 2);
     $helper->addMessage('baz', null, 5);
     $this->assertEquals('3', count($helper->getCurrentMessages()));
     $helper->clearCurrentMessages();
     $this->assertEquals('0', count($helper->getCurrentMessages()));
 }