예제 #1
0
 private static function _run($val, $type, $default = NULL)
 {
     $data = '';
     if (FALSE === request::isEmpty($val)) {
         switch (trim($type)) {
             case 'email':
                 $data = self::email($val);
                 break;
             case 'url':
                 $data = self::url($val);
                 break;
             case 'int':
                 $data = self::int($val);
                 break;
             case 'float':
                 $data = self::float($val);
                 break;
             case 'boolean':
                 $data = self::boolean($val);
                 break;
             case 'raw':
                 $data = self::raw($val);
                 break;
             default:
                 //error
                 $caller = debug_backtrace()[3];
                 trigger_error("Undefined method: " . $type . " in " . $caller['file'] . ' on line ' . $caller['line'] . ' and defined ', E_USER_NOTICE);
                 return;
                 break;
         }
     }
     if (TRUE === request::isEmpty($data)) {
         if (gettype($default) == "object" && $default instanceof \Closure) {
             $data = $default($val);
         } else {
             $data = $default;
         }
     }
     $return = '';
     if (FALSE === request::isEmpty($data)) {
         switch ($type) {
             case 'email':
                 $return = self::email($data);
                 break;
             case 'url':
                 $return = self::url($data);
                 break;
             case 'int':
                 $return = self::int($data);
                 break;
             case 'float':
                 $return = self::float($data);
                 break;
             case 'boolean':
                 $return = self::boolean($data);
                 break;
         }
     }
     return $return;
 }
예제 #2
0
 public function __construct($routes)
 {
     $this->routes = $routes;
     $this->pathinfo = \limepie\request::getPathinfo();
     $this->segments = \limepie\request::getSegments();
     // set request segment
     request::addData("segment", $this->segments);
 }
예제 #3
0
 private static function _run($val, $type, $default = NULL)
 {
     $data = '';
     if (FALSE === request::isEmpty($val)) {
         switch (trim($type)) {
             case 'email':
                 $data = self::email($val);
                 break;
             case 'url':
                 $data = self::url($val);
                 break;
             case 'int':
                 $data = self::int($val);
                 break;
             case 'float':
                 $data = self::float($val);
                 break;
             case 'string':
                 $data = self::string($val);
                 break;
             case 'boolean':
                 $data = self::boolean($val);
                 break;
             case 'htmlentities':
                 $data = self::htmlentities($val);
                 break;
             case 'htmlescape':
                 $data = self::htmlescape($val);
                 break;
             case 'raw':
                 $data = self::raw($val);
                 break;
             default:
                 //error
                 $caller = debug_backtrace()[3];
                 trigger_error("Undefined method: " . $type . " in " . $caller['file'] . ' on line ' . $caller['line'] . ' and defined ', E_USER_NOTICE);
                 return;
                 break;
         }
     }
     if (TRUE === request::isEmpty($data)) {
         if (gettype($default) == "object" && $default instanceof \Closure) {
             $data = $default($val);
         } else {
             $data = $default;
         }
     }
     $valid = TRUE;
     if (FALSE === request::isEmpty($data)) {
         switch ($type) {
             case 'email':
                 $valid = validate::email($data);
                 break;
             case 'url':
                 $valid = validate::url($data);
                 break;
             case 'int':
                 $valid = validate::int($data);
                 break;
             case 'float':
                 $valid = validate::float($data);
                 break;
             default:
                 $valid = $data;
                 break;
         }
     }
     if (TRUE === is_null($data) || FALSE === request::isEmpty($valid)) {
         return $data;
     } else {
         $caller = debug_backtrace()[4];
         if (TRUE === is_null($default)) {
             trigger_error("Argument 1 passed to " . $type . " or NULL must be an instance of " . $caller['function'] . ", " . gettype($data) . " given, called in " . $caller['file'] . ' on line ' . $caller['line'] . '' . ' and defined ', E_USER_NOTICE);
         } else {
             trigger_error("Argument 3 passed to " . $type . " or NULL must be an instance of " . $caller['function'] . ", " . gettype($data) . " given, called in " . $caller['file'] . ' on line ' . $caller['line'] . '' . ' and defined ', E_USER_NOTICE);
         }
     }
 }
예제 #4
0
    return $this->optional($value) || preg_match('/^\\d+$/', $value);
});
validator::addMethod('alpha', function ($name, $value, $param) {
    return $this->optional($value) || preg_match('#^[a-z]+$#', $value);
});
validator::addMethod('remote', function ($name, $value, $param) {
    if ($this->optional($value)) {
        return TRUE;
    }
    if (!$value) {
        return FALSE;
    }
    if (preg_match('#^http#i', $param)) {
        $domain = $param;
    } else {
        $domain = \limepie\request::currentDomain() . $param;
    }
    $domain .= '?' . $name . '=' . $value . '&test=7';
    $getHttp = function ($url, $params = []) {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
        curl_setopt($ch, CURLOPT_HEADER, FALSE);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
        curl_setopt($ch, CURLOPT_TIMEOUT, 5);
        if ($params) {
            $postData = http_build_query($params);
            curl_setopt($ch, CURLOPT_POST, count($postData));
            curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
        }
        $output = curl_exec($ch);