public function filter($value) { if ($this->format) { return SchemaFormatter::format($this->format, $value); } if ($this->type == 'boolean' && !is_bool($value)) { $value = filter_var($value, FILTER_VALIDATE_BOOLEAN); } if ($this->filters) { foreach ($this->filters as $filter) { if (is_array($filter)) { foreach ($filter['args'] as &$data) { if ($data == '@value') { $data = $value; } elseif ($data == '@api') { $data = $this; } } $value = call_user_func_array($filter['method'], $filter['args']); } else { $value = call_user_func($filter, $value); } } } return $value; }
/** * Run a value through the filters OR format attribute associated with the parameter * * @param mixed $value Value to filter * * @return mixed Returns the filtered value */ public function filter($value) { // Formats are applied exclusively and supersed filters if ($this->format) { return SchemaFormatter::format($this->format, $value); } // Convert Boolean values if ($this->type == 'boolean' && !is_bool($value)) { $value = filter_var($value, FILTER_VALIDATE_BOOLEAN); } // Apply filters to the value if ($this->filters) { foreach ($this->filters as $filter) { if (is_array($filter)) { // Convert complex filters that hold value place holders foreach ($filter['args'] as &$data) { if ($data == '@value') { $data = $value; } elseif ($data == '@api') { $data = $this; } } $value = call_user_func_array($filter['method'], $filter['args']); } else { $value = call_user_func($filter, $value); } } } return $value; }
/** * @expectedException \Guzzle\Common\Exception\InvalidArgumentException */ public function testValidatesDateTimeInput() { SchemaFormatter::format('date-time', false); }