Ejemplo n.º 1
0
 /**
  * @param array of string $fields
  */
 function __construct($name, DBTable $table, array $fields)
 {
     Assert::isScalar($name);
     Assert::isNotEmpty($fields, 'constraint cannot be across zero fields');
     $this->name = $name;
     $this->table = $table;
     $this->fields = $fields;
 }
 /**
  * Gets the list of imported/default values
  * @return array
  */
 function getSelectedValues()
 {
     Assert::isNotEmpty($this->ids, 'options not yet set');
     $value = $this->getValue();
     if ($value) {
         return array($value);
     } else {
         return array();
     }
 }
Ejemplo n.º 3
0
 /**
  * Perform the authorisation request
  * @return DbAuth
  */
 public function authenticate()
 {
     $credential = $this->getCredential();
     Assert::isNotEmpty($credential, "You must set a password before authentication");
     $identity = $this->getIdentity();
     Assert::isNotEmpty($identity, "You must set an username before authentication");
     //We first get user from db if its exists
     $criteria = new Criteria(Restriction::is($this->identityColumn, $identity));
     $records = TableGateway::loadMatching($this->table, $criteria);
     if ($records->count() == 0) {
         return false;
     }
     /** @var $user Customer */
     $user = $records->current();
     //Yes we need to reassign this to variable.
     $credentialColumn = $this->credentialColumn;
     $credentialSaltColumn = $this->credentialSaltColumn;
     $slatedCredentialColumn = $this->slatedCredentialColumn;
     //We check if we should use salt checking
     if (!empty($credentialSaltColumn) && !empty($slatedCredentialColumn) && !empty($user->{$credentialSaltColumn}) && !empty($user->{$slatedCredentialColumn})) {
         //Fo salt we check if password is same like credential
         $authenticated = SaltPasswordManager::checkPasswordWithHash($user->{$slatedCredentialColumn}, $user->{$credentialSaltColumn}, $this->credential);
     } else {
         //If don't have salt we must check if we have hashed password
         if ($this->hash) {
             $credential = SaltPasswordManager::generateSimpleHash($this->credential);
         } else {
             $credential = $this->credential;
         }
         //We check if we are authenticated
         $authenticated = $credential == $user->{$credentialColumn};
         /**
          * If we are authenticated and have original password, we can create and add slated password for user and
          * we should do it. It means we are not Auto Login or something.
          */
         if ($authenticated && $this->hash) {
             if (!empty($credentialSaltColumn) && !empty($slatedCredentialColumn)) {
                 list($password, $hash) = SaltPasswordManager::generateSaltedPassword($this->credential);
                 $this->addSalt($user, $password, $hash);
             }
         }
     }
     if (empty($authenticated)) {
         return false;
     }
     return $this->authorisedId = $records->current()->__get($this->identityKey);
 }
Ejemplo n.º 4
0
 /**
  * @return void
  */
 private function checkMemberIndependency(array $members)
 {
     $thrashed = array_unique($members);
     if (sizeof($thrashed) != sizeof($members)) {
         $duplicates = $this->getDuplicates($members);
         Assert::isNotEmpty($duplicates, 'core error: duplicates not found');
         Assert::isUnreachable('%s %s enumeration constants has the same value %s', join($duplicates, ', '), get_class($this), $members[reset($duplicates)]);
     }
 }
 public function getById($id, $expires = Cache::EXPIRES_MEDIUM)
 {
     Assert::isScalar($id);
     Assert::isNotEmpty($id);
     if (isset($this->identityMap[$id])) {
         return $this->identityMap[$id];
     }
     return $this->addObjectToMap(Cache::worker($this)->getById($id, $expires));
 }
 function __construct($name, $label)
 {
     Assert::isNotEmpty($label, 'label should be specified');
     parent::__construct($name, $label, $label);
 }
 /**
  * @param Model $model
  * @return string
  */
 public function toString($model = null)
 {
     Assert::isNotEmpty($this->callback, 'callback can not be empty!');
     $json = parent::toString($model);
     return $this->callback . '(' . $json . ');';
 }
 /**
  * Gets the text representastion of the requested URL
  *
  * @return string
  */
 function getSelfHref()
 {
     Assert::isNotEmpty($this->trace, 'trace is not set');
     return $this->trace->getWebContext()->getRequest()->getHttpUrl()->getUri();
 }
 protected function getTagId()
 {
     Assert::isNotEmpty($this->tagId, sprintf('Your descendant %s should call %s::__construct() to initialize the object', get_class($this), __CLASS__));
     return $this->tagId;
 }