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


PHP Tools::triggerError方法代码示例

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


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

示例1: validate

 /**
  * Validate if all elements match the format specifier.
  *
  * Called by the framework for validation of a record. Raised an error
  * with triggerError if a value is not valid.
  *
  * @param array $record The record to validate
  * @param string $mode Insert or update mode (ignored by this attribute)
  */
 public function validate(&$record, $mode)
 {
     $elems = $this->_breakDown();
     $values = $this->_valueBreakDown($record[$this->fieldName()]);
     for ($i = 0, $j = 0, $_i = count($elems); $i < $_i; ++$i) {
         if ($elems[$i]['type'] != '/') {
             if (!$this->_checkString($elems[$i]['type'], $values[$j])) {
                 Tools::triggerError($record, $this->fieldName(), 'err', $this->_formatErrorString($j + 1, str_repeat($elems[$i]['type'], $elems[$i]['size'])));
             }
             ++$j;
         }
     }
 }
开发者ID:sintattica,项目名称:atk,代码行数:22,代码来源:FormatAttribute.php

示例2: validate

 /**
  * Validates email address through regular expression and dns check.
  *
  * @param array $record Record that contains value to be validated.
  *                       Errors are saved in this record, in the 'atkerror'
  *                       field.
  * @param string $mode Validation mode. Can be either "add" or "update"
  */
 public function validate(&$record, $mode)
 {
     $email = $record[$this->fieldName()];
     //first check complete string
     if (!self::validateAddressSyntax($email)) {
         Tools::triggerError($record, $this, 'error_invalid_email');
     } else {
         if ($this->m_dnsSearch) {
             //now check if domain exists, searches DNS for MX records
             list(, $domain) = explode('@', $email, 2);
             if (!self::validateAddressDomain($domain, false)) {
                 Tools::triggerError($record, $this->fieldName(), 'error_unkown_domain', Tools::atktext('error_unkown_domain') . ' ' . $domain);
             }
         }
     }
 }
开发者ID:sintattica,项目名称:atk,代码行数:24,代码来源:EmailAttribute.php

示例3: validate

 /**
  * Validates the supplied passwords.
  *
  * @param array $record Record that contains value to be validated.
  *                       Errors are saved in this record
  * @param string $mode can be either "add" or "update"
  */
 public function validate(&$record, $mode)
 {
     $error = false;
     $value = $record[$this->fieldName()];
     if ($mode == 'update' && (Tools::atk_strlen($value['new']) > 0 || Tools::atk_strlen($value['again']) > 0) && !$this->hasFlag(self::AF_PASSWORD_NO_VALIDATE) && !$this->verify($value['current'], $value['hash'])) {
         Tools::triggerError($record, $this->fieldName(), 'error_password_incorrect');
     }
     if (Tools::atk_strlen($value['new']) > 0 && Tools::atk_strlen($value['again']) > 0 && $value['new'] != $value['again']) {
         $error = true;
         Tools::triggerError($record, $this->fieldName(), 'error_password_nomatch');
     }
     if ($mode == 'add' && $this->hasFlag(self::AF_OBLIGATORY) && Tools::atk_strlen($value['new']) == 0) {
         $error = true;
         Tools::triggerError($record, $this->fieldName(), 'error_obligatoryfield');
     }
     // Check if the password meets the restrictions. If not, set error to true and
     // triger an error with the human readable form of the restrictions as message.
     if (isset($value['new']) && Tools::atk_strlen($value['new']) > 0 && !$this->validateRestrictions($value['new'])) {
         $error = true;
         Tools::triggerError($record, $this->fieldName(), $this->getRestrictionsText());
     }
     // new password?
     if (!$error && isset($value['new']) && Tools::atk_strlen($value['new']) > 0) {
         $record[$this->fieldName()]['hash'] = $this->encode($record[$this->fieldName()]['new']);
     }
 }
开发者ID:sintattica,项目名称:atk,代码行数:33,代码来源:PasswordAttribute.php

