本文整理汇总了PHP中Zend_Validate_Abstract::getDefaultTranslator方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Validate_Abstract::getDefaultTranslator方法的具体用法?PHP Zend_Validate_Abstract::getDefaultTranslator怎么用?PHP Zend_Validate_Abstract::getDefaultTranslator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Validate_Abstract
的用法示例。
在下文中一共展示了Zend_Validate_Abstract::getDefaultTranslator方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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_Validate_Abstract::getDefaultTranslator()
// will get either the static translator attached to Zend_Validate_Abstract
// or the 'Zend_Translate' from Zend_Registry.
if (Zend_Validate_Abstract::hasDefaultTranslator() && !Zend_Form::hasDefaultTranslator()) {
$translator = Zend_Validate_Abstract::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();
if (empty($value)) {
if ($this->isRequired() || !$this->isRequired() && !$this->getAllowEmpty()) {
$value = '';
}
}
foreach ((array) $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) {
//.........这里部分代码省略.........
示例2: getDefaultTranslator
/**
* Returns the default translation object
*
* @return Zend_Translate_Adapter|null
*/
public static function getDefaultTranslator($translator = null)
{
require_once 'Zend/Validate/Abstract.php';
return Zend_Validate_Abstract::getDefaultTranslator();
}
示例3: testLocalTranslatorPreferredOverGlobalTranslator
public function testLocalTranslatorPreferredOverGlobalTranslator()
{
$this->testCanSetGlobalDefaultTranslator();
set_error_handler(array($this, 'errorHandlerIgnore'));
$translator = new Zend_Translate('array', array(), 'en');
restore_error_handler();
$this->validator->setTranslator($translator);
$this->assertNotSame(Zend_Validate_Abstract::getDefaultTranslator(), $this->validator->getTranslator());
}
示例4: testSetGetDefaultTranslator
public function testSetGetDefaultTranslator()
{
set_error_handler(array($this, 'errorHandlerIgnore'));
$translator = new Zend_Translate('array', array(), 'en');
restore_error_handler();
Zend_Validate_Abstract::setDefaultTranslator($translator);
$this->assertSame($translator->getAdapter(), Zend_Validate_Abstract::getDefaultTranslator());
}
示例5: send
//.........这里部分代码省略.........
}
}
} elseif ($conf['zfversion'] == 2) {
//TODO add attachements
}
/*
*
* TODO add attachements
*
if (count($config)>0&&count($attachment)>0) {
foreach ($attachment as $att) {
if ($att->filename) {
$extension = strtolower(pathinfo(strval($att->filename),PATHINFO_EXTENSION));
if (isset(EhrlichAndreas_Util_Mime::$MIME_TYPE[$extension])) {
$att->type = EhrlichAndreas_Util_Mime::$MIME_TYPE[$extension];
}
}
}
}
if (isset($conf['attachment'])&&strlen($conf['attachment'])>0&&$conf['attachment']) {
foreach ($attachment as $att) {
$mail->addAttachment($att);
}
}
*
*/
if ($conf['zfversion'] == 1) {
} elseif ($conf['zfversion'] == 2) {
$headers = $message->getHeaders();
//$headers->setEncoding('ASCII');
$classGenericMultiHeader = 'Zend\\Mail\\Header\\GenericMultiHeader';
$headerTmp = new $classGenericMultiHeader('Content-Transfer-Encoding', $conf['encoding']);
$headerTmp->setEncoding('ASCII');
$headers->addHeader($headerTmp);
if (!is_null($bodyText) && !is_null($bodyHtml)) {
$headers->removeHeader('Content-Transfer-Encoding');
$headers->removeHeader('content-type');
$boundary = $message->getBody()->getMime()->boundary();
$classGenericMultiHeader = 'Zend\\Mail\\Header\\GenericMultiHeader';
$headerTmp = new $classGenericMultiHeader('content-type', 'multipart/alternative; boundary="' . $boundary . '"');
$headerTmp->setEncoding('ASCII');
$headers->addHeader($headerTmp);
}
if (false && $message->getBody()->isMultiPart()) {
$classGenericMultiHeader = 'Zend\\Mail\\Header\\GenericMultiHeader';
$headerTmp = new $classGenericMultiHeader('content-type', 'multipart/alternative; charset=' . $conf['charset']);
$headerTmp->setEncoding('ASCII');
$headers->addHeader($headerTmp);
}
}
/* *
echo '<pre>';
var_dump
(
$fromEmail,
$fromName,
$replytoEmail,
$replytoName,
$toEmail,
$toName,
$ccEmail,
$ccName,
$bccEmail,
$bccName,
$header,
$subject,
$bodyHtml,
$bodyText
);
//print_r($replacement);
//die();
/* */
if ($conf['zfversion'] == 1) {
$defaultTranslator = Zend_Validate_Abstract::getDefaultTranslator();
if (is_object($defaultTranslator)) {
Zend_Validate_Abstract::setDefaultTranslator(null);
$defaultTranslatorOptions = $defaultTranslator->getOptions();
$defaultTranslator->setOptions(array('logUntranslated' => false));
}
} else {
}
$messageTransport = $conf['transport'];
try {
$messageTransport->send($message);
$sendTmp = true;
} catch (Exception $e) {
$sendTmp = false;
}
$send = $send && $sendTmp;
if ($conf['zfversion'] == 1) {
if (is_object($defaultTranslator)) {
$defaultTranslator->setOptions($defaultTranslatorOptions);
Zend_Validate_Abstract::setDefaultTranslator($defaultTranslator);
}
} else {
}
}
return $send;
}
示例6: getDefaultTranslator
/**
* Returns the default translation object
*
* @return Zend_Translate_Adapter|null
*/
public static function getDefaultTranslator($translator = null)
{
return Zend_Validate_Abstract::getDefaultTranslator();
}