예제 #1
0
 public final function __construct($value)
 {
     $self = new \ReflectionClass($this);
     if (!in_array($value, $self->getConstants())) {
         throw \IllegalArgumentException();
     }
     $this->value = $value;
 }
 public function getFullPath($rootPath, array $options, $tableName)
 {
     $path = $rootPath;
     $options = array_merge($this->options, $options);
     foreach ($options as $key => $value) {
         $pathSegment = $key . $value;
         if (!preg_match('@^[a-zA-Z0-9.]*$@', $pathSegment)) {
             throw IllegalArgumentException();
         }
         $path .= '/' . $pathSegment;
     }
     if (!preg_match('@^[a-zA-Z0-9.]*$@', $tableName)) {
         throw IllegalArgumentException();
     }
     return $path .= '/' . $tableName . '.dat';
 }
 public function getFullPath(array $options, $tableName)
 {
     Preconditions::checkIsString($tableName);
     Preconditions::check($tableName != '', "Table name must be non-empty");
     $path = '';
     $options = array_merge($this->options, $options);
     foreach ($options as $key => $value) {
         $pathSegment = $key . $value;
         if (!preg_match(self::ALLOWED_CHARS_REGEX, $pathSegment)) {
             throw IllegalArgumentException('Invalid characters in options');
         }
         $path .= '/' . $pathSegment;
     }
     if (!preg_match(self::ALLOWED_CHARS_REGEX, $tableName)) {
         throw IllegalArgumentException('Invalid characters in tableName');
     }
     return $path .= '/' . $tableName;
 }
예제 #4
0
 public function setGender($gender, $user)
 {
     if ($gender != 'male' && $gender != 'female' && $gender != 'both') {
         throw IllegalArgumentException('Invalid gender.');
     }
     // If no user, don't do anything.
     if ($user == null || trim($user) == '') {
         return;
     }
     $sql = "SELECT * FROM users WHERE case_id = :user";
     $query = $this->db->prepare($sql);
     $parameters = array(':user' => $user);
     $query->execute($parameters);
     $result = $query->fetch();
     if ($result == false) {
         $sql = "INSERT INTO users (case_id, joined) VALUES (:user, CURRENT_TIMESTAMP)";
         $query = $this->db->prepare($sql);
         $parameters = array(':user' => $user);
         $query->execute($parameters);
     } else {
         $sql = "UPDATE users SET gender = :gender WHERE case_id = :user";
         $query = $this->db->prepare($sql);
         $parameters = array(':gender' => $gender, ':user' => $user);
         //echo '[ PDO DEBUG ]: ' . Helper::debugPDO($sql, $parameters);  exit();
         $query->execute($parameters);
     }
 }