Esempio n. 1
0
 public function extract($popType = self::POPULATE_MODEL)
 {
     // Check we have everything
     if ($this->pathOK()) {
         $result = NULL;
         // Cache hit?
         if ($this->cacheRetrieve($result)) {
             return $this->hydrate($popType, $result);
         }
         // Graph Processing
         PandraLog::debug('processing graph');
         if (!empty($this->_graph[self::CONTEXT_SUPERCOLUMN])) {
         }
         $preResult = PandraCore::getCFSliceMulti($this->_keySpace, $this->_keys, $this->_columnFamily);
         //public function getCFSliceMulti($keySpace, array $keyIDs, $columnFamilyName, $superColumnName = NULL, $columnNames = array(), $consistencyLevel = NULL) {
         // We've got a basic result set, so filter out what we don't want
         // Cache and populate
         if ($result !== NULL) {
             $this->cacheStore($result);
             return $this->hydrate($popType, $result);
         }
     } else {
         throw new RuntimeException('Missing Keys, Keyspace or ColumnFamily');
     }
     return NULL;
 }
Esempio n. 2
0
 /**
  * Validates a field
  * @param string $errorMsg custom error message for field validation error
  * @return bool field validated correctly
  */
 public static function check($value, $label, $typeDefs, &$errors)
 {
     if (empty($typeDefs)) {
         return TRUE;
     }
     if (!is_array($typeDefs)) {
         $typeDefs = array($typeDefs);
     }
     // normalise to real type defs if complex types found
     self::typeExpander($typeDefs);
     $error = FALSE;
     $errorMsg = array();
     foreach ($typeDefs as $type) {
         if (preg_match('/=/', $type)) {
             list($type, $args) = explode("=", $type);
         }
         if (!in_array($type, self::$primitive)) {
             throw new RuntimeException("undefined type definition ({$type})");
         }
         // check for basic validator types
         switch ($type) {
             case 'notempty':
                 $error = empty($value);
                 if ($error) {
                     $errorMsg[] = "Field cannot be empty";
                 }
                 break;
             case 'isempty':
                 // NULL is never allowed, just empty strings
                 $error = $value != '';
                 if ($error) {
                     $errorMsg[] = "Field must be empty";
                 }
                 break;
             case 'email':
                 $error = !filter_var($value, FILTER_VALIDATE_EMAIL);
                 if ($error) {
                     $errorMsg[] = "Invalid email address";
                 }
                 break;
             case 'url':
                 $error = !filter_var($value, FILTER_VALIDATE_URL);
                 if ($error) {
                     $errorMsg[] = "Invalid URL";
                 }
                 break;
             case 'int':
             case 'float':
             case 'numeric':
                 $error = !is_numeric($value);
                 if ($error) {
                     $errorMsg[] = "Field error, expected " . $type;
                 }
                 break;
             case 'string':
                 $error = !is_string($value);
                 if ($error) {
                     $errorMsg[] = "Field error, expected " . $type;
                 }
                 break;
             case 'bool':
                 $val = strtolower($value);
                 $boolVals = array('true', 'false', 't', 'f', '1', '0', 'y', 'n');
                 $error = !is_bool($value) && !in_array($val, $boolVals);
                 if ($error) {
                     $errorMsg[] = "Field error, expected " . $type;
                 }
                 break;
             case 'maxlength':
                 if (empty($args)) {
                     throw new RuntimeException("type {$type} requires argument");
                 }
                 $error = strlen($value) > $args;
                 if ($error) {
                     $errorMsg[] = "Maximum length {$args} exceeded";
                 }
                 break;
             case 'minlength':
                 if (empty($args)) {
                     throw new RuntimeException("type {$type} requires argument");
                 }
                 $error = strlen($value) < $args;
                 if ($error) {
                     $errorMsg[] = "Minimum length {$args} unmet";
                 }
                 break;
             case 'enum':
                 if (empty($args)) {
                     throw new RuntimeException("type {$type} requires argument");
                 }
                 $enums = explode(",", $args);
                 $error = !in_array($value, $enums);
                 if ($error) {
                     $errorMsg[] = "Invalid Argument";
                 }
                 break;
             default:
                 throw new RuntimeException("Unhandled type definition ({$type}) or unexpected end of case");
                 break;
         }
     }
     if (!empty($errorMsg)) {
         $errors[] = array($label => $errorMsg);
         PandraLog::debug(array($label => $errorMsg));
     }
     return empty($errorMsg);
 }