本文整理匯總了PHP中Respect\Validation\Validator::date方法的典型用法代碼示例。如果您正苦於以下問題:PHP Validator::date方法的具體用法?PHP Validator::date怎麽用?PHP Validator::date使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Respect\Validation\Validator
的用法示例。
在下文中一共展示了Validator::date方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: createHolidayAction
public function createHolidayAction()
{
$title = $this->app->request->post('title');
$date = $this->app->request->post('date');
$days = $this->app->request->post('days');
$is_enabled = !empty($this->app->request->post('is_enabled')) ? true : false;
$is_recurring = !empty($this->app->request->post('is_recurring')) ? true : false;
$date = c::parse($date)->toDateString();
$rules = array('title' => v::string()->notEmpty()->setName('title'), 'date' => v::date()->notEmpty()->setName('date'), 'days' => v::int()->notEmpty()->setName('days'), 'is_enabled' => v::bool()->setName('is_enabled'), 'is_recurring' => v::bool()->setName('is_recurring'));
$data = $this->app->request->post();
$data['date'] = $date;
$data['is_enabled'] = $is_enabled;
$data['is_recurring'] = $is_recurring;
$message = array('type' => 'success', 'text' => 'Successfully added event');
foreach ($data as $key => $value) {
try {
$rules[$key]->check($value);
} catch (\InvalidArgumentException $e) {
$message = array('type' => 'error', 'text' => $e->getMainMessage());
break;
}
}
$event = R::dispense('events');
$event->title = $title;
$event->date = $date;
$event->days = $days;
$event->is_enabled = $is_enabled;
$event->is_recurring = $is_recurring;
R::store($event);
$this->app->flash('message', $message);
$this->app->redirect('/');
}
示例2: validatePatchVars
public function validatePatchVars($vars)
{
$validations = [v::intVal()->validate($vars['id']), v::stringType()->length(2)->validate($vars['nome']), v::stringType()->length(2)->validate($vars['sobrenome'])];
if ($vars['nascimento']) {
$validations[] = v::date()->validate($vars['nascimento']);
}
return $validations;
}
示例3: validate
public function validate($prop, $label)
{
$value = $this->getValue($prop);
if ($value == '' && !$this->_required) {
return;
}
if (!v::date($this->_format)->validate($value)) {
$this->addException("Campo {$label} com uma data inválida");
}
}
示例4: defineAtualizadoEm
public function defineAtualizadoEm($atualizadoEm)
{
$atualizadoEmValidador = Validator::date('Y-m-d H:i:s');
try {
$atualizadoEmValidador->check($atualizadoEm);
$this->atualizadoEm = $atualizadoEm;
} catch (ValidationException $exception) {
print_r($exception->getMainMessage());
}
}
示例5: defineDataHoraFim
public function defineDataHoraFim($dataHoraFim)
{
$dataHoraFimValidador = Validator::date('Y-m-d H:i:s');
try {
$dataHoraFimValidador->check($dataHoraFim);
$this->dataHoraFim = $dataHoraFim;
} catch (ValidationException $exception) {
print_r($exception->getMainMessage());
}
}
示例6: prohibit
/**
* @param string|\DateTime $value
* @return bool
*/
protected function prohibit($value)
{
if ($value instanceof \DateTime) {
$value = $value->format(self::FORMAT);
} else {
if (!is_string($value) || !Validator::date($this->format)->validate($value)) {
return true;
}
}
return parent::prohibit($value);
}
示例7: testKeysAsValidatorNames
public function testKeysAsValidatorNames()
{
try {
Validator::key('username', Validator::length(1, 32))->key('birthdate', Validator::date())->setName("User Subscription Form")->assert(array('username' => '', 'birthdate' => ''));
} catch (NestedValidationExceptionInterface $e) {
$this->assertEquals('\\-These rules must pass for User Subscription Form
|-Key username must be valid
| \\-"" must have a length between 1 and 32
\\-Key birthdate must be valid
\\-"" must be a valid date', $e->getFullMessage());
}
}
示例8: initRule
/**
* init valid rule
*/
protected function initRule()
{
$this->validRule['uid'] = v::numeric();
$this->validRule['eduid'] = v::numeric();
$this->validRule['schoolName'] = v::stringType()->length(1, 32);
$this->validRule['majorName'] = v::stringType()->length(1, 32);
$this->validRule['majorCat'] = v::stringType()->length(1, 32);
$this->validRule['area'] = v::stringType()->length(1, 32);
$this->validRule['schoolCountry'] = v::stringType()->length(1, 32);
$this->validRule['startDate'] = v::date('Y-m');
$this->validRule['endDate'] = v::date('Y-m');
$this->validRule['degreeStatus'] = v::intVal()->between(1, 3);
}
示例9: __invoke
/**
* Handle domain logic for an action.
*
* @param array $input
* @return PayloadInterface
*/
public function __invoke(array $input)
{
//Ensure that the use has permission to create shifts
$user = $input[AuthHandler::TOKEN_ATTRIBUTE]->getMetadata('entity');
$this->authorizeUser($user, 'create', 'shifts');
//If no manager_id is specified in request, default to user creating shift
if (!array_key_exists('manager_id', $input)) {
$input['manager_id'] = $user->getId();
}
//Validate input
$inputValidator = v::key('break', v::floatVal())->key('start_time', v::date())->key('end_time', v::date()->min($input['start_time']))->key('manager_id', v::intVal());
$inputValidator->assert($input);
//Execute command to create shift
$shift = $this->commandBus->handle(new CreateShift($input['manager_id'], $input['employee_id'], $input['break'], $input['start_time'], $input['end_time']));
$this->item->setData($shift)->setTransformer($this->shiftTransformer);
return $this->payload->withStatus(PayloadInterface::OK)->withOutput($this->fractal->parseIncludes(['manager', 'employee'])->createData($this->item)->toArray());
}
示例10: filter_datetime
public static function filter_datetime($datetime)
{
$arrayDate = explode(' ', $datetime);
if (count($arrayDate) != 2) {
throw new Exception('Data/Horário no formato inválido para conversão');
}
$date_sql = self::filter_date($arrayDate[0]);
if (!v::date('H:i:s')->validate($arrayDate[1]) && !v::date('H:i')->validate($arrayDate[1])) {
throw new Exception('Horário no formato inválido para conversão');
}
$time_sql = date('H:i:s', strtotime($arrayDate[1]));
$datetime_sql = $date_sql . ' ' . $time_sql;
if (!v::date()->validate($datetime_sql)) {
throw new Exception('Erro na conversão');
}
return $datetime_sql;
}
示例11: getFieldDefinitions
/**
* Get Fields Definitions
*
* @access public
* @return array
*/
protected function getFieldDefinitions()
{
return ['auth_id' => ['Authorisation ID', V::notEmpty()->numeric()], 'auth_pass' => ['Authorisation Password', V::notEmpty()->string()], 'card_num' => ['Card Number', V::notEmpty()->string()->length(16, 16)->digit()->noWhitespace()->creditCard()], 'card_cvv' => ['Card CVV', V::notEmpty()->string()->length(3, 3)->digit()->noWhitespace()], 'card_start' => ['Card Start Date', V::date('my')], 'card_issue' => ['Card Issue Number', V::string()->length(null, 2)->digit()->noWhitespace(), ''], 'card_expiry' => ['Card Expiry Date', V::notEmpty()->date('my')], 'cust_name' => ['Customer Name', V::notEmpty()->string()], 'cust_address' => ['Customer Address', V::notEmpty()->string()], 'cust_postcode' => ['Customer Postcode', V::notEmpty()->string()], 'cust_country' => ['Customer Country', V::notEmpty()->string()->countryCode()], 'cust_ip' => ['Customer IP Address', V::notEmpty()->string()->ip(), $_SERVER['REMOTE_ADDR']], 'cust_email' => ['Customer Email Address', V::notEmpty()->string()->email()], 'cust_tel' => ['Customer Telephone Number', V::notEmpty()->string()->phone()], 'tran_ref' => ['Transaction Reference', V::notEmpty()->string()], 'tran_desc' => ['Transaction Description', V::notEmpty()->string()], 'tran_amount' => ['Transaction Amount', V::notEmpty()->float()], 'tran_currency' => ['Transaction Currency', V::notEmpty()->string()->length(3, 3)->alpha()->noWhitespace()], 'tran_testmode' => ['Test Mode', V::notEmpty()->bool(), false], 'acs_eci' => ['Access Control Server (ECI)', V::int()], 'acs_cavv' => ['Cardholder Authentication Verification Value', V::string()->length(28, 28), ''], 'acs_xid' => ['Access Control Server (Unique Authentication ID)', V::string()->length(28, 28), '']];
}
示例12: prototyper_validate_type
/**
* Validates input type
*
* @param string $hook "validate:type"
* @param string $type "prototyper"
* @param ValidationStatus $validation Current validation status
* @param array $params Hook params
* @return ValidationStatus
*/
function prototyper_validate_type($hook, $type, $validation, $params)
{
if (!$validation instanceof ValidationStatus) {
$validation = new ValidationStatus();
}
$field = elgg_extract('field', $params);
if (!$field instanceof Field) {
return $validation;
}
$rule = elgg_extract('rule', $params);
if ($rule != "type") {
return $validation;
}
$value = elgg_extract('value', $params);
$expectation = elgg_extract('expectation', $params);
switch ($expectation) {
case 'text':
case 'string':
if (!v::string()->validate($value)) {
$validation->setFail(elgg_echo('prototyper:validate:error:type:string', array($field->getLabel())));
}
break;
case 'alnum':
case 'alphanum':
if (!v::alnum()->validate($value)) {
$validation->setFail(elgg_echo('prototyper:validate:error:type:alnum', array($field->getLabel())));
}
break;
case 'alpha':
if (!v::alpha()->validate($value)) {
$validation->setFail(elgg_echo('prototyper:validate:error:type:alpha', array($field->getLabel())));
}
break;
case 'number':
case 'numeric':
if (!v::numeric()->validate($value)) {
$validation->setFail(elgg_echo('prototyper:validate:error:type:numeric', array($field->getLabel())));
}
break;
case 'integer':
case 'int':
if (!v::int()->validate($value)) {
$validation->setFail(elgg_echo('prototyper:validate:error:type:int', array($field->getLabel())));
}
break;
case 'date':
if (!v::date()->validate($value)) {
$validation->setFail(elgg_echo('prototyper:validate:error:type:date', array($field->getLabel())));
}
break;
case 'url':
if (!v::filterVar(FILTER_VALIDATE_URL, FILTER_FLAG_PATH_REQUIRED)->validate($value)) {
$validation->setFail(elgg_echo('prototyper:validate:error:type:url', array($field->getLabel())));
}
break;
case 'email':
if (!v::filterVar(FILTER_VALIDATE_EMAIL)->validate($value)) {
$validation->setFail(elgg_echo('prototyper:validate:error:type:email', array($field->getLabel())));
}
break;
case 'guid':
case 'entity':
if (!elgg_entity_exists($value)) {
$validation->setFail(elgg_echo('prototyper:validate:error:type:guid', array($field->getLabel())));
}
break;
case 'image':
$type = elgg_extract('type', $value);
if (!$type || substr_count($type, 'image/') == 0) {
$validation->setFail(elgg_echo('prototyper:validate:error:type:image', array($field->getLabel())));
}
break;
}
return $validation;
}
示例13: setVcard4
public function setVcard4($vcard)
{
$validate_date = Validator::date('Y-m-d');
if (isset($vcard->bday->date) && $validate_date->validate($vcard->bday->date)) {
$this->__set('date', (string) $vcard->bday->date);
}
$this->__set('name', (string) $vcard->nickname->text);
$this->__set('fn', (string) $vcard->fn->text);
$this->__set('url', (string) $vcard->url->uri);
if (isset($vcard->gender)) {
$this->__set('gender ', (string) $vcard->gender->sex->text);
}
if (isset($vcard->marital)) {
$this->__set('marital', (string) $vcard->marital->status->text);
}
$this->__set('adrlocality', (string) $vcard->adr->locality);
$this->__set('adrcountry', (string) $vcard->adr->country);
$this->__set('adrpostalcode', (string) $vcard->adr->code);
if (isset($vcard->impp)) {
foreach ($vcard->impp->children() as $c) {
list($key, $value) = explode(':', (string) $c);
switch ($key) {
case 'twitter':
$this->__set('twitter', str_replace('@', '', $value));
break;
case 'skype':
$this->__set('skype', (string) $value);
break;
case 'ymsgr':
$this->__set('yahoo', (string) $value);
break;
}
}
}
$this->__set('email', (string) $vcard->email->text);
$this->__set('description', trim((string) $vcard->note->text));
}
示例14: grossSubscriberFee
function grossSubscriberFee($contractNo, $checkStartDate, $checkDate)
{
//Get user details
#Validate
if (!v::numeric()->validate($contractNo)) {
$xmlstr = <<<_XML_
<?xml version='1.0' standalone='yes'?>
<returnCall>
<status>Fail</status>
<msg>Invalid contract number</msg>
</returnCall>
_XML_;
return $xmlstr;
}
if (!v::date()->validate($checkStartDate)) {
$xmlstr = <<<_XML_
<?xml version='1.0' standalone='yes'?>
<returnCall>
<status>Fail</status>
<msg>Invalid date format</msg>
</returnCall>
_XML_;
return $xmlstr;
}
if (!v::date()->validate($checkDate)) {
$xmlstr = <<<_XML_
<?xml version='1.0' standalone='yes'?>
<returnCall>
<status>Fail</status>
<msg>Invalid date format</msg>
</returnCall>
_XML_;
return $xmlstr;
}
#Get contract details
$resultSet = mysqli_query($this->conn, "SELECT * FROM accountrecords WHERE contractNo = '" . mysqli_real_escape_string($this->conn, $contractNo) . "';", MYSQLI_STORE_RESULT);
if (mysqli_errno($this->conn) != 0) {
#Failed to run query
$xmlstr = <<<_XML_
<?xml version='1.0' standalone='yes'?>
<returnCall>
<status>Fail</status>
<msg>Failed to execute query</msg>
<errorMsg>{$this->conn}->error<errorMsgmsg>
</returnCall>
_XML_;
return $xmlstr;
}
//$row_cnt = mysqli_num_rows($resultSet);
//file_put_contents('log.log', print_r($resultSet));
$row_cnt = mysqli_num_rows($resultSet);
if ($row_cnt === 0) {
$xmlstr = <<<_XML_
<?xml version='1.0' standalone='yes'?>
<returnCall>
<status>Fail</status>
<msg>Contract does not exist</msg>
</returnCall>
_XML_;
return $xmlstr;
}
$returnContractRow = mysqli_fetch_assoc($resultSet);
//Check that the date passed is greater or equal to the subscriptionStartDate
$date1 = new DateTime($checkDate);
$date2 = $returnContractRow['subscriptionStartDate'];
if ($date1 >= $date2) {
//Pass, now check if all admin fees paid
$resultPaymentSet = mysqli_query($this->conn, "SELECT sum(amount) as total FROM payments WHERE paymentDate < '" . substr($returnContractRow['subscriptionStartDate'], 0, 7) . "';", MYSQLI_STORE_RESULT);
if (mysqli_errno($this->conn) != 0) {
#Failed to run query
$xmlstr = <<<_XML_
<?xml version='1.0' standalone='yes'?>
<returnCall>
<status>Fail</status>
<msg>Failed to execute query summing of payments</msg>
<errorMsg>{$this->conn}->error<errorMsgmsg>
</returnCall>
_XML_;
return $xmlstr;
}
$returnPaymentRow = mysqli_fetch_assoc($resultPaymentSet);
if ($returnPaymentRow['total'] >= $returnContractRow['adminFeePayable']) {
//Admin fee has been fully paid
//Check that subscription amount was paid for this month
$subscriptionFee = $returnContractRow['subscriptionBalance'] / $returnContractRow['noInstalmentsBalance'];
$resultPaymentSubscriptionMonth = mysqli_query($this->conn, "SELECT sum(amount) as total FROM payments WHERE contractNo = '" . mysqli_real_escape_string($this->conn, $contractNo) . "' AND paymentDate >= '" . $checkStartDate . "' AND paymentDate <= '" . $checkDate . "';", MYSQLI_STORE_RESULT);
//$resultPaymentSubscriptionMonth = mysqli_query($this->conn, "SELECT sum(amount) as total FROM payments WHERE paymentDate <= '".substr($returnContractRow['subscriptionStartDate'],0,7)."' AND paymentDate <= '".mysqli_real_escape_string($this->conn,$checkStartDate)."';",MYSQLI_STORE_RESULT);
$returnPaymentSubscriptionMonthRow = mysqli_fetch_assoc($resultPaymentSubscriptionMonth);
$totalPaidThisMonth = $returnPaymentSubscriptionMonthRow['total'];
if ($returnPaymentSubscriptionMonthRow['total'] >= $subscriptionFee) {
//This contract has paid a figure greate or equal to their monthly subscription
$xmlstr = <<<_XML_
<?xml version='1.0' standalone='yes'?>
<returnCall>
//.........這裏部分代碼省略.........
示例15: foreach
if (!isset($params['name']) || !Validation::string()->length(null, 50)->validate($params['name'])) {
array_push($invalids, 'name');
}
if (!isset($params['phone']) || !Validation::string()->length(null, 15)->validate($params['phone'])) {
array_push($invalids, 'phone');
}
if (!isset($params['address']) || !Validation::string()->length(null, 50)->validate($params['address'])) {
array_push($invalids, 'address');
}
if (!isset($params['deliver']) || !Validation::int()->min(0, true)->max(1, true)->validate($params['deliver'])) {
array_push($invalids, 'deliver');
}
if (!isset($params['timeFrom']) || !Validation::date('H:i')->validate($params['timeFrom'])) {
array_push($invalids, 'timeFrom');
}
if (!isset($params['timeTo']) || !Validation::date('H:i')->validate($params['timeTo'])) {
array_push($invalids, 'timeTo');
}
if (!isset($params['paid']) || !Validation::int()->min(0, true)->max(1, true)->validate($params['paid'])) {
array_push($invalids, 'paid');
}
if (!isset($params['items']) || !Validation::arr()->length(1, null)->validate($params['items'])) {
array_push($invalids, 'items');
}
foreach ($params['items'] as $index => $product) {
if (!isset($product['productId']) || !Validation::int()->min(0, true)->validate($product['productId'])) {
array_push($invalids, 'productId-' . $index);
}
if (!isset($product['plu']) || !Validation::int()->max(999999)->validate($product['plu'])) {
array_push($invalids, 'plu-' . $index);
}