示例4: validateUrl

 /**
  * Validates absolute, relative and anchor URL through regular expression.
  *
  * @param array $record Record that contains value to be validated.
  *                           Errors are saved in this record, in the 'atkerror'
  *                           field.
  * @param string $mode Validation mode. Can be either "add" or "update"
  * @param bool $show_error fire a triggerError when validation fails
  */
 public function validateUrl(&$record, $mode, $show_error = false)
 {
     $result = false;
     $absolute_result = true;
     $anchor_result = true;
     $absolute_anchor_result = true;
     $relative_result = true;
     $base_url_regex = "(ft|htt)ps?:\\/\\/[a-zA-Z0-9\\.\\-\\_]+\\.[a-zA-Z]{2,4}";
     $relative_url_regex = "[a-zA-Z0-9\\.\\-\\_\\/?&=%]";
     $relative_url_regex_with_anchor = "[a-zA-Z0-9\\.\\-\\_\\/?&=%#]";
     /*
      * Validate URL, check if format is absolute (external URL's) and has no anchor
      *
      * Example: http://www2-dev.test_url.com
      * or:      ftp://www2-dev.test_url.com/index.php?/feeds/index.rss2
      */
     if (($this->m_accepts_url_flag & self::ABSOLUTE) == self::ABSOLUTE) {
         $absolute_result = preg_match('/^' . $base_url_regex . $relative_url_regex . '*$/Ui', $record[$this->fieldName()]) ? true : false;
         $result = $result || $absolute_result;
     }
     /*
      * Validate URL, check if format is a valid anchor
      *
      * Example: #internal_bookmark
      */
     if (($this->m_accepts_url_flag & self::ANCHOR) == self::ANCHOR) {
         $anchor_result = preg_match('/^#' . $relative_url_regex . '*$/Ui', $record[$this->fieldName()]) ? true : false;
         $result = $result || $anchor_result;
     }
     /*
      * Validate URL, check if format is absolute (external URL's) and has (optional) anchor
      *
      * Example: http://www2-dev.test_url.com
      * or:      ftp://www2-dev.test_url.com/index.php?/feeds/index.rss2
      * or:      https://www2-dev.test_url.com/index.php?/history.html#bookmark
      */
     if (($this->m_accepts_url_flag & self::ABSOLUTE) == self::ABSOLUTE && ($this->m_accepts_url_flag & self::ANCHOR) == self::ANCHOR) {
         $absolute_anchor_result = preg_match('/^' . $base_url_regex . $relative_url_regex_with_anchor . '*$/Ui', $record[$this->fieldName()]) ? true : false;
         $result = $result || $absolute_anchor_result;
     }
     /*
      * Validate URL, check if format is relative
      *
      * Example: /mysite/guestbook/index.html
      */
     if (($this->m_accepts_url_flag & self::RELATIVE) == self::RELATIVE) {
         $relative_result = preg_match('/^' . $relative_url_regex_with_anchor . '+$/Ui', $record[$this->fieldName()]) ? true : false;
         $result = $result || $relative_result;
     }
     /*
      * If an error occured, show applicable message(s)
      */
     if (!$result && $show_error) {
         // if result of all validations is false, display error-messages
         if ($absolute_result === false) {
             Tools::triggerError($record, $this->fieldName(), 'invalid_absolute_no_anchor_url', Tools::atktext('invalid_absolute_no_anchor_url'));
         }
         if ($anchor_result === false) {
             Tools::triggerError($record, $this->fieldName(), 'invalid_url_anchor', Tools::atktext('invalid_url_anchor'));
         }
         if ($absolute_anchor_result === false) {
             Tools::triggerError($record, $this->fieldName(), 'invalid_absolute_url', Tools::atktext('invalid_absolute_url'));
         }
         if ($relative_result === false) {
             Tools::triggerError($record, $this->fieldName(), 'invalid_relative_url', Tools::atktext('invalid_relative_url'));
         }
     }
     if (!$result) {
         parent::validate($record, $mode);
     }
 }
开发者ID:sintattica,项目名称:atk,代码行数:80,代码来源:UrlAttribute.php

