Ejemplo n.º 1
0
Archivo: parse.php Proyecto: nob/joi
 /**
  * Recursively parses a condition (key:value), returning the key and value
  *
  * @param string  $condition  Condition to parse
  * @return array
  */
 public static function condition($condition)
 {
     // has a colon, is a comparison
     if (strstr($condition, ":") !== FALSE) {
         // breaks this into key => value
         $parts = explode(":", $condition, 2);
         $condition_array = array("key" => trim($parts[0]), "value" => Parse::conditionValue(trim($parts[1])));
         // doesn't have a colon, looking for existence (or lack thereof)
     } else {
         $condition = trim($condition);
         $condition_array = array("key" => $condition, "value" => array());
         if (substr($condition, 0, 1) === "!") {
             $condition_array['key'] = substr($condition, 1);
             $condition_array['value'] = array("kind" => "existence", "type" => "lacks");
         } else {
             $condition_array['value'] = array("kind" => "existence", "type" => "has");
         }
     }
     // return the parsed array
     return $condition_array;
 }