本文整理汇总了PHP中Valid::regex方法的典型用法代码示例。如果您正苦于以下问题:PHP Valid::regex方法的具体用法?PHP Valid::regex怎么用?PHP Valid::regex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Valid
的用法示例。
在下文中一共展示了Valid::regex方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: convert_to_jpeg
/**
* Конвертация изображений с разным расширением в jpeg
*
* @param string $source
* @param string $target_directory
* @param integer $quality
* @param boolean $remove_source_image
* @return boolean
* @throws Kohana_Exception
*/
public static function convert_to_jpeg($source, $target_directory = NULL, $quality = 100, $remove_source_image = FALSE)
{
if (!file_exists($source)) {
return FALSE;
}
$ext = pathinfo($source, PATHINFO_EXTENSION);
$filename = pathinfo($source, PATHINFO_FILENAME);
if ($target_directory !== NULL) {
if (!is_dir($target_directory) and is_writable($target_directory)) {
mkdir($target_directory, 0777);
}
} else {
$target_directory = pathinfo($source, PATHINFO_DIRNAME);
}
if (!is_writable($target_directory)) {
throw new Kohana_Exception('Unable to write to the target directory :resource', array(':resource' => $target_directory));
}
if (Valid::regex($ext, '/jpg|jpeg/i')) {
$image_tmp = imagecreatefromjpeg($source);
} else {
if (Valid::regex($ext, '/png/i')) {
$image_tmp = imagecreatefrompng($source);
} else {
if (Valid::regex($ext, '/gif/i')) {
$image_tmp = imagecreatefromgif($source);
} else {
if (Valid::regex($ext, '/bmp/i')) {
$image_tmp = imagecreatefrombmp($source);
} else {
return FALSE;
}
}
}
}
// quality is a value from 0 (worst) to 100 (best)
imagejpeg($image_tmp, $dirname . $filename . '.jpg', $quality);
imagedestroy($image_tmp);
if ($remove_source_image === TRUE) {
unlink($source);
}
return TRUE;
}
示例2: test_regex
/**
* Tests Valid::range()
*
* Tests if a number is within a range.
*
* @test
* @dataProvider provider_regex
* @param string Value to test against
* @param string Valid pcre regular expression
* @param bool Does the value match the expression?
*/
public function test_regex($value, $regex, $expected)
{
$this->AssertSame($expected, Valid::regex($value, $regex));
}
示例3: rest_output
/**
* Handling of output data set in action methods with $this->rest_output($data).
*
* @param array|object $data
* @param int $code
*/
protected function rest_output($data = array(), $code = 200)
{
// Handle an empty and valid response.
if (empty($data) && 200 == $code) {
$data = array('code' => 404, 'error' => 'No records found');
$code = 404;
}
if ($this->_suppress_response_codes) {
$this->response->status(200);
$data['responseCode'] = $code;
} else {
$this->response->status($code);
}
$mime = File::mime_by_ext($this->output_format);
$format_method = '_format_' . $this->output_format;
// If the format method exists, call and return the output in that format
if (method_exists($this, $format_method)) {
$output_data = $this->{$format_method}($data);
$this->response->headers('content-type', File::mime_by_ext($this->output_format));
$this->response->headers('content-length', (string) strlen($output_data));
// Support attachment header
if (isset($this->_params['attachment']) && Valid::regex($this->_params['attachment'], '/^[-\\pL\\pN_, ]++$/uD')) {
$this->response->headers('content-disposition', 'attachment; filename=' . $this->_params['attachment'] . '.' . $this->output_format);
}
$this->response->body($output_data);
} else {
// Report an error.
$this->response->status(500);
throw new Kohana_Exception('Unknown format method requested');
}
}