Friday, January 2, 2009

Reference guide

By thomasw at 13:49:13

Hy interested ones,

the last two weeks I was working on a new dependency guide.

It is available for you since yesterday. You can download it from trunk.
Those who can not wait have to build the manual themself.
All others will get the guide with the next release when the manual is build by Zend and made public on the projects homepage.

The new dependency guide supports now also Sub-dependencies which means that you can use it to seperate Components from the rest of the Framework even when this is no good practice and you should not do it.

There are 4 depencendies:
Hard:
Hard Components are required. Without them the class will not work

Soft:
Soft Components can be required when using special methods. It could be that the class can work without them.

Fix:
Fixed Subcomponents are required by Hard Components. Without them the Component will not work.

Sub:
Subbed Subcomponents can be required by Soft or Fixed Components when using special methods. Also this Components are only needed optional.

This dependency guide is based of ZF 1.7.2 and can be found in the reference section. When I find time in the next few days, I will also add the new manual here as download.
Note that it refers only to components and not to single classes. A component consists of a base class and a directory.

I hope you find it usefull and wish you a good new year.

Greetings
Thomas Weidner
I18N Team Leader, Zend Framework

Zend Framework Advisory Board Member
Zend Certified Engineer for Zend Framework

Friday, December 5, 2008

News from behind

By thomasw at 19:08:54

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

Saturday, November 1, 2008

File Transfer, hashing and other news

By thomasw at 20:45:57

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

Saturday, October 18, 2008

I18N compatibility mode

By thomasw at 23:03:34

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

Sunday, October 5, 2008

Migrating your Script using Zend_File_Transfer from 1.6.1 to a newer release

By thomasw at 13:01:16

Hy interested ones,

most of you know this already. But it seems that users tend not to read migration notes so I will say it once more here.

When you are using Zend_File_Transfer in conjunction with validations you will have to note that the API has changed.

I added a $breakChainOnFailure parameter which allows to break the validation chain for further validators if a validation error occurs.

To give you an example:

// Example for 1.6.1 or earlier
$upload = new Zend_File_Transfer_Adapter_Http();
$upload->addValidator('FilesSize', array('1B', '100kB'));
// Same example for 1.6.2 and newer
// Note the added boolean false
$upload = new Zend_File_Transfer_Adapter_Http();
$upload->addValidator('FilesSize', false, array('1B', '100kB'));

So as conclusio for you:
If you have to migrate old scripts simply add a boolean false after the validator name.

Greetings
Thomas Weidner, I18N Team Leader, Zend Framework

Sunday, September 7, 2008

Destination and renaming of uploaded files

By thomasw at 23:45:09

Hy insterested ones,

I added for you two new improvements to Zend_File_Transfer or if you work with Forms, to the file element.

The first one is that Zend_File_Transfer allows now the usage of file filters. Note that, of course, file filters work differently to normal string filters. They do not return the content, but the location of the file, aka the real location and filename. It should also be noted that file filters will be attached AFTER the file has been received. This is due to the fact that we are not allowed to change the file before it has been received, as we would then get a attacker exception from PHP itself. Input elements, for example, will do filtering before validation. File elements will always do validation and afterwards filtering. So you could now add your own filters if you are in need. Or you wait for me to do this.

The second improvement is the first file filter.

I am happy to announce that the “Rename” filter is ready in core.
What can it do ?

Well, it will allow you to have much more influence of the behaviour of uploaded files.
Let’s see an example:

$filter = new Zend_Filter_File_Rename('C:\pictures\newpics', true);

or when you use the adapter

$adapter->addFilter('Rename', array('C:\pictures\newpics', true));

All uploads will now be moved to the directory C:\pictures\newpics and will be overwritten if they exist.
The default is false, which means that the filter will not overwrite existing files. Beware: If the file exists, you will get a false as soon as you receive the file with an error, that the file already exists if you do not set the overwrite property.

Of course the rename adapter allows much more.
You can define the location for each single file separatly.
You can even define a new filename and extension for the uploaded file.

$adapter->addFilter('Rename', 'C:\pictures\newname.txt');

For more details about supported notations look into the manual.

I hope you find this addition usefull and use it in your own projects.
PS: If you have a good idea for a additional feature to any of my components dont be shy and share your idea.

Greetings
Thomas, I18N Team Leader, Zend Framework

Zend_File_Transfer and isRequired

By thomasw at 00:41:58

Hy fellows,

some of you have mentioned that Zend_Form_Element_File does not properly handle file uploads when the element was set as not required.