示例5: validate

 /**
  * Validate a record.
  *
  * @param string $mode Override the mode
  * @param array $ignoreList Override the ignoreList
  */
 public function validate($mode = '', $ignoreList = array())
 {
     // check overrides
     if (count($ignoreList)) {
         $this->setIgnoreList($ignoreList);
     }
     if ($mode != '') {
         $this->setMode($mode);
     }
     Tools::atkdebug('validate() with mode ' . $this->m_mode . ' for node ' . $this->m_nodeObj->atkNodeUri());
     // set the record
     $record =& $this->m_record;
     // Check flags and values
     $db = $this->m_nodeObj->getDb();
     foreach ($this->m_nodeObj->m_attribIndexList as $attribdata) {
         $attribname = $attribdata['name'];
         if (!Tools::atk_in_array($attribname, $this->m_ignoreList)) {
             $p_attrib = $this->m_nodeObj->m_attribList[$attribname];
             $this->validateAttributeValue($p_attrib, $record);
             if ($p_attrib->hasFlag(Attribute::AF_PRIMARY) && !$p_attrib->hasFlag(Attribute::AF_AUTO_INCREMENT)) {
                 $atkorgkey = $record['atkprimkey'];
                 if ($atkorgkey == '' || $atkorgkey != $this->m_nodeObj->primaryKey($record)) {
                     $cnt = $this->m_nodeObj->select($this->m_nodeObj->primaryKey($record))->ignoreDefaultFilters(true)->ignorePostvars(true)->getRowCount();
                     if ($cnt > 0) {
                         Tools::triggerError($record, $p_attrib, 'error_primarykey_exists');
                     }
                 }
             }
             // if no root elements may be added to the tree, then every record needs to have a parent!
             if ($p_attrib->hasFlag(Attribute::AF_PARENT) && $this->m_nodeObj->hasFlag(TreeNode::NF_TREE_NO_ROOT_ADD) && $this->m_nodeObj->m_action == 'save') {
                 $p_attrib->m_flags |= Attribute::AF_OBLIGATORY;
             }
             // validate obligatory fields (but not the auto_increment ones, because they don't have a value yet)
             if ($p_attrib->hasFlag(Attribute::AF_OBLIGATORY) && !$p_attrib->hasFlag(Attribute::AF_AUTO_INCREMENT) && $p_attrib->isEmpty($record)) {
                 Tools::atkTriggerError($record, $p_attrib, 'error_obligatoryfield');
             } else {
                 if ($p_attrib->hasFlag(Attribute::AF_UNIQUE) && !$p_attrib->hasFlag(Attribute::AF_PRIMARY) && !$p_attrib->isEmpty($record)) {
                     $condition = $this->m_nodeObj->getTable() . ".{$attribname}='" . $db->escapeSQL($p_attrib->value2db($record)) . "'";
                     if ($this->m_mode != 'add') {
                         $condition .= ' AND NOT (' . $this->m_nodeObj->primaryKey($record) . ')';
                     }
                     $cnt = $this->m_nodeObj->select($condition)->ignoreDefaultFilters(true)->ignorePostvars(true)->getRowCount();
                     if ($cnt > 0) {
                         Tools::atkTriggerError($record, $p_attrib, 'error_uniquefield');
                     }
                 }
             }
         }
     }
     if (isset($record['atkerror']) && count($record['atkerror']) > 0) {
         for ($i = 0, $_i = count($record['atkerror']); $i < $_i; ++$i) {
             $record['atkerror'][$i]['node'] = $this->m_nodeObj->m_type;
         }
     }
     $this->validateUniqueFieldSets($record);
     if (isset($record['atkerror'])) {
         for ($i = 0, $_i = count($record['atkerror']); $i < $_i; ++$i) {
             $record['atkerror'][$i]['node'] = $this->m_nodeObj->m_type;
         }
         return false;
     }
     return true;
 }
开发者ID:sintattica,项目名称:atk,代码行数:69,代码来源:NodeValidator.php

示例6: validate

 /**
  * Checks if a value is valid.
  *
  * @param array $rec The record that holds the value for this
  *                     attribute. If an error occurs, the error will
  *                     be stored in the 'atkerror' field of the record.
  * @param string $mode The mode for which should be validated ("add" or
  *                     "update")
  */
 public function validate(&$rec, $mode)
 {
     $value = $rec[$this->fieldName()];
     if ($this->hasFlag(self::AF_OBLIGATORY) && ($value['hours'] == -1 || $value['minutes'] == -1)) {
         Tools::triggerError($rec, $this->fieldName(), 'error_obligatoryfield');
     }
 }
开发者ID:sintattica,项目名称:atk,代码行数:16,代码来源:TimeAttribute.php

示例7: validate

 public function validate(&$record, $mode)
 {
     $sessionmanager = SessionManager::getInstance();
     $storetype = null;
     if ($sessionmanager) {
         $storetype = $sessionmanager->stackVar('atkstore');
     }
     if ($storetype !== 'session' && !$this->_isSelectableRecord($record, $mode)) {
         Tools::triggerError($record, $this->fieldName(), 'error_integrity_violation');
     }
 }
