Monday, January 5, 2009
By thomasw at 23:43:42
Thanks to Pàdraic Brady I’ve been tagged in this blog posting chain. You’ve asked for it… so if you don’t want to know more about me you should not read further :-)
So here are my 7to7 for a lucky new year:
7 things to know about me:
- I actually don’t have a degree in Computional Science. In fact I’ve learned one year in a school to be allowed to study. In 2005 I started to study Computional Science at the Uni of Hagen in Germany. It’s a part-time study because I have a fulltime job, a wife, two children and a house… so my amount of time is really very small :-)
- My first PC was a C64. This was also my first programming experience and a long long time ago. Many of you young guys even don’t know how a C64 looks like but it was a great thing for it’s time.
- Before my programming career I was telecommunications engineer. I installed and programmed big PBXes for a big telecom company. This was the first job I learned and I did it for about 5 years.
- I installed security in the airport of vienna. Yes, I really worked 2 years for a security company and installed hardware, f.e. the security gates, at the airport.
- I am no black sheep. Even if my avatar is often a blacksheep and even my blog is named “blacksheep’s paradise” I am a real man. :-)
- I learned Jiu Jitsu (Jūjutsu) for 3 years. I even had the orange belt (4.Kyu). Nowadays I have not enough time to keep it doing anymore but it was interesting. My wife even has the brown belt (1.Kyu) and won the austrian junior mastership.
- I love to read science fiction and fantasy stories. I think that I have about 300 books at home and I have read them all more than once. When you want to make me happy here is my Amazon Wishlist because I have always space for a good new book :-)
And now 7 people to know about:
- Weier O’Phinney, who is a great guy and one of the best fellows around Zend Framework I know
- Rob Allen, who wrote a book about Zend Framework… I was one of the proof readers and got a hardcopy of his new book 3 days ago… you should not miss it
- Ralf Eggert, who was my first contact to Zend… he was the german leader… nowadays he has much other things to do and let this job also to me :-) He’s a great guy
- Sebastian Krebs, who is always a great discussion partner on the german forums
- Andries Seutens, who helps where he can… I’m sorry that we have not meet when I was in Amsterdam, but I am sure that we will have the change somewhere in the future
- Matthew Ratzloff, who had and have some great ideas for ZF
- Sebastian Bergmann, a guy you must know. He is the creator of PHPUnit and one of the greatest addition to the php community
Here are the rules for all who pass on the above blog:
- Link your original tagger(s), and list these rules on your blog
- Share seven facts about yourself in the post - some random, some wierd
- Tag seven people at the end of your post by leaving their names and the links to their blogs
- Let them know they’ve been tagged by leaving a comment on their blogs and/or Twitter
Friday, January 2, 2009
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
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
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
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
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
Thursday, September 25, 2008
By thomasw at 20:29:25
Hy interested ones,
when you are using Zend_Form for your file upload I have new informations for you.
*) Subforms
Using file elements in sub forms was not possible in the past. The reason was that sub forms are created by using multidimensional names, but in HTML multidimensional names are not supported for file elements.
Now this is possible. I have added a new decorator with the help of Matthew which is automatically be used for file elements. It changes the elements name in a way which is supported by HTML.
As you can see in the following example, even multi-nested subforms are supported.
$form = new Zend_Form();
$form->setEnctype('multipart/form-data');
$form->setAction('index2.php');
// Button
$button = new Zend_Form_Element_Submit('submit');
$form->addElement($button);
// File Upload Elements
$element = new Zend_Form_Element_File('firstfile');
$element2 = new Zend_Form_Element_File('secondfile');
// 3-Level subform
$subform0 = new Zend_Form_SubForm();
$subform0->addElement($element);
$subform0->addElement($element2);
$subform1 = new Zend_Form_SubForm();
$subform1->addSubform($subform0, 'subform0');
$subform2 = new Zend_Form_SubForm();
$subform2->addSubform($subform1, 'subform1');
$subform3 = new Zend_Form_SubForm();
$subform3->addSubform($subform2, 'subform2');
$form->addSubform($subform3, 'subform3');
$form->setView(new Zend_View());
echo $form;
But note that the name of the file elements you set in a form and all it’s subforms must be unique. File elements with the same name are displayed but not submitted by your form.
*) Multiple file elements
Sometimes it is usefull to have multiple file elements which uses the same settings and validators. Writing plain HTML you would simply set a name like filename[] several times. Zend_Form_Element_File can handle this for you much simpler. Just create your element like before and call setMultiFile() with the number of files you want to have.
$element = new Zend_Form_Element_File("uploaded");
$element->setMultiFile(3);
The above example will create 3 seperated file elements named uploaded[].
I hope you find these two features handy.
New things will come soon.
Greetings
Thomas, I18N Team Leader, Zend Framework
Sunday, September 21, 2008
By thomasw at 15:57:09
Hy interested ones,
in the last days I worked on Zend_File_Transfer to get this new component more comfortable.
I integrated several new features which will allow simpler usage specially when you use the file element helper.
So what is new:
*) breakChainOnFailure
Like it’s cousine Zend_Form, now also Zend_File_Transfer allows the usage of the breakChainOnFailure parameter when adding validators. This feature will stop the validation for defined validators.
$adapter = new Zend_File_Transfer_Adapter_Http();
$adapter->addValidator('Size', true, '1MB')
->addValidator('Extension', false, 'jpg,png');
This example will stop validation as soon as a file extends 1MB regardless of it’s extension. So you will not get the error for false extension when the file is for example 1.5MB.
*) Translating error messages
You can now add a translator, which will translate all error messages for you. This feature works the same way like in Zend_Form. You can set a translation with setTranslator().
$adapter = new Zend_File_Transfer_Adapter_Http();
$adapter->addValidator('Size', true, '1MB')
->setTranslator($mytranslator);
When you now get an error when validation occurs, all returned error messages will be routed through the translator and when you have set a translation you will get your error instead of the adapters one.
So instead of “file not found” you could write “Hey man, give me my file”.
*) Knowing if a error has been occured
I added the hasErrors() method to the adapter which will return true when an error has occured during validation.
$adapter = new Zend_File_Transfer_Adapter_Http();
$adapter->addValidator('Size', true, '1MB');
if ($adapter->receive()) {
$errors = 'unknown error';
if ($adapter->hasErrors()) {
$errors = $adapter->getErrors();
}
}
The example does not really need the hasErrors() method as you may mention. But sometimes there is a need of this functionality, so I added it. Also the hasErrors() method of Zend_Form_Element_File routes to the adapters hasErrors() method.
*) Seperated validation from receiving of files
The originate implementation of Zend_Form_Element_File called receive() when the element was validated.
Of course this is not true and leaded to several problems, like the file being transfered even if other form validations failed.
This has been changed by me, but does also lead to a BC break, as you have to call receive() after validation.
But this does not mean that you have to call 2 methods.
$adapter = new Zend_File_Transfer_Adapter_Http();
$adapter->addValidator('Size', true, '1MB');
if (!$adapter->isValid()) {
print "Validation error";
}
if (!$adapter->receive()) {
print "Problem receiving the file";
}
When the adapter has been validated, then the receive() method will not call isValid() again.
But when you have not validated the adapter, it will automatically call isValid() before the file will be transfered to it’s destination.
So you could simply write
$adapter = new Zend_File_Transfer_Adapter_Http();
$adapter->addValidator('Size', true, '1MB');
if (!$adapter->receive()) {
print "Problem receiving the file, probably validation problem";
}
*) Checking of the destination exists
Previously you could set anything as destination path and would get an false as soon as you receive the file but you would not know why as the validation would have passed. So I added a check for existance of the destination path. You will now get an exception if the directory you set does not exist, or is not readable.
$adapter = new Zend_File_Transfer_Adapter_Http();
try {
$adapter->setDestination('/path/does/not/exist');
} catch (Zend_File_Transfer_Exception $e) {
print $e->getMessage();
}
More to come soon…
Greetings
Thomas
I18N Team Leader, Zend Framework
Sunday, September 7, 2008
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
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