コード例 #1
0
 public function buildPredicateAttribute(array $predicateAttribute)
 {
     if ($this->_slicePredicateType === self::TYPE_COLUMNS) {
         $this->slice_range = NULL;
         if (empty($predicateAttribute)) {
             // Warn that there's no point in building an empty predicate
             PandraLog::warning('Empty Predicate : an empty result set will be returned');
         }
         $this->column_names = $predicateAttribute;
     } elseif ($this->_slicePredicateType === self::TYPE_RANGE) {
         $this->column_names = NULL;
         $this->slice_range = new cassandra_SliceRange(array('start' => '', 'finish' => '', 'reversed' => false, 'count' => DEFAULT_ROW_LIMIT));
         foreach ($predicateAttribute as $key => $value) {
             if (isset($this->slice_range->{$key})) {
                 $this->slice_range->{$key} = $value;
             }
         }
     } else {
         $msg = 'Unsupported Predicate Type';
         PandraLog::crit($msg);
         throw new RuntimeException($msg);
     }
 }
コード例 #2
0
ファイル: Query.class.php プロジェクト: jlaprise/Pandra
 public function memcached()
 {
     if (!PandraCore::getMemcachedvailable()) {
         PandraLog::warn('Memcached Unavailable');
     } else {
         $this->_cacheScheme = self::CACHE_MEM;
     }
     return $this;
 }
コード例 #3
0
ファイル: Validator.class.php プロジェクト: jlaprise/Pandra
 /**
  * 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);
 }
コード例 #4
0
ファイル: Core.class.php プロジェクト: ruflin/Pandra
 /**
  * Adds an error message to Core's running log, and sends the message to any registered loggers
  * @param string $errorMsg Error Message
  * @param int $priority error priority level (PandraLog::LOG_)
  */
 public static function registerError($errorMsg, $priority = PandraLog::LOG_WARNING)
 {
     $message = '(PandraCore) ' . $errorMsg;
     PandraLog::logPriorityMessage($priority, $message);
     self::$lastError = $errorMsg;
 }