public function addHash($options) { if (!is_array($options)) { $options = (array) $options; } $options['algorithm'] = 'md5'; parent::addHash($options); return $this; }
/** * Adds the md5 hash for one or multiple files * * @param string|array $hash Hash to check for * @param string $algorithm (Depreciated) Algorithm to use, fixed to md5 * @return Zend_Validate_File_Hash Provides a fluent interface */ public function addHash($hash, $algorithm = 'md5') { parent::addHash($hash, 'md5'); return $this; }
/** * Ensures that addHash() returns expected value * * @return void */ public function testAddHash() { $validator = new Zend_Validate_File_Hash('12345'); $validator->addHash('12344'); $this->assertEquals(array('12345' => 'crc32', '12344' => 'crc32'), $validator->getHash()); $validator->addHash(array('12321', '12121')); $this->assertEquals(array('12345' => 'crc32', '12344' => 'crc32', '12321' => 'crc32', '12121' => 'crc32'), $validator->getHash()); }
/** * @param integer $sqArtefato * @return boolean */ public function hasImage($sqArtefato, $sqTipoArtefato = null) { try { if ($sqTipoArtefato == \Core_Configuration::getSgdoceTipoArtefatoProcesso()) { $entityArtefato = $this->_getRepository($this->_entityArtefato)->find($sqArtefato); $sqTipoArtefato = $entityArtefato->getSqTipoArtefatoAssunto()->getSqTipoArtefato()->getSqTipoArtefato(); /** * se for processo recupera a 1ª peça para verificar se tem imagem */ if ($sqTipoArtefato == \Core_Configuration::getSgdoceTipoArtefatoProcesso()) { $entityArtefatoVinculoPrimeiraPeca = $this->_getRepository($this->_entityArtefatoVinculo)->findOneBy(array('sqArtefatoPai' => $sqArtefato, 'sqTipoVinculoArtefato' => \Core_Configuration::getSgdoceTipoVinculoArtefatoAutuacao())); /** * Não existe vinculo de primeira peça para o processo */ if (null === $entityArtefatoVinculoPrimeiraPeca) { return false; } //pega o sqArtefato do pai $sqArtefato = $entityArtefatoVinculoPrimeiraPeca->getSqArtefatoFilho()->getSqArtefato(); } } $filePath = $this->getImagePath($sqArtefato); if (empty($filePath)) { return false; } $file = sprintf('%1$s%2$s..%2$sdata%2$s%3$s', APPLICATION_PATH, DIRECTORY_SEPARATOR, $filePath); if (!file_exists($file)) { throw new \Core_Exception_ServiceLayer('Imagem cadastrada, porém não foi encontrado o arquivo da mesma'); } $artefatoImagemEntity = $this->_getArtefatoImageEntity($sqArtefato); $hashValidate = new \Zend_Validate_File_Hash(array('hash' => $artefatoImagemEntity->getTxHash(), 'algorithm' => self::HASH_ALGORITHM)); if (!$hashValidate->isValid($file)) { throw new \Core_Exception_ServiceLayer('Autenticidade da imagem violada'); } } catch (\Exception $exp) { $message = sprintf('[SGDoc-e] Exception %s in %s(%d): "%s"', get_class($exp), __METHOD__, $sqArtefato, $exp->getMessage()); error_log($message); throw $exp; } return true; }