Example #1
0
 function get($url, $parameters = array())
 {
     if (!empty($parameters)) {
         $url .= StringMethods::indexOf($url, "?") ? "&" : "?";
         $url .= is_string($parameters) ? $parameters : http_build_query($parameters, "", "&");
     }
     return $this->request("GET", $url);
 }
Example #2
0
 protected function _partial($tree, $content)
 {
     $address = trim($tree["raw"], " /");
     if (StringMethods::indexOf($address, "http") != 0) {
         $host = RequestMethods::server("HTTP_HOST");
         $address = "http://{$host}/{$address}";
     }
     $request = new Request();
     $response = addslashes(trim($request->get($address)));
     return "\$_text[] = \"{$response}\";";
 }
Example #3
0
 /**
  * Optimize set string from a template for final function
  * Store data for sharing by any parsed templates
  * @param array $key    Node from the template tree
  * @param mixed $value  Value to be stored
  */
 public function set($key, $value)
 {
     if (StringMethods::indexOf($value, "\$_text") > -1) {
         $first = StringMethods::indexOf($value, "\"");
         $last = StringMethods::lastIndexOf($value, "\"");
         $value = stripslashes(substr($value, $first + 1, $last - $first - 1));
     }
     if (is_array($key)) {
         $key = $this->_getKey($key);
     }
     $this->_setValue($key, $value);
 }
Example #4
0
 /**
  * Evaluates a $source string to determine if it matches a tag or statement.
  * @param type $source
  * @return type
  */
 public function match($source)
 {
     $type = null;
     $delimiter = null;
     foreach ($this->_map as $_delimiter => $_type) {
         if (!$delimiter || StringMethods::indexOf($source, $type["opener"]) == -1) {
             $delimiter = $_delimiter;
             $type = $_type;
         }
         $indexOf = StringMethods::indexOf($source, $_type["opener"]);
         if ($indexOf > -1) {
             if (StringMethods::indexOf($source, $type["opener"]) > $indexOf) {
                 $delimiter = $_delimiter;
                 $type = $_type;
             }
         }
     }
     if ($type == null) {
         return null;
     }
     return array("type" => $type, "delimiter" => $delimiter);
 }
Example #5
0
 /**
  * Begins by getting a list of columns and iterating over that list. For each column, we determine whether validation should occur.
  * We then split the @validate metadata into a list of validation conditions. If a condition has arguments, we extract the arguments.
  * We then run each validation method on the column data and generate error messages for those validation conditions that failed.
  * 
  * @return type
  * @throws Exception\Validation
  */
 public function validate()
 {
     $this->_errors = array();
     foreach ($this->columns as $column) {
         if ($column["validate"]) {
             $pattern = "#[a-z]+\\(([a-zA-Z0-9, ]+)\\)#";
             $raw = $column["raw"];
             $name = $column["name"];
             $validators = $column["validate"];
             $label = $column["label"];
             $defined = $this->getValidators();
             foreach ($validators as $validator) {
                 $function = $validator;
                 $arguments = array($this->{$raw});
                 $match = StringMethods::match($validator, $pattern);
                 if (count($match) > 0) {
                     $matches = StringMethods::split($match[0], ",\\s*");
                     $arguments = array_merge($arguments, $matches);
                     $offset = StringMethods::indexOf($validator, "(");
                     $function = substr($validator, 0, $offset);
                 }
                 if (!isset($defined[$function])) {
                     throw new Exception\Validation("The {$function} validator is not defined");
                 }
                 $template = $defined[$function];
                 if (!call_user_func_array(array($this, $template["handler"]), $arguments)) {
                     $replacements = array_merge(array($label ? $label : $raw), $arguments);
                     $message = $template["message"];
                     foreach ($replacements as $i => $replacement) {
                         $message = str_replace("{{$i}}", $replacement, $message);
                     }
                     if (!isset($this->_errors[$name])) {
                         $this->_errors[$name] = array();
                     }
                     $this->_errors[$name][] = $message;
                 }
             }
         }
     }
     return !sizeof($this->errors);
 }