Пример #1
0
 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
0
 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
0
 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
0
 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();
 }