Friday
5
December
2008

News from behind

Hy fellows,

as you may have noted there has been no update since several weeks.
This is not because I did nothing. Much has been done in background.

Therefor I will give you some information about what I am actually working on and what new features will be available in the near future.

Encryption/Decryption
I’ve been working on a encryption/decryption filter for files and for strings. It’s already finished and can be found on incubator. Actually it awaits the acceptance of the devteam for core integration.

It’s based on PHP’s mcrypt extension which supports more than 20 different encodings.

WordCount validator
I made a new validator which counts words within a textfile. The WordCount validator can also be found within the incubator and awaits review of the devteam.

Zend_Date
I started the rework of Zend_Date for ZF2.0. I planned to shrink the code, and make some internal improvements. The benefit will be a performance improvement. But it will be for 2.0 and not before.
Until now I’ve not decided if we change from mktime to the new date extension. There is no real performance benefit, so I have to do some research before I can decide.

More to come soon, I’ll keep you informed.

Greetings
Thomas Weidner
I18N Team Leader, Zend Framework

Zend Framework Advisory Board Member
Zend Certified Engineer for Zend Framework

Back to top
Saturday
1
November
2008

File Transfer, hashing and other news

Hy interested ones,

the last days I added hashing functionality to Zend_File_Transfer.
The getHash() method will return you the hash value of uploaded files.
It accepts up to 34 different hash algorithms.

$upload->getHash('uploadform');

Additionally I added a hash validator (Zend_Validate_File_Hash) which can be used to validate for the hash of a filecontent. For convinience Crc32, Md5 and Sha1 are also available.

$upload->addValidator('Hash', false, '3b512d52', 'crc32');

Beside that as reminder for you:
When you want to check if a file has been uploaded you can use isUploaded instead of checking the filename.

if ($upload->isUploaded('uploadform')) {...}

Some of you have also mentioned that they have not seen a complet working example with files osing Zend_Form. Well, I’m no forms expert, but here is an example which can be helpfull to see if the problem is your code, or your environment. This one works when you save it in a file and call it from your browser when your environment is configured correct:

ini_set('include_path',ini_get('include_path').PATH_SEPARATOR.'../library');
require_once('Zend/Loader.php');
Zend_Loader::registerAutoload();
	
$request = new Zend_Controller_Request_Http();
	
// setup the form
$form = new Zend_Form();
$form->setMethod("post");
$form->setAttrib("enctype",Zend_Form::ENCTYPE_MULTIPART);
	
// file element, upload is optional, but if file is uploaded run multiple validators
$file1 = $form->createElement("file","file1");
$file1->setRequired(false)
       ->setLabel("File:")
       ->addValidator('Count', true, 2)     
       ->addValidator('Size', true, "100KB")
       ->addValidator('Extension', true, 'jpg')
       ->addValidator('MimeType',true,array('image/jpeg'))
       ->addValidator('ImageSize',true,array(0,0,340,480))
       ->setMultiFile(3);
	
// add another file element with same validators      
$file2 = clone $file1;
$file2->setName("file2")
       ->setMultiFile(0);
	
$submit = $form->createElement("submit","submit");
$submit->setLabel("GO!");
	
$form->addElements(array($file1,$file2,$submit));
	
// check the form
if($request->isPost()) {
    $formData = $request->getPost();
    if($form->isValid($formData)) {
        echo "FORM VALID";
    } else {
        print_r($form->getMessages());                              
    }
}
?>
<html>
<head>
<title>File Test</title>
</head>
<body>
<?php echo $form->render(new Zend_View());?>
</body>
</html>

After the validation was successfull you will only have to receive the files.
You can do this eighter by calling it on the adapter class

if (!$form->getTransferAdapter()->receive()) {
    print "There was a failure at receiving the files";
}

or by calling it on the file element

if (!$form->file1->receive()) {
    print "There was a failure at receiving file1";
}

but the second will only receive this single file element… so you would have to call it on every file element you want to receive.

Additionally I was told by the devteam to add the getValue() method which has also to validate and receive files. So if you call this method all of your files will be validated and received in one step… additionally you will get the filenames returned, but without the file path because of security reasons. If you need the complete path simply call getFileName().

Attention:
Due to this change, which is in my eyes problematic, you should not call isValid() afterwards. The reson is that after you received the files, by getValues(), they are no longer available. So your validation will fail. You can get around this problem when you check if the file has already been received.

if (!$form->getTransferAdapter()->isReceived()) {
    if (!$form->getTransferAdapter()->receive()) {
        print "There was a failure while receiving the files";
    }
}

Beware that getValues() is called by some methods of Zend_Form or their elements automatically.

Anyway, I hope you find this additional functions usefull. Feel free to test it and report problems on it to our issuetracker.

Greetings
Thomas Weidner
I18N Team Leader, Zend Framework

Zend Framework Advisory Board Member
Zend Certified Engineer for Zend Framework

Back to top
Saturday
18
October
2008

I18N compatibility mode

Hy interested ones,

to prevent problems when you want to change from Zend Framework 1.6 to 1.7 I added a so called “compatibility mode”.

It’s simply a static variable which changes between old API and new API behaviour.
Within release 1.7 the old behaviour is per default active (true).
So your old code will still work with this settings but it will throw a user warning.

You can change this mode by simply setting it to false in your bootstrap.

Zend_Locale::$compatibilityMode = false;

This will no longer return user warnings, but could be in a position where you have to change your code to work again. See the migration chapter of Zend_Locale for details.

The changes include:
* changes on isLocale which now only returns boolean
* changes on getDefault which returns only the framework default
* changes on calling information methods which were made static
* changes on returned locales which do no longer degrade to other types

In 75% of the cases you will not have to change anything. But you should properly check this.

With the next release 1.8 we will change the compatibility mode to false per default, and with 1.9 we will delete it completly so only the new API behaviour is active.

Greetings
Thomas Weidner
I18N Team Leader, Zend Framework

Zend Framework Advisory Board Member
Zend Certified Engineer for Zend Framework

Back to top