View ProjeQtOr On SourceForge.net
ProjeQtOr - Project Management Tool
Support us on Capterra
OIN - Open Invention Network
ProjeQtOr free project management software - Request handling - ProjeQtOr
 

Request handling

More
22 Feb 2017 11:33 #1 by antonio.grr
Request handling was created by antonio.grr
Hi.
In order to get a cleaner code and to reduce NetBeans warning I introduced the singleton in attachment.
Using it I changed code (e.g.)
$mode="";
$testCaseRunId=null;
if ( array_key_exists('testCaseRunId',$_REQUEST) ) {
$testCaseRunId=$_REQUEST;
Security::checkValidId($testCaseRunId);
$mode='edit';
} else {
$mode='add';
}
$testSessionId=0;
if ( array_key_exists('testSessionId',$_REQUEST)) {
$testSessionId=$_REQUEST;
}

Security::checkValidId($testSessionId);

in
$request = RequestHdl::istanza();
$testCaseRunId = $request->get_validated_id('testCaseRunId', null);
if ($testCaseRunId) {
$mode = 'edit';
} else {
$mode = 'add';
}
$testSessionId = $request->get_validated_id('testSessionId', 0);

File Attachment:

File Name: RequestHdl.txt
File Size:3 KB
Attachments:

Please Log in or Create an account to join the conversation.

More
27 Feb 2017 20:16 #2 by babynus
Replied by babynus on topic Request handling
Very Good idea.
Ticket #2582 recorded

(notice that community version will be soewhat different from yours, for instance because we use camelCase for naming conventions)

Babynus
Administrator of ProjeQtOr web site

Please Log in or Create an account to join the conversation.

More
18 Mar 2017 20:26 - 18 Mar 2017 21:00 #3 by babynus
Replied by babynus on topic Request handling
For information, we started implementing Request Handler, but not as singleton : it is an abstract class will all static functions.
We also use camelCase naming.
We start using is for new needs and will try and find time to replace all direct call to $_REQUEST with call to functions of this class.
Thnaks for the idea.

Here is first version :
abstract class RequestHandler {

  public static function getValue($code,$required=false,$default=null) {
    if (isset($_REQUEST[$code])) {
      return $_REQUEST[$code];
    } else {
      if ($required) {
        throwError("parameter '$code' not found in Request");
        exit;
      } else {
        return $default;
      }  
    }
  }
  
  public static function getClass($code,$required=false,$default=null) {
    $val=self::getValue($code,$required,$default);
    if ($val==$default) return $val;
    return Security::checkValidClass($val);
  }
  
  public static function getId($code,$required=false,$default=null) {
    $val=self::getValue($code,$required,$default);
    if ($val==$default) return $val;
    return Security::checkValidId($val);
  }
  
  public static function getNumeric($code,$required=false,$default=null) {
    $val=self::getValue($code,$required,$default);
    if ($val==$default) return $val;
    return Security::checkValidNumeric($val);
  }
  
  public static function getAlphanumeric($code,$required=false,$default=null) {
    $val=self::getValue($code,$required,$default);
    if ($val==$default) return $val;
    return Security::checkValidAlphanumeric($val);
  }
  
  public static function getDatetime($code,$required=false,$default=null) {
    $val=self::getValue($code,$required,$default);
    if ($val==$default) return $val;
    return Security::checkValidDateTime($val);
  }
  
  public static function getYear($code,$required=false,$default=null) {
    $val=self::getValue($code,$required,$default);
    if ($val==$default) return $val;
    return Security::checkValidYear($val);
  }
  
  public static function getMonth($code,$required=false,$default=null) {
    $val=self::getValue($code,$required,$default);
    if ($val==$default) return $val;
    return Security::checkValidMonth($val);
  }
  public static function getExpected($code,$expectedList) {
    $val=self::getValue($code,true,null);
    if (in_array($val, $expectedList)) {
      return $val;
    } else {
      throwError("parameter $code='$val' has an unexpected value");
      exit;
    }
  }
  
}

Babynus
Administrator of ProjeQtOr web site
Last edit: 18 Mar 2017 21:00 by babynus.

Please Log in or Create an account to join the conversation.

More
20 Mar 2017 08:23 #4 by antonio.grr
Replied by antonio.grr on topic Request handling
Ok. I prefer singleton, but the result is quite the same.
At the moment I have used RequestHandler in a large amount of modules; if you believe that this can help you, I can send my code to you.
Best regards.

Please Log in or Create an account to join the conversation.

More
22 Mar 2017 08:39 #5 by babynus
Replied by babynus on topic Request handling
Hi,
Thanks for your proposale.
Yes, please snd your code, I'll have a look at least and check if I can use it (or part of it).

Babynus
Administrator of ProjeQtOr web site

Please Log in or Create an account to join the conversation.

More
22 Mar 2017 11:19 #6 by antonio.grr
Replied by antonio.grr on topic Request handling
Ok,
in attachment a version of getSingleData.php based on RequestHandler class.
I had to add a method to the class
public static function isRequestSet($code) {
return isset($_REQUEST[$code]);
}

Let me know if this kind of cooperation can be useful. If so, I'll send new modules time by time.
Best regards

File Attachment:

File Name: getSingleData.zip
File Size:2 KB
Attachments:

Please Log in or Create an account to join the conversation.

Moderators: babynusprotion
Time to create page: 0.063 seconds

Cookies settings

×

Functional Cookies

Ce site utilise des cookies pour assurer son bon fonctionnement et ne peuvent pas être désactivés de nos systèmes. Nous ne les utilisons pas à des fins publicitaires. Si ces cookies sont bloqués, certaines parties du site ne pourront pas fonctionner.

Session

Please login to see yours activities!

Other cookies

Ce site web utilise un certain nombre de cookies pour gérer, par exemple, les sessions utilisateurs.