The reason was that Zend_File_Transfer checks all given input, in our case of HTTP POST the complete $_FILES array. Within this array we will find all files, of course also the prepared but not uploaded ones.

So, to get around this, we would have to ignore errors when isRequired is set to false. This was the solution of an issue which has been added by one of you. But this would lead to another problem: When you have multiple file elements, one required, and the other not required, this would not work because the elements setting isRequired to false would also negotate errors from the fileupload which is set required.

The finished and working solution acts different:
I added an new option to Zend_File_Transfer: ignoreNoFile. When it is set it will ignore all errors for the file where this option is set. Of course Zend_Form_Element_File was also changed to handle this new feature itself.

For you, as customer, there is no change in your code. The file element will handle this option in the background.
Of course, to get around of this nasty problem, you will have to use the SVN trunk or wait until 1.6.1

Enjoy it… new features are, of course, already in development and I will inform you as first one. :-)

Greetings
Thomas, I18N Team Leader, Zend Framework

Wednesday, August 27, 2008

Zend_Translate and SVN

By thomasw at 22:50:04

Hy interested ones,

using Zend_Translate with a software version control system like SVN or CVS can drive developers crazy when you use directory search. This is due to the fact that all files are searched and added.

In the special case of a VCS system also the VCS directories are searched and added which often hold a complete but old version of the source file. This leads to the behaviour that old messageids are also added and presented. Your developer will not know why he get’s only old translations or wrong encoded files.

To solve this behaviour I added a new option ignore which defaults to ‘.’. All directories and files beginning with the value of this option will be ignored.

Now with this new option for example all .svn directories are ignored and not added. So your developer will always see the latest translation files.

You could change this option, for example, to ignore .svn if you want to have other . files and directories like .tmp or .source still added.

Greetings
Thomas Weidner, I18N Team Leader, Zend Framework

Wednesday, August 6, 2008

News on the Zend Framework I18N core

By thomasw at 20:39:39

Hy interested ones,

I have good and bad news for you.

The bad news are that due to minor BC changes and the lack of time from the dev-team, which has to review the changes in the API, all new features from the I18N core are delayed until release 1.7.
This is also the case for the application wide locale which I described a chapter before. But, and this is more bad, most fixed issues will also be delayed until 1.7.

The good news are that the new release is scheduled for end September. But you can use all new features already when you are using the trunk.

What has been changed until now for the I18N core:
* I integrated an application wide locale… all I18N components can reuse an instance of Zend_Locale when registered in Zend_Registry.
* I integrated the new CLDR 1.6.1… it add’s not only several more complete informations for different languages, but also new data which will be added soon… for example, telephone data, character fall back rules, unit names just to mention some of them
* A new measurement class for time duration has been added

More things will come soon.

Another good thing is that Zend_File_Transfer was cored yesterday. It is officially available for release 1.6. Also here new features will be available soon, but not until 1.6.

I will keep you informed.

Greetings
Thomas, I18N Team Leader, Zend Framework

Monday, July 28, 2008

Application wide locale in Zend Framework

By thomasw at 00:08:38

Hy interested ones,

a new feature has been added within Zend Framework. it now supports the usage of an application wide locale. Anyone who is using I18N classes in his application will love this feature.

So what’s all about this new feature…. let’s look into details. Until Zend Framework 1.5 when you wanted to use several I18N aware classes you had to set the locale you wanted to use within all classes. This looked like this:

$locale = new Zend_Locale('en_US');
$date1 = new Zend_Date($locale);
$date2 = new Zend_Date($locale);
$currency = new Zend_Currency($locale);

When you use only one or two instances there is not much difference. But the more instances you use the more work you would have with the syntax. Looking at this in detail I thought why not simply set the locale once within your bootstrap and let the framework do the rest.

The solution was the usage of the registry. So let’s look at the same example and the difference in the usage:

$locale = new Zend_Locale('en_US');
Zend_Registry::set('Zend_Locale', $locale);
	
...
$date1 = new Zend_Date();
$date2 = new Zend_Date();
$currency = new Zend_Currency();

As you can notice now, you can forget about the locale as it’s automatically taken from the registry. This is a small and simple solution but it will solve you several headache. You can use this feature within the actual trunk or you have to wait until 1.7 is released.

Have fun with it, anyway.

Greetings,
Thomas Weidner, I18N Team Leader, Zend Framework

Calendar

  • January 2009
    SunMonTueWedThuFriSat
     123
    45678910
    11121314151617
    18192021222324
    25262728293031

Last 8 comments

Certificates

zf-zce-logo.gif

zf-education-advisory-board-m.png

Admin area