本文整理汇总了PHP中Contract::term方法的典型用法代码示例。如果您正苦于以下问题:PHP Contract::term方法的具体用法?PHP Contract::term怎么用?PHP Contract::term使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Contract
的用法示例。
在下文中一共展示了Contract::term方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: filterByValidUser
public function filterByValidUser($usersData)
{
/* Before filtering the data, establish the agreement for the method parameters. */
$contract = new Contract();
$contract->term('usersData')->arraylist();
$contract->metOrThrow();
/* Users data must be an array of elements, each element an array itself, with an id, name, registered date, and active boolean true.
Allowed fields to be returned are the defined elements: id, name, registered, active. */
$contract->term('usersData')->elements()->arraylist()->element('id')->id()->end()->element('name')->optional()->alpha()->end()->element('registered')->datetime()->end()->element('active')->boolean()->equals(true)->end();
$filteredData = $contract->term('usersData')->data();
return $filteredData;
}
示例2: createUser
public function createUser($userId, $userData)
{
/* Define Contract Requirements for Model Data */
$contract = new Contract();
$contract->term('userId')->id();
$contract->term('userData')->arraylist()->element('type')->in(array('member', 'administrator'))->end()->element('username')->alphaNumeric()->length(8, 16)->end()->element('name')->required()->end()->element('address')->required()->end()->element('city')->required()->end()->element('state')->length(2)->end()->element('zip')->length(5, 10)->end()->element('country')->required()->end()->element('email')->email()->end()->element('phone')->phone()->end()->element('fax')->optional()->phone()->end()->element('photo')->optional()->file()->end()->element('website')->optional()->url()->end()->element('registered')->datetime()->end()->element('active')->boolean()->end();
$contract->metOrThrow();
/* Follow w/ Basic MySQL Query */
$rows = array();
/* $select = "SELECT * FROM user WHERE id = {$userId}";
while($row = mysql_query($select)) $rows[] = $row; */
return $rows;
}
示例3: login
public function login()
{
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
/* Hypothetical Data */
$loginUserEmail = $_REQUEST['email'];
$loginUserPass = $_REQUEST['pass'];
$loginUserIp = $_SERVER['REMOTE_ADDR'];
$loginDateTime = date('Y-m-d H:i:s');
try {
$contract = new Contract();
$contract->term('userEmail', $loginUserEmail)->email()->metOrThrow();
$contract->term('userPass', $loginUserPass)->alphaNumeric()->length(8, 16)->metOrThrow();
$contract->term('userIp', $loginUserPass)->ip()->metOrThrow();
$contract->term('dateTime', $loginDateTime)->datetime()->metOrThrow();
/* Get User For Login */
$user = $userModel->getUser($userEmail, $userPass);
$contract->term('user', $user)->arraylist()->element('id')->id()->end()->element('active')->equals(1)->end()->metOrThrow();
$loginUserId = $user['id'];
/* Proceed Safely to Model for Storage of User Login */
$logged = $userModel->login($loginUserId, $loginUserIp, $loginDateTime);
$contract->term('userLogged', $logged)->boolean()->equals(TRUE)->metOrThrow();
} catch (Contract_Exception $e) {
/* Collect error messages from contract exception */
$messages = array();
switch ($e->term) {
case 'userEmail':
$messages[] = 'Please enter an email address.';
break;
case 'userPass':
$messages[] = 'Please enter a password.';
break;
case 'userIp':
$messages[] = 'Please enter a valid ip address.';
break;
case 'dateTime':
$messages[] = 'Please enter a valid date time.';
break;
case 'user':
$messages[] = 'Please enter a valid user.';
break;
case 'userLogged':
$messages[] = 'Sorry. You could not be logged in.';
break;
default:
$messages[] = 'We do not get it either!';
break;
}
}
}
}
示例4: parents
public function parents($data)
{
$contract = new Contract();
$contract->term('data')->arraylist()->element('outer')->arraylist()->element('inner')->arraylist()->element('number')->integer()->parent()->element('letter')->alpha()->parent('outer')->element('inner2')->arraylist()->element('email')->email()->parent(TRUE)->metOrThrow();
}