本文整理匯總了PHP中Valid::not_empty方法的典型用法代碼示例。如果您正苦於以下問題:PHP Valid::not_empty方法的具體用法?PHP Valid::not_empty怎麽用?PHP Valid::not_empty使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Valid
的用法示例。
在下文中一共展示了Valid::not_empty方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: action_index
/**
* @return void
*/
public function action_index()
{
$this->template->content->active = "options";
$session = Session::instance();
// Check for post
if ($this->request->method() === "POST") {
$bucket_name = trim($this->request->post('bucket_name'));
// Check for updates to the bucket name
if (Valid::not_empty($bucket_name) and strcmp($bucket_name, $this->bucket['name']) !== 0) {
$bucket_id = $this->bucket['id'];
$parameters = array('name' => $bucket_name, 'public' => (bool) $this->request->post('bucket_publish'));
//
if (($bucket = $this->bucket_service->modify_bucket($bucket_id, $parameters, $this->user)) != FALSE) {
$session->set('message', __("Bucket settings successfully saved"));
// Reload the settings page using the updated bucket name
$this->redirect($bucket['url'] . '/settings', 302);
} else {
$session->set('error', __("The bucket settings could not be updated"));
}
}
}
// Set the messages and/or error messages
$this->template->content->set('message', $session->get('message'))->set('error', $session->get('error'));
$this->settings_content = View::factory('pages/bucket/settings/display')->bind('bucket', $this->bucket)->bind('collaborators_view', $collaborators_view);
// Collaboraotors view
$collaborators_view = View::factory('/template/collaborators')->bind('fetch_url', $fetch_url)->bind('collaborator_list', $collaborators);
$fetch_url = $this->bucket_base_url . '/collaborators';
$collaborators = json_encode($this->bucket_service->get_collaborators($this->bucket['id']));
$session->delete('message');
$session->delete('error');
}
示例2: check_code
public function check_code($value)
{
$_site_type = empty($this->_original_values['type']) ? $this->_object['type'] : $this->_original_values['type'];
if ($_site_type === 'master') {
return !Valid::not_empty($value);
} else {
return Valid::not_empty($value);
}
}
示例3: email_domain
/**
* Validate the domain of an email address by checking if the domain has a
* valid MX record and is nmot blaklisted as a temporary email
*
* @link http://php.net/checkdnsrr not added to Windows until PHP 5.3.0
*
* @param string $email email address
* @return boolean
*/
public static function email_domain($email)
{
if (!Valid::not_empty($email)) {
return FALSE;
}
// Empty fields cause issues with checkdnsrr()
$domain = preg_replace('/^[^@]++@/', '', $email);
if (core::config('general.black_list') == TRUE and in_array($domain, self::get_banned_domains())) {
return FALSE;
}
// Check if the email domain has a valid MX record
return (bool) checkdnsrr($domain, 'MX');
}
示例4: check_data
public static function check_data($value, $data)
{
switch ($data['type']) {
case 'static':
return TRUE;
case 'module':
return Valid::not_empty($value) and Valid::alpha_dash($value) and $value != '-';
case 'page':
return Valid::not_empty($value) and Valid::digit($value) and $value != '-' and $data['id'] != $value;
case 'url':
return Valid::not_empty($value) and Model_Page::check_link($value) and $value != '-';
}
return FALSE;
}
示例5: at_least
/**
* Checks that at least $needed of $fields are not_empty
*
* @param array array of values
* @param integer Number of fields required
* @param array Field names to check.
* @return boolean
*/
public static function at_least($validation, $needed = 1, $fields)
{
$found = 0;
foreach ($fields as $field)
{
if (isset($validation[$field]) AND Valid::not_empty($validation[$field]))
{
$found++;
}
}
if ($found >= $needed)
return TRUE;
$validation->error($fields[0], 'at_least', array($needed, $fields));
}
示例6: email_domain
/**
* Validate the domain of an email address by checking if the domain has a
* valid MX record.
*
* @link http://php.net/checkdnsrr not added to Windows until PHP 5.3.0
*
* @param string $email email address
*
* @return boolean
*/
public static function email_domain($email)
{
if (!Valid::not_empty($email)) {
return false;
}
// Empty fields cause issues with checkdnsrr()
// Check if the email domain has a valid MX record
return (bool) checkdnsrr(preg_replace('/^[^@]++@/', '', $email), 'MX');
}
示例7: token
public function token()
{
// Validate the request
$request_params = $this->validate_token_params();
// Response Params
$response_params = array('token_type' => OAuth2::TOKEN_TYPE_BEARER, 'expires_in' => Model_OAuth2_Access_Token::$lifetime);
$client = Model_OAuth2_Client::find_client($request_params['client_id'], $request_params['client_secret']);
$user_id = NULL;
if ($request_params['grant_type'] == OAuth2::GRANT_TYPE_AUTH_CODE) {
$auth_code = Model_OAuth2_Auth_Code::find_code($request_params['code']);
$user_id = $auth_code->user_id;
$auth_code->delete();
} elseif ($request_params['grant_type'] == OAuth2::GRANT_TYPE_REFRESH_TOKEN) {
$refresh_token = Model_OAuth2_Refresh_Token::find_token($request_params['refresh_token']);
$user_id = $refresh_token->user_id;
$refresh_token->delete();
} elseif ($request_params['grant_type'] == OAuth2::GRANT_TYPE_CLIENT_CREDENTIALS) {
$user_id = NULL;
} elseif ($request_params['grant_type'] == OAuth2::GRANT_TYPE_PASSWORD) {
$user_id = $this->_validate_user($request_params['username'], $request_params['password']);
}
// Generate an access token
$access_token = Model_OAuth2_Access_Token::create_token($request_params['client_id'], $user_id, $request_params['scope']);
$response_params['access_token'] = $access_token->access_token;
// If refreh tokens are supported, add one.
if (in_array(OAuth2::GRANT_TYPE_REFRESH_TOKEN, OAuth2::$supported_grant_types)) {
// Generate a refresh token
$refresh_token = Model_OAuth2_Refresh_Token::create_token($request_params['client_id'], $user_id, $request_params['scope']);
$response_params['refresh_token'] = $refresh_token->refresh_token;
}
// Add scope if needed
if (Valid::not_empty($request_params['scope'])) {
$response_params['scope'] = $request_params['scope'];
}
return json_encode($response_params);
}
示例8: action_places
/**
* Links restful api
*/
public function action_places()
{
// Is the logged in user an owner?
if (!$this->owner) {
throw new HTTP_Exception_403();
}
$this->template = "";
$this->auto_render = FALSE;
$droplet_id = intval($this->request->param('id', 0));
$place_id = intval($this->request->param('id2', 0));
switch ($this->request->method()) {
case "POST":
$places_array = json_decode($this->request->body(), true);
$place_name = $places_array['place_name'];
if (!Valid::not_empty($place_name)) {
$this->response->status(400);
$this->response->headers('Content-Type', 'application/json');
$errors = array(__("Invalid location"));
echo json_encode(array('errors' => $errors));
return;
}
$account_id = $this->visited_account->id;
$place_orm = Model_Account_Droplet_Place::get_place($place_name, $droplet_id, $account_id);
echo json_encode(array('id' => $place_orm->place->id, 'place_name' => $place_orm->place->place_name, 'place_name_canonical' => $place_orm->place->place_name_canonical));
break;
case "DELETE":
Model_Droplet::delete_place($droplet_id, $place_id, $this->visited_account->id);
break;
}
}
示例9: check
public function check()
{
if (JsonApiApplication::$profiling === TRUE) {
$benchmark = Profiler::start('Validation', __FUNCTION__);
}
$data = $this->_errors = array();
$original = $this->_data;
$expected = Arr::merge(array_keys($original), array_keys($this->_labels));
$rules = $this->_rules;
foreach ($expected as $field) {
$data[$field] = Arr::get($this, $field);
if (isset($rules[TRUE])) {
if (!isset($rules[$field])) {
$rules[$field] = array();
}
$rules[$field] = array_merge($rules[$field], $rules[TRUE]);
}
}
$this->_data = $data;
unset($rules[TRUE]);
$this->bind(':validation', $this);
$this->bind(':data', $this->_data);
foreach ($rules as $field => $set) {
$value = $this[$field];
$this->bind(array(':field' => $field, ':value' => $value));
foreach ($set as $array) {
list($rule, $params) = $array;
foreach ($params as $key => $param) {
if (is_string($param) and array_key_exists($param, $this->_bound)) {
$params[$key] = $this->_bound[$param];
}
}
$error_name = $rule;
if (is_array($rule)) {
if (is_string($rule[0]) and array_key_exists($rule[0], $this->_bound)) {
$rule[0] = $this->_bound[$rule[0]];
}
$error_name = $rule[1];
$passed = call_user_func_array($rule, $params);
} elseif (!is_string($rule)) {
$error_name = FALSE;
$passed = call_user_func_array($rule, $params);
} elseif (method_exists('Valid', $rule)) {
$method = new ReflectionMethod('Valid', $rule);
$passed = $method->invokeArgs(NULL, $params);
} elseif (strpos($rule, '::') === FALSE) {
$function = new ReflectionFunction($rule);
$passed = $function->invokeArgs($params);
} else {
list($class, $method) = explode('::', $rule, 2);
$method = new ReflectionMethod($class, $method);
$passed = $method->invokeArgs(NULL, $params);
}
if (!in_array($rule, $this->_empty_rules) and !Valid::not_empty($value)) {
continue;
}
if ($passed === FALSE and $error_name !== FALSE) {
$this->error($field, $error_name, $params);
break;
} elseif (isset($this->_errors[$field])) {
break;
}
}
}
unset($this->_bound[':validation']);
unset($this->_bound[':data']);
unset($this->_bound[':field']);
unset($this->_bound[':value']);
$this->_data = $original;
if (isset($benchmark)) {
Profiler::stop($benchmark);
}
return empty($this->_errors);
}
示例10: _valid_group
protected function _valid_group($group)
{
// Group cannot be empty
if (!Valid::not_empty($group)) {
return FALSE;
}
// Can only consist of alpha-numeric values, dashes, underscores, and slashes
if (preg_match('/[^a-zA-Z0-9\\/_-]/', $group)) {
return FALSE;
}
// Must also contain at least one alpha-numeric value
if (!preg_match('/[a-zA-Z0-9]/', $group)) {
return FALSE;
}
// --group="/" breaks things but "a/b" should be allowed
return TRUE;
}
示例11: action_newUser
public function action_newUser()
{
// echo '<pre>'; print_r($_POST); exit;
// form post handling
if (isset($_POST) && Valid::not_empty($_POST)) {
// validate
$post = Validation::factory($_POST)->rule('email', 'not_empty')->rule('email', 'email')->rule('email', 'email_domain')->rule('username', 'not_empty')->rule('username', Kohana::$config->load('musyme.account.create.username.format'))->rule('username', 'min_length', array(':value', Kohana::$config->load('musyme.account.create.username.min_length')))->rule('username', 'max_length', array(':value', Kohana::$config->load('musyme.account.create.username.max_length')))->rule('password', 'not_empty')->rule('password', 'min_length', array(':value', Kohana::$config->load('musyme.account.create.password.min_length')))->rule('password', array($this, 'pwdneusr'), array(':validation', ':field', 'username'));
if ($post->check()) {
// save
$model = ORM::factory('User');
$model->values(array('email' => $post['email'], 'username' => HTML::entities(strip_tags($post['username'])), 'password' => $post['password']));
try {
$model->save();
$model->add('roles', ORM::factory('Role')->where('name', '=', 'login')->find());
$model->add('roles', ORM::factory('Role')->where('name', '=', 'participant')->find());
$this->redirect('dashboard/users');
} catch (ORM_Validation_Exception $e) {
$errors = $e->errors('user');
}
} else {
$errors = $post->errors('user');
}
}
// TODO i18n
$this->template->title = __('Create an account');
// display
$this->template->content = View::factory('dashboard/users/new')->bind('post', $post)->bind('errors', $errors);
}
示例12: action_buckets
/**
* XHR endpoint for managing a user's buckets
*/
public function action_buckets()
{
$this->template = "";
$this->auto_render = FALSE;
switch ($this->request->method()) {
case "POST":
$payload = json_decode($this->request->body(), TRUE);
if (Valid::not_empty($payload['name'])) {
$bucket_name = $payload['name'];
$bucket = $this->bucket_service->create_bucket($bucket_name, $this->user);
$this->response->headers("Content-Type", "application/json;charset=UTF-8");
echo json_encode($bucket);
}
break;
case "DELETE":
$bucket_id = $this->request->param('id', 0);
$this->bucket_service->delete_bucket($bucket_id);
break;
}
}
示例13: required
/**
* Checks if a field is set.
*
* Modified version of Validate::not_empty, also accepts FALSE
* as a valid value
*
* @return boolean
*/
public static function required($value)
{
return Valid::not_empty($value) || $value === FALSE;
}
示例14: test_not_empty
/**
* Tests Valid::not_empty()
*
* Checks if a field is not empty.
*
* @test
* @dataProvider provider_not_empty
* @param mixed $value Value to check
* @param boolean $empty Is the value really empty?
*/
public function test_not_empty($value, $empty)
{
return $this->assertSame($empty, Valid::not_empty($value));
}
示例15: action_password
public function action_password()
{
// user already logged in, redirect to dashboard
if (Auth::instance()->logged_in('participant')) {
$this->request->redirect('dashboard');
}
// try to match
if (isset($_GET['token']) && isset($_GET['email'])) {
if (strlen($_GET['token']) == 32 && Valid::email($_GET['email'])) {
// match $_GET with user
$user = ORM::factory('user')->where('email', '=', $_GET['email'])->where('reset_token', '=', $_GET['token'])->find();
if ($user->loaded()) {
$found = 1;
} else {
$found = 0;
}
} else {
$this->request->redirect();
}
} else {
$this->request->redirect();
}
// handle post
if (isset($_POST) && Valid::not_empty($_POST)) {
// validate the login form
$post = Validation::factory($_POST)->rule('username', 'not_empty')->rule('password', 'not_empty')->rule('password', 'min_length', array(':value', Kohana::$config->load('ko32example.account.create.password.min_length')))->rule('password', array($this, 'pwdneusr'), array(':validation', ':field', 'username'));
// if the form is valid and the username and password matches
if ($post->check()) {
// modify the password
$user->reset_token = NULL;
$user->password = $post['password'];
$user->save();
// log the user
if (Auth::instance()->login($post['username'], $post['password'])) {
Session::instance()->set('success_pwd', 1);
$this->request->redirect('dashboard');
}
} else {
$errors = $post->errors('user');
}
}
// display
$this->template->title = 'Reset password step 2';
$this->template->content = View::factory('account/password')->bind('post', $post)->bind('errors', $errors)->bind('found', $found)->bind('user', $user);
}