From 83f6b3178d3f27b6522c006a6f6dfda8efb812c2 Mon Sep 17 00:00:00 2001 From: Alphametric Date: Tue, 2 Apr 2019 10:10:32 +0100 Subject: [PATCH] Added EncodedImage rule --- README.md | 1 + src/EncodedImage.php | 84 +++++++++++++++++++++++++++++++++++++ support/assets/image.jpeg | Bin 0 -> 12588 bytes support/assets/image.png | Bin 0 -> 10559 bytes tests/EncodedImageTest.php | 63 ++++++++++++++++++++++++++++ 5 files changed, 148 insertions(+) create mode 100644 src/EncodedImage.php create mode 100644 support/assets/image.jpeg create mode 100644 support/assets/image.png create mode 100644 tests/EncodedImageTest.php diff --git a/README.md b/README.md index fc5f941..7b1feee 100755 --- a/README.md +++ b/README.md @@ -39,6 +39,7 @@ The following validation rules are currently available: | DisposableEmail | validation.disposable_email | Requires the presence of an email address which is not disposable | | DoesNotExist | validation.does_not_exist | Requires that the given value is not present in a given database table / column - see class for details | | Decimal | validation.decimal | Requires that the given value is a decimal with an appropriate format - see class for details | +| EncodedImage | validation.encoded_image | Requires that the given value is a base64-encoded image of a given mime type - see class for details | The package will receive new rules over time, however since these updates will not be breaking changes, they will not receive major version numbers unless Laravel changes in such a way that the package requires a re-write. diff --git a/src/EncodedImage.php b/src/EncodedImage.php new file mode 100644 index 0000000..67cf00e --- /dev/null +++ b/src/EncodedImage.php @@ -0,0 +1,84 @@ +file = tmpfile(); + + fwrite($this->file, base64_decode(str_after($data, 'base64,'))); + + return new UploadedFile( + stream_get_meta_data($this->file)['uri'], 'image', + 'text/plain', null, null, true + ); + } + + + + /** + * Determine if the validation rule passes. + * + * The rule requires a single parameter, which is + * the expected mime type of the file e.g. png, jpeg etc. + * + * @param string $attribute. + * @param mixed $value. + * @return bool. + * + **/ + public function passes($attribute, $value) + { + if (! starts_with($value, "data:image/{$this->parameters[0]};base64,")) { + return false; + } + + $result = validator(['file' => $this -> createTemporaryFile($value)], ['file' => 'image']) + -> passes(); + + fclose($this->file); + + return $result; + } + + + + /** + * Get the validation error message. + * + * @param none. + * @return string. + * + **/ + public function message() + { + return Helper::getLocalizedErrorMessage( + 'encoded_image', + "The :attribute must be a valid {$this->parameters[0]} image" + ); + } + +} \ No newline at end of file diff --git a/support/assets/image.jpeg b/support/assets/image.jpeg new file mode 100644 index 0000000000000000000000000000000000000000..046412af8aa1e6d8c5de89a393423be9dfc819c3 GIT binary patch literal 12588 zcmeHs2Ut_f*7l@8sD|D<(nNZ%0qG!8REmufdY2**kSG=uR1_5uR4j;K0TmGo5|OSb zMVg=zKm-&dK}v)q``d7obG~x#xzGRH=luWke`mt%d9$)+&04c()_!LL^+9C7<7n$( z3lInZPQf1l4T1eOgwP-WoSnfs000|cLGS?-j1ce#AjAO63I@OtA-;;;5z0SxkN~8I z0`yOvZE(9>V9U$Bf40cW$X^b6e z74Jt-i;9!~Wx+Zy4j&sD6CWBKC9`bN&p$dL-b_wT10F%+=Mc+q)mL+wzsuh<@b?V- zJp+Hwz~3|Q_YC~+n}OfiPGA&FaS~xJ1E48j=o%6o9~~DG9V4Tot_ch`I5?x1Nf%sJ zu)+%D>5@GDE(_d8PwZ#Uo1|?>g@(D=9IUK-T-{x49X8sm@IEe@UrbB{k_UjusQ6fS zyA3j4-rHm_BQRlOhv}aR5b(pt#aOz!Zd|tct6j0bdYSK8p?Bb|+On-x@xKOm17KPN z^Fvoy-9I1>9|_|Ja3$koV&efoorUG{iSaSZ_z{c+Vqphi+`5c|f5YTu?Ef2{UD4U% zZUq3E4Q8-hetxmR0B{Mwa+y8&VAu|qE{rv!0z#u;8~|f;e25?1auvaNePm?xGH!>l zvi~3K1pfj1`T4Kf^z#c|#lOV@_k;(w4vmY6@Y}oc<==UUj7WgzYo#c{SFVs)dv~~n zV@33ZM?0rr(ZZKV$<^dUXcfd+B*Eg zq45q|e&N74o6Wy)Y_$98SV6H?mcQhFu`v2+Cn0?6syrmnVby+8$QI9EI(tGrHvPhJ z;hR_eNeZ!AmB%KyulgStWw+s%eo(CKYV475u=H2Fp$@Bk<3qOC|B~bVe)m5x%J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i z!oiateuq6DM=cV|3rS&ZKMbUg7S1D{F6U|rhAAz(^Gx#9xN5**~!!@zfSrh-hK|}2xug-aHCorS)-v4OLuK| z(tTp{@&QGqsb8(&n7?`JGo40@^2uxDwni5eJ%O_3JeBi#V#i0XFkaOMe(43#>gI&& zyKasXWO^wRyM`zx^T%mVmrMwUXqiJ%kJT^CkaxUmHXTsCE?Io&;+@GlE)!l0>4C$7 zGz8g)rWQ#zP7xa9WlE|w^aI7Gof>=ArgvFtrxd#A)l^=j>M%K-hPkaA^XrD}4#;&* zD{z$(Z@vG)^sq$;QGsZ>+j*_Y5Y)mZ;;|a`Dq4CZ<<6WvaY*Uuy)*77pG&mNhaBY^ zdwb@&Y5sIL?KUNG%9C193jqn?`9nLs!lg7mD4ka?kqS{b>2{FcHcONj(ZPF`%d@|b z@&nsn!8~9Nr_b8RF?eUSV=fbGLrI^?X;|iSPu!weI5nx}EaN&UEbEwbrRUKH<@_lQ z4?82vW|KWDs&*=V+)ikX)r{TYq+9>c&eg87Cj3v1=>Kcql>OV@=A!=WHOKNp?cY>U Te|AdzH;uFG@BhDVqTl@ova!Gq literal 0 HcmV?d00001 diff --git a/support/assets/image.png b/support/assets/image.png new file mode 100644 index 0000000000000000000000000000000000000000..94e1b8d9465a6fcaac03c2dc40e42ebf00a648b1 GIT binary patch literal 10559 zcmeHsXH=74vu}tfy{HtWH!0G4he%P8rt~V(2@paJy@V z&R5R`-=Bk$31>rAdjmgw_hfAY0M8jyflt`W@j+Db`VS~K6;+?BNf;Nk00=tPG#WDOq#RslhX9yvR_fi);LH&sR+?ksn|u1Ms?+z@>I8NJ;s!Rz{EJL&RFp z7n1D3Rn~#0GYMVREXlQu%aVqMv)Vu6z8LnI9Tr^i+D7qkB&4#hZngSRw=in5eYfJf zkdIppRMji;DhemaW2+S4v@d0Fweb|LRB#28fXYg$*=Guq~v9L{fbf}(YE;i1u zR3|1Z;~uWJb^gk>;d6N zUM|bRJbiCTQ)7N5orSG%8s5+ac){V@a|b~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56!MHYg=&d zPQw(eN*w(hCTmJsMcvu%;sq^zL*3NM;lT&=G)SR?7rb+QXV?NSgw!Jeqab(-w;CH} zt3y|;@vU&9B)5a=Tx|wY%-uEy2&8gsiy$#qWwb~zb>7no8wDmttkxN27ibHE_>d;8 zJ{}{>Hb%fk_bn}7bVdCR_Lg*S6r5jZ^-Z|Ifh>M)eH7j6aMupoofKhOCcsUj9uW_q z?;OnpMGKZ(2j3=g#3q|PAY0iGi`xwf8s3m-hpQOpQh^Wmy^OWl;K75_L^BTv)Fz^GO2rRW5DnBtiWsU^nAhIy4Kv3LDlhwu-Z(W=-siO@eYES_|-8Dl?3+VZBo(0=g*ooyQ|W zjo$GzOQBY=Sl0Fk-s-aYG+i9}I>B>zpl&x^3{sbtmgZ=-u!$Bqj?rKnIsD^4YxONXQgcsv$9=XuH5` z(lAn_ne7x!&2J+Ta%iR;HKqV8=G>uBMm__1o=n6{VQV@_tItVwmaK2uo_GGpsQP-X zbpdZvR21QSm1V@R!mCF{SQXAy7B6Fa$w8k193;Pev`Mg?uFuxj{?+4F98( nznQ{62jU-Z`2RXW959aMhg`Wx?3VxegIGmbL#a~XP4NE#xUt*A literal 0 HcmV?d00001 diff --git a/tests/EncodedImageTest.php b/tests/EncodedImageTest.php new file mode 100644 index 0000000..24fb678 --- /dev/null +++ b/tests/EncodedImageTest.php @@ -0,0 +1,63 @@ + [new EncodedImage('png')]]; + $jpeg_rule = ['image' => [new EncodedImage('jpeg')]]; + + // Execute the tests + $this->assertFalse(validator(['image' => $this -> getFile('image.jpeg')], $png_rule)->passes()); + $this->assertTrue(validator(['image' => $this -> getFile('image.png')], $png_rule)->passes()); + $this->assertTrue(validator(['image' => $this -> getFile('image.jpeg')], $jpeg_rule)->passes()); + $this->assertFalse(validator(['image' => $this -> getFile('image.png')], $jpeg_rule)->passes()); + $this->assertFalse(validator(['image' => $this -> invalidImage('image.jpeg')], $jpeg_rule)->passes()); + $this->assertFalse(validator(['image' => $this -> invalidImage('image.png')], $jpeg_rule)->passes()); + $this->assertFalse(validator(['image' => $this -> invalidImage()], $jpeg_rule)->passes()); + } + +} \ No newline at end of file