本文整理匯總了PHP中Contract::metOrThrow方法的典型用法代碼示例。如果您正苦於以下問題:PHP Contract::metOrThrow方法的具體用法?PHP Contract::metOrThrow怎麽用?PHP Contract::metOrThrow使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Contract
的用法示例。
在下文中一共展示了Contract::metOrThrow方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: testB
public function testB()
{
$testValue1 = 100;
$testValue2 = 'red';
$testValue3 = array('name' => 'John Smith', 'age' => 30);
$contract = new Contract(array('test1' => array('data' => $testValue1, 'definition' => 'integer'), 'test2' => array('data' => $testValue2, 'definition' => array('length' => 3, 'in' => array('red', 'green', 'blue'))), 'test3' => array('data' => $testValue3, 'definition' => array('arraylist', 'element' => array('age' => array('integer', 'lessThan' => 29), 'name' => array('alpha', 'in' => array('John Doe', 'Jane Smith')))))));
$contract->metOrThrow();
}
示例2: 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;
}
示例3: 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;
}
示例4: children
public function children($data)
{
$contract = new Contract();
$contract->term('data/outer/inner')->arraylist()->element('number')->integer()->end()->element('letter')->alpha()->end();
$contract->metOrThrow();
}