当前位置: 首页>>代码示例>>PHP>>正文


PHP Contract::term方法代码示例

本文整理汇总了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;
 }
开发者ID:jeisc,项目名称:PHP-Contract,代码行数:12,代码来源:Filter.php

示例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;
 }
开发者ID:jeisc,项目名称:PHP-Contract,代码行数:13,代码来源:Model.php

示例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;
             }
         }
     }
 }
开发者ID:jeisc,项目名称:PHP-Contract,代码行数:50,代码来源:Controller.php

示例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();
 }
开发者ID:jeisc,项目名称:PHP-Contract,代码行数:5,代码来源:Find.php


注:本文中的Contract::term方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。