开发者ID:sintattica,项目名称:atk,代码行数:11,代码来源:ManyToOneRelation.php

示例8: handleAddError

 /**
  * Handle error in preAdd/addDb.
  *
  * @param array $record
  */
 public function handleAddError($record)
 {
     // Do a rollback on an error
     $db = $this->m_node->getDb();
     $db->rollback();
     if ($db->getErrorType() == 'user') {
         Tools::triggerError($record, 'Error', $db->getErrorMsg(), '', '');
         // still an error, back to where we came from
         $this->goBack($record);
     } else {
         $location = $this->m_node->feedbackUrl('save', self::ACTION_FAILED, $record, $db->getErrorMsg());
         $this->_handleRedirect($location);
     }
 }
开发者ID:sintattica,项目名称:atk,代码行数:19,代码来源:SaveHandler.php

示例9: validate

 /**
  * Checks if the value is a valid IP address.
  *
  * @param array $record The record that holds the value for this
  *                       attribute. If an error occurs, the error will
  *                       be stored in the 'atkerror' field of the record.
  * @param string $mode The mode for which should be validated ("add" or
  *                       "update")
  */
 public function validate(&$record, $mode)
 {
     // Check for valid ip string
     $strvalue = Tools::atkArrayNvl($record, $this->fieldName(), '');
     if ($strvalue != '' && $strvalue != '...') {
         if ($this->hasFlag(self::AF_IP_ALLOW_WILDCARDS) && !$this->hasFlag(self::AF_IP_STORENUMERIC)) {
             $strvalue = str_replace('*', '0', $strvalue);
         }
         $num = '(\\d|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5])';
         if (preg_match("/^{$num}\\.{$num}\\.{$num}\\.{$num}\$/", $strvalue, $matches) <= 0) {
             Tools::triggerError($record, $this->fieldName(), 'error_not_a_valid_ip');
         }
     }
     parent::validate($record, $mode);
 }
开发者ID:sintattica,项目名称:atk,代码行数:24,代码来源:IpAttribute.php

示例10: validate

 /**
  * This function controls actions on the selected file is allowed.
  *
  * @param array $rec Array that contains the identifier of the record
  * @param string $mode The mode we're in
  */
 public function validate(&$rec, $mode)
 {
     if (!ereg($this->m_filefilter, $rec['filename'])) {
         Tools::triggerError($rec, 'filename', 'filename_invalid');
     } else {
         if ($mode == 'add' && file_exists($this->m_dir . $rec['filename'])) {
             Tools::triggerError($rec, 'filename', 'file_exists');
         }
     }
 }
开发者ID:sintattica,项目名称:atk,代码行数:16,代码来源:FileEditor.php

示例11: validate

 public function validate(&$rec, $mode)
 {
     if (is_array($rec[$this->fieldName()])) {
         // Coming from selectscreen, no search necessary anymore.
     } else {
         $this->m_matches = $this->getMatches($rec[$this->fieldName()]);
         $mustselect = false;
         if ($this->m_mode == 'multiselect' || $this->m_mode == 'selectperkeyword') {
             // In multiselect and selectperkeyword mode, we present the selector
             // if one or more keywords returned more than one match. If they
             // all returned exactly one match, we pass all records and don't
             // offer selection.
             foreach ($this->m_matches as $keyword => $res) {
                 if (count($res) > 1) {
                     $mustselect = true;
                     break;
                 }
             }
         } else {
             if ($this->m_mode == 'select') {
                 // In single select mode, we show the selector if they all return
                 // just one match together.
                 $total = 0;
                 foreach ($this->m_matches as $keyword => $res) {
                     $total += count($res);
                 }
                 $mustselect = $total > 1;
             }
         }
         if ($mustselect) {
             Tools::triggerError($rec, $this->fieldName(), 'fsa_pleasemakeselection');
             return false;
         }
     }
     return true;
 }
开发者ID:sintattica,项目名称:atk,代码行数:36,代码来源:FuzzySearchAttribute.php

示例12: validate

 /**
  * Validate's dates.
  *
  * @param array $record Record that contains value to be validated.
  *                       Errors are saved in this record
  * @param string $mode can be either "add" or "update"
  *
  * @return array|null $record or null
  */
 public function validate(&$record, $mode)
 {
     $value =& $record[$this->fieldName()];
     $current = 0;
     /* array or no array */
     if (!is_array($value)) {
         $value = self::dateArray(adodb_date('Ymd', strtotime($value)));
     }
     /* if not obligatory and one of the fields is null then the date will be saved as null */
     if (!$this->hasFlag(self::AF_OBLIGATORY) && (empty($value['year']) || empty($value['month']) || empty($value['day']))) {
         return null;
     }
     // If one of the fields is not filled, we don't check
     if (!($value['year'] == '' || $value['month'] == 0 || $value['day'] == 0)) {
         /* currently selected date */
         if ($this->checkDateArray($value)) {
             $current = adodb_mktime(0, 0, 0, $value['month'], $value['day'], $value['year']);
         } else {
             Tools::triggerError($record, $this->fieldName(), 'error_date_invalid');
             return null;
         }
     }
     /* allright, if not obligatory, and we have come all this way, we'll bail out */
     if (!$this->hasFlag(self::AF_OBLIGATORY)) {
         return null;
     } else {
         if ($value['year'] == '' || $value['month'] == 0 || $value['day'] == 0) {
             Tools::triggerError($record, $this->fieldName(), 'error_obligatoryfield');
             return null;
         }
     }
     /* minimum date */
     $minimum = 0;
     $str_min = $this->m_date_min;
     if (strlen($str_min) == 8) {
         $date = self::dateArray($str_min);
         if ($this->checkDateArray($date)) {
             $minimum = adodb_mktime(0, 0, 0, $date['month'], $date['day'], $date['year']);
         }
     }
     /* maximum date */
     $maximum = 0;
     $str_max = $this->m_date_max;
     if (strlen($str_max) == 8) {
         $date = self::dateArray($str_max);
         if ($this->checkDateArray($date)) {
             $maximum = adodb_mktime(0, 0, 0, $date['month'], $date['day'], $date['year']);
         }
     }
     /* date < minimum */
     if (!empty($minimum) && $current < $minimum) {
         Tools::triggerError($record, $this->fieldName(), 'error_date_minimum', Tools::atktext('error_date_minimum') . ' ' . $this->formatDate(adodb_getdate($minimum), $this->m_date_format_view, 0));
         return null;
     }
     /* date > maximum */
     if (!empty($maximum) && $current > $maximum) {
         Tools::triggerError($record, $this->fieldName(), 'error_date_maximum', Tools::atktext('error_date_maximum') . ' ' . $this->formatDate(adodb_getdate($maximum), $this->m_date_format_view, 0));
     }
 }
开发者ID:sintattica,项目名称:atk,代码行数:68,代码来源:DateAttribute.php

示例13: validate

 /**
  * Validates if value is numeric.
  *
  * @param array $record Record that contains value to be validated.
  *                       Errors are saved in this record
  * @param string $mode can be either "add" or "update"
  */
 public function validate(&$record, $mode)
 {
     if (!is_numeric($record[$this->fieldName()]) && $record[$this->fieldName()] != '') {
         Tools::triggerError($record, $this->fieldName(), 'error_notnumeric');
     }
     if ($this->m_maxvalue !== false && $record[$this->fieldName()] > $this->m_maxvalue) {
         Tools::triggerError($record, $this->fieldName(), 'above_maximum_value');
     }
     if ($this->m_minvalue !== false && $record[$this->fieldName()] < $this->m_minvalue) {
         Tools::triggerError($record, $this->fieldName(), 'below_minimum_value');
     }
 }
开发者ID:sintattica,项目名称:atk,代码行数:19,代码来源:NumberAttribute.php

示例14: updateRecordInDb

 /**
  * Update a record in the database.
  *
  * @param array $record Record to update
  *
  * @return mixed Result of the update, true, false or string with error
  */
 private function updateRecordInDb(&$record)
 {
     $db = $this->m_node->getDb();
     if ($this->m_node->updateDb($record)) {
         $db->commit();
         $this->notify('update', $record);
         $this->clearCache();
         return true;
     } else {
         $db->rollback();
         if ($db->getErrorType() == 'user') {
             Tools::triggerError($record, 'Error', $db->getErrorMsg(), '', '');
             return false;
         }
         return $db->getErrorMsg();
     }
 }
开发者ID:sintattica,项目名称:atk,代码行数:24,代码来源:UpdateHandler.php


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