コード例 #1
0
 public function __construct()
 {
     $logo = new FileInput('logo');
     $logo->setRequired(false)->setAllowEmpty(false);
     $logo->getValidatorChain()->attach(new Size(array('messageTemplates' => array(Size::TOO_BIG => 'The file TOO_BIG', Size::TOO_SMALL => 'The file TOO_SMALL', Size::NOT_FOUND => 'The NOT_FOUND', NotEmpty::IS_EMPTY => 'Mail no debe ser vacía.'), 'options' => array('max' => 40000))));
     // Validator File Type //
     $mimeType = new MimeType();
     $mimeType->setMimeType(array('image/gif', 'image/jpg', 'image/jpeg', 'image/png'));
     $logo->getValidatorChain()->attach($mimeType);
     /** Move File to Uploads/product **/
     $nameFile = sprintf("%simg_%s", './public/assets/images/providers/', time());
     $rename = new RenameUpload($nameFile);
     //$rename->setTarget($nameFile);
     $rename->setUseUploadExtension(true);
     //$rename->setUseUploadName(true);
     $rename->setRandomize(true);
     $rename->setOverwrite(true);
     $logo->getFilterChain()->attach($rename);
     $this->add($logo);
     $this->add(array('name' => 'company', 'required' => true, 'validators' => array(array('name' => 'Alnum', 'options' => $this->opcionesAlnum)), 'filters' => array(array('name' => 'StripTags'), array('name' => 'StringTrim'))));
     $this->add(array('name' => 'company_id', 'required' => true, 'validators' => array(array('name' => 'Alnum', 'options' => $this->opcionesAlnum)), 'filters' => array(array('name' => 'StripTags'), array('name' => 'StringTrim'))));
     $this->add(array('name' => 'email', 'required' => true, 'filters' => array(array('name' => 'StripTags'), array('name' => 'StringTrim')), 'validators' => array(array('name' => 'EmailAddress', 'options' => array('messages' => array('emailAddressInvalidFormat' => 'Email address format is not invalid'))), array('name' => 'NotEmpty', 'options' => array('messages' => array('isEmpty' => 'Email address is required'))))));
     $this->add(array('name' => 'password', 'required' => true, 'filters' => array(array('name' => 'StripTags'), array('name' => 'StringTrim')), 'validators' => array(array('name' => 'NotEmpty', 'options' => array('messages' => array('isEmpty' => 'Password is required'))))));
     $this->add(array('name' => 'confirmarPassword', 'required' => true, 'filters' => array(array('name' => 'StripTags'), array('name' => 'StringTrim')), 'validators' => array(array('name' => 'identical', 'options' => array('token' => 'password')))));
 }
コード例 #2
0
 public static function createInstance()
 {
     $inputFilter = new InputFilter();
     $input = new Input('file');
     $input->setRequired(true)->setAllowEmpty(false);
     $inputFilter->add($input);
     $mimeType = new MimeType();
     $mimeType->setMimeType(['text/csv', 'application/vnd.ms-excel', 'application/vnd.ms-office', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet']);
     $input->getValidatorChain()->attach(new UploadFile())->attach($mimeType);
     return $inputFilter;
 }
コード例 #3
0
ファイル: FileHandler.php プロジェクト: bravadomizzou/dewdrop
 public function getValidatorChain()
 {
     if (!$this->validatorChain) {
         $this->validatorChain = new ValidatorChain();
         $uploadFileValidator = new UploadFileValidator();
         $this->validatorChain->attach($uploadFileValidator);
         $mimeTypeValidator = new MimeTypeValidator();
         $mimeTypeValidator->addMimeType($this->allowedMimeTypes);
         $this->validatorChain->attach($mimeTypeValidator);
     }
     return $this->validatorChain;
 }
コード例 #4
0
ファイル: IsCompressed.php プロジェクト: navassouza/zf2
 /**
  * Sets validator options
  *
  * @param string|array|Traversable $options
  */
 public function __construct($options = array())
 {
     // http://de.wikipedia.org/wiki/Liste_von_Dateiendungen
     $default = array('application/arj', 'application/gnutar', 'application/lha', 'application/lzx', 'application/vnd.ms-cab-compressed', 'application/x-ace-compressed', 'application/x-arc', 'application/x-archive', 'application/x-arj', 'application/x-bzip', 'application/x-bzip2', 'application/x-cab-compressed', 'application/x-compress', 'application/x-compressed', 'application/x-cpio', 'application/x-debian-package', 'application/x-eet', 'application/x-gzip', 'application/x-java-pack200', 'application/x-lha', 'application/x-lharc', 'application/x-lzh', 'application/x-lzma', 'application/x-lzx', 'application/x-rar', 'application/x-sit', 'application/x-stuffit', 'application/x-tar', 'application/zip', 'application/zoo', 'multipart/x-gzip');
     if ($options instanceof Traversable) {
         $options = ArrayUtils::iteratorToArray($options);
     }
     if (empty($options)) {
         $options = array('mimeType' => $default);
     }
     parent::__construct($options);
 }
コード例 #5
0
 public function __construct()
 {
     // echo sprintf("%s/data/uploads/attachment.%s.txt", __DIR__ . '/../../../../..', time());die;
     $productImage = new FileInput('productImage');
     $productImage->setRequired(true)->setAllowEmpty(false);
     $productImage->getValidatorChain()->attach(new Size(array('messageTemplates' => array(Size::TOO_BIG => 'The file TOO_BIG', Size::TOO_SMALL => 'The file TOO_SMALL', Size::NOT_FOUND => 'The NOT_FOUND'), 'options' => array('max' => 40000))));
     // Validator File Type //
     $mimeType = new MimeType();
     $mimeType->setMimeType(array('image/gif', 'image/jpg', 'image/jpeg', 'image/png'));
     $productImage->getValidatorChain()->attach($mimeType);
     /** Move File to Uploads/product **/
     $nameFile = sprintf("%simg_%s", './public/assets/images/products/catalog/', time());
     $rename = new RenameUpload($nameFile);
     //$rename->setTarget($nameFile);
     $rename->setUseUploadExtension(true);
     //$rename->setUseUploadName(true);
     $rename->setRandomize(true);
     $rename->setOverwrite(true);
     $productImage->getFilterChain()->attach($rename);
     $this->add($productImage);
 }
コード例 #6
0
ファイル: IsImage.php プロジェクト: kingsj/core
 /**
  * Sets validator options
  *
  * @param  string|array|Traversable $mimetype
  * @return void
  */
 public function __construct($options = array())
 {
     // http://de.wikipedia.org/wiki/Liste_von_Dateiendungen
     // http://www.iana.org/assignments/media-types/image/
     $default = array('application/cdf', 'application/dicom', 'application/fractals', 'application/postscript', 'application/vnd.hp-hpgl', 'application/vnd.oasis.opendocument.graphics', 'application/x-cdf', 'application/x-cmu-raster', 'application/x-ima', 'application/x-inventor', 'application/x-koan', 'application/x-portable-anymap', 'application/x-world-x-3dmf', 'image/bmp', 'image/c', 'image/cgm', 'image/fif', 'image/gif', 'image/jpeg', 'image/jpm', 'image/jpx', 'image/jp2', 'image/naplps', 'image/pjpeg', 'image/png', 'image/svg', 'image/svg+xml', 'image/tiff', 'image/vnd.adobe.photoshop', 'image/vnd.djvu', 'image/vnd.fpx', 'image/vnd.net-fpx', 'image/x-cmu-raster', 'image/x-cmx', 'image/x-coreldraw', 'image/x-cpi', 'image/x-emf', 'image/x-ico', 'image/x-icon', 'image/x-jg', 'image/x-ms-bmp', 'image/x-niff', 'image/x-pict', 'image/x-pcx', 'image/x-png', 'image/x-portable-anymap', 'image/x-portable-bitmap', 'image/x-portable-greymap', 'image/x-portable-pixmap', 'image/x-quicktime', 'image/x-rgb', 'image/x-tiff', 'image/x-unknown', 'image/x-windows-bmp', 'image/x-xpmi');
     if ($options instanceof Traversable) {
         $options = IteratorToArray::convert($options);
     }
     if (empty($options)) {
         $options = array('mimeType' => $default);
     }
     parent::__construct($options);
 }
コード例 #7
0
 public function __construct()
 {
     // echo sprintf("%s/data/uploads/attachment.%s.txt", __DIR__ . '/../../../../..', time());die;
     $productImage = new FileInput('productImage');
     $productImage->setRequired(false)->setAllowEmpty(false);
     $productImage->getValidatorChain()->attach(new Size(array('messageTemplates' => array(Size::TOO_BIG => 'The file TOO_BIG', Size::TOO_SMALL => 'The file TOO_SMALL', Size::NOT_FOUND => 'The NOT_FOUND', NotEmpty::IS_EMPTY => 'Mail no debe ser vacía.'), 'options' => array('max' => 40000))));
     // Validator File Type //
     $mimeType = new MimeType();
     $mimeType->setMimeType(array('image/gif', 'image/jpg', 'image/jpeg', 'image/png'));
     $productImage->getValidatorChain()->attach($mimeType);
     /** Move File to Uploads/product **/
     $nameFile = sprintf("%simg_%s", './public/assets/images/products/catalog/', time());
     $rename = new RenameUpload($nameFile);
     //$rename->setTarget($nameFile);
     $rename->setUseUploadExtension(true);
     //$rename->setUseUploadName(true);
     $rename->setRandomize(true);
     $rename->setOverwrite(true);
     $productImage->getFilterChain()->attach($rename);
     $this->add($productImage);
     $this->add(array('name' => 'productName', 'required' => true, 'validators' => array(array('name' => 'Alnum', 'options' => $this->opcionesAlnum)), 'filters' => array(array('name' => 'StripTags'), array('name' => 'StringTrim'))));
     $this->add(array('name' => 'productDescription', 'required' => true, 'validators' => array(array('name' => 'not_empty')), 'filters' => $this->filterGeneric));
     $this->add(array('name' => 'productModel', 'required' => true, 'validators' => array(array('name' => 'Alnum', 'options' => $this->opcionesAlnum2))));
     $this->add(array('name' => 'productPrice', 'required' => true, 'validators' => array(array('name' => 'float', 'options' => array('locale' => 'en_US')), array('name' => 'stringLength', 'options' => array('min' => 1, 'max' => 10))), 'filters' => array(array('name' => 'StripTags'), array('name' => 'StringTrim'))));
     //         $productQuantity = new Input('productQuantity');
     //         $productQuantity->setAllowEmpty(true);
     //         $productQuantity->getValidatorChain()
     //             ->attach(new Digits());
     //         $this->add($productQuantity);
     $this->add(array('name' => 'productMinimun', 'required' => false, 'validators' => array(array('name' => 'Digits'))));
     // Meta-Data Form
     $this->add(array('name' => 'productMetaTittle', 'required' => true, 'validators' => array(array('name' => 'Alnum', 'options' => $this->opcionesAlnum)), 'filters' => array(array('name' => 'StripTags'), array('name' => 'StringTrim'))));
     $this->add(array('name' => 'productSeoUrl', 'required' => true, 'validators' => array(array('name' => 'not_empty')), 'filters' => array(array('name' => 'StripTags'), array('name' => 'StringTrim'), array('name' => 'StringToLower'))));
     $this->add(array('name' => 'productMetaDescription', 'continue_if_empty' => true, 'filters' => array(array('name' => 'StripTags'), array('name' => 'StringTrim'))));
     $this->add(array('name' => 'productMetaKeywords', 'continue_if_empty' => true, 'filters' => array(array('name' => 'StripTags'), array('name' => 'StringTrim'))));
 }
コード例 #8
0
ファイル: IsCompressed.php プロジェクト: Flesh192/magento
 /**
  * Sets validator options
  *
  * @param string|array|Traversable $options
  */
 public function __construct($options = array())
 {
     // http://hul.harvard.edu/ois/systems/wax/wax-public-help/mimetypes.htm
     $default = array('application/arj', 'application/gnutar', 'application/lha', 'application/lzx', 'application/vnd.ms-cab-compressed', 'application/x-ace-compressed', 'application/x-arc', 'application/x-archive', 'application/x-arj', 'application/x-bzip', 'application/x-bzip2', 'application/x-cab-compressed', 'application/x-compress', 'application/x-compressed', 'application/x-cpio', 'application/x-debian-package', 'application/x-eet', 'application/x-gzip', 'application/x-java-pack200', 'application/x-lha', 'application/x-lharc', 'application/x-lzh', 'application/x-lzma', 'application/x-lzx', 'application/x-rar', 'application/x-sit', 'application/x-stuffit', 'application/x-tar', 'application/zip', 'application/x-zip', 'application/zoo', 'multipart/x-gzip');
     if ($options instanceof Traversable) {
         $options = ArrayUtils::iteratorToArray($options);
     }
     if ($options === null) {
         $options = array();
     }
     parent::__construct($options);
     if (!$this->getMimeType()) {
         $this->setMimeType($default);
     }
 }
コード例 #9
0
 /**
  * Sets validator options
  *
  * @param array|Traversable|string $options
  */
 public function __construct($options = [])
 {
     // http://www.iana.org/assignments/media-types/media-types.xhtml#image
     $default = ['application/cdf', 'application/dicom', 'application/fractals', 'application/postscript', 'application/vnd.hp-hpgl', 'application/vnd.oasis.opendocument.graphics', 'application/x-cdf', 'application/x-cmu-raster', 'application/x-ima', 'application/x-inventor', 'application/x-koan', 'application/x-portable-anymap', 'application/x-world-x-3dmf', 'image/bmp', 'image/c', 'image/cgm', 'image/fif', 'image/gif', 'image/jpeg', 'image/jpm', 'image/jpx', 'image/jp2', 'image/naplps', 'image/pjpeg', 'image/png', 'image/svg', 'image/svg+xml', 'image/tiff', 'image/vnd.adobe.photoshop', 'image/vnd.djvu', 'image/vnd.fpx', 'image/vnd.net-fpx', 'image/x-cmu-raster', 'image/x-cmx', 'image/x-coreldraw', 'image/x-cpi', 'image/x-emf', 'image/x-ico', 'image/x-icon', 'image/x-jg', 'image/x-ms-bmp', 'image/x-niff', 'image/x-pict', 'image/x-pcx', 'image/x-png', 'image/x-portable-anymap', 'image/x-portable-bitmap', 'image/x-portable-greymap', 'image/x-portable-pixmap', 'image/x-quicktime', 'image/x-rgb', 'image/x-tiff', 'image/x-unknown', 'image/x-windows-bmp', 'image/x-xpmi'];
     if ($options instanceof Traversable) {
         $options = ArrayUtils::iteratorToArray($options);
     }
     if ($options === null) {
         $options = [];
     }
     parent::__construct($options);
     if (!$this->getMimeType()) {
         $this->setMimeType($default);
     }
 }
コード例 #10
0
ファイル: MimeTypeTest.php プロジェクト: rafalwrzeszcz/zf2
 /**
  * @group ZF-10461
  */
 public function testDisablingMagicFileByConstructor()
 {
     $files = array('name' => 'picture.jpg', 'size' => 200, 'tmp_name' => dirname(__FILE__) . '/_files/picture.jpg', 'error' => 0, 'magicFile' => false);
     $validator = new File\MimeType($files);
     $this->assertFalse($validator->getMagicFile());
 }
コード例 #11
0
ファイル: FileUpload.php プロジェクト: webpants/YAWIK
 public function getInputSpecification()
 {
     $validators = array();
     $mimetypes = $this->getAllowedTypes();
     $fileCount = $this->getMaxFileCount();
     if ($mimetypes) {
         $mimeTypeValidator = new MimeType();
         $mimeTypeValidator->setMagicFile(false)->disableMagicFile(true)->setMimeType($this->getAllowedTypes());
         $validators[] = $mimeTypeValidator;
     }
     $validators[] = new Size($this->getMaxSize());
     if (0 < $fileCount) {
         $validators[] = new Callback(array($this, 'fileCountValidationCallback'));
     }
     return array('name' => $this->getName(), 'required' => false, 'validators' => $validators);
 }
コード例 #12
0
ファイル: MimeTypeTest.php プロジェクト: alab1001101/zf2
 /**
  * @group ZF-11258
  */
 public function testZF11258()
 {
     $validator = new File\MimeType(array('image/gif', 'image/jpg', 'headerCheck' => true));
     $this->assertFalse($validator->isValid(__DIR__ . '/_files/nofile.mo'));
     $this->assertTrue(array_key_exists('fileMimeTypeNotReadable', $validator->getMessages()));
     $this->assertContains("'nofile.mo'", current($validator->getMessages()));
 }
コード例 #13
0
ファイル: MimeTypeTest.php プロジェクト: pnaq57/zf2demo
 public function testEmptyFileShouldReturnFalseAndDisplayNotFoundMessage()
 {
     if (!extension_loaded('fileinfo')) {
         $this->markTestSkipped('This PHP Version has no finfo installed');
     }
     $validator = new File\MimeType();
     $this->assertFalse($validator->isValid(''));
     $filesArray = array('name' => '', 'size' => 0, 'tmp_name' => '', 'error' => UPLOAD_ERR_NO_FILE, 'type' => '');
     $this->assertFalse($validator->isValid($filesArray));
 }
コード例 #14
0
 /**
  * @group ZF-9686
  */
 public function testDualValidation()
 {
     $valuesExpected = array(array('image', true));
     $filetest = __DIR__ . '/_files/picture.jpg';
     $files = array('name' => 'picture.jpg', 'type' => 'image/jpg', 'size' => 200, 'tmp_name' => $filetest, 'error' => 0);
     foreach ($valuesExpected as $element) {
         $options = array_shift($element);
         $expected = array_shift($element);
         $validator = new File\MimeType($options);
         $validator->enableHeaderCheck();
         $this->assertEquals($expected, $validator->isValid($filetest, $files), "Test expected " . var_export($expected, 1) . " with " . var_export($options, 1) . "\nMessages: " . var_export($validator->getMessages(), 1));
         $validator = new File\MimeType($options);
         $validator->enableHeaderCheck();
         $this->assertEquals($expected, $validator->isValid($filetest, $files), "Test expected " . var_export($expected, 1) . " with " . var_export($options, 1) . "\nMessages: " . var_export($validator->getMessages(), 1));
     }
 }
コード例 #15
0
ファイル: IdeaService.php プロジェクト: debranova/project
 /**
  * @param Idea $idea
  * @param      $fileData
  * @param null $alternativeName
  */
 public function addFileToIdea(Idea $idea, $fileData, $alternativeName = null)
 {
     //Parse first the type of file to see in which table it should be stored
     $mimeType = new MimeType();
     $mimeType->isValid($fileData);
     /*
      * Use the fileSize validator to validate the size
      */
     $fileSize = new FilesSize(PHP_INT_MAX);
     $fileSize->isValid($fileData);
     $contentType = $this->getGeneralService()->findContentTypeByContentTypeName($fileData['type']);
     switch ($mimeType->type) {
         case 'application/pdf':
             //All treated as document
         //All treated as document
         case 'application/msword':
             //All treated as document
         //All treated as document
         case 'application/vnd.ms-excel':
             //All treated as document
         //All treated as document
         case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document':
             //All treated as document
         //All treated as document
         case 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet':
             //All treated as document
         //All treated as document
         case 'application/vnd.openxmlformats-officedocument.presentationml.presentation':
             $ideaDocument = new Document();
             $ideaDocument->setIdea($idea);
             $ideaDocument->setFilename($fileData['name']);
             $ideaDocument->setSize($fileSize->size);
             if (is_null($alternativeName)) {
                 $ideaDocument->setDocument($fileData['name']);
             } else {
                 $ideaDocument->setDocument($alternativeName);
             }
             $ideaDocumentObject = new DocumentObject();
             $ideaDocumentObject->setObject(file_get_contents($fileData['tmp_name']));
             $ideaDocument->setContentType($contentType);
             $ideaDocumentObject->setDocument($ideaDocument);
             $this->newEntity($ideaDocumentObject);
             break;
         case 'image/jpeg':
         case 'image/png':
             $ideaImage = new Image();
             $ideaImage->setIdea($idea);
             if (is_null($alternativeName)) {
                 $ideaImage->setImage($fileData['name']);
             } else {
                 $ideaImage->setImage($alternativeName);
             }
             $ideaImage->setSize($fileSize->size);
             $ideaImage->setContentType($contentType);
             $ideaImageObject = new ImageObject();
             $ideaImageObject->setObject(file_get_contents($fileData['tmp_name']));
             $thumb = new GD($fileData['tmp_name']);
             $thumb->resize(200);
             $ideaImageObject->setThumb($thumb->getImageAsString());
             $ideaImageObject->setImage($ideaImage);
             $this->newEntity($ideaImageObject);
             break;
     }
 }
コード例 #16
0
ファイル: MimeTypeTest.php プロジェクト: bradley-holt/zf2
 public function testOptionsAtConstructor()
 {
     $validator = new File\MimeType(array('image/gif', 'image/jpg', 'headerCheck' => true));
     $this->assertTrue($validator->getHeaderCheck());
     $this->assertEquals('image/gif,image/jpg', $validator->getMimeType());
 }