Beispiel #1
0
 /**
  * Render Form
  *
  * @param string $caption Any valid HTML code. Calling code must escape content if necessary.
  * @param array $params Optional name/value pairs that will be included as hidden elements.
  * @return string Form code
  */
 public function __invoke($caption, $params = array())
 {
     $hiddenFields = '';
     foreach ($params as $name => $value) {
         $hiddenFields .= $this->_htmlTag->__invoke('input', null, array('type' => 'hidden', 'name' => $name, 'value' => $value));
     }
     return sprintf("<div class='form_yesno'>\n" . "<p>%s</p>\n" . "<form action='' method='POST'>\n" . "<p>\n%s<input type='submit' name='yes' value='%s'>&nbsp;\n" . "<input type='submit' name='no' value='%s'>\n</p>\n" . "</form>\n</div>\n", $caption, $hiddenFields, $this->_translate->__invoke('Yes'), $this->_translate->__invoke('No'));
 }
 public function testCustomInvokeArguments()
 {
     $input = 'input';
     $expected = 'translated';
     $textDomain = 'textDomain';
     $locale = 'en_US';
     $translatorMock = $this->getMock('Zend\\I18n\\Translator\\Translator');
     $translatorMock->expects($this->once())->method('translate')->with($this->equalTo($input), $this->equalTo($textDomain), $this->equalTo($locale))->will($this->returnValue($expected));
     $this->helper->setTranslator($translatorMock);
     $this->assertEquals($expected, $this->helper->__invoke($input, $textDomain, $locale));
 }
Beispiel #3
0
 public function __invoke()
 {
     $args = func_get_args();
     $message = parent::__invoke($args[0]);
     unset($args[0]);
     /**
      * @todo Execption to few Arguments
      */
     $message = @vsprintf($message, $args);
     return $message;
 }
Beispiel #4
0
 public function __invoke($message, $textDomain = null, $locale = null)
 {
     if ($textDomain == null) {
         // Try to get the current module's name
         /** @var \Zend\View\HelperPluginManager $helperManager */
         $helperManager = $this->serviceLocator;
         /** @var \Zend\ServiceManager\ServiceManager $locator */
         $locator = $helperManager->getServiceLocator();
         /** @var \Zend\Mvc\Application $app */
         $app = $locator->get('application');
         $route = $app->getMvcEvent()->getRouteMatch();
         if ($route) {
             $controller = $route->getParam('controller');
             $textDomain = explode('\\', $controller)[0];
         }
     }
     return parent::__invoke($message, $textDomain, $locale);
 }
Beispiel #5
0
 /**
  * Translate and format messages with sprintf()-style placeholders
  *
  * This helper takes a list of items and returns a list of translated and
  * formatted messages. Each item can be a simple string which will just be
  * translated, or an associative array. Only the first element of an array
  * item is evaluated. The key is a message string with sprintf()-style
  * placeholders that will be translated and then be fed with the array
  * value, which must be an array of arguments. If only 1 argument is
  * required, it can be passed directly.
  *
  * Example:
  *
  *     $input = array(
  *         'message1',
  *         array('message2 %s' => 'arg'),
  *         array('message3 %s %s' => array('arg1', 'arg2'))
  *     );
  *     $output = array(
  *         'translated1',
  *         'translated2 arg',
  *         'translated3 arg1 arg2'
  *     );
  *
  * All strings and arguments get escaped. \Zend\Uri\Http arguments are
  * converted to hyperlinks.
  *
  * @param mixed[] $messages
  * @return string[]
  */
 public function __invoke(array $messages)
 {
     foreach ($messages as &$message) {
         if (is_array($message)) {
             $format = key($message);
             $args = current($message);
             if (!is_array($args)) {
                 $args = array($args);
             }
             foreach ($args as &$arg) {
                 if ($arg instanceof \Zend\Uri\Http) {
                     $arg = $this->_htmlElement->__invoke('a', $this->_escapeHtml->__invoke($arg), array('href' => $arg), true);
                 } else {
                     $arg = $this->_escapeHtml->__invoke($arg);
                 }
             }
             $message = vsprintf($this->_translate->__invoke($format), $args);
         } else {
             $message = $this->_translate->__invoke($message);
         }
     }
     return $messages;
 }