本文整理汇总了PHP中str::starts_with方法的典型用法代码示例。如果您正苦于以下问题:PHP str::starts_with方法的具体用法?PHP str::starts_with怎么用?PHP str::starts_with使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类str
的用法示例。
在下文中一共展示了str::starts_with方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: query
public function query($sql, $active_link = NULL, $as_master = NO)
{
if (!is_resource($active_link)) {
if ($this->has_master()) {
if ($as_master) {
is_resource($this->link_master) or $this->connect(YES);
$active_link = $this->link_master;
} else {
if (str::starts_with(trim($sql), "select")) {
$active_link = $this->link;
} else {
is_resource($this->link_master) or $this->connect(YES);
$active_link = $this->link_master;
}
}
} else {
$active_link = $this->link;
}
}
// Only cache if it's turned on, and only cache if it's not a write statement
if ($this->db_config['cache'] and !preg_match('#\\b(?:INSERT|UPDATE|REPLACE|SET)\\b#i', $sql)) {
$hash = $this->query_hash($sql);
if (!isset(self::$query_cache[$hash])) {
// Set the cached object
self::$query_cache[$hash] = new Database_Mysql_Result(mysql_query($sql, $this->link), $this->link, $this->db_config['object'], $sql);
}
// Return the cached query
return self::$query_cache[$hash];
}
return new Database_Mysql_Result(mysql_query($sql, $active_link), $active_link, $this->db_config['object'], $sql);
}
示例2: __autoload
/**
* Attempts to autoload tests
*/
public function __autoload($class)
{
if (!str::starts_with($class, 'test_')) {
return FALSE;
}
if (class_exists($class, FALSE)) {
return TRUE;
}
$filename = str_replace('test/', 'tests/', str_replace('_', '/', strtolower($class)));
if (!($path = Eight::find_file('classes', $filename, FALSE))) {
return FALSE;
}
require $path;
return TRUE;
}
示例3: validate
/**
* Validate this input based on the set rules.
*
* @return bool
*/
public function validate()
{
// Validation has already run
if (is_bool($this->is_valid)) {
return $this->is_valid;
}
// No data to validate
if ($this->input_value() == NO) {
return $this->is_valid = NO;
}
// Load the submitted value
$this->load_value();
// No rules to validate
if (count($this->rules) == 0 and count($this->matches) == 0 and count($this->callbacks) == 0) {
return $this->is_valid = YES;
}
if (!empty($this->rules)) {
foreach ($this->rules as $rule) {
if (str::e($rule)) {
continue;
}
if (($offset = strpos($rule, '[')) !== NO) {
// Get the args
$args = preg_split('/, ?/', trim(substr($rule, $offset), '[]'));
// Remove the args from the rule
$rule = substr($rule, 0, $offset);
}
if (is_callable($rule)) {
$this->value = $rule($this->value);
} elseif (substr($rule, 0, 6) === 'valid_' and method_exists('valid', substr($rule, 6))) {
$func = substr($rule, 6);
if ($this->value and !valid::$func($this->value)) {
$this->errors[$rule] = YES;
}
} elseif (str::starts_with($rule, "callback_")) {
if (method_exists(Eight::instance(), substr($rule, 9))) {
if (is_array($args)) {
$new_args = array_merge(array(&$this), $args);
} else {
$new_args = array(&$this);
}
call_user_func_array(array(Eight::instance(), substr($rule, 9)), $new_args);
} else {
throw new Eight_Exception('validation.invalid_callback', substr($rule, 9));
}
} elseif (method_exists($this, 'rule_' . $rule)) {
// The rule function is always prefixed with rule_
$rule = 'rule_' . $rule;
if (isset($args)) {
// Manually call up to 2 args for speed
switch (count($args)) {
case 1:
$this->{$rule}($args[0]);
break;
case 2:
$this->{$rule}($args[0], $args[1]);
break;
default:
call_user_func_array(array($this, $rule), $args);
break;
}
} else {
// Just call the rule
$this->{$rule}();
}
// Prevent args from being re-used
unset($args);
} else {
throw new Eight_Exception('validation.invalid_rule', $rule);
}
// Stop when an error occurs
if (!empty($this->errors)) {
break;
}
}
}
if (!empty($this->matches)) {
foreach ($this->matches as $input) {
if ($this->value != $input->value) {
// Field does not match
$this->errors['matches'] = array($input->label ? utf8::strtolower($input->label) : $input->name);
break;
}
}
}
if (!empty($this->callbacks)) {
foreach ($this->callbacks as $callback) {
call_user_func($callback, $this);
// Stop when an error occurs
if (!empty($this->errors)) {
break;
}
}
}
// If there are errors, validation failed
//.........这里部分代码省略.........