@@ -238,6 +238,9 @@ |
||
| 238 | 238 | |
| 239 | 239 | } |
| 240 | 240 | |
| 241 | + /** |
|
| 242 | + * @return string |
|
| 243 | + */ |
|
| 241 | 244 | protected function getImagePath( $value ) |
| 242 | 245 | { |
| 243 | 246 | |
@@ -28,17 +28,17 @@ discard block |
||
| 28 | 28 | public function validateImageSize($attribute, $value, $parameters) |
| 29 | 29 | { |
| 30 | 30 | |
| 31 | - $image = $this->getImagePath( $value ); |
|
| 31 | + $image = $this->getImagePath($value); |
|
| 32 | 32 | |
| 33 | 33 | // Get the image dimension info, or fail. |
| 34 | 34 | |
| 35 | - $image_size = @getimagesize( $image ); |
|
| 35 | + $image_size = @getimagesize($image); |
|
| 36 | 36 | if ($image_size===false) return false; |
| 37 | 37 | |
| 38 | 38 | |
| 39 | 39 | // If only one dimension rule is passed, assume it applies to both height and width. |
| 40 | 40 | |
| 41 | - if ( !isset($parameters[1]) ) |
|
| 41 | + if (!isset($parameters[1])) |
|
| 42 | 42 | { |
| 43 | 43 | $parameters[1] = $parameters[0]; |
| 44 | 44 | } |
@@ -51,8 +51,8 @@ discard block |
||
| 51 | 51 | // ">300" - dimension must be greater than 300 pixels |
| 52 | 52 | // ">=300" - dimension must be greater than or equal to 300 pixels |
| 53 | 53 | |
| 54 | - $width_check = $this->checkDimension( $parameters[0], $image_size[0] ); |
|
| 55 | - $height_check = $this->checkDimension( $parameters[1], $image_size[1] ); |
|
| 54 | + $width_check = $this->checkDimension($parameters[0], $image_size[0]); |
|
| 55 | + $height_check = $this->checkDimension($parameters[1], $image_size[1]); |
|
| 56 | 56 | |
| 57 | 57 | return $width_check['pass'] && $height_check['pass']; |
| 58 | 58 | |
@@ -70,15 +70,15 @@ discard block |
||
| 70 | 70 | public function replaceImageSize($message, $attribute, $rule, $parameters) |
| 71 | 71 | { |
| 72 | 72 | |
| 73 | - $width = $height = $this->checkDimension( $parameters[0] ); |
|
| 74 | - if ( isset($parameters[1]) ) |
|
| 73 | + $width = $height = $this->checkDimension($parameters[0]); |
|
| 74 | + if (isset($parameters[1])) |
|
| 75 | 75 | { |
| 76 | - $height = $this->checkDimension( $parameters[1] ); |
|
| 76 | + $height = $this->checkDimension($parameters[1]); |
|
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | return str_replace( |
| 80 | - array( ':width', ':height' ), |
|
| 81 | - array( $width['message'], $height['message'] ), |
|
| 80 | + array(':width', ':height'), |
|
| 81 | + array($width['message'], $height['message']), |
|
| 82 | 82 | $message |
| 83 | 83 | ); |
| 84 | 84 | |
@@ -95,11 +95,11 @@ discard block |
||
| 95 | 95 | public function validateImageAspect($attribute, $value, $parameters) |
| 96 | 96 | { |
| 97 | 97 | |
| 98 | - $image = $this->getImagePath( $value ); |
|
| 98 | + $image = $this->getImagePath($value); |
|
| 99 | 99 | |
| 100 | 100 | // Get the image dimension info, or fail. |
| 101 | 101 | |
| 102 | - $image_size = @getimagesize( $image ); |
|
| 102 | + $image_size = @getimagesize($image); |
|
| 103 | 103 | if ($image_size===false) return false; |
| 104 | 104 | |
| 105 | 105 | $image_width = $image_size[0]; |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | |
| 118 | 118 | $both_orientations = false; |
| 119 | 119 | |
| 120 | - if (substr($parameters[0],0,1)=='~') |
|
| 120 | + if (substr($parameters[0], 0, 1)=='~') |
|
| 121 | 121 | { |
| 122 | 122 | $parameters[0] = substr($parameters[0], 1); |
| 123 | 123 | $both_orientations = true; |
@@ -134,19 +134,19 @@ discard block |
||
| 134 | 134 | |
| 135 | 135 | if ($aspect_width==0 || $aspect_height==0) |
| 136 | 136 | { |
| 137 | - throw new \RuntimeException('Aspect is zero or infinite: ' . $parameters[0] ); |
|
| 137 | + throw new \RuntimeException('Aspect is zero or infinite: ' . $parameters[0]); |
|
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | $check = ($image_width * $aspect_height) / $aspect_width; |
| 141 | 141 | |
| 142 | - if (round($check) == $image_height) |
|
| 142 | + if (round($check)==$image_height) |
|
| 143 | 143 | { |
| 144 | 144 | return true; |
| 145 | 145 | } |
| 146 | 146 | |
| 147 | - if ( $both_orientations ) { |
|
| 147 | + if ($both_orientations) { |
|
| 148 | 148 | $check = ($image_width * $aspect_width) / $aspect_height; |
| 149 | - if (round($check) == $image_height) |
|
| 149 | + if (round($check)==$image_height) |
|
| 150 | 150 | { |
| 151 | 151 | return true; |
| 152 | 152 | } |
@@ -168,7 +168,7 @@ discard block |
||
| 168 | 168 | */ |
| 169 | 169 | public function replaceImageAspect($message, $attribute, $rule, $parameters) |
| 170 | 170 | { |
| 171 | - return str_replace( ':aspect', join(':', $parameters), $message ); |
|
| 171 | + return str_replace(':aspect', join(':', $parameters), $message); |
|
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | |
@@ -179,24 +179,24 @@ discard block |
||
| 179 | 179 | * @param integer $dimension |
| 180 | 180 | * @return array |
| 181 | 181 | */ |
| 182 | - protected function checkDimension($rule, $dimension=0) |
|
| 182 | + protected function checkDimension($rule, $dimension = 0) |
|
| 183 | 183 | { |
| 184 | 184 | |
| 185 | 185 | $dimension = intval($dimension); |
| 186 | 186 | |
| 187 | - if ($rule == '*') |
|
| 187 | + if ($rule=='*') |
|
| 188 | 188 | { |
| 189 | 189 | $message = $this->translator->trans('image-validator::validation.anysize'); |
| 190 | 190 | $pass = true; |
| 191 | 191 | } |
| 192 | - else if ( preg_match('/^(\d+)\-(\d+)$/', $rule, $matches) ) |
|
| 192 | + else if (preg_match('/^(\d+)\-(\d+)$/', $rule, $matches)) |
|
| 193 | 193 | { |
| 194 | 194 | $size1 = intval($matches[1]); |
| 195 | 195 | $size2 = intval($matches[2]); |
| 196 | - $message = $this->translator->trans('image-validator::validation.between', compact('size1','size2')); |
|
| 196 | + $message = $this->translator->trans('image-validator::validation.between', compact('size1', 'size2')); |
|
| 197 | 197 | $pass = ($dimension >= $size1) && ($dimension <= $size2); |
| 198 | 198 | } |
| 199 | - else if ( preg_match('/^([<=>]*)(\d+)$/', $rule, $matches) ) |
|
| 199 | + else if (preg_match('/^([<=>]*)(\d+)$/', $rule, $matches)) |
|
| 200 | 200 | { |
| 201 | 201 | |
| 202 | 202 | $size = intval($matches[2]); |
@@ -222,33 +222,33 @@ discard block |
||
| 222 | 222 | case '=': |
| 223 | 223 | case '': |
| 224 | 224 | $message = $this->translator->trans('image-validator::validation.equal', compact('size')); |
| 225 | - $pass = $dimension == $size; |
|
| 225 | + $pass = $dimension==$size; |
|
| 226 | 226 | break; |
| 227 | 227 | default: |
| 228 | - throw new \RuntimeException('Unknown image size validation rule: ' . $rule ); |
|
| 228 | + throw new \RuntimeException('Unknown image size validation rule: ' . $rule); |
|
| 229 | 229 | } |
| 230 | 230 | |
| 231 | 231 | } |
| 232 | 232 | else |
| 233 | 233 | { |
| 234 | - throw new \RuntimeException('Unknown image size validation rule: ' . $rule ); |
|
| 234 | + throw new \RuntimeException('Unknown image size validation rule: ' . $rule); |
|
| 235 | 235 | } |
| 236 | 236 | |
| 237 | - return compact('message','pass'); |
|
| 237 | + return compact('message', 'pass'); |
|
| 238 | 238 | |
| 239 | 239 | } |
| 240 | 240 | |
| 241 | - protected function getImagePath( $value ) |
|
| 241 | + protected function getImagePath($value) |
|
| 242 | 242 | { |
| 243 | 243 | |
| 244 | 244 | // if were passed an instance of UploadedFile, return the path |
| 245 | - if ( $value instanceof UploadedFile ) |
|
| 245 | + if ($value instanceof UploadedFile) |
|
| 246 | 246 | { |
| 247 | 247 | return $value->getPathname(); |
| 248 | 248 | } |
| 249 | 249 | |
| 250 | 250 | // if we're passed a PHP file upload array, return the "tmp_name" |
| 251 | - if ( is_array($value) && array_get($value, 'tmp_name') !== null) { |
|
| 251 | + if (is_array($value) && array_get($value, 'tmp_name')!==null) { |
|
| 252 | 252 | return $value['tmp_name']; |
| 253 | 253 | } |
| 254 | 254 | |
@@ -33,7 +33,9 @@ discard block |
||
| 33 | 33 | // Get the image dimension info, or fail. |
| 34 | 34 | |
| 35 | 35 | $image_size = @getimagesize( $image ); |
| 36 | - if ($image_size===false) return false; |
|
| 36 | + if ($image_size===false) { |
|
| 37 | + return false; |
|
| 38 | + } |
|
| 37 | 39 | |
| 38 | 40 | |
| 39 | 41 | // If only one dimension rule is passed, assume it applies to both height and width. |
@@ -100,7 +102,9 @@ discard block |
||
| 100 | 102 | // Get the image dimension info, or fail. |
| 101 | 103 | |
| 102 | 104 | $image_size = @getimagesize( $image ); |
| 103 | - if ($image_size===false) return false; |
|
| 105 | + if ($image_size===false) { |
|
| 106 | + return false; |
|
| 107 | + } |
|
| 104 | 108 | |
| 105 | 109 | $image_width = $image_size[0]; |
| 106 | 110 | $image_height = $image_size[1]; |
@@ -188,15 +192,13 @@ discard block |
||
| 188 | 192 | { |
| 189 | 193 | $message = $this->translator->trans('image-validator::validation.anysize'); |
| 190 | 194 | $pass = true; |
| 191 | - } |
|
| 192 | - else if ( preg_match('/^(\d+)\-(\d+)$/', $rule, $matches) ) |
|
| 195 | + } else if ( preg_match('/^(\d+)\-(\d+)$/', $rule, $matches) ) |
|
| 193 | 196 | { |
| 194 | 197 | $size1 = intval($matches[1]); |
| 195 | 198 | $size2 = intval($matches[2]); |
| 196 | 199 | $message = $this->translator->trans('image-validator::validation.between', compact('size1','size2')); |
| 197 | 200 | $pass = ($dimension >= $size1) && ($dimension <= $size2); |
| 198 | - } |
|
| 199 | - else if ( preg_match('/^([<=>]*)(\d+)$/', $rule, $matches) ) |
|
| 201 | + } else if ( preg_match('/^([<=>]*)(\d+)$/', $rule, $matches) ) |
|
| 200 | 202 | { |
| 201 | 203 | |
| 202 | 204 | $size = intval($matches[2]); |
@@ -228,8 +230,7 @@ discard block |
||
| 228 | 230 | throw new \RuntimeException('Unknown image size validation rule: ' . $rule ); |
| 229 | 231 | } |
| 230 | 232 | |
| 231 | - } |
|
| 232 | - else |
|
| 233 | + } else |
|
| 233 | 234 | { |
| 234 | 235 | throw new \RuntimeException('Unknown image size validation rule: ' . $rule ); |
| 235 | 236 | } |
@@ -1,7 +1,6 @@ |
||
| 1 | 1 | <?php namespace Cviebrock\ImageValidator; |
| 2 | 2 | |
| 3 | 3 | use Illuminate\Support\ServiceProvider; |
| 4 | -use Illuminate\Validation\Factory; |
|
| 5 | 4 | |
| 6 | 5 | class ImageValidatorServiceProvider extends ServiceProvider |
| 7 | 6 | { |
@@ -7,10 +7,10 @@ discard block |
||
| 7 | 7 | { |
| 8 | 8 | |
| 9 | 9 | /** |
| 10 | - * Indicates if loading of the provider is deferred. |
|
| 11 | - * |
|
| 12 | - * @var bool |
|
| 13 | - */ |
|
| 10 | + * Indicates if loading of the provider is deferred. |
|
| 11 | + * |
|
| 12 | + * @var bool |
|
| 13 | + */ |
|
| 14 | 14 | protected $defer = false; |
| 15 | 15 | |
| 16 | 16 | protected $rules = array( |
@@ -20,10 +20,10 @@ discard block |
||
| 20 | 20 | |
| 21 | 21 | |
| 22 | 22 | /** |
| 23 | - * Bootstrap the application events. |
|
| 24 | - * |
|
| 25 | - * @return void |
|
| 26 | - */ |
|
| 23 | + * Bootstrap the application events. |
|
| 24 | + * |
|
| 25 | + * @return void |
|
| 26 | + */ |
|
| 27 | 27 | public function boot() |
| 28 | 28 | { |
| 29 | 29 | $this->loadTranslationsFrom(__DIR__.'/../lang', 'image-validator'); |
@@ -48,17 +48,17 @@ discard block |
||
| 48 | 48 | |
| 49 | 49 | |
| 50 | 50 | /** |
| 51 | - * Get the list of new rules being added to the validator. |
|
| 52 | - * @return array |
|
| 53 | - */ |
|
| 51 | + * Get the list of new rules being added to the validator. |
|
| 52 | + * @return array |
|
| 53 | + */ |
|
| 54 | 54 | public function getRules() |
| 55 | 55 | { |
| 56 | 56 | return $this->rules; |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | /** |
| 60 | - * Add new rules to the validator. |
|
| 61 | - */ |
|
| 60 | + * Add new rules to the validator. |
|
| 61 | + */ |
|
| 62 | 62 | protected function addNewRules() |
| 63 | 63 | { |
| 64 | 64 | foreach($this->getRules() as $rule) |
@@ -69,10 +69,10 @@ discard block |
||
| 69 | 69 | |
| 70 | 70 | |
| 71 | 71 | /** |
| 72 | - * Extend the validator with new rules. |
|
| 73 | - * @param string $rule |
|
| 74 | - * @return void |
|
| 75 | - */ |
|
| 72 | + * Extend the validator with new rules. |
|
| 73 | + * @param string $rule |
|
| 74 | + * @return void |
|
| 75 | + */ |
|
| 76 | 76 | protected function extendValidator($rule) |
| 77 | 77 | { |
| 78 | 78 | $method = studly_case($rule); |
@@ -83,20 +83,20 @@ discard block |
||
| 83 | 83 | |
| 84 | 84 | |
| 85 | 85 | /** |
| 86 | - * Register the service provider. |
|
| 87 | - * |
|
| 88 | - * @return void |
|
| 89 | - */ |
|
| 86 | + * Register the service provider. |
|
| 87 | + * |
|
| 88 | + * @return void |
|
| 89 | + */ |
|
| 90 | 90 | public function register() |
| 91 | 91 | { |
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | |
| 95 | 95 | /** |
| 96 | - * Get the services provided by the provider. |
|
| 97 | - * |
|
| 98 | - * @return array |
|
| 99 | - */ |
|
| 96 | + * Get the services provided by the provider. |
|
| 97 | + * |
|
| 98 | + * @return array |
|
| 99 | + */ |
|
| 100 | 100 | public function provides() |
| 101 | 101 | { |
| 102 | 102 | return []; |
@@ -26,13 +26,13 @@ discard block |
||
| 26 | 26 | */ |
| 27 | 27 | public function boot() |
| 28 | 28 | { |
| 29 | - $this->loadTranslationsFrom(__DIR__.'/../lang', 'image-validator'); |
|
| 29 | + $this->loadTranslationsFrom(__DIR__ . '/../lang', 'image-validator'); |
|
| 30 | 30 | |
| 31 | 31 | $messages = trans('image-validator::validation'); |
| 32 | 32 | |
| 33 | 33 | $this->app->bind('Cviebrock\ImageValidator\ImageValidator', function($app) use ($messages) |
| 34 | 34 | { |
| 35 | - $validator = new ImageValidator($app['translator'], [], [], $messages ); |
|
| 35 | + $validator = new ImageValidator($app['translator'], [], [], $messages); |
|
| 36 | 36 | |
| 37 | 37 | if (isset($app['validation.presence'])) |
| 38 | 38 | { |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | */ |
| 62 | 62 | protected function addNewRules() |
| 63 | 63 | { |
| 64 | - foreach($this->getRules() as $rule) |
|
| 64 | + foreach ($this->getRules() as $rule) |
|
| 65 | 65 | { |
| 66 | 66 | $this->extendValidator($rule); |
| 67 | 67 | } |
@@ -76,9 +76,9 @@ discard block |
||
| 76 | 76 | protected function extendValidator($rule) |
| 77 | 77 | { |
| 78 | 78 | $method = studly_case($rule); |
| 79 | - $translation = $this->app['translator']->trans('image-validator::validation.'.$rule); |
|
| 79 | + $translation = $this->app['translator']->trans('image-validator::validation.' . $rule); |
|
| 80 | 80 | $this->app['validator']->extend($rule, 'Cviebrock\ImageValidator\ImageValidator@validate' . $method, $translation); |
| 81 | - $this->app['validator']->replacer($rule, 'Cviebrock\ImageValidator\ImageValidator@replace' . $method ); |
|
| 81 | + $this->app['validator']->replacer($rule, 'Cviebrock\ImageValidator\ImageValidator@replace' . $method); |
|
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | |
@@ -1,15 +1,15 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | return array( |
| 4 | - 'image_size' => ':attribute 的宽度为 :width, 高度为 :height', |
|
| 4 | + 'image_size' => ':attribute 的宽度为 :width, 高度为 :height', |
|
| 5 | 5 | |
| 6 | - 'between' => '必须在 :size1 和 :size2 像素之间', |
|
| 7 | - 'lessthan' => '必须小于 :size 像素', |
|
| 8 | - 'lessthanorequal' => '必须小于或等于 :size 像素', |
|
| 9 | - 'greaterthan' => '必须大于 :size 像素', |
|
| 10 | - 'greaterthanorequal' => '必须大于或等于 :size 像素', |
|
| 11 | - 'equal' => '必须等于 :size 像素', |
|
| 12 | - 'anysize' => '可以为任意大小', |
|
| 6 | + 'between' => '必须在 :size1 和 :size2 像素之间', |
|
| 7 | + 'lessthan' => '必须小于 :size 像素', |
|
| 8 | + 'lessthanorequal' => '必须小于或等于 :size 像素', |
|
| 9 | + 'greaterthan' => '必须大于 :size 像素', |
|
| 10 | + 'greaterthanorequal' => '必须大于或等于 :size 像素', |
|
| 11 | + 'equal' => '必须等于 :size 像素', |
|
| 12 | + 'anysize' => '可以为任意大小', |
|
| 13 | 13 | |
| 14 | - 'image_aspect' => ':attribute 长宽比必须为 :aspect', |
|
| 14 | + 'image_aspect' => ':attribute 长宽比必须为 :aspect', |
|
| 15 | 15 | ); |
@@ -1,15 +1,15 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | return array( |
| 4 | - 'image_size' => ':attribute :width genişliği ve :height yüksekliği olmalıdır.', |
|
| 4 | + 'image_size' => ':attribute :width genişliği ve :height yüksekliği olmalıdır.', |
|
| 5 | 5 | |
| 6 | - 'between' => ':size1 ve :size2 piksel aralığında', |
|
| 7 | - 'lessthan' => ':size pikselden az', |
|
| 8 | - 'lessthanorequal' => ':size piksele eşit veya az', |
|
| 9 | - 'greaterthan' => ':size pikselden fazla', |
|
| 10 | - 'greaterthanorequal' => ':size piksele eşit veya fazla', |
|
| 11 | - 'equal' => ':size piksel', |
|
| 12 | - 'anysize' => 'herhangi bir', |
|
| 6 | + 'between' => ':size1 ve :size2 piksel aralığında', |
|
| 7 | + 'lessthan' => ':size pikselden az', |
|
| 8 | + 'lessthanorequal' => ':size piksele eşit veya az', |
|
| 9 | + 'greaterthan' => ':size pikselden fazla', |
|
| 10 | + 'greaterthanorequal' => ':size piksele eşit veya fazla', |
|
| 11 | + 'equal' => ':size piksel', |
|
| 12 | + 'anysize' => 'herhangi bir', |
|
| 13 | 13 | |
| 14 | - 'image_aspect' => ':attribute en/boy oranı :aspect olmalıdır.', |
|
| 14 | + 'image_aspect' => ':attribute en/boy oranı :aspect olmalıdır.', |
|
| 15 | 15 | ); |
| 16 | 16 | \ No newline at end of file |
@@ -1,15 +1,15 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | return array( |
| 4 | - 'image_size' => ':attribute 欄位的寬度 :width, 而高度 :height', |
|
| 4 | + 'image_size' => ':attribute 欄位的寬度 :width, 而高度 :height', |
|
| 5 | 5 | |
| 6 | - 'between' => '必須介於 :size1 與 :size2 像素之間', |
|
| 7 | - 'lessthan' => '必須小於 :size 像素', |
|
| 8 | - 'lessthanorequal' => '必須小於或等於 :size 像素', |
|
| 9 | - 'greaterthan' => '必須大於 :size 像素', |
|
| 10 | - 'greaterthanorequal' => '必須大於或等於 :size 像素', |
|
| 11 | - 'equal' => '必須等於 :size 像素', |
|
| 12 | - 'anysize' => '可以是任意大小', |
|
| 6 | + 'between' => '必須介於 :size1 與 :size2 像素之間', |
|
| 7 | + 'lessthan' => '必須小於 :size 像素', |
|
| 8 | + 'lessthanorequal' => '必須小於或等於 :size 像素', |
|
| 9 | + 'greaterthan' => '必須大於 :size 像素', |
|
| 10 | + 'greaterthanorequal' => '必須大於或等於 :size 像素', |
|
| 11 | + 'equal' => '必須等於 :size 像素', |
|
| 12 | + 'anysize' => '可以是任意大小', |
|
| 13 | 13 | |
| 14 | - 'image_aspect' => ':attribute 欄位的長寬比必須是 :aspect', |
|
| 14 | + 'image_aspect' => ':attribute 欄位的長寬比必須是 :aspect', |
|
| 15 | 15 | ); |
| 16 | 16 | \ No newline at end of file |