当前位置: 首页>>代码示例>>PHP>>正文


PHP AbstractValidator::getDefaultTranslator方法代码示例

本文整理汇总了PHP中Zend\Validator\AbstractValidator::getDefaultTranslator方法的典型用法代码示例。如果您正苦于以下问题:PHP AbstractValidator::getDefaultTranslator方法的具体用法?PHP AbstractValidator::getDefaultTranslator怎么用?PHP AbstractValidator::getDefaultTranslator使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Zend\Validator\AbstractValidator的用法示例。


在下文中一共展示了AbstractValidator::getDefaultTranslator方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testDefaultTranslator

 public function testDefaultTranslator()
 {
     $translator = $this->createMock('Zend\\Mvc\\I18n\\Translator');
     $application = \Library\Application::init('Console', true);
     // Run test initializion after application initialization because it
     // would be overwritten otherwise
     \Zend\Validator\AbstractValidator::setDefaultTranslator(null);
     $serviceManager = $application->getServiceManager();
     $serviceManager->setAllowOverride(true);
     $serviceManager->setService('MvcTranslator', $translator);
     // Invoke bootstrap event handler manually. It has already been run
     // during application initialization, but we changed the default
     // translator in the meantime.
     (new \Console\Module())->onBootstrap($application->getMvcEvent());
     $this->assertSame($translator, \Zend\Validator\AbstractValidator::getDefaultTranslator());
 }
开发者ID:hschletz,项目名称:braintacle,代码行数:16,代码来源:LocalizationTest.php

示例2: testSetGetDefaultTranslator

 public function testSetGetDefaultTranslator()
 {
     set_error_handler(array($this, 'errorHandlerIgnore'));
     $translator = new \Zend\Translator\Translator('ArrayAdapter', array(), 'en');
     restore_error_handler();
     Validator\AbstractValidator::setDefaultTranslator($translator);
     $this->assertSame($translator->getAdapter(), Validator\AbstractValidator::getDefaultTranslator());
 }
开发者ID:rafalwrzeszcz,项目名称:zf2,代码行数:8,代码来源:ValidateTest.php

示例3: testGlobalDefaultTranslatorNullByDefault

 public function testGlobalDefaultTranslatorNullByDefault()
 {
     $this->assertNull(Validator\AbstractValidator::getDefaultTranslator());
 }
开发者ID:alab1001101,项目名称:zf2,代码行数:4,代码来源:AbstractTest.php

示例4: isValid

 /**
  * Validate element value
  *
  * If a translation adapter is registered, any error messages will be
  * translated according to the current locale, using the given error code;
  * if no matching translation is found, the original message will be
  * utilized.
  *
  * Note: The *filtered* value is validated.
  *
  * @param  mixed $value
  * @param  mixed $context
  * @return boolean
  */
 public function isValid($value, $context = null)
 {
     $this->setValue($value);
     $value = $this->getValue();
     if (('' === $value || null === $value) && !$this->isRequired() && $this->getAllowEmpty()) {
         return true;
     }
     if ($this->isRequired() && $this->autoInsertNotEmptyValidator() && !$this->getValidator('NotEmpty')) {
         $validators = $this->getValidators();
         $notEmpty = array('validator' => 'NotEmpty', 'breakChainOnFailure' => true);
         array_unshift($validators, $notEmpty);
         $this->setValidators($validators);
     }
     // Find the correct translator. Zend\Validator\AbstractValidator::getDefaultTranslator()
     // will get either the static translator attached to Zend\Validator\AbstractValidator
     // or the 'Zend_Translate' from Zend\Registry.
     if (AbstractValidator::hasDefaultTranslator() && !Form::hasDefaultTranslator()) {
         $translator = AbstractValidator::getDefaultTranslator();
         if ($this->hasTranslator()) {
             // only pick up this element's translator if it was attached directly.
             $translator = $this->getTranslator();
         }
     } else {
         $translator = $this->getTranslator();
     }
     $this->_messages = array();
     $this->_errors = array();
     $result = true;
     $isArray = $this->isArray();
     foreach ($this->getValidators() as $key => $validator) {
         if (method_exists($validator, 'setTranslator')) {
             if (method_exists($validator, 'hasTranslator')) {
                 if (!$validator->hasTranslator()) {
                     $validator->setTranslator($translator);
                 }
             } else {
                 $validator->setTranslator($translator);
             }
         }
         if (method_exists($validator, 'setDisableTranslator')) {
             $validator->setDisableTranslator($this->translatorIsDisabled());
         }
         if ($isArray && is_array($value)) {
             $messages = array();
             $errors = array();
             foreach ($value as $val) {
                 if (!$validator->isValid($val, $context)) {
                     $result = false;
                     if ($this->_hasErrorMessages()) {
                         $messages = $this->_getErrorMessages();
                         $errors = $messages;
                     } else {
                         $messages = array_merge($messages, $validator->getMessages());
                         $errors = array_merge($errors, $validator->getErrors());
                     }
                 }
             }
             if ($result) {
                 continue;
             }
         } elseif ($validator->isValid($value, $context)) {
             continue;
         } else {
             $result = false;
             if ($this->_hasErrorMessages()) {
                 $messages = $this->_getErrorMessages();
                 $errors = $messages;
             } else {
                 $messages = $validator->getMessages();
                 $errors = array_keys($messages);
             }
         }
         $result = false;
         $this->_messages = array_merge($this->_messages, $messages);
         $this->_errors = array_merge($this->_errors, $errors);
         if ($validator->zfBreakChainOnFailure) {
             break;
         }
     }
     // If element manually flagged as invalid, return false
     if ($this->_isErrorForced) {
         return false;
     }
     return $result;
 }
开发者ID:rexmac,项目名称:zf2,代码行数:99,代码来源:Element.php

示例5: testSetGetDefaultTranslator

 public function testSetGetDefaultTranslator()
 {
     $translator = new Translator\Translator();
     AbstractValidator::setDefaultTranslator($translator);
     $this->assertSame($translator, AbstractValidator::getDefaultTranslator());
 }
开发者ID:razvansividra,项目名称:pnlzf2-1,代码行数:6,代码来源:StaticValidatorTest.php

示例6: testDefaultTranslatorMethods

 public function testDefaultTranslatorMethods()
 {
     $this->assertFalse(AbstractValidator::hasDefaultTranslator());
     $this->assertNull(AbstractValidator::getDefaultTranslator());
     $this->assertEquals('default', AbstractValidator::getDefaultTranslatorTextDomain());
     $this->assertFalse($this->validator->hasTranslator());
     $translatorMock = $this->getMock('Zend\\I18n\\Translator\\Translator');
     AbstractValidator::setDefaultTranslator($translatorMock, 'foo');
     $this->assertEquals($translatorMock, AbstractValidator::getDefaultTranslator());
     $this->assertEquals($translatorMock, $this->validator->getTranslator());
     $this->assertEquals('foo', AbstractValidator::getDefaultTranslatorTextDomain());
     $this->assertEquals('foo', $this->validator->getTranslatorTextDomain());
     $this->assertTrue(AbstractValidator::hasDefaultTranslator());
 }
开发者ID:haoyanfei,项目名称:zf2,代码行数:14,代码来源:AbstractTest.php

示例7: isTranslatorEnabled

 /**
  * Returns whether translator is enabled and should be used
  *
  * @return bool
  */
 public function isTranslatorEnabled()
 {
     $this->translator = AbstractValidator::getDefaultTranslator();
     return $this->translatorEnabled;
 }
开发者ID:pedro151,项目名称:zfcomplement,代码行数:10,代码来源:AbstractRule.php


注:本文中的Zend\Validator\AbstractValidator::getDefaultTranslator